Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor js data table #1883

Merged
merged 48 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
19e7ca0
Bare Minimum Data Table Functionality - removed Buttons for new File,…
gerald-byrket Feb 24, 2022
4e4f714
Updated code to reflect global instead of window and only where neces…
gerald-byrket Feb 28, 2022
d473187
Feature/refactor copy path (#1876)
gbyrket Mar 2, 2022
0ce9b50
Feature/refactor js upload (#1873)
gbyrket Mar 2, 2022
1ae3727
Feature/refactor copy move (#1879)
gbyrket Mar 2, 2022
a9b10f6
Completed Delete Functionality (#1881)
gbyrket Mar 2, 2022
6da6486
completed rename (#1882)
gbyrket Mar 2, 2022
8589f1d
Implemented refactored show Owner/Perms/Dotfiles (#1884)
gbyrket Mar 3, 2022
5af731d
Fixed ToolTip issue (#1886)
gbyrket Mar 3, 2022
916e088
Extracted Basic Datatable and removed all dependencies from datatable.js
gbyrket Mar 15, 2022
238ce5f
Completed Create File Functionality
gbyrket Mar 17, 2022
fa04216
Completed New File with Pub/Sub
gbyrket Mar 21, 2022
96a8544
Completed Create Folder
gbyrket Mar 21, 2022
9256cd1
Completed upload functionality
gbyrket Mar 21, 2022
cfc914f
Completed upload functionality
gbyrket Mar 21, 2022
424b117
Completed File/Folder Download
gerald-byrket Mar 22, 2022
976e64f
Completed Delete Functionality
gerald-byrket Mar 23, 2022
702194f
WIP Copy/Move
gerald-byrket Mar 23, 2022
5092c6b
WIP
gbyrket Mar 25, 2022
40cac1d
Completed Copy/Move functionality
gbyrket Mar 29, 2022
88176e7
Completed File Transfer Status
gbyrket Mar 29, 2022
c8712ac
Got handlebars working properly for inline dropdown menu in datatable
gbyrket Mar 30, 2022
b9c508d
Completed Datatable file operations
gbyrket Mar 30, 2022
530bf2b
Completed JS Refactor. Ready for Code Review
gbyrket Mar 30, 2022
3917327
Move what was in document.ready to outside
gbyrket Mar 31, 2022
08deeb9
Undo last commit
gbyrket Mar 31, 2022
59be7f5
Modified document.ready to jQuery(function() {
gbyrket Apr 1, 2022
07eedb8
Implemented Constants
gbyrket Apr 4, 2022
365eb10
Moved 'Data Validation' to receiver.
gbyrket Apr 5, 2022
b5de72e
Fixed formatting
gbyrket Apr 6, 2022
20ac0a7
Rename js files
gbyrket Apr 7, 2022
60211f1
Rename js files
gbyrket Apr 7, 2022
02d5274
Refactored EventName to be defined in appropriate JS Class
gbyrket Apr 8, 2022
fc3e6c6
Fixed page reload issue
gerald-byrket Apr 11, 2022
b8273ec
added newline at eof
gbyrket Apr 11, 2022
e772ede
added newline at eof
gbyrket Apr 11, 2022
31e2c3f
Modified render syntax to remove '.html.erb'
gbyrket Apr 12, 2022
5bdee6d
Moved to button clicks to the appropriate java file
gbyrket Apr 18, 2022
0052392
Merge branch 'master' into feature/refactorJsDataTable
gbyrket Apr 18, 2022
e07c369
Renamed new-dir-btn to new-folder-btn
gbyrket Apr 18, 2022
3b52501
Changed folder to dir
gbyrket Apr 19, 2022
60fdcbe
updated test to reflect updated id
gbyrket Apr 19, 2022
16c6075
Removed clipboard dependency from datatable
gbyrket Apr 19, 2022
06089c5
removed local references in template
gbyrket Apr 19, 2022
7a6c13f
Fixed 'change directory' bug in listener
gbyrket Apr 19, 2022
bbea4a0
Cleaned up code causing JS Errors
gbyrket Apr 19, 2022
3aca115
Added call to update clipboard view on clipboard instantiation
gerald-byrket Apr 20, 2022
7ed0141
Fixed testing
gerald-byrket Apr 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ tags
# Ignore copies of .rubocop.yml
.rubocop.yml
!/.rubocop.yml

# Ignore .vscode
.vscode
184 changes: 184 additions & 0 deletions apps/dashboard/app/javascript/packs/files/clip_board.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import ClipboardJS from 'clipboard'
import Handlebars from 'handlebars';
import {CONTENTID} from './data_table.js';
import {EVENTNAME as SWAL_EVENTNAME} from './sweet_alert.js';
import {EVENTNAME as FILEOPS_EVENTNAME} from './file_ops.js';
gbyrket marked this conversation as resolved.
Show resolved Hide resolved

export {EVENTNAME};

const EVENTNAME = {
clearClipboard: 'clearClipboard',
updateClipboard: 'updateClipboard',
updateClipboardView: 'updateClipboardView',
}

jQuery(function () {

var clipBoard = new ClipBoard();

$("#copy-move-btn").on("click", function () {
let table = $(CONTENTID).DataTable();
let selection = table.rows({ selected: true }).data();

const eventData = {
selection: selection
};

$(CONTENTID).trigger(EVENTNAME.updateClipboard, eventData);

});


$(CONTENTID).on('success', function (e) {
$(e.trigger).tooltip({ title: 'Copied path to clipboard!', trigger: 'manual', placement: 'bottom' }).tooltip('show');
setTimeout(() => $(e.trigger).tooltip('hide'), 2000);
e.clearSelection();
});

$(CONTENTID).on('error', function (e) {
e.clearSelection();
});

$(CONTENTID).on(EVENTNAME.clearClipboard, function (e, options) {
clipBoard.clearClipboard();
clipBoard.updateViewForClipboard();
});

$(CONTENTID).on(EVENTNAME.updateClipboard, function (e, options) {
if (options.selection.length == 0) {
const eventData = {
'title': 'Select a file, files, or directory to copy or move.',
'message': 'You have selected none.',
};

$(CONTENTID).trigger(SWAL_EVENTNAME.showError, eventData);
$(CONTENTID).trigger(EVENTNAME.clearClipbaord, eventData);

} else {
clipBoard.updateClipboardFromSelection(options.selection);
clipBoard.updateViewForClipboard();
}
});

$(CONTENTID).on(EVENTNAME.updateClipboardView, function (e, options) {
clipBoard.updateViewForClipboard();
});


});

class ClipBoard {
_clipBoard = null;

constructor() {
this._clipBoard = new ClipboardJS('#copy-path');
}

getClipBoard() {
return this._clipBoard;
}

clearClipboard() {
localStorage.removeItem('filesClipboard');
}

updateClipboardFromSelection(selection) {

if (selection.length == 0) {
this.clearClipboard();
} else {
let clipboardData = {
from: history.state.currentDirectory,
files: selection.toArray().map((f) => {
return { directory: f.type == 'd', name: f.name };
})
};

localStorage.setItem('filesClipboard', JSON.stringify(clipboardData));
}
}


updateViewForClipboard() {
let clipboard = JSON.parse(localStorage.getItem('filesClipboard') || '{}'),
template_str = $('#clipboard-template').html(),
template = Handlebars.compile(template_str);

$('#clipboard').html(template(clipboard));

$('#clipboard-clear').on("click", () => {
this.clearClipboard();
this.updateViewForClipboard();
});

$('#clipboard-move-to-dir').on("click", () => {
let clipboard = JSON.parse(localStorage.getItem('filesClipboard') || 'null');
if (clipboard) {
clipboard.to = history.state.currentDirectory;

if (clipboard.from == clipboard.to) {
console.error('clipboard from and to are identical')
// TODO:
}
else {
let files = {};
clipboard.files.forEach((f) => {
files[`${clipboard.from}/${f.name}`] = `${history.state.currentDirectory}/${f.name}`
});

const eventData = {
'files': files,
'token': csrf_token
};

$(CONTENTID).trigger(FILEOPS_EVENTNAME.moveFile, eventData);
}
}
else {
console.error('files clipboard is empty');
}
});


$('#clipboard-copy-to-dir').on("click", () => {
let clipboard = JSON.parse(localStorage.getItem('filesClipboard') || 'null');

if (clipboard) {
clipboard.to = history.state.currentDirectory;

if (clipboard.from == clipboard.to) {
console.error('clipboard from and to are identical')

// TODO: we want to support this use case
// copy and paste as a new filename
// but lots of edge cases
// (overwrite or rename duplicates)
// _copy
// _copy_2
// _copy_3
// _copy_4
}
else {
// [{"/from/file/path":"/to/file/path" }]
let files = {};
clipboard.files.forEach((f) => {
files[`${clipboard.from}/${f.name}`] = `${history.state.currentDirectory}/${f.name}`
});

const eventData = {
'files': files,
'token': csrf_token
};

$(CONTENTID).trigger(FILEOPS_EVENTNAME.copyFile, eventData);
}
}
else {
console.error('files clipboard is empty');
}
});

}


}
114 changes: 0 additions & 114 deletions apps/dashboard/app/javascript/packs/files/clipboard.js

This file was deleted.

Loading