Skip to content

Commit

Permalink
add test for DOS encoded files (#3228)
Browse files Browse the repository at this point in the history
Add test for DOS encoded files and convert these files from DOS to Unix format.
  • Loading branch information
johrstrom authored Dec 7, 2023
1 parent 717c32d commit 8246f3d
Show file tree
Hide file tree
Showing 9 changed files with 557 additions and 554 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ jobs:
- name: Run ShellCheck
run: bundle exec rake test:shellcheck

- name: Check file encodings
run: bundle exec rake test:unix

- name: Run Zeitwerk check
run: |
cd apps/dashboard
Expand Down
362 changes: 181 additions & 181 deletions apps/dashboard/app/javascript/files/clip_board.js
Original file line number Diff line number Diff line change
@@ -1,181 +1,181 @@
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';
import { csrfToken } from '../config.js';

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');
this.updateViewForClipboard();
}

getClipBoard() {
return this._clipBoard;
}

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

updateClipboardFromSelection(selection) {

if (selection.length == 0) {
this.clearClipboard();
} else {
let clipboardData = {
from: history.state.currentDirectory,
from_fs: history.state.currentFilesystem,
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;
clipboard.to_fs = history.state.currentFilesystem;

if (clipboard.from == clipboard.to) {
// No files are changed, so we just have to clear and update the clipboard
this.clearClipboard();
this.updateViewForClipboard();
}
else {
let files = {};
clipboard.files.forEach((f) => {
files[`${clipboard.from}/${f.name}`] = `${history.state.currentDirectory}/${f.name}`
});

const eventData = {
'files': files,
'token': csrfToken(),
'from_fs': clipboard.from_fs,
'to_fs': clipboard.to_fs,
};

$(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;
clipboard.to_fs = history.state.currentFilesystem;

// files is a hashmap with keys of file current path and value as the corresponding files desired path
let files = {};

clipboard.files.forEach((f) => {
files[`${clipboard.from}/${f.name}`] = `${clipboard.to}/${f.name}`;
});

const eventData = {
'files': files,
'token': csrfToken(),
'from_fs': clipboard.from_fs,
'to_fs': clipboard.to_fs,
};

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

}


}
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';
import { csrfToken } from '../config.js';

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');
this.updateViewForClipboard();
}

getClipBoard() {
return this._clipBoard;
}

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

updateClipboardFromSelection(selection) {

if (selection.length == 0) {
this.clearClipboard();
} else {
let clipboardData = {
from: history.state.currentDirectory,
from_fs: history.state.currentFilesystem,
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;
clipboard.to_fs = history.state.currentFilesystem;

if (clipboard.from == clipboard.to) {
// No files are changed, so we just have to clear and update the clipboard
this.clearClipboard();
this.updateViewForClipboard();
}
else {
let files = {};
clipboard.files.forEach((f) => {
files[`${clipboard.from}/${f.name}`] = `${history.state.currentDirectory}/${f.name}`
});

const eventData = {
'files': files,
'token': csrfToken(),
'from_fs': clipboard.from_fs,
'to_fs': clipboard.to_fs,
};

$(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;
clipboard.to_fs = history.state.currentFilesystem;

// files is a hashmap with keys of file current path and value as the corresponding files desired path
let files = {};

clipboard.files.forEach((f) => {
files[`${clipboard.from}/${f.name}`] = `${clipboard.to}/${f.name}`;
});

const eventData = {
'files': files,
'token': csrfToken(),
'from_fs': clipboard.from_fs,
'to_fs': clipboard.to_fs,
};

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

}


}
Loading

0 comments on commit 8246f3d

Please sign in to comment.