yunohost-admin/app/src/views/tool/ToolMigrations.vue

140 lines
4.2 KiB
Vue
Raw Normal View History

2020-09-11 14:20:06 +02:00
<template>
2021-02-19 18:52:54 +01:00
<view-base :queries="queries" @queries-response="onQueriesResponse" ref="view">
2020-09-11 14:20:06 +02:00
<!-- PENDING MIGRATIONS -->
<card :title="$t('migrations_pending')" icon="cogs" no-body>
<template #header-buttons v-if="pending">
<b-button size="sm" variant="success" @click="runMigrations">
<icon iname="play" /> {{ $t('run') }}
</b-button>
</template>
<b-card-body v-if="pending === null">
2020-09-11 14:20:06 +02:00
<span class="text-success">
<icon iname="check-circle" /> {{ $t('migrations_no_pending') }}
</span>
</b-card-body>
<b-list-group v-else-if="pending" flush>
2020-09-11 14:20:06 +02:00
<b-list-group-item
v-for="{ number, description, id, disclaimer } in pending" :key="number"
>
<div class="d-flex align-items-center">
{{ number }}. {{ description }}
<div class="ml-auto">
<b-button @click="skipMigration(id)" size="sm" variant="warning">
2020-09-11 14:20:06 +02:00
<icon iname="close" /> {{ $t('skip') }}
</b-button>
</div>
</div>
<template v-if="disclaimer">
<hr>
<p v-html="disclaimer" />
<b-form-checkbox
:id="'checkbox-' + number" :name="'checkbox-' + number"
:aria-describedby="'checkbox-feedback-' + number"
v-model="checked[id]"
>
{{ $t('migrations_disclaimer_check_message') }}
</b-form-checkbox>
<b-form-invalid-feedback
v-if="checked[id] === false" :state="false"
:id="'checkbox-feedback-' + number"
>
{{ $t('migrations_disclaimer_not_checked') }}
</b-form-invalid-feedback>
</template>
</b-list-group-item>
</b-list-group>
</card>
2020-09-11 14:20:06 +02:00
<!-- DONE MIGRATIONS -->
<card
:title="$t('migrations_done')" icon="cogs"
collapsable collapsed no-body
2020-09-11 14:20:06 +02:00
>
<b-card-body v-if="done === null">
<span class="text-success">
<icon iname="check-circle" /> {{ $t('migrations_no_done') }}
</span>
</b-card-body>
<b-list-group flush v-else-if="done">
<b-list-group-item v-for="{ number, description } in done" :key="number">
{{ number }}. {{ description }}
</b-list-group-item>
</b-list-group>
</card>
<template #skeleton>
<card-list-skeleton :item-count="3" />
<b-card no-body>
<template #header>
<b-skeleton width="30%" height="36px" class="m-0" />
</template>
</b-card>
</template>
</view-base>
2020-09-11 14:20:06 +02:00
</template>
<script>
2020-10-12 17:36:47 +02:00
import api from '@/api'
2020-09-11 14:20:06 +02:00
// FIXME not tested with pending migrations (disclaimer and stuff)
export default {
name: 'ToolMigrations',
data () {
return {
queries: [
2021-02-19 18:52:54 +01:00
['GET', 'migrations?pending'],
['GET', 'migrations?done']
],
2020-09-11 14:20:06 +02:00
pending: undefined,
done: undefined,
checked: {}
}
},
methods: {
2021-02-19 18:52:54 +01:00
onQueriesResponse ({ migrations: pending }, { migrations: done }) {
this.done = done.length ? done.reverse() : null
pending.forEach(migration => {
if (migration.disclaimer) {
migration.disclaimer = migration.disclaimer.replace('\n', '<br>')
this.$set(this.checked, migration.id, null)
}
2020-09-11 14:20:06 +02:00
})
// FIXME change to pending
this.pending = pending.length ? pending.reverse() : null
2020-09-11 14:20:06 +02:00
},
runMigrations () {
// Display an error on migration's disclaimer that aren't checked.
for (const [id, value] of Object.entries(this.checked)) {
if (value !== true) {
this.checked[id] = false
}
}
// Check that every migration's disclaimer has been checked.
if (Object.values(this.checked).every(value => value === true)) {
2021-06-03 18:15:15 +02:00
api.put('migrations/run?accept_disclaimer', {}, 'migrations.run').then(() => {
this.$refs.view.fetchQueries()
})
2020-09-11 14:20:06 +02:00
}
},
async skipMigration (id) {
const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_migrations_skip'))
if (!confirmed) return
2021-06-03 18:15:15 +02:00
api.put('/migrations/run', { skip: '', targets: id }, 'migration.skip').then(() => {
this.$refs.view.fetchQueries()
})
}
2020-09-11 14:20:06 +02:00
}
}
</script>