Moaaar buttons (migration view)

This commit is contained in:
Alexandre Aubin 2019-10-18 19:52:55 +02:00
parent a73f87575b
commit 119d485a05
2 changed files with 38 additions and 51 deletions

View file

@ -264,7 +264,7 @@
});
});
// Reboot or shutdown button
// Migrations
app.get('#/tools/migrations', function (c) {
c.api('GET', '/migrations?pending', {}, function(pending_migrations) {
c.api('GET', '/migrations?done', {}, function(done_migrations) {
@ -286,59 +286,46 @@
c.view('tools/tools_migrations', {
'pending_migrations' : pending_migrations.reverse(),
'done_migrations' : done_migrations.reverse()
}, function() {
// Configure button 'Run'
$('button[data-action="run"]').on("click", function() {
var disclaimerAcks = $(".disclaimer-ack");
for (var i = 0 ; i < disclaimerAcks.length ; i++)
{
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_to('#/tools/migrations', {slide: false});
return;
}
};
c.api('POST', '/migrations/migrate?accept_disclaimer', {}, function (data) {
c.redirect_to('#/tools/migrations', {slide: false});
});
});
// Configure buttons 'Skip'
$('button[data-action="skip"]').on("click", function() {
var migration_id = $(this).data("migration");
c.confirm(
y18n.t('migrations'),
y18n.t('confirm_migrations_skip'),
function(){
c.api('POST', '/migrations/migrate?skip&targets=' + migration_id, {}, function(data) {
c.redirect_to('#/tools/migrations', {slide: false});
});
}
);
});
});
});
});
});
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_to('#/tools/migrations', {slide: false});
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('POST', '/migrations/migrate?accept_disclaimer', {}, function (data) {
c.redirect_to('#/tools/migrations', {slide: false});
})
}
else
{
c.api('POST', '/migrations/migrate', {}, function (data) {
c.redirect_to('#/tools/migrations', {slide: false});
})
}
});
app.get('#/tools/migrations/skip/:migration_id', function (c) {
c.confirm(
y18n.t('migrations'),
y18n.t('confirm_migrations_skip'),
function(){
c.api('POST', '/migrations/migrate?skip&targets=' + c.params['migration_id'], {}, function(data) {
c.redirect_to('#/tools/migrations', {slide: false});
});
}
);
});
// List available apps lists
app.get('#/tools/appslists', function (c) {
c.api('GET', '/appslists', {}, function(data) {

View file

@ -11,7 +11,7 @@
<h2 class="panel-title"><span class="fa-fw fa-cogs"></span> {{t 'migrations_pending'}}
{{#if pending_migrations}}
<div class="btn-toolbar pull-right">
<a href="#/tools/migrations/run" class="btn btn-sm btn-success"><span class="fa-fw fa-play"></span> {{t 'run'}}</a>
<button class="btn btn-sm btn-success" data-action="run"><span class="fa-fw fa-play"></span> {{t 'run'}}</button>
</div>
{{/if}}
</h2>
@ -24,7 +24,7 @@
<h3 class="list-group-item-heading">
{{ number }}. {{ description }}
<div class="btn-toolbar pull-right">
<a href="#/tools/migrations/skip/{{ id }}" class="btn btn-xs btn-warning" style="color:white;"><span class="fa-fw fa-close"></span> {{t 'skip'}}</a>
<button class="btn btn-xs btn-warning" style="color:white;" data-action="skip" data-migration="{{id}}"><span class="fa-fw fa-close"></span> {{t 'skip'}}</button>
</div>
</h3>
{{#if disclaimer }}