mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(client) refresh: panel, options, callback -> options, callback: add currentName
This commit is contained in:
parent
b13f1f4de7
commit
110e421dd6
8 changed files with 133 additions and 124 deletions
123
client/client.js
123
client/client.js
|
|
@ -77,15 +77,16 @@ function CloudCmdProto(Util, DOM) {
|
|||
* }
|
||||
* @param callback
|
||||
*/
|
||||
this.loadDir = function(params, callback) {
|
||||
this.loadDir = (params, callback) => {
|
||||
var imgPosition;
|
||||
var panelChanged;
|
||||
var p = params;
|
||||
|
||||
var isRefresh = p.isRefresh;
|
||||
var panel = p.panel;
|
||||
var history = p.history;
|
||||
var noCurrent = p.noCurrent;
|
||||
const refresh = p.isRefresh;
|
||||
const panel = p.panel;
|
||||
const history = p.history;
|
||||
const noCurrent = p.noCurrent;
|
||||
const currentName = p.currentName;
|
||||
|
||||
if (!noCurrent)
|
||||
if (panel && panel !== Info.panel) {
|
||||
|
|
@ -93,16 +94,17 @@ function CloudCmdProto(Util, DOM) {
|
|||
panelChanged = true;
|
||||
}
|
||||
|
||||
if (panelChanged || isRefresh || !history)
|
||||
if (panelChanged || refresh || !history)
|
||||
imgPosition = 'top';
|
||||
|
||||
Images.show.load(imgPosition, panel);
|
||||
|
||||
/* загружаем содержимое каталога */
|
||||
ajaxLoad(p.path, {
|
||||
refresh: isRefresh,
|
||||
history: history,
|
||||
noCurrent: noCurrent
|
||||
refresh,
|
||||
history,
|
||||
noCurrent,
|
||||
currentName,
|
||||
}, panel, callback);
|
||||
};
|
||||
|
||||
|
|
@ -349,26 +351,27 @@ function CloudCmdProto(Util, DOM) {
|
|||
}, obj);
|
||||
};
|
||||
|
||||
this.refresh = function(panelParam, options, callback) {
|
||||
var panel = panelParam || Info.panel;
|
||||
var NEEDREFRESH = true;
|
||||
var path = DOM.getCurrentDirPath(panel);
|
||||
var noCurrent;
|
||||
|
||||
if (options)
|
||||
noCurrent = options.noCurrent;
|
||||
|
||||
this.refresh = (options = {}, callback) => {
|
||||
if (!callback && typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
const panel = options.panel || Info.panel;
|
||||
const path = DOM.getCurrentDirPath(panel);
|
||||
|
||||
const isRefresh = true;
|
||||
const history = false;
|
||||
const noCurrent = options ? options.noCurrent : false;
|
||||
const currentName = options.currentName;
|
||||
|
||||
CloudCmd.loadDir({
|
||||
path : path,
|
||||
isRefresh : NEEDREFRESH,
|
||||
history : false,
|
||||
panel : panel,
|
||||
noCurrent : noCurrent
|
||||
path,
|
||||
isRefresh,
|
||||
history,
|
||||
panel,
|
||||
noCurrent,
|
||||
currentName,
|
||||
}, callback);
|
||||
};
|
||||
|
||||
|
|
@ -383,26 +386,26 @@ function CloudCmdProto(Util, DOM) {
|
|||
*
|
||||
*/
|
||||
function ajaxLoad(path, options, panel, callback) {
|
||||
var create = function(error, json) {
|
||||
var RESTful = DOM.RESTful,
|
||||
name = Info.name,
|
||||
obj = Util.json.parse(json),
|
||||
isRefresh = options.refresh,
|
||||
noCurrent = options.noCurrent;
|
||||
const create = (error, json) => {
|
||||
const RESTful = DOM.RESTful;
|
||||
const name = options.currentName || Info.name;
|
||||
const obj = Util.json.parse(json);
|
||||
const isRefresh = options.refresh;
|
||||
const noCurrent = options.noCurrent;
|
||||
|
||||
if (!isRefresh && json)
|
||||
return createFileTable(obj, panel, options, callback);
|
||||
|
||||
var position = DOM.getPanelPosition(panel);
|
||||
var sort = CloudCmd.sort[position];
|
||||
var order = CloudCmd.order[position];
|
||||
const position = DOM.getPanelPosition(panel);
|
||||
const sort = CloudCmd.sort[position];
|
||||
const order = CloudCmd.order[position];
|
||||
|
||||
var query = rendy('?sort={{ sort }}&order={{ order }}', {
|
||||
sort: sort,
|
||||
order: order,
|
||||
const query = rendy('?sort={{ sort }}&order={{ order }}', {
|
||||
sort,
|
||||
order,
|
||||
});
|
||||
|
||||
RESTful.read(path + query, 'json', function(error, obj) {
|
||||
RESTful.read(path + query, 'json', (error, obj) => {
|
||||
if (error)
|
||||
return;
|
||||
|
||||
|
|
@ -411,10 +414,9 @@ function CloudCmdProto(Util, DOM) {
|
|||
options.sort = sort;
|
||||
options.order = order;
|
||||
|
||||
createFileTable(obj, panel, options, function() {
|
||||
if (isRefresh && !noCurrent) {
|
||||
createFileTable(obj, panel, options, () => {
|
||||
if (isRefresh && !noCurrent)
|
||||
DOM.setCurrentByName(name);
|
||||
}
|
||||
|
||||
exec(callback);
|
||||
});
|
||||
|
|
@ -530,30 +532,27 @@ function CloudCmdProto(Util, DOM) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
this.goToParentDir = function() {
|
||||
var path = Info.dirPath,
|
||||
dir = Info.dir,
|
||||
parentPath = Info.parentDirPath;
|
||||
this.goToParentDir = () => {
|
||||
let path = Info.dirPath;
|
||||
const dir = Info.dir;
|
||||
const parentPath = Info.parentDirPath;
|
||||
|
||||
if (path !== parentPath) {
|
||||
path = parentPath;
|
||||
if (path === Info.parentDirPath)
|
||||
return;
|
||||
|
||||
path = parentPath;
|
||||
|
||||
CloudCmd.loadDir({path}, () => {
|
||||
const panel = Info.panel;
|
||||
let current = DOM.getCurrentByName(dir);
|
||||
|
||||
CloudCmd.loadDir({
|
||||
path: path,
|
||||
}, function() {
|
||||
var current,
|
||||
panel = Info.panel;
|
||||
|
||||
current = DOM.getCurrentByName(dir);
|
||||
|
||||
if (!current)
|
||||
current = DOM.getFiles(panel)[0];
|
||||
|
||||
DOM.setCurrentFile(current, {
|
||||
history: history
|
||||
});
|
||||
if (!current)
|
||||
current = DOM.getFiles(panel)[0];
|
||||
|
||||
DOM.setCurrentFile(current, {
|
||||
history
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -130,8 +130,13 @@ function CmdProto() {
|
|||
};
|
||||
|
||||
RESTful.write(path(type), (error) => {
|
||||
!error && CloudCmd.refresh(null, () => {
|
||||
DOM.setCurrentByName(name);
|
||||
if (error)
|
||||
return;
|
||||
|
||||
const currentName = name;
|
||||
|
||||
CloudCmd.refresh({
|
||||
currentName
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ module.exports = (dir, files) => {
|
|||
eachSeries(array, loadFile(dir, n), onEnd(name));
|
||||
};
|
||||
|
||||
function _onEnd(name) {
|
||||
CloudCmd.refresh(null, () => {
|
||||
DOM.setCurrentByName(name);
|
||||
function _onEnd(currentName) {
|
||||
CloudCmd.refresh({
|
||||
currentName
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -161,7 +161,8 @@ function onPathElementClick(panel, event) {
|
|||
case 'js-refresh':
|
||||
noCurrent = isNoCurrent(panel);
|
||||
|
||||
CloudCmd.refresh(panel, {
|
||||
CloudCmd.refresh({
|
||||
panel,
|
||||
noCurrent
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -107,9 +107,10 @@ CloudCmd.EditNames = function EditNamesProto(callback) {
|
|||
if (res.status === 404)
|
||||
return res.text().then(reject);
|
||||
|
||||
CloudCmd.refresh(null, () => {
|
||||
const name = to[nameIndex];
|
||||
DOM.setCurrentByName(name);
|
||||
const currentName = to[nameIndex];
|
||||
|
||||
CloudCmd.refresh({
|
||||
currentName
|
||||
});
|
||||
}).catch(alert);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -248,15 +248,14 @@ function MenuProto(position) {
|
|||
function uploadFromCloud() {
|
||||
Images.show.load('top');
|
||||
|
||||
CloudCmd.execFromModule('Cloud', 'saveFile', (name, data) => {
|
||||
const path = DOM.getCurrentDirPath() + name;
|
||||
const setCurrent = () => DOM.setCurrentByName(name);
|
||||
CloudCmd.execFromModule('Cloud', 'saveFile', (currentName, data) => {
|
||||
const path = DOM.getCurrentDirPath() + currentName;
|
||||
|
||||
RESTful.write(path, data, (error) => {
|
||||
if (error)
|
||||
return;
|
||||
|
||||
CloudCmd.refresh(null, setCurrent);
|
||||
CloudCmd.refresh({currentName});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -443,11 +443,12 @@ function OperationProto(operation, data) {
|
|||
};
|
||||
|
||||
if (!Info.isOnePanel)
|
||||
CloudCmd.refresh(panelPassive, {
|
||||
noCurrent: true
|
||||
CloudCmd.refresh({
|
||||
panel: panelPassive,
|
||||
noCurrent: true,
|
||||
});
|
||||
|
||||
CloudCmd.refresh(panel, setCurrent);
|
||||
CloudCmd.refresh({panel}, setCurrent);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -467,57 +468,57 @@ function OperationProto(operation, data) {
|
|||
}
|
||||
|
||||
function twopack(operation, type) {
|
||||
var op,
|
||||
fileFrom,
|
||||
Images = DOM.Images,
|
||||
name = Info.name,
|
||||
path = Info.path,
|
||||
dirPath = Info.dirPath,
|
||||
activeFiles = DOM.getActiveFiles(),
|
||||
names = DOM.getFilenames(activeFiles);
|
||||
let op;
|
||||
let fileFrom;
|
||||
let currentName = Info.name;
|
||||
|
||||
const Images = DOM.Images;
|
||||
const path = Info.path;
|
||||
const dirPath = Info.dirPath;
|
||||
const activeFiles = DOM.getActiveFiles();
|
||||
const names = DOM.getFilenames(activeFiles);
|
||||
|
||||
checkEmpty('operation', operation);
|
||||
|
||||
if (!names.length) {
|
||||
Dialog.alert.noFiles(TITLE);
|
||||
} else {
|
||||
switch(operation) {
|
||||
case 'extract':
|
||||
op = extractFn;
|
||||
|
||||
fileFrom = {
|
||||
from : path,
|
||||
to : dirPath
|
||||
};
|
||||
|
||||
name = name.replace(getTypeReg(type), '');
|
||||
|
||||
break;
|
||||
if (!names.length)
|
||||
return Dialog.alert.noFiles(TITLE);
|
||||
|
||||
case 'pack':
|
||||
op = packFn;
|
||||
|
||||
if (names.length > 1)
|
||||
name = Info.dir;
|
||||
|
||||
name += DOM.getPackerExt(type);
|
||||
|
||||
fileFrom = {
|
||||
from : dirPath,
|
||||
to : dirPath + name,
|
||||
names : names
|
||||
};
|
||||
break;
|
||||
}
|
||||
switch(operation) {
|
||||
case 'extract':
|
||||
op = extractFn;
|
||||
|
||||
Images.show.load('top');
|
||||
fileFrom = {
|
||||
from : path,
|
||||
to : dirPath
|
||||
};
|
||||
|
||||
op(fileFrom, function(error) {
|
||||
!error && CloudCmd.refresh(null, function() {
|
||||
DOM.setCurrentByName(name);
|
||||
});
|
||||
});
|
||||
currentName = currentName.replace(getTypeReg(type), '');
|
||||
|
||||
break;
|
||||
|
||||
case 'pack':
|
||||
op = packFn;
|
||||
|
||||
if (names.length > 1)
|
||||
currentName = Info.dir;
|
||||
|
||||
currentName += DOM.getPackerExt(type);
|
||||
|
||||
fileFrom = {
|
||||
from: dirPath,
|
||||
to: dirPath + currentName,
|
||||
names,
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
||||
Images.show.load('top');
|
||||
|
||||
op(fileFrom, (error) => {
|
||||
!error && CloudCmd.refresh({
|
||||
currentName
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function message(msg) {
|
||||
|
|
|
|||
|
|
@ -30,8 +30,11 @@ CloudCmd.sortPanel = (name, panel = getPanel()) => {
|
|||
sortPrevious =
|
||||
sort[position] = name;
|
||||
|
||||
CloudCmd.refresh(panel, {
|
||||
noCurrent: position !== Info.panelPosition
|
||||
const noCurrent = position !== Info.panelPosition;
|
||||
|
||||
CloudCmd.refresh({
|
||||
panel,
|
||||
noCurrent,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue