mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
[enh] Refactoring to avoid duplicate code
This commit is contained in:
parent
25e2475100
commit
c83e33e3c4
6 changed files with 187 additions and 209 deletions
177
src/dist/js/script.min.js
vendored
177
src/dist/js/script.min.js
vendored
|
@ -6556,7 +6556,67 @@ var app = Sammy('#main', function (sam) {
|
|||
return arr1.filter(function (a) {
|
||||
return ((arr2.indexOf(a) == -1) && (a !== ""));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
groupHooks: function(hooks) {
|
||||
data={};
|
||||
var rules=[
|
||||
{
|
||||
id:'configuration',
|
||||
isIn:function (hook) {
|
||||
return hook.indexOf('conf_')==0
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
$.each(hooks, function(i, hook) {
|
||||
var group_id=hook;
|
||||
$.each(rules, function(i, rule) {
|
||||
if (rule.isIn(hook))
|
||||
{
|
||||
group_id='adminjs_group_'+rule.id;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if(group_id in data)
|
||||
data[group_id]={
|
||||
name:y18n.t('hook_'+group_id),
|
||||
value:data[group_id].value+','+hook,
|
||||
description:data[group_id].description+', '+y18n.t('hook_'+hook)
|
||||
};
|
||||
else
|
||||
data[group_id]={
|
||||
name:y18n.t('hook_'+group_id),
|
||||
value:hook,
|
||||
description:(group_id==hook)?y18n.t('hook_desc_'+hook):y18n.t('hook_'+hook)
|
||||
};
|
||||
});
|
||||
return data;
|
||||
},
|
||||
|
||||
ungroupHooks: function(hooks,apps) {
|
||||
var data={};
|
||||
data['apps']=apps;
|
||||
data['hooks']=hooks;
|
||||
if (data['hooks']==undefined)
|
||||
data['hooks']=[];
|
||||
else if (data['hooks'].constructor !== Array)
|
||||
data['hooks']=[data['hooks']];
|
||||
if (data['apps']==undefined)
|
||||
data['apps']=[];
|
||||
else if (data['apps'].constructor !== Array)
|
||||
data['apps']=[params['apps']];
|
||||
if (data['hooks'].length==0)
|
||||
data['ignore_hooks']='';
|
||||
if (data['apps'].length==0)
|
||||
data['ignore_apps']='';
|
||||
var split_hooks=[];
|
||||
$.each(data['hooks'], function(i, hook) {
|
||||
split_hooks.concat(hook.split(','));
|
||||
});
|
||||
data['hooks']=split_hooks;
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
@ -8077,64 +8137,26 @@ var app = Sammy('#main', function (sam) {
|
|||
data['storage']={
|
||||
id:c.params['storage'],
|
||||
name:y18n.t('local_archives')
|
||||
};
|
||||
data['hooks']=[
|
||||
{
|
||||
id:'system_home',
|
||||
name:y18n.t('home_data')
|
||||
},
|
||||
{
|
||||
id:'system_mail',
|
||||
name:y18n.t('mail')
|
||||
},
|
||||
{
|
||||
id:'adminjs_group_hooks_config',
|
||||
name:y18n.t('configuration'),
|
||||
hooks:config_hooks
|
||||
}
|
||||
];
|
||||
//TODO: (ljf) add personal hools in data['items']
|
||||
data['apps']=[];
|
||||
c.api('/apps?raw', function(dataraw) { // http://api.yunohost.org/#!/app/app_list_get_8
|
||||
$.each(dataraw, function(app_id, app) {
|
||||
if (app['installed']) {
|
||||
data['apps'].push({
|
||||
id: app_id,
|
||||
app_id: app_id,
|
||||
name: app['manifest']['name']
|
||||
});
|
||||
}
|
||||
};
|
||||
c.api('/hooks/backup', function(hooks) {
|
||||
data['hooks']=c.groupHooks(hooks['hooks']);
|
||||
data['apps']={};
|
||||
c.api('/apps?raw', function(apps) { // http://api.yunohost.org/#!/app/app_list_get_8
|
||||
$.each(apps, function(app_id, app) {
|
||||
if (app['installed'])
|
||||
data['apps'][app_id]={
|
||||
name: app['manifest']['name']
|
||||
};
|
||||
});
|
||||
c.view('backup/backup_create', data);
|
||||
});
|
||||
c.view('backup/backup_create', data);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
sam.post('#/backup/:storage', function (c) {
|
||||
var params = {
|
||||
'hooks': c.params['hooks'],
|
||||
'apps': c.params['apps']
|
||||
};
|
||||
if (params['hooks']==undefined)
|
||||
params['hooks']=[];
|
||||
else if (params['hooks'].constructor !== Array)
|
||||
params['hooks']=[params['hooks']];
|
||||
if (params['apps']==undefined)
|
||||
params['apps']=[];
|
||||
else if (params['apps'].constructor !== Array)
|
||||
params['apps']=[params['apps']];
|
||||
var config_pos=params['hooks'].indexOf('adminjs_group_hooks_config');
|
||||
if (config_pos>-1)
|
||||
{
|
||||
params['hooks'].splice(config_pos, 1);
|
||||
params['hooks']=params['hooks'].concat(config_hooks);
|
||||
}
|
||||
if (params['hooks'].length==0)
|
||||
params['ignore_hooks']='';
|
||||
if (params['apps'].length==0)
|
||||
params['ignore_apps']='';
|
||||
|
||||
var params = c.ungroupHooks(c.params['hooks'],c.params['apps']);
|
||||
c.api('/backup', function() {
|
||||
store.clear('slide');
|
||||
c.redirect('#/backup/'+ c.params['storage']);
|
||||
|
@ -8147,27 +8169,7 @@ var app = Sammy('#main', function (sam) {
|
|||
y18n.t('backup'),
|
||||
y18n.t('confirm_restore', [c.params['archive']]),
|
||||
$.proxy(function(c){
|
||||
var params={};
|
||||
params['apps']=c.params['apps'];
|
||||
params['hooks']=c.params['hooks'];
|
||||
if (params['hooks']==undefined)
|
||||
params['hooks']=[];
|
||||
else if (params['hooks'].constructor !== Array)
|
||||
params['hooks']=[params['hooks']];
|
||||
if (params['apps']==undefined)
|
||||
params['apps']=[];
|
||||
else if (params['apps'].constructor !== Array)
|
||||
params['apps']=[params['apps']];
|
||||
if (params['hooks'].length==0)
|
||||
params['ignore_hooks']='';
|
||||
if (params['apps'].length==0)
|
||||
params['ignore_apps']='';
|
||||
var config_pos=params['hooks'].indexOf('adminjs_group_hooks_config');
|
||||
if (config_pos>-1)
|
||||
{
|
||||
params['hooks'].splice(config_pos, 1);
|
||||
params['hooks']=params['hooks'].concat(config_hooks);
|
||||
}
|
||||
var params=c.ungroupHooks(c.params['hooks'],c.params['apps']);
|
||||
params['force']='';
|
||||
c.api('/backup/restore/'+c.params['archive'], function(data) {
|
||||
store.clear('slide');
|
||||
|
@ -8227,33 +8229,8 @@ var app = Sammy('#main', function (sam) {
|
|||
name:y18n.t('local_archives')
|
||||
};
|
||||
data['other_storages']=[];
|
||||
data['name']=c.params['archive'];
|
||||
data['hooks2']={};
|
||||
|
||||
$.each(data['hooks'], function(hook, paths) {
|
||||
if (hook.substring(0, 7)=='system_')
|
||||
{
|
||||
var service=hook.slice(7);
|
||||
if (service=='home')
|
||||
data['hooks2']['system_home']={
|
||||
name:y18n.t('home_data')
|
||||
};
|
||||
else if (service=='mail')
|
||||
data['hooks2']['system_mail']={
|
||||
name:y18n.t('mail')
|
||||
};
|
||||
else
|
||||
data['hooks2']['adminjs_group_hooks_config']={
|
||||
name:y18n.t('configuration')
|
||||
};
|
||||
|
||||
}
|
||||
else
|
||||
data['hooks2'][hook]={
|
||||
name:hook
|
||||
};
|
||||
});
|
||||
data['hooks']=data['hooks2'];
|
||||
data['name']=c.params['archive'];
|
||||
data['hooks']=c.groupHooks(Object.keys(data['hooks']));
|
||||
data['items']=(data['hooks']!={} || data['apps']!=[]);
|
||||
c.view('backup/backup_info', data);
|
||||
});
|
||||
|
|
177
src/js/app.js
177
src/js/app.js
|
@ -341,7 +341,67 @@ var app = Sammy('#main', function (sam) {
|
|||
return arr1.filter(function (a) {
|
||||
return ((arr2.indexOf(a) == -1) && (a !== ""));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
groupHooks: function(hooks) {
|
||||
data={};
|
||||
var rules=[
|
||||
{
|
||||
id:'configuration',
|
||||
isIn:function (hook) {
|
||||
return hook.indexOf('conf_')==0
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
$.each(hooks, function(i, hook) {
|
||||
var group_id=hook;
|
||||
$.each(rules, function(i, rule) {
|
||||
if (rule.isIn(hook))
|
||||
{
|
||||
group_id='adminjs_group_'+rule.id;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if(group_id in data)
|
||||
data[group_id]={
|
||||
name:y18n.t('hook_'+group_id),
|
||||
value:data[group_id].value+','+hook,
|
||||
description:data[group_id].description+', '+y18n.t('hook_'+hook)
|
||||
};
|
||||
else
|
||||
data[group_id]={
|
||||
name:y18n.t('hook_'+group_id),
|
||||
value:hook,
|
||||
description:(group_id==hook)?y18n.t('hook_desc_'+hook):y18n.t('hook_'+hook)
|
||||
};
|
||||
});
|
||||
return data;
|
||||
},
|
||||
|
||||
ungroupHooks: function(hooks,apps) {
|
||||
var data={};
|
||||
data['apps']=apps;
|
||||
data['hooks']=hooks;
|
||||
if (data['hooks']==undefined)
|
||||
data['hooks']=[];
|
||||
else if (data['hooks'].constructor !== Array)
|
||||
data['hooks']=[data['hooks']];
|
||||
if (data['apps']==undefined)
|
||||
data['apps']=[];
|
||||
else if (data['apps'].constructor !== Array)
|
||||
data['apps']=[params['apps']];
|
||||
if (data['hooks'].length==0)
|
||||
data['ignore_hooks']='';
|
||||
if (data['apps'].length==0)
|
||||
data['ignore_apps']='';
|
||||
var split_hooks=[];
|
||||
$.each(data['hooks'], function(i, hook) {
|
||||
split_hooks.concat(hook.split(','));
|
||||
});
|
||||
data['hooks']=split_hooks;
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
@ -1862,64 +1922,26 @@ var app = Sammy('#main', function (sam) {
|
|||
data['storage']={
|
||||
id:c.params['storage'],
|
||||
name:y18n.t('local_archives')
|
||||
};
|
||||
data['hooks']=[
|
||||
{
|
||||
id:'system_home',
|
||||
name:y18n.t('home_data')
|
||||
},
|
||||
{
|
||||
id:'system_mail',
|
||||
name:y18n.t('mail')
|
||||
},
|
||||
{
|
||||
id:'adminjs_group_hooks_config',
|
||||
name:y18n.t('configuration'),
|
||||
hooks:config_hooks
|
||||
}
|
||||
];
|
||||
//TODO: (ljf) add personal hools in data['items']
|
||||
data['apps']=[];
|
||||
c.api('/apps?raw', function(dataraw) { // http://api.yunohost.org/#!/app/app_list_get_8
|
||||
$.each(dataraw, function(app_id, app) {
|
||||
if (app['installed']) {
|
||||
data['apps'].push({
|
||||
id: app_id,
|
||||
app_id: app_id,
|
||||
name: app['manifest']['name']
|
||||
});
|
||||
}
|
||||
};
|
||||
c.api('/hooks/backup', function(hooks) {
|
||||
data['hooks']=c.groupHooks(hooks['hooks']);
|
||||
data['apps']={};
|
||||
c.api('/apps?raw', function(apps) { // http://api.yunohost.org/#!/app/app_list_get_8
|
||||
$.each(apps, function(app_id, app) {
|
||||
if (app['installed'])
|
||||
data['apps'][app_id]={
|
||||
name: app['manifest']['name']
|
||||
};
|
||||
});
|
||||
c.view('backup/backup_create', data);
|
||||
});
|
||||
c.view('backup/backup_create', data);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
sam.post('#/backup/:storage', function (c) {
|
||||
var params = {
|
||||
'hooks': c.params['hooks'],
|
||||
'apps': c.params['apps']
|
||||
};
|
||||
if (params['hooks']==undefined)
|
||||
params['hooks']=[];
|
||||
else if (params['hooks'].constructor !== Array)
|
||||
params['hooks']=[params['hooks']];
|
||||
if (params['apps']==undefined)
|
||||
params['apps']=[];
|
||||
else if (params['apps'].constructor !== Array)
|
||||
params['apps']=[params['apps']];
|
||||
var config_pos=params['hooks'].indexOf('adminjs_group_hooks_config');
|
||||
if (config_pos>-1)
|
||||
{
|
||||
params['hooks'].splice(config_pos, 1);
|
||||
params['hooks']=params['hooks'].concat(config_hooks);
|
||||
}
|
||||
if (params['hooks'].length==0)
|
||||
params['ignore_hooks']='';
|
||||
if (params['apps'].length==0)
|
||||
params['ignore_apps']='';
|
||||
|
||||
var params = c.ungroupHooks(c.params['hooks'],c.params['apps']);
|
||||
c.api('/backup', function() {
|
||||
store.clear('slide');
|
||||
c.redirect('#/backup/'+ c.params['storage']);
|
||||
|
@ -1932,27 +1954,7 @@ var app = Sammy('#main', function (sam) {
|
|||
y18n.t('backup'),
|
||||
y18n.t('confirm_restore', [c.params['archive']]),
|
||||
$.proxy(function(c){
|
||||
var params={};
|
||||
params['apps']=c.params['apps'];
|
||||
params['hooks']=c.params['hooks'];
|
||||
if (params['hooks']==undefined)
|
||||
params['hooks']=[];
|
||||
else if (params['hooks'].constructor !== Array)
|
||||
params['hooks']=[params['hooks']];
|
||||
if (params['apps']==undefined)
|
||||
params['apps']=[];
|
||||
else if (params['apps'].constructor !== Array)
|
||||
params['apps']=[params['apps']];
|
||||
if (params['hooks'].length==0)
|
||||
params['ignore_hooks']='';
|
||||
if (params['apps'].length==0)
|
||||
params['ignore_apps']='';
|
||||
var config_pos=params['hooks'].indexOf('adminjs_group_hooks_config');
|
||||
if (config_pos>-1)
|
||||
{
|
||||
params['hooks'].splice(config_pos, 1);
|
||||
params['hooks']=params['hooks'].concat(config_hooks);
|
||||
}
|
||||
var params=c.ungroupHooks(c.params['hooks'],c.params['apps']);
|
||||
params['force']='';
|
||||
c.api('/backup/restore/'+c.params['archive'], function(data) {
|
||||
store.clear('slide');
|
||||
|
@ -2012,33 +2014,8 @@ var app = Sammy('#main', function (sam) {
|
|||
name:y18n.t('local_archives')
|
||||
};
|
||||
data['other_storages']=[];
|
||||
data['name']=c.params['archive'];
|
||||
data['hooks2']={};
|
||||
|
||||
$.each(data['hooks'], function(hook, paths) {
|
||||
if (hook.substring(0, 7)=='system_')
|
||||
{
|
||||
var service=hook.slice(7);
|
||||
if (service=='home')
|
||||
data['hooks2']['system_home']={
|
||||
name:y18n.t('home_data')
|
||||
};
|
||||
else if (service=='mail')
|
||||
data['hooks2']['system_mail']={
|
||||
name:y18n.t('mail')
|
||||
};
|
||||
else
|
||||
data['hooks2']['adminjs_group_hooks_config']={
|
||||
name:y18n.t('configuration')
|
||||
};
|
||||
|
||||
}
|
||||
else
|
||||
data['hooks2'][hook]={
|
||||
name:hook
|
||||
};
|
||||
});
|
||||
data['hooks']=data['hooks2'];
|
||||
data['name']=c.params['archive'];
|
||||
data['hooks']=c.groupHooks(Object.keys(data['hooks']));
|
||||
data['items']=(data['hooks']!={} || data['apps']!=[]);
|
||||
c.view('backup/backup_info', data);
|
||||
});
|
||||
|
|
|
@ -259,9 +259,20 @@
|
|||
"backup_create": "Create a backup",
|
||||
"restore": "Restore",
|
||||
"download": "Download",
|
||||
"home_data": "User data",
|
||||
"mail": "Mail",
|
||||
"configuration": "Configuration",
|
||||
"hook_data_home": "User data",
|
||||
"hook_desc_data_home": "User data located in /home/USER",
|
||||
"hook_data_mail": "Mail",
|
||||
"hook_desc_data_mail": "Mail which are on the server",
|
||||
"hook_conf_ldap": "LDAP",
|
||||
"hook_conf_ssh": "SSH",
|
||||
"hook_conf_ynh_mysql": "Password MySQL",
|
||||
"hook_conf_nginx": "Nginx",
|
||||
"hook_conf_cron": "Regular tasks",
|
||||
"hook_conf_xmpp": "XMPP",
|
||||
"hook_conf_ynh_firewall": "Firewall",
|
||||
"hook_conf_ynh_certs": "Security certificates",
|
||||
"hook_conf_ssowat": "SSOwat",
|
||||
"hook_adminjs_group_configuration": "Configuration",
|
||||
"backup_optional_encryption": "Optional encryption",
|
||||
"backup_optional_password": "Optional password",
|
||||
"backup_encryption_warning": "Don't forget this password, you will need it if you want restore the archive",
|
||||
|
|
|
@ -240,9 +240,20 @@
|
|||
"backup_create": "Créer une sauvegarde",
|
||||
"restore": "Restorer",
|
||||
"download": "Télécharger",
|
||||
"home_data": "Données utilisateurs",
|
||||
"mail": "Mail",
|
||||
"configuration": "Configuration",
|
||||
"hook_data_home": "Données utilisateurs",
|
||||
"hook_desc_data_home": "Les données des utilisateurs situées dans /home/USER",
|
||||
"hook_data_mail": "Mail",
|
||||
"hook_desc_data_mail": "Les mails qui sont encore sur le serveur",
|
||||
"hook_conf_ldap": "LDAP",
|
||||
"hook_conf_ssh": "SSH",
|
||||
"hook_conf_ynh_mysql": "Mot de passe MySQL",
|
||||
"hook_conf_nginx": "Nginx",
|
||||
"hook_conf_cron": "Tâches régulières",
|
||||
"hook_conf_xmpp": "XMPP",
|
||||
"hook_conf_ynh_firewall": "Pare-feu",
|
||||
"hook_conf_ynh_certs": "Certificats de sécurité",
|
||||
"hook_conf_ssowat": "SSOwat",
|
||||
"hook_adminjs_group_configuration": "Configuration",
|
||||
"backup_optional_encryption": "Chiffrement optionnel",
|
||||
"backup_optional_password": "Mot de passe optionnel",
|
||||
"backup_encryption_warning": "N'oubliez pas ce mot de passe, vous en aurez besoin pour restaurer cette sauvegarde",
|
||||
|
|
|
@ -11,9 +11,10 @@
|
|||
<form action="#/backup/{{storage.id}}" method="POST" class="form-horizontal">
|
||||
<div class="list-group">
|
||||
{{#each hooks}}
|
||||
<label for="{{id}}" class="list-group-item">
|
||||
<span class="pull-right"><input type="checkbox" id="{{id}}" name="hooks" value="{{id}}" checked></span>
|
||||
<label for="{{@key}}" class="list-group-item">
|
||||
<span class="pull-right"><input type="checkbox" id="{{@key}}" name="hooks" value="{{value}}" checked></span>
|
||||
<h2 class="list-group-item-heading">{{name}}</h2>
|
||||
<p class="list-group-item-text">{{description}}</p>
|
||||
</label>
|
||||
{{/each}}
|
||||
{{#each apps}}
|
||||
|
|
|
@ -13,8 +13,9 @@
|
|||
<div class="list-group">
|
||||
{{#each hooks}}
|
||||
<label for="{{@key}}" class="list-group-item">
|
||||
<span class="pull-right"><input type="checkbox" id="{{@key}}" name="hooks" value="{{@key}}" checked></span>
|
||||
<span class="pull-right"><input type="checkbox" id="{{@key}}" name="hooks" value="{{value}}" checked></span>
|
||||
<h2 class="list-group-item-heading">{{name}}</h2>
|
||||
<p class="list-group-item-text">{{description}}</p>
|
||||
</label>
|
||||
{{/each}}
|
||||
{{#each apps}}
|
||||
|
|
Loading…
Reference in a new issue