mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-27 00:36:44 +03:00
Split Sieve/Filters code from app.js so that i can work on the new Sieve GUI
This commit is contained in:
parent
ec6a79d9d6
commit
d6dc4d291c
23 changed files with 460 additions and 490 deletions
|
|
@ -1,4 +1,89 @@
|
|||
import { SieveScriptModel } from 'Sieve/Model/Script';
|
||||
|
||||
export const
|
||||
// import { i18n } from 'Common/Translator';
|
||||
i18n = rl.i18n,
|
||||
|
||||
// import { forEachObjectValue, forEachObjectEntry } from 'Common/Utils';
|
||||
forEachObjectValue = (obj, fn) => Object.values(obj).forEach(fn),
|
||||
forEachObjectEntry = (obj, fn) => Object.entries(obj).forEach(([key, value]) => fn(key, value)),
|
||||
|
||||
// import { koArrayWithDestroy } from 'External/ko';
|
||||
// With this we don't need delegateRunOnDestroy
|
||||
koArrayWithDestroy = data => {
|
||||
data = ko.observableArray(data);
|
||||
data.subscribe(changes =>
|
||||
changes.forEach(item =>
|
||||
'deleted' === item.status && null == item.moved && item.value.onDestroy && item.value.onDestroy()
|
||||
)
|
||||
, data, 'arrayChange');
|
||||
return data;
|
||||
},
|
||||
|
||||
// import { koComputable } from 'External/ko';
|
||||
koComputable = fn => ko.computed(fn, {'pure':true}),
|
||||
|
||||
arrayToString = (arr, separator) =>
|
||||
arr.map(item => item.toString ? item.toString() : item).join(separator);
|
||||
arr.map(item => item.toString ? item.toString() : item).join(separator),
|
||||
/*
|
||||
getNotificationMessage = code => {
|
||||
let key = getKeyByValue(Notification, code);
|
||||
return key ? I18N_DATA.NOTIFICATIONS[i18nKey(key).replace('_NOTIFICATION', '_ERROR')] : '';
|
||||
rl.i18n('NOTIFICATIONS/')
|
||||
},
|
||||
getNotification = (code, message = '', defCode = 0) => {
|
||||
code = parseInt(code, 10) || 0;
|
||||
if (Notification.ClientViewError === code && message) {
|
||||
return message;
|
||||
}
|
||||
|
||||
return getNotificationMessage(code)
|
||||
|| getNotificationMessage(parseInt(defCode, 10))
|
||||
|| '';
|
||||
},
|
||||
*/
|
||||
getNotification = code => 'ERROR ' + code,
|
||||
|
||||
Remote = rl.app.Remote,
|
||||
|
||||
// capabilities
|
||||
capa = ko.observableArray(),
|
||||
|
||||
// Sieve scripts SieveScriptModel
|
||||
scripts = koArrayWithDestroy(),
|
||||
|
||||
loading = ko.observable(false),
|
||||
serverError = ko.observable(false),
|
||||
serverErrorDesc = ko.observable(''),
|
||||
setError = text => {
|
||||
serverError(true);
|
||||
serverErrorDesc(text);
|
||||
},
|
||||
|
||||
updateList = () => {
|
||||
if (!loading()) {
|
||||
loading(true);
|
||||
serverError(false);
|
||||
|
||||
Remote.request('Filters', (iError, data) => {
|
||||
loading(false);
|
||||
scripts([]);
|
||||
|
||||
if (iError) {
|
||||
capa([]);
|
||||
setError(getNotification(iError));
|
||||
} else {
|
||||
capa(data.Result.Capa);
|
||||
/*
|
||||
scripts(
|
||||
data.Result.Scripts.map(aItem => SieveScriptModel.reviveFromJson(aItem)).filter(v => v)
|
||||
);
|
||||
*/
|
||||
forEachObjectValue(data.Result.Scripts, value => {
|
||||
value = SieveScriptModel.reviveFromJson(value);
|
||||
value && scripts.push(value)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue