diff --git a/apps/dashboard/app/javascript/packs/files/clipboard.js b/apps/dashboard/app/javascript/packs/files/clipboard.js index dc137c8bbc..642123625e 100755 --- a/apps/dashboard/app/javascript/packs/files/clipboard.js +++ b/apps/dashboard/app/javascript/packs/files/clipboard.js @@ -11,16 +11,19 @@ $(document).ready(function(){ clipboardjs = new ClipboardJS('#copy-path'); + /* + NOTE: Had to move the following functionality to the template (_inline_js.html.erb) so the tooltip would be recognized. + clipboardjs.on('success', function(e) { - //FIXME: for some reason the jQuery function tooltip is not being recognized. Will need to figure out why or move on to new tooltip plugin. - - // $(e.trigger).tooltip({title: 'Copied path to clipboard!', trigger: 'manual', placement: 'bottom'}).tooltip('show'); - // setTimeout(() => $(e.trigger).tooltip('hide'), 2000); + //FIXME: for some reason the jQuery function tooltip is not being recognized. Will need to figure out why or move on to new tooltip plugin. - gerald + $(e.trigger).popover({title: 'Copied path to clipboard!', trigger: 'manual', placement: 'bottom'}).tooltip('show'); + setTimeout(() => $(e.trigger).tooltip('hide'), 2000); e.clearSelection(); }); clipboardjs.on('error', function(e) { e.clearSelection(); }); + */ //FIXME: so need to handle updateViewForClipboard based on EVENTS emitted by local storage modifications updateViewForClipboard(); diff --git a/apps/dashboard/app/javascript/packs/files/datatable.js b/apps/dashboard/app/javascript/packs/files/datatable.js index 4d5fdb2c7b..aedc812940 100755 --- a/apps/dashboard/app/javascript/packs/files/datatable.js +++ b/apps/dashboard/app/javascript/packs/files/datatable.js @@ -9,16 +9,15 @@ import {} from './uppy.js'; import {} from './clipboard.js'; let table = null; - +let onpopstate = null; +let actionsBtnTemplate = null; +let reportTransferTemplate = null; export { actionsBtnTemplate, reportTransferTemplate, table, dataFromJsonResponse, getEmptyDirs, getFilesAndDirectoriesFromDirectory, - getShowDotFiles, getShowOwnerMode, Handlebars, reloadTable, update_datatables_status + getShowDotFiles, getShowOwnerMode, Handlebars, onpopstate, reloadTable, update_datatables_status }; -let actionsBtnTemplate = null; -let reportTransferTemplate = null; - global.reloadTable = reloadTable; // Required to be marked as global since we are using this in the template. $(document).ready(function() { @@ -261,6 +260,12 @@ $(document).ready(function() { updateShowOwnerModeVisibility(); }); + onpopstate = function(event){ + // FIXME: handle edge case if state ! exist + setTimeout(() => { + goto(event.state.currentDirectoryUrl, false); + }, 0); + }; }); diff --git a/apps/dashboard/app/javascript/packs/files/index.js b/apps/dashboard/app/javascript/packs/files/index.js deleted file mode 100644 index b4b87eb321..0000000000 --- a/apps/dashboard/app/javascript/packs/files/index.js +++ /dev/null @@ -1,106 +0,0 @@ -import ClipboardJS from 'clipboard' -import Swal from 'sweetalert2' -import { Uppy, BasePlugin } from '@uppy/core' -import Dashboard from '@uppy/dashboard' -import XHRUpload from '@uppy/xhr-upload' -import Handlebars from 'handlebars'; -import _ from 'lodash'; -import 'datatables.net'; -import 'datatables.net-bs4/js/dataTables.bootstrap4'; -import 'datatables.net-select'; -import 'datatables.net-select-bs4'; - -window.ClipboardJS = ClipboardJS -window.Uppy = Uppy -window.BasePlugin = BasePlugin -window.Dashboard = Dashboard -window.XHRUpload = XHRUpload -window.Swal = Swal.mixin({ - showClass: { - popup: 'swal2-noanimation', - backdrop: 'swal2-noanimation' - }, - hideClass: { - popup: '', - backdrop: '' - } -}); -window.alertError = alertError; -window.dataFromJsonResponse = dataFromJsonResponse; -window.newFile = newFile; -window.newDirectory = newDirectory; -window.reloadTable = reloadTable; -window.goto = goto; -window.loading = loading; -window.doneLoading = doneLoading; -window.$ = $; -window.jQuery = jQuery; -window._ = _; -window.Handlebars = Handlebars; - -function alertError(error_title, error_message){ - Swal.fire(error_title, error_message, 'error'); -} - -function dataFromJsonResponse(response){ - return new Promise((resolve, reject) => { - Promise.resolve(response) - .then(response => response.ok ? Promise.resolve(response) : Promise.reject(new Error(response.statusText))) - .then(response => response.json()) - .then(data => data.error_message ? Promise.reject(new Error(data.error_message)) : resolve(data)) - .catch((e) => reject(e)) - }); -} - -function newFile(filename){ - fetch(`${history.state.currentDirectoryUrl}/${encodeURI(filename)}?touch=true`, {method: 'put', headers: { 'X-CSRF-Token': csrf_token }}) - .then(response => dataFromJsonResponse(response)) - .then(() => reloadTable()) - .catch(e => alertError('Error occurred when attempting to create new file', e.message)); -} - -function newDirectory(filename){ - fetch(`${history.state.currentDirectoryUrl}/${encodeURI(filename)}?dir=true`, {method: 'put', headers: { 'X-CSRF-Token': csrf_token }}) - .then(response => dataFromJsonResponse(response)) - .then(() => reloadTable()) - .catch(e => alertError('Error occurred when attempting to create new directory', e.message)); -} - -function reloadTable(url){ - var request_url = url || history.state.currentDirectoryUrl; - - return fetch(request_url, {headers: {'Accept':'application/json'}}) - .then(response => dataFromJsonResponse(response)) - .then(function(data) { - $('#shell-wrapper').replaceWith((data.shell_dropdown_html)) - - table.clear(); - table.rows.add(data.files); - table.draw(); - - $('#open-in-terminal-btn').attr('href', data.shell_url); - $('#open-in-terminal-btn').removeClass('disabled'); - - return Promise.resolve(data); - }) - .catch((e) => { - Swal.fire(e.message, `Error occurred when attempting to access ${request_url}`, 'error'); - - $('#open-in-terminal-btn').addClass('disabled'); - return Promise.reject(e); - }); -} - - -function loading(title){ - Swal.fire({ - title: title, - allowOutsideClick: false, - showConfirmButton: false, - willOpen: () => { Swal.showLoading() } - }); -} - -function doneLoading(){ - Swal.close(); -} diff --git a/apps/dashboard/app/javascript/packs/files/uppy.js b/apps/dashboard/app/javascript/packs/files/uppy.js index f664d67ce3..285f96d81b 100755 --- a/apps/dashboard/app/javascript/packs/files/uppy.js +++ b/apps/dashboard/app/javascript/packs/files/uppy.js @@ -109,11 +109,12 @@ $(document).ready(function(){ }); // https://stackoverflow.com/questions/6756583/prevent-browser-from-loading-a-drag-and-dropped-file - window.addEventListener("dragover",function(e){ + global.addEventListener("dragover",function(e){ e = e || event; e.preventDefault(); },false); - window.addEventListener("drop",function(e){ + + global.addEventListener("drop",function(e){ e = e || event; e.preventDefault(); },false); diff --git a/apps/dashboard/app/views/files/_inline_js.html.erb b/apps/dashboard/app/views/files/_inline_js.html.erb index 444b5f34e8..a247f49547 100755 --- a/apps/dashboard/app/views/files/_inline_js.html.erb +++ b/apps/dashboard/app/views/files/_inline_js.html.erb @@ -17,4 +17,18 @@ history.replaceState({ reloadTable(); <% end %> +$(document).ready(function(){ + clipboardjs = new ClipboardJS('#copy-path'); + clipboardjs.on('success', function(e) { + //FIXME: Have to put this in the template so it will recognize tooltip. + + $(e.trigger).tooltip({title: 'Copied path to clipboard!', trigger: 'manual', placement: 'bottom'}).tooltip('show'); + setTimeout(() => $(e.trigger).tooltip('hide'), 2000); + e.clearSelection(); + }); + clipboardjs.on('error', function(e) { + e.clearSelection(); + }); +}); +