mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
fix(cloudcmd) directoryStorage
This commit is contained in:
parent
12e813c432
commit
2d08fb98b7
4 changed files with 96 additions and 15 deletions
|
|
@ -472,6 +472,7 @@ function CloudCmdProto(DOM) {
|
|||
const owner = DOM.getCurrentOwner(current);
|
||||
const mode = DOM.getCurrentMode(current);
|
||||
const date = DOM.getCurrentDate(current);
|
||||
const type = DOM.getCurrentType(current);
|
||||
|
||||
return {
|
||||
name,
|
||||
|
|
@ -479,6 +480,7 @@ function CloudCmdProto(DOM) {
|
|||
mode,
|
||||
owner,
|
||||
date,
|
||||
type,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -280,3 +280,23 @@ module.exports.setTitle = (name) => {
|
|||
return DOM;
|
||||
};
|
||||
|
||||
/**
|
||||
* check is current file is a directory
|
||||
*
|
||||
* @param currentFile
|
||||
*/
|
||||
module.exports.isCurrentIsDir = (currentFile) => {
|
||||
const current = currentFile || DOM.getCurrentFile();
|
||||
const fileType = DOM.getCurrentType(current);
|
||||
|
||||
return DOM.isContainClass(fileType, [
|
||||
'directory',
|
||||
'directory-link',
|
||||
]);
|
||||
};
|
||||
|
||||
module.exports.getCurrentType = (currentFile) => {
|
||||
const current = currentFile || DOM.getCurrentFile();
|
||||
return DOM.getByDataName('js-type', current);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -168,6 +168,78 @@ test('current-file: isCurrentFile', (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('current-file: getCurrentType', (t) => {
|
||||
const {
|
||||
DOM,
|
||||
CloudCmd,
|
||||
} = global;
|
||||
|
||||
global.DOM = getDOM();
|
||||
global.CloudCmd = getCloudCmd();
|
||||
|
||||
const {getByDataName} = global.DOM;
|
||||
|
||||
const current = create();
|
||||
|
||||
currentFile.getCurrentType(current);
|
||||
|
||||
global.DOM = DOM;
|
||||
global.CloudCmd = CloudCmd;
|
||||
|
||||
t.ok(getByDataName.calledWith('js-type', current));
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('current-file: isCurrentIsDir: getCurrentType', (t) => {
|
||||
const {
|
||||
DOM,
|
||||
CloudCmd,
|
||||
} = global;
|
||||
|
||||
global.DOM = getDOM();
|
||||
global.CloudCmd = getCloudCmd();
|
||||
|
||||
const {getCurrentType} = global.DOM;
|
||||
|
||||
const current = create();
|
||||
|
||||
currentFile.isCurrentIsDir(current);
|
||||
|
||||
global.DOM = DOM;
|
||||
global.CloudCmd = CloudCmd;
|
||||
|
||||
t.ok(getCurrentType.calledWith(current));
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('current-file: isCurrentIsDir: isContainClass', (t) => {
|
||||
const {
|
||||
DOM,
|
||||
CloudCmd,
|
||||
} = global;
|
||||
|
||||
global.DOM = getDOM({
|
||||
getCurrentType: stub().returns('file'),
|
||||
});
|
||||
|
||||
global.CloudCmd = getCloudCmd();
|
||||
|
||||
const {isContainClass} = global.DOM;
|
||||
|
||||
const current = create();
|
||||
|
||||
currentFile.isCurrentIsDir(current);
|
||||
|
||||
global.DOM = DOM;
|
||||
global.CloudCmd = CloudCmd;
|
||||
|
||||
t.ok(isContainClass.calledWith('file', [
|
||||
'directory',
|
||||
'directory-link',
|
||||
]));
|
||||
t.end();
|
||||
});
|
||||
|
||||
function getCloudCmd({emit} = {}) {
|
||||
return {
|
||||
prefix: '',
|
||||
|
|
@ -181,12 +253,14 @@ function getDOM({
|
|||
getCurrentDirName = stub(),
|
||||
getByDataName = stub(),
|
||||
isContainClass = stub(),
|
||||
getCurrentType = stub(),
|
||||
} = {}) {
|
||||
return {
|
||||
getCurrentDirPath,
|
||||
getCurrentDirName,
|
||||
getByDataName,
|
||||
isContainClass,
|
||||
getCurrentType,
|
||||
CurrentInfo: {
|
||||
link,
|
||||
dirPath: '/',
|
||||
|
|
|
|||
|
|
@ -462,21 +462,6 @@ function CmdProto() {
|
|||
return DOM.isContainClass(selected, SELECTED_FILE);
|
||||
};
|
||||
|
||||
/**
|
||||
* check is current file is a directory
|
||||
*
|
||||
* @param currentFile
|
||||
*/
|
||||
this.isCurrentIsDir = (currentFile) => {
|
||||
const current = currentFile || DOM.getCurrentFile();
|
||||
const fileType = DOM.getByDataName('js-type', current);
|
||||
|
||||
return DOM.isContainClass(fileType, [
|
||||
'directory',
|
||||
'directory-link',
|
||||
]);
|
||||
};
|
||||
|
||||
/**
|
||||
* get link from current (or param) file
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue