Skip to content

Commit

Permalink
[js:command] tiny performance tuning on selecting items
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Jun 12, 2021
1 parent f29aa16 commit cab081e
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 27 deletions.
14 changes: 11 additions & 3 deletions js/commands/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,20 @@ elFinder.prototype.commands.archive = function() {
this.getstate = function(select) {
var sel = this.files(select),
cnt = sel.length,
chk = (cnt && ! fm.isRoot(sel[0]) && (fm.file(sel[0].phash) || {}).write && ! $.grep(sel, function(f){ return f.read ? false : true; }).length),
chk = (cnt && ! fm.isRoot(sel[0]) && (fm.file(sel[0].phash) || {}).write),
filter = function(files) {
var fres = true;
return $.grep(files, function(f) {
fres = fres && f.read && f.hash.indexOf(cwdId) === 0 ? true : false;
return fres;
});
},
cwdId;

if (chk && fm.searchStatus.state > 1) {
cwdId = fm.cwd().volumeid;
chk = (cnt === $.grep(sel, function(f) { return f.read && f.hash.indexOf(cwdId) === 0 ? true : false; }).length);
if (chk = (cnt === filter(sel).length)) {
cwdId = fm.cwd().volumeid;
}
}

return chk && !this._disabled && mimes.length && (cnt || (dfrd && dfrd.state() == 'pending')) ? 0 : -1;
Expand Down
17 changes: 10 additions & 7 deletions js/commands/chmod.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ elFinder.prototype.commands.chmod = function() {
files : fm.i18n('files')
},
isPerm = function(perm){
return (!isNaN(parseInt(perm, 8) && parseInt(perm, 8) <= 511) || perm.match(/^([r-][w-][x-]){3}$/i));
return (!isNaN(parseInt(perm, 8)) && parseInt(perm, 8) <= 511) || perm.match(/^([r-][w-][x-]){3}$/i);
};

this.tpl = {
Expand Down Expand Up @@ -53,12 +53,15 @@ elFinder.prototype.commands.chmod = function() {
};

this.checkstate = function(sel) {
var cnt = sel.length;
if (!cnt) return false;
var chk = $.grep(sel, function(f) {
return (f.isowner && f.perm && isPerm(f.perm) && (cnt == 1 || f.mime != 'directory')) ? true : false;
}).length;
return (cnt == chk)? true : false;
var cnt = sel.length,
filter = function(files) {
var fres = true;
return $.grep(sel, function(f) {
fres = fres && f.isowner && f.perm && isPerm(f.perm) && (cnt == 1 || f.mime != 'directory') ? true : false;
return fres;
});
};
return (cnt && cnt === filter(sel).length)? true : false;
};

this.exec = function(select) {
Expand Down
11 changes: 9 additions & 2 deletions js/commands/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ elFinder.prototype.commands.copy = function() {

this.getstate = function(select) {
var sel = this.files(select),
cnt = sel.length;
cnt = sel.length,
filter = function(files) {
var fres = true;
return $.grep(files, function(f) {
fres = fres && f.read ? true : false;
return fres;
});
};

return cnt && $.grep(sel, function(f) { return f.read ? true : false; }).length == cnt ? 0 : -1;
return cnt && filter(sel).length == cnt ? 0 : -1;
};

this.exec = function(hashes) {
Expand Down
11 changes: 9 additions & 2 deletions js/commands/cut.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ elFinder.prototype.commands.cut = function() {

this.getstate = function(select) {
var sel = this.files(select),
cnt = sel.length;
cnt = sel.length,
filter = function(files) {
var fres = true;
return $.grep(files, function(f) {
fres = fres && f.read && ! f.locked && ! fm.isRoot(f) ? true : false;
return fres;
});
};

return cnt && $.grep(sel, function(f) { return f.read && ! f.locked && ! fm.isRoot(f) ? true : false; }).length == cnt ? 0 : -1;
return cnt && filter(sel).length == cnt ? 0 : -1;
};

this.exec = function(hashes) {
Expand Down
11 changes: 9 additions & 2 deletions js/commands/duplicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ elFinder.prototype.commands.duplicate = function() {

this.getstate = function(select) {
var sel = this.files(select),
cnt = sel.length;
cnt = sel.length,
filter = function(files) {
var fres = true;
return $.grep(files, function(f) {
fres = fres && f.read && f.phash === fm.cwd().hash && ! fm.isRoot(f)? true : false;
return fres;
});
};

return cnt && fm.cwd().write && $.grep(sel, function(f) { return f.read && f.phash === fm.cwd().hash && ! fm.isRoot(f)? true : false; }).length == cnt ? 0 : -1;
return cnt && fm.cwd().write && filter(sel).length == cnt ? 0 : -1;
};

this.exec = function(hashes) {
Expand Down
11 changes: 9 additions & 2 deletions js/commands/empty.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ elFinder.prototype.commands.empty = function() {

this.getstate = function(select) {
var sel = selFiles(select),
cnt;
cnt,
filter = function(files) {
var fres = true;
return $.grep(files, function(f) {
fres = fres && f.read && f.write && f.mime === 'directory' ? true : false;
return fres;
});
};

cnt = sel.length;
return $.grep(sel, function(f) { return f.read && f.write && f.mime === 'directory' ? true : false; }).length == cnt ? 0 : -1;
return filter(sel).length == cnt ? 0 : -1;
};

this.exec = function(hashes) {
Expand Down
6 changes: 4 additions & 2 deletions js/commands/getfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
var self = this,
fm = this.fm,
filter = function(files) {
var o = self.options;
var o = self.options,
fres = true;

files = $.grep(files, function(file) {
return (file.mime != 'directory' || o.folders) && file.read ? true : false;
fres = fres && (file.mime != 'directory' || o.folders) && file.read ? true : false;
return fres;
});

return o.multiple || files.length == 1 ? files : [];
Expand Down
11 changes: 9 additions & 2 deletions js/commands/mkdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,19 @@ elFinder.prototype.commands.mkdir = function() {
this.getstate = function(select) {
var cwd = fm.cwd(),
sel = (curOrg === 'navbar' || (select && select[0] !== cwd.hash))? this.files(select || fm.selected()) : [],
cnt = sel.length;
cnt = sel.length,
filter = function(files) {
var fres = true;
return $.grep(files, function(f) {
fres = fres && f.read && ! f.locked? true : false;
return fres;
});
};

if (curOrg === 'navbar') {
return cnt && sel[0].write && sel[0].read? 0 : -1;
} else {
return cwd.write && (!cnt || $.grep(sel, function(f) { return f.read && ! f.locked? true : false; }).length == cnt)? 0 : -1;
return cwd.write && (!cnt || filter(sel).length == cnt)? 0 : -1;
}
};

Expand Down
9 changes: 8 additions & 1 deletion js/commands/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@

this.getstate = function(select) {
var sel = this.files(select),
cnt = sel.length;
cnt = sel.length,
filter = function(files) {
var fres = true;
return $.grep(files, function(file) {
fres = fres && file.mime == 'directory' || ! file.read ? false : true;
return fres;
});
};

return cnt == 1
? (sel[0].read ? 0 : -1)
Expand Down
6 changes: 5 additions & 1 deletion js/commands/places.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ elFinder.prototype.commands.places = function() {
var self = this,
fm = this.fm,
filter = function(hashes) {
return $.grep(self.files(hashes), function(f) { return f.mime == 'directory' ? true : false; });
var fres = true;
return $.grep(self.files(hashes), function(f) {
fres = fres && f.mime == 'directory' ? true : false;
return fres;
});
},
places = null;

Expand Down
13 changes: 10 additions & 3 deletions js/commands/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,17 @@ elFinder.prototype.commands.rm = function() {
};

this.getstate = function(select) {
var sel = this.hashes(select);
var sel = this.hashes(select),
filter = function(files) {
var fres = true;
return $.grep(files, function(h) {
var f;
fres = fres && (f = fm.file(h)) && ! f.locked && ! fm.isRoot(f)? true : false;
return fres;
});
};

return sel.length && $.grep(sel, function(h) { var f = fm.file(h); return f && ! f.locked && ! fm.isRoot(f)? true : false; }).length == sel.length
? 0 : -1;
return sel.length && filter(sel).length == sel.length ? 0 : -1;
};

this.exec = function(hashes, cOpts) {
Expand Down

0 comments on commit cab081e

Please sign in to comment.