Migration Improvements (#47)

Make "migration" "import everywhere"

Add checking for migration status before trying to migrate

Add get status from migrations

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: vikunja/frontend#47
This commit is contained in:
konrad 2020-01-20 21:22:32 +00:00
parent 9b232c7d4f
commit d61a7511da
4 changed files with 50 additions and 9 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="content"> <div class="content">
<h1>Migrate your data from other services to Vikunja</h1> <h1>Import your data from other services to Vikunja</h1>
<p>Click on the logo of one of the third-party services below to get started.</p> <p>Click on the logo of one of the third-party services below to get started.</p>
<div class="migration-services-overview"> <div class="migration-services-overview">
<router-link :to="{name: 'migrateWunderlist'}"> <router-link :to="{name: 'migrateWunderlist'}">

View File

@ -2,11 +2,11 @@
<div class="content"> <div class="content">
<h1>Import your data from Wunderlist to Vikunja</h1> <h1>Import your data from Wunderlist to Vikunja</h1>
<p>Vikunja will import all folders, lists, tasks, notes, reminders and files you have access to.</p> <p>Vikunja will import all folders, lists, tasks, notes, reminders and files you have access to.</p>
<template v-if="isMigrating === false && message === ''"> <template v-if="isMigrating === false && message === '' && lastMigrationDate === 0">
<p>To authorize Vikunja to access your Wunderlist Account, click the button below.</p> <p>To authorize Vikunja to access your Wunderlist Account, click the button below.</p>
<a :href="authUrl" class="button is-primary" :class="{'is-loading': migrationService.loading}" :disabled="migrationService.loading">Get Started</a> <a :href="authUrl" class="button is-primary" :class="{'is-loading': migrationService.loading}" :disabled="migrationService.loading">Get Started</a>
</template> </template>
<div class="migration-in-progress-container" v-else-if="isMigrating === true && message === ''"> <div class="migration-in-progress-container" v-else-if="isMigrating === true && message === '' && lastMigrationDate === 0">
<div class="migration-in-progress"> <div class="migration-in-progress">
<img src="/images/migration/wunderlist.png" alt="Wunderlist Logo"/> <img src="/images/migration/wunderlist.png" alt="Wunderlist Logo"/>
<div class="progress-dots"> <div class="progress-dots">
@ -21,7 +21,18 @@
</div> </div>
<img src="/images/logo.svg" alt="Vikunja Logo"> <img src="/images/logo.svg" alt="Vikunja Logo">
</div> </div>
<p>Migration in progress, hang tight...</p> <p>Importing in progress, hang tight...</p>
</div>
<div v-else-if="lastMigrationDate > 0">
<p>
It looks like you've already imported your stuff from wunderlist at {{ new Date(lastMigrationDate * 1000) }}.<br/>
Importing again is possible, but might create duplicates.
Are you sure?
</p>
<div class="buttons">
<button class="button is-primary" @click="migrate">I am sure, please start migrating now!</button>
<router-link :to="{name: 'home'}" class="button is-danger is-outlined">Cancel</router-link>
</div>
</div> </div>
<div v-else> <div v-else>
<div class="message is-primary"> <div class="message is-primary">
@ -45,6 +56,7 @@
migrationService: WunderlistMigrationService, migrationService: WunderlistMigrationService,
authUrl: '', authUrl: '',
isMigrating: false, isMigrating: false,
lastMigrationDate: 0,
message: '', message: '',
wunderlistCode: '', wunderlistCode: '',
} }
@ -55,9 +67,18 @@
this.message = '' this.message = ''
if(typeof this.$route.query.code !== 'undefined') { if(typeof this.$route.query.code !== 'undefined') {
this.isMigrating = true
this.wunderlistCode = this.$route.query.code this.wunderlistCode = this.$route.query.code
this.migrate() this.migrationService.getStatus()
.then(r => {
if(r.time_unix > 0) {
this.lastMigrationDate = r.time_unix
return
}
this.migrate()
})
.catch(e => {
message.error(e, this)
})
} }
}, },
methods: { methods: {
@ -71,6 +92,8 @@
}) })
}, },
migrate() { migrate() {
this.isMigrating = true
this.lastMigrationDate = 0
this.migrationService.migrate({code: this.wunderlistCode}) this.migrationService.migrate({code: this.wunderlistCode})
.then(r => { .then(r => {
this.message = r.message this.message = r.message

View File

@ -282,9 +282,21 @@ export default class AbstractService {
return Promise.reject({message: 'This model is not able to get data.'}) return Promise.reject({message: 'This model is not able to get data.'})
} }
return this.getM(this.paths.get, model, params)
}
/**
* This is a more abstract implementation which only does a get request.
* Services which need more flexibility can use this.
* @param url
* @param model
* @param params
* @returns {Q.Promise<unknown>}
*/
getM(url, model = {}, params = {}) {
const cancel = this.setLoading() const cancel = this.setLoading()
model = this.beforeGet(model) model = this.beforeGet(model)
return this.http.get(this.getReplacedRoute(this.paths.get, model), {params: params}) return this.http.get(this.getReplacedRoute(url, model), {params: params})
.catch(error => { .catch(error => {
return this.errorHandler(error) return this.errorHandler(error)
}) })

View File

@ -3,15 +3,21 @@ import AbstractService from '../abstractService'
// This service builds on top of the abstract service and basically just hides away method names. // This service builds on top of the abstract service and basically just hides away method names.
// It enables migration services to be created with minimal overhead and even better method names. // It enables migration services to be created with minimal overhead and even better method names.
export default class AbstractMigrationService extends AbstractService { export default class AbstractMigrationService extends AbstractService {
serviceUrlKey = ''
constructor(serviceUrlKey) { constructor(serviceUrlKey) {
super({ super({
update: '/migration/'+serviceUrlKey+'/migrate', update: '/migration/'+serviceUrlKey+'/migrate',
get: '/migration/'+serviceUrlKey+'/auth',
}) })
this.serviceUrlKey = serviceUrlKey
} }
getAuthUrl() { getAuthUrl() {
return this.get({}) return this.getM('/migration/'+this.serviceUrlKey+'/auth')
}
getStatus() {
return this.getM('/migration/'+this.serviceUrlKey+'/status')
} }
migrate(data) { migrate(data) {