feature: package: @putout/plugin-cloudcmd v2.0.0: CloudCmd.loadDir() -> CloudCmd.changeDir()'

This commit is contained in:
coderaiser 2023-01-16 16:52:28 +02:00
parent 026c292bae
commit e28215ddf3
8 changed files with 25 additions and 63 deletions

View file

@ -1,4 +1,7 @@
{
"plugins": [
"cloudcmd"
],
"ignore": [
"html",
"fixture*",

View file

@ -77,28 +77,8 @@ function CloudCmdProto(DOM) {
right: 'asc',
};
/**
* Функция привязываеться ко всем ссылкам и
* загружает содержимое каталогов
*
* @param params - {
* paramLink - ссылка
* needRefresh - необходимость обязательной загрузки данных с сервера
* panel
* }
* @param callback
*/
this.loadDir = async (params) => {
const p = params;
const refresh = p.isRefresh;
const {
panel,
history = true,
noCurrent,
currentName,
} = p;
this.changeDir = async (path, {isRefresh, panel, history = true, noCurrent, currentName} = {}) => {
const refresh = isRefresh;
let panelChanged;
if (!noCurrent && panel && panel !== Info.panel) {
@ -112,10 +92,9 @@ function CloudCmdProto(DOM) {
imgPosition = 'top';
Images.show.load(imgPosition, panel);
const path = addSlashToEnd(p.path);
/* загружаем содержимое каталога */
await ajaxLoad(path, {
await ajaxLoad(addSlashToEnd(path), {
refresh,
history,
noCurrent,
@ -302,8 +281,7 @@ function CloudCmdProto(DOM) {
const history = false;
const noCurrent = options ? options.noCurrent : false;
await CloudCmd.loadDir({
path,
await CloudCmd.changeDir(path, {
isRefresh,
history,
panel,
@ -455,9 +433,7 @@ function CloudCmdProto(DOM) {
const path = parentDirPath;
await CloudCmd.loadDir({
path,
});
await CloudCmd.changeDir(path);
const current = DOM.getCurrentByName(dir);
const [first] = DOM.getFiles(panel);

View file

@ -719,9 +719,7 @@ module.exports.goToDirectory = async () => {
if (cancel)
return;
await CloudCmd.loadDir({
path,
});
await CloudCmd.changeDir(path);
};
module.exports.duplicatePanel = async () => {
@ -739,8 +737,7 @@ module.exports.duplicatePanel = async () => {
const path = getPath(isDir);
await CloudCmd.loadDir({
path,
await CloudCmd.changeDir(path, {
panel,
noCurrent,
});
@ -760,14 +757,12 @@ module.exports.swapPanels = async () => {
let currentIndex = files.indexOf(element);
await CloudCmd.loadDir({
path,
await CloudCmd.changeDir(path, {
panel: panelPassive,
noCurrent: true,
});
await CloudCmd.loadDir({
path: dirPathPassive,
await CloudCmd.changeDir(dirPathPassive, {
panel,
});

View file

@ -11,10 +11,10 @@ global.CloudCmd = {};
test('cloudcmd: client: dom: goToDirectory', async (t) => {
const path = '';
const {CloudCmd} = global;
const loadDir = stub();
const changeDir = stub();
const prompt = stub().returns([null, path]);
CloudCmd.loadDir = loadDir;
CloudCmd.changeDir = changeDir;
mockRequire('./dialog', {
prompt,
@ -26,7 +26,7 @@ test('cloudcmd: client: dom: goToDirectory', async (t) => {
stopAll();
t.calledWith(loadDir, [{path}]);
t.calledWith(changeDir, [path]);
t.end();
});

View file

@ -133,7 +133,7 @@ async function switchKey(event) {
const {
Operation,
loadDir,
changeDir,
config,
} = CloudCmd;
const {keyCode} = event;
@ -200,9 +200,7 @@ async function switchKey(event) {
event.preventDefault();
if (Info.isDir)
await loadDir({
path,
});
await changeDir(path);
else if (shift)
CloudCmd.View.show(null, {
raw: true,
@ -402,7 +400,7 @@ async function switchKey(event) {
case KEY.ENTER:
if (Info.isDir)
await loadDir({path});
await changeDir(path);
else
CloudCmd.View.show();
@ -415,9 +413,7 @@ async function switchKey(event) {
case KEY.BACKSLASH:
if (ctrlMeta)
await loadDir({
path: '/',
});
await changeDir('/');
break;

View file

@ -212,8 +212,7 @@ async function onPathElementClick(panel, event) {
const {href} = element;
const path = decodePath(href);
await CloudCmd.loadDir({
path,
await CloudCmd.changeDir(path, {
isRefresh: false,
panel: noCurrent ? panel : Info.panel,
});
@ -272,9 +271,7 @@ async function onDblClick(event) {
if (!isDir)
return CloudCmd.View.show();
await CloudCmd.loadDir({
path,
});
await CloudCmd.changeDir(path);
}
async function onTouch(event) {
@ -289,9 +286,7 @@ async function onTouch(event) {
if (!isCurrent)
return;
await CloudCmd.loadDir({
path: DOM.getCurrentPath(current),
});
await CloudCmd.changeDir(DOM.getCurrentPath(current));
}
/*
@ -472,8 +467,7 @@ function pop() {
return CloudCmd.route(location.hash);
const history = false;
await CloudCmd.loadDir({
path,
await CloudCmd.changeDir(path, {
history,
});
});

View file

@ -71,9 +71,7 @@ async function onPath(path) {
if (Info.dirPath === path)
return;
await CloudCmd.loadDir({
path,
});
await CloudCmd.changeDir(path);
}
const getDirPath = () => {

View file

@ -87,7 +87,7 @@
"@cloudcmd/move-files": "^6.0.0",
"@cloudcmd/read-files-sync": "^2.0.0",
"@putout/cli-validate-args": "^1.0.1",
"@putout/plugin-cloudcmd": "^1.2.0",
"@putout/plugin-cloudcmd": "^2.0.0",
"apart": "^2.0.0",
"chalk": "^4.0.0",
"compression": "^1.7.4",