feature(cloudcmd) rm option: localStorage

This commit is contained in:
coderaiser 2018-05-14 15:10:46 +03:00
parent 62f166f15c
commit 28892b3933
10 changed files with 12 additions and 136 deletions

View file

@ -221,8 +221,6 @@ function CloudCmdProto(Util, DOM) {
config[key] = value;
};
DOM.Storage.setAllowed(CloudCmd.config('localStorage'));
if (config.onePanelMode)
CloudCmd.MIN_ONE_PANEL_WIDTH = Infinity;

View file

@ -6,7 +6,6 @@ const itype = require('itype/legacy');
const currify = require('currify/legacy');
const exec = require('execon');
const Storage = require('./storage');
const load = require('./load');
const RESTful = require('./rest');
@ -136,7 +135,6 @@ function getConfig(callback) {
Promises.config.then((data) => {
is = false;
Storage.setAllowed(data.localStorage);
callback(null, data);

View file

@ -6,22 +6,10 @@ const exec = require('execon');
const tryCatch = require('try-catch');
const setItem = localStorage.setItem.bind(localStorage);
/* приватный переключатель возможности работы с кэшем */
let Allowed;
/**
* allow Storage usage
*/
module.exports.setAllowed = (isAllowed) => {
Allowed = isAllowed;
};
/** remove element */
module.exports.remove = (item, callback) => {
if (Allowed)
localStorage.removeItem(item);
exec(callback, null, Allowed);
localStorage.removeItem(item);
exec(callback, null);
return module.exports;
};
@ -50,7 +38,7 @@ module.exports.set = (name, data, callback) => {
if (itype.object(data))
str = jonny.stringify(data);
if (Allowed && name)
if (name)
[error] = tryCatch(setItem, name, str || data);
exec(callback, error);
@ -60,10 +48,7 @@ module.exports.set = (name, data, callback) => {
/** Если доступен Storage принимаем из него данные*/
module.exports.get = (name, callback) => {
let ret;
if (Allowed)
ret = localStorage.getItem(name);
const ret = localStorage.getItem(name);
exec(callback, null, ret);
@ -72,12 +57,9 @@ module.exports.get = (name, callback) => {
/** функция чистит весь кэш для всех каталогов*/
module.exports.clear = (callback) => {
const ret = Allowed;
localStorage.clear();
if (ret)
localStorage.clear();
exec(callback, null, ret);
exec(callback);
return module.exports;
};

View file

@ -6,6 +6,7 @@ const Info = DOM.CurrentInfo;
const exec = require('execon');
const clipboard = require('@cloudcmd/clipboard');
const wraptile = require('wraptile/legacy');
const Events = require('../dom/events');
const Buffer = require('../dom/buffer');
@ -465,11 +466,7 @@ function KeyProto() {
case Key.D:
if (ctrlMeta) {
CloudCmd.log('clearing storage...');
DOM.Storage.clear(() => {
CloudCmd.log('storage cleared');
});
DOM.Storage.clear(wraptile(CloudCmd.log, 'storage cleared'));
event.preventDefault();
}
break;

View file

@ -101,10 +101,6 @@ function initSocket() {
Config.save = save;
});
socket.on('config', (config) => {
DOM.Storage.setAllowed(config.localStorage);
});
socket.on('message', onSave);
socket.on('log', CloudCmd.log);
@ -205,17 +201,11 @@ function onChange(el) {
const obj = {};
const name = input.getName(el);
const data = input.getValue(name, Element);
const type = el.type;
if (name === 'name')
onNameChange(data);
else if (type === 'checkbox')
if (/^(diff|buffer|dirStorage)$/.test(name))
onLSChange(name, data);
else if (name === 'localStorage')
onLocalStorageChange();
else if (name === 'auth')
onAuthChange(data);
else if (name === 'auth')
onAuthChange(data);
obj[name] = data;
@ -229,8 +219,6 @@ function onSave(obj) {
CloudCmd._config(name, data);
input.setValue(name, data, Element);
});
DOM.Storage.setAllowed(obj.localStorage);
}
function saveHttp(obj) {
@ -244,50 +232,6 @@ function saveHttp(obj) {
});
}
function onLocalStorageChange() {
const names = ['diff', 'buffer', 'dirStorage', 'localStorage'];
const elements = names.map((name) => {
return input.getElementByName(name, Element);
});
const el = {};
const msg = 'Diff, Buffer and Directory Storage do not work without localStorage';
let isChecked;
elements.forEach((element) => {
const name = input.getName(element);
el[name] = element;
if (element.checked)
isChecked = true;
});
if (!isChecked || el.localStorage.checked)
return;
alert(msg);
elements.forEach((element) => {
if (!element.checked)
return;
element.checked = false;
onChange(element);
});
}
function onLSChange(name, data) {
const elLocalStorage = input.getElementByName('localStorage', Element);
const msg = `${name} depends on localStorage`;
if (!data || elLocalStorage.checked)
return;
Dialog.alert(TITLE, msg);
elLocalStorage.checked = true;
}
function onAuthChange(checked) {
const elUsername = input.getElementByName('username', Element);
const elPassword = input.getElementByName('password', Element);