mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(user-menu) add Compare Directories (#220)
This commit is contained in:
parent
303213c48b
commit
3273c1abe5
2 changed files with 74 additions and 0 deletions
|
|
@ -20,6 +20,37 @@ module.exports = {
|
|||
CloudCmd,
|
||||
});
|
||||
},
|
||||
'D - Compare directories': async ({DOM}) => {
|
||||
const {
|
||||
CurrentInfo,
|
||||
getFilenames,
|
||||
getCurrentByName,
|
||||
selectFile,
|
||||
} = DOM;
|
||||
|
||||
const {
|
||||
files,
|
||||
filesPassive,
|
||||
panel,
|
||||
panelPassive,
|
||||
} = CurrentInfo;
|
||||
|
||||
const names = getFilenames(files);
|
||||
const namesPassive = getFilenames(filesPassive);
|
||||
|
||||
const selectedNames = compare(names, namesPassive);
|
||||
const selectedNamesPassive = compare(namesPassive, names);
|
||||
|
||||
selectNames(selectedNames, panel, {
|
||||
selectFile,
|
||||
getCurrentByName,
|
||||
});
|
||||
|
||||
selectNames(selectedNamesPassive, panelPassive, {
|
||||
selectFile,
|
||||
getCurrentByName,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
async function createDefaultMenu({path, data, DOM, CloudCmd}) {
|
||||
|
|
@ -40,3 +71,23 @@ async function readDefaultMenu({prefix}) {
|
|||
return data;
|
||||
}
|
||||
|
||||
function selectNames(names, panel, {selectFile, getCurrentByName}) {
|
||||
for (const name of names) {
|
||||
const file = getCurrentByName(name, panel);
|
||||
selectFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
function compare(a, b) {
|
||||
const result = [];
|
||||
|
||||
for (const el of a) {
|
||||
if (b.includes(el))
|
||||
continue;
|
||||
|
||||
result.push(el);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ const wraptile = require('wraptile');
|
|||
|
||||
const defaultMenu = require('./user-menu');
|
||||
|
||||
const {create} = autoGlobals;
|
||||
|
||||
const {_data} = defaultMenu;
|
||||
const reject = wraptile(async (a) => {
|
||||
throw Error(a);
|
||||
|
|
@ -107,6 +109,21 @@ test('cloudcmd: static: user menu: no EditFile.show', async (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: static: user menu: compare directories', async (t) => {
|
||||
const name = 'D - Compare directories';
|
||||
const DOM = getDOM();
|
||||
const CloudCmd = getCloudCmd();
|
||||
|
||||
await defaultMenu[name]({
|
||||
DOM,
|
||||
CloudCmd,
|
||||
});
|
||||
|
||||
const {files} = DOM.CurrentInfo.files;
|
||||
t.ok(DOM.getFilenames.calledWith(files), 'should call getFilenames');
|
||||
t.end();
|
||||
});
|
||||
|
||||
function getDOM() {
|
||||
const IO = {
|
||||
write: stub(),
|
||||
|
|
@ -114,12 +131,18 @@ function getDOM() {
|
|||
|
||||
const CurrentInfo = {
|
||||
dirPath: '/',
|
||||
files: [],
|
||||
filesPasive: [],
|
||||
panel: create(),
|
||||
panelPassive: create(),
|
||||
};
|
||||
|
||||
return {
|
||||
IO,
|
||||
CurrentInfo,
|
||||
setCurrentByName: stub(),
|
||||
getFilenames: stub().returns([]),
|
||||
getCurrentByName: stub(),
|
||||
renameCurrent: stub(),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue