2020-01-19 19:23:06 +00:00
|
|
|
<template>
|
|
|
|
<div class="content">
|
2021-09-04 19:26:38 +00:00
|
|
|
<h1>{{ $t('migrate.titleService', {name: name}) }}</h1>
|
2021-06-23 23:24:57 +00:00
|
|
|
<p>{{ $t('migrate.descriptionDo') }}</p>
|
2020-07-05 15:31:15 +00:00
|
|
|
<template v-if="isMigrating === false && message === '' && lastMigrationDate === null">
|
2021-09-04 19:26:38 +00:00
|
|
|
<template v-if="isFileMigrator">
|
|
|
|
<p>{{ $t('migrate.importUpload', {name: name}) }}</p>
|
|
|
|
<input
|
|
|
|
@change="migrate"
|
|
|
|
class="is-hidden"
|
|
|
|
ref="uploadInput"
|
|
|
|
type="file"
|
|
|
|
/>
|
|
|
|
<x-button
|
|
|
|
:loading="migrationService.loading"
|
|
|
|
:disabled="migrationService.loading"
|
|
|
|
@click="$refs.uploadInput.click()"
|
|
|
|
>
|
|
|
|
{{ $t('migrate.upload') }}
|
|
|
|
</x-button>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<p>{{ $t('migrate.authorize', {name: name}) }}</p>
|
|
|
|
<x-button
|
|
|
|
:loading="migrationService.loading"
|
|
|
|
:disabled="migrationService.loading"
|
|
|
|
:href="authUrl"
|
|
|
|
>
|
|
|
|
{{ $t('migrate.getStarted') }}
|
|
|
|
</x-button>
|
|
|
|
</template>
|
2020-01-19 19:23:06 +00:00
|
|
|
</template>
|
2020-07-05 15:31:15 +00:00
|
|
|
<div
|
2020-09-05 20:35:52 +00:00
|
|
|
class="migration-in-progress-container"
|
|
|
|
v-else-if="isMigrating === true && message === '' && lastMigrationDate === null">
|
2020-01-19 19:23:06 +00:00
|
|
|
<div class="migration-in-progress">
|
2021-10-03 18:48:02 +00:00
|
|
|
<img :alt="name" :src="serviceIconSource"/>
|
2020-01-19 19:23:06 +00:00
|
|
|
<div class="progress-dots">
|
2021-09-08 21:45:28 +00:00
|
|
|
<span v-for="i in progressDotsCount" :key="i" />
|
2020-01-19 19:23:06 +00:00
|
|
|
</div>
|
2021-10-03 18:48:02 +00:00
|
|
|
<img alt="Vikunja" :src="logoUrl">
|
2020-01-19 19:23:06 +00:00
|
|
|
</div>
|
2021-06-23 23:24:57 +00:00
|
|
|
<p>{{ $t('migrate.inProgress') }}</p>
|
2020-01-20 21:22:32 +00:00
|
|
|
</div>
|
2020-05-24 13:49:58 +00:00
|
|
|
<div v-else-if="lastMigrationDate">
|
2020-01-20 21:22:32 +00:00
|
|
|
<p>
|
2021-09-04 19:26:38 +00:00
|
|
|
{{ $t('migrate.alreadyMigrated1', {name: name, date: formatDate(lastMigrationDate)}) }}<br/>
|
2021-06-23 23:24:57 +00:00
|
|
|
{{ $t('migrate.alreadyMigrated2') }}
|
2020-01-20 21:22:32 +00:00
|
|
|
</p>
|
|
|
|
<div class="buttons">
|
2021-06-23 23:24:57 +00:00
|
|
|
<x-button @click="migrate">{{ $t('migrate.confirm') }}</x-button>
|
|
|
|
<x-button :to="{name: 'home'}" type="tertary" class="has-text-danger">{{ $t('misc.cancel') }}</x-button>
|
2020-01-20 21:22:32 +00:00
|
|
|
</div>
|
2020-01-19 19:23:06 +00:00
|
|
|
</div>
|
|
|
|
<div v-else>
|
|
|
|
<div class="message is-primary">
|
|
|
|
<div class="message-body">
|
|
|
|
{{ message }}
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-23 23:24:57 +00:00
|
|
|
<x-button :to="{name: 'home'}">{{ $t('misc.refresh') }}</x-button>
|
2020-01-19 19:23:06 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-09-04 19:26:38 +00:00
|
|
|
import AbstractMigrationService from '../../services/migrator/abstractMigration'
|
|
|
|
import AbstractMigrationFileService from '../../services/migrator/abstractMigrationFile'
|
2021-10-03 18:48:02 +00:00
|
|
|
import {SERVICE_ICONS} from '../../helpers/migrator'
|
|
|
|
|
|
|
|
import logoUrl from '@/assets/logo.svg'
|
2020-01-19 19:23:06 +00:00
|
|
|
|
2021-09-08 21:45:28 +00:00
|
|
|
const PROGRESS_DOTS_COUNT = 8
|
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
export default {
|
|
|
|
name: 'migration',
|
|
|
|
data() {
|
|
|
|
return {
|
2021-09-08 21:45:28 +00:00
|
|
|
progressDotsCount: PROGRESS_DOTS_COUNT,
|
2020-09-05 20:35:52 +00:00
|
|
|
authUrl: '',
|
|
|
|
isMigrating: false,
|
|
|
|
lastMigrationDate: null,
|
|
|
|
message: '',
|
2020-12-17 13:44:22 +00:00
|
|
|
migratorAuthCode: '',
|
2021-09-08 21:45:28 +00:00
|
|
|
migrationService: null,
|
2021-10-03 18:48:02 +00:00
|
|
|
logoUrl,
|
2020-09-05 20:35:52 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
2020-01-19 19:23:06 +00:00
|
|
|
},
|
2020-09-05 20:35:52 +00:00
|
|
|
identifier: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
2020-05-24 13:31:27 +00:00
|
|
|
},
|
2021-09-04 19:26:38 +00:00
|
|
|
isFileMigrator: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-09-05 20:35:52 +00:00
|
|
|
},
|
2021-10-03 18:48:02 +00:00
|
|
|
computed: {
|
|
|
|
serviceIconSource() {
|
|
|
|
return SERVICE_ICONS[this.identifier]()
|
|
|
|
},
|
|
|
|
},
|
2020-09-05 20:35:52 +00:00
|
|
|
created() {
|
2021-09-04 19:26:38 +00:00
|
|
|
this.message = ''
|
|
|
|
|
|
|
|
if (this.isFileMigrator) {
|
|
|
|
this.migrationService = new AbstractMigrationFileService(this.identifier)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-05 20:35:52 +00:00
|
|
|
this.migrationService = new AbstractMigrationService(this.identifier)
|
|
|
|
this.getAuthUrl()
|
2020-01-19 19:23:06 +00:00
|
|
|
|
2020-12-17 13:44:22 +00:00
|
|
|
if (typeof this.$route.query.code !== 'undefined' || location.hash.startsWith('#token=')) {
|
|
|
|
if (location.hash.startsWith('#token=')) {
|
|
|
|
this.migratorAuthCode = location.hash.substring(7)
|
2021-04-25 16:01:17 +00:00
|
|
|
console.debug(location.hash.substring(7))
|
2020-12-17 13:44:22 +00:00
|
|
|
} else {
|
|
|
|
this.migratorAuthCode = this.$route.query.code
|
|
|
|
}
|
2020-09-05 20:35:52 +00:00
|
|
|
this.migrationService.getStatus()
|
|
|
|
.then(r => {
|
|
|
|
if (r.time) {
|
2020-12-17 13:44:22 +00:00
|
|
|
if (typeof r.time === 'string' && r.time.startsWith('0001-')) {
|
|
|
|
this.lastMigrationDate = null
|
|
|
|
} else {
|
|
|
|
this.lastMigrationDate = new Date(r.time)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.lastMigrationDate) {
|
|
|
|
return
|
|
|
|
}
|
2020-09-05 20:35:52 +00:00
|
|
|
}
|
|
|
|
this.migrate()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-10-11 17:37:20 +00:00
|
|
|
async getAuthUrl() {
|
|
|
|
const { url } = this.migrationService.getAuthUrl()
|
|
|
|
this.authUrl = url
|
2020-01-19 19:23:06 +00:00
|
|
|
},
|
2021-10-11 17:37:20 +00:00
|
|
|
|
|
|
|
async migrate() {
|
2020-09-05 20:35:52 +00:00
|
|
|
this.isMigrating = true
|
2020-12-17 13:44:22 +00:00
|
|
|
this.lastMigrationDate = null
|
|
|
|
this.message = ''
|
2021-09-04 19:26:38 +00:00
|
|
|
|
2021-10-11 17:37:20 +00:00
|
|
|
let migrationConfig = { code: this.migratorAuthCode }
|
|
|
|
|
2021-09-04 19:26:38 +00:00
|
|
|
if (this.isFileMigrator) {
|
2021-10-11 17:37:20 +00:00
|
|
|
if (this.$refs.uploadInput.files.length === 0) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
migrationConfig = this.$refs.uploadInput.files[0]
|
2021-09-04 19:26:38 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 17:37:20 +00:00
|
|
|
try {
|
|
|
|
const { message } = await this.migrationService.migrate(migrationConfig)
|
|
|
|
this.message = message
|
|
|
|
return this.$store.dispatch('namespaces/loadNamespaces')
|
|
|
|
} finally {
|
|
|
|
this.isMigrating = false
|
2021-09-04 19:26:38 +00:00
|
|
|
}
|
|
|
|
},
|
2020-09-05 20:35:52 +00:00
|
|
|
},
|
|
|
|
}
|
2020-01-19 19:23:06 +00:00
|
|
|
</script>
|