From de5be0fd580af6b47b60bb0d1a95e254a43f3580 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 5 Feb 2018 16:38:27 +0100 Subject: [PATCH] Handle run/skip actions --- src/js/yunohost/controllers/tools.js | 68 +++++++++++++++++++++++++--- src/locales/en.json | 1 + src/views/tools/tools_migrations.ms | 4 +- 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/js/yunohost/controllers/tools.js b/src/js/yunohost/controllers/tools.js index 96e12e47..5d21b7bf 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') + '
'); } @@ -252,11 +252,8 @@ // Reboot or shutdown button app.get('#/tools/migrations', function (c) { - console.log("test"); c.api('/migrations?pending', function(pending_migrations) { c.api('/migrations?done', function(done_migrations) { - console.log(pending_migrations); - console.log(done_migrations); c.view('tools/tools_migrations', { 'pending_migrations' : pending_migrations.migrations.reverse(), 'done_migrations' : done_migrations.migrations.reverse() @@ -265,5 +262,62 @@ }); }); + app.get('#/tools/migrations/run', function (c) { + c.api('/migrations?pending', function(pending_migrations) { + var disclaimers = []; + var migrationsLength = pending_migrations.length; + for(var i = 0; i < migrationsLength; i++) { + if (pending_migrations[i].disclaimer) + { + disclaimers.push(pending_migrations[i].disclaimer); + console.log("Disclaimer found !"); + } + }; + console.log(disclaimers); + if (disclaimers.length) + { + c.confirm( + y18n.t('migrations'), + disclaimers.join('
'), + function(){ + c.api('/migrations/migrate?accept-disclaimer', + function (data) { + store.clear('slide'); + c.redirect('#/tools/migrations'); + }, 'POST') + }, + function(){ + store.clear('slide'); + c.redirect('#/tools/migrations'); + } + ); + } + 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 047a354e..aa3c28ce 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -67,6 +67,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?", diff --git a/src/views/tools/tools_migrations.ms b/src/views/tools/tools_migrations.ms index c0fe0b6e..56db0f09 100644 --- a/src/views/tools/tools_migrations.ms +++ b/src/views/tools/tools_migrations.ms @@ -11,8 +11,8 @@

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