diff --git a/src/js/yunohost/controllers/tools.js b/src/js/yunohost/controllers/tools.js index 752d3740..dad87a23 100644 --- a/src/js/yunohost/controllers/tools.js +++ b/src/js/yunohost/controllers/tools.js @@ -95,7 +95,7 @@ ); } }); - + // Upgrade a specific apps app.get('#/upgrade/apps/:app', function (c) { c.confirm( @@ -197,15 +197,15 @@ c.redirect('#/logout'); }, 'PUT', {}, false, function (xhr) { c.flash('success', y18n.t('tools_' + action + '_done')) - // Disconnect from the webadmin + // Disconnect from the webadmin store.clear('url'); store.clear('connected'); store.set('path', '#/'); - + // Rename the page to allow refresh without ask for rebooting window.location.href = window.location.href.split('#')[0] + '#/'; // Display reboot or shutdown info - // We can't use template because now the webserver is off + // We can't use template because now the webserver is off if (action == 'reboot') { $('#main').replaceWith('
' + y18n.t('tools_rebooting') + '
'); } @@ -250,4 +250,88 @@ }); }); + // Reboot or shutdown button + app.get('#/tools/migrations', function (c) { + c.api('/migrations?pending', function(pending_migrations) { + c.api('/migrations?done', function(done_migrations) { + pending_migrations = pending_migrations.migrations; + done_migrations = done_migrations.migrations; + + // Get rid of _ in the raw name of migrations (cosmetic) + for(var i = 0; i < pending_migrations.length; i++) { + pending_migrations[i].name = pending_migrations[i].name.replace(/_/g, " ") + if (pending_migrations[i].disclaimer) + { + pending_migrations[i].disclaimer = pending_migrations[i].disclaimer.replace(/\n/g, "
"); + } + } + for(var i = 0; i < done_migrations.length; i++) { + done_migrations[i].name = done_migrations[i].name.replace(/_/g, " ") + } + + c.view('tools/tools_migrations', { + 'pending_migrations' : pending_migrations.reverse(), + 'done_migrations' : done_migrations.reverse() + }); + }); + }); + }); + + app.get('#/tools/migrations/run', function (c) { + var disclaimerAcks = $(".disclaimer-ack"); + var withAcceptDisclaimerFlag = false; + for (var i = 0 ; i < disclaimerAcks.length ; i++) + { + console.log($(disclaimerAcks[i]).find("input:checked").val()); + if (! $(disclaimerAcks[i]).find("input:checked").val()) + { + // FIXME / TODO i18n + c.flash('fail', "Some of these migrations require you to acknowledge a disclaimer before running them."); + c.redirect('#/tools/migrations'); + return; + } + else + { + withAcceptDisclaimerFlag = true; + } + }; + + // Not sure if necessary, but this distinction is to avoid accidentally + // triggering a migration with a disclaimer if one goes to the + // /tools/migrations/run page "directly" somehow ... + if (withAcceptDisclaimerFlag) + { + c.api('/migrations/migrate?accept_disclaimer', + function (data) { + store.clear('slide'); + c.redirect('#/tools/migrations'); + }, 'POST') + } + else + { + c.api('/migrations/migrate', + function (data) { + store.clear('slide'); + c.redirect('#/tools/migrations'); + }, 'POST') + } + }); + + app.get('#/tools/migrations/skip', function (c) { + c.confirm( + y18n.t('migrations'), + y18n.t('confirm_migrations_skip'), + function(){ + c.api('/migrations/migrate?skip', function(data) { + store.clear('slide'); + c.redirect('#/tools/migrations'); + }, 'POST'); + }, + function(){ + store.clear('slide'); + c.redirect('#/tools/migrations'); + } + ); + }); + })(); diff --git a/src/locales/en.json b/src/locales/en.json index c7925e39..e2c8debb 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -73,6 +73,7 @@ "confirm_firewall_close": "Are you sure you want to close port %s? (protocol: %s, connection: %s)", "confirm_install_custom_app": "Installing 3rd party applications may compromise the security of your system. Use at your own risk.", "confirm_install_domain_root": "You will not be able to install any other app on %s. Continue ?", + "confirm_migrations_skip": "Skipping migrations is not recommended. Are you sure you want to do that?", "confirm_postinstall": "You are about to launch the post-installation process on the domain %s. It may take a few minutes, *do not interrupt the operation*.", "confirm_restore": "Are you sure you want to restore %s ?", "confirm_service_start": "Are you sure you want to start %s?", @@ -190,6 +191,11 @@ "manage_users": "Manage users", "memory": "Memory", "menu": "Menu", + "migrations": "Migrations", + "migrations_pending": "Pending migrations", + "migrations_done": "Previous migrations", + "migrations_no_pending": "No pending migrations", + "migrations_no_done": "No previous migrations", "mode": "Mode", "monitoring": "Monitoring", "monitoring_check_glances": "Check glances service status.", @@ -238,6 +244,7 @@ "refresh_app_list": "Refresh list", "remove_access": "Remove access", "restore": "Restore", + "run": "Run", "running": "Running", "save": "Save", "select_user": "Select user", @@ -248,6 +255,7 @@ "services_list": "Service list", "set_default": "Set default", "size": "Size", + "skip": "Skip", "start": "Start", "status": "Status", "stop": "Stop", diff --git a/src/views/tools/tools_list.ms b/src/views/tools/tools_list.ms index 3458de9c..199720e3 100644 --- a/src/views/tools/tools_list.ms +++ b/src/views/tools/tools_list.ms @@ -11,6 +11,10 @@

{{t 'diagnosis'}}

+ + +

{{t 'migrations'}}

+

{{t 'monitoring'}}

diff --git a/src/views/tools/tools_migrations.ms b/src/views/tools/tools_migrations.ms new file mode 100644 index 00000000..6fe1079a --- /dev/null +++ b/src/views/tools/tools_migrations.ms @@ -0,0 +1,81 @@ +
+ {{t 'home'}} + {{t 'tools'}} + {{t 'migrations'}} +
+ +
+ +
+
+

{{t 'migrations_pending'}} + {{#if pending_migrations}} + + {{/if}} +

+
+ + {{#if pending_migrations}} +
+ {{#pending_migrations}} +
+

+ {{ number }}. {{ name }} +

+

+ {{ description }} +

+ {{#if disclaimer }} +
+

+ {{{ disclaimer }}} +

+ +
+

+ {{/if}} +
+ {{/pending_migrations}} +
+ {{else}} +
+ {{t 'migrations_no_pending' }} +
+ {{/if}} +
+ +
+
+

{{t 'migrations_done'}} +

+
+ + {{#if done_migrations}} +
+ {{#done_migrations}} +
+

+ + {{ number }}. {{ name }} + +

+

+ {{ description }} +

+
+ {{/done_migrations}} +
+ {{else}} +
+ {{t 'migrations_no_done' }} +
+ {{/if}} +
+ + +