mirror of
https://github.com/documize/community.git
synced 2025-07-24 23:59:47 +02:00
[WIP] Restore process
Co-Authored-By: Harvey Kandola <harvey@documize.com>
This commit is contained in:
parent
e0457b40da
commit
71a2860716
7 changed files with 281 additions and 22 deletions
|
@ -9,6 +9,7 @@
|
|||
//
|
||||
// https://documize.com
|
||||
|
||||
import $ from 'jquery';
|
||||
import { inject as service } from '@ember/service';
|
||||
import Notifier from '../../mixins/notifier';
|
||||
import Component from '@ember/component';
|
||||
|
@ -16,20 +17,40 @@ import Component from '@ember/component';
|
|||
export default Component.extend(Notifier, {
|
||||
appMeta: service(),
|
||||
browserSvc: service('browser'),
|
||||
buttonLabel: 'Run Backup',
|
||||
buttonLabel: 'Start Backup',
|
||||
backupSpec: null,
|
||||
backupFilename: '',
|
||||
backupError: false,
|
||||
backupSuccess: false,
|
||||
backupSuccess: false,
|
||||
restoreSpec: null,
|
||||
restoreButtonLabel: 'Perform Restore',
|
||||
restoreUploading: false,
|
||||
restoreUploadReady: false,
|
||||
|
||||
didReceiveAttrs() {
|
||||
this._super(...arguments);
|
||||
this._super(...arguments);
|
||||
|
||||
this.set('backupSpec', {
|
||||
retain: false,
|
||||
// org: '*'
|
||||
retain: true,
|
||||
org: this.get('appMeta.orgId')
|
||||
});
|
||||
},
|
||||
|
||||
this.set('restoreSpec', {
|
||||
overwriteOrg: true,
|
||||
recreateUsers: true
|
||||
});
|
||||
|
||||
this.set('restoreFile', null);
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
this._super(...arguments);
|
||||
|
||||
this.$('#restore-file').on('change', function(){
|
||||
var fileName = document.getElementById("restore-file").files[0].name;
|
||||
$(this).next('.custom-file-label').html(fileName);
|
||||
});
|
||||
},
|
||||
|
||||
actions: {
|
||||
onBackup() {
|
||||
|
@ -37,17 +58,91 @@ export default Component.extend(Notifier, {
|
|||
this.set('buttonLabel', 'Please wait, backup running...');
|
||||
this.set('backupFilename', '');
|
||||
this.set('backupSuccess', false);
|
||||
this.set('backupFailed', false);
|
||||
this.set('backupFailed', false);
|
||||
|
||||
this.get('onBackup')(this.get('backupSpec')).then((filename) => {
|
||||
this.set('buttonLabel', 'Run Backup');
|
||||
// If Documize Global Admin we perform system-level backup.
|
||||
// Otherwise it is current tenant backup.
|
||||
let spec = this.get('backupSpec');
|
||||
if (this.get('session.isGlobalAdmin')) {
|
||||
spec.org = "*";
|
||||
}
|
||||
|
||||
this.get('onBackup')(spec).then((filename) => {
|
||||
this.showDone();
|
||||
this.set('buttonLabel', 'Start Backup');
|
||||
this.set('backupSuccess', true);
|
||||
this.set('backupFilename', filename);
|
||||
}, ()=> {
|
||||
this.showDone();
|
||||
this.set('buttonLabel', 'Run Backup');
|
||||
this.set('backupFailed', true);
|
||||
});
|
||||
},
|
||||
|
||||
onRestore() {
|
||||
// do we have upload file?
|
||||
// let files = document.getElementById("restore-file").files;
|
||||
// if (is.undefined(files) || is.null(files)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// let file = document.getElementById("restore-file").files[0];
|
||||
// if (is.undefined(file) || is.null(file)) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
let filedata = this.get('restoreFile');
|
||||
if (is.null(filedata)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// start restore process
|
||||
this.showWait();
|
||||
this.set('restoreButtonLabel', 'Please wait, restore running...');
|
||||
this.set('restoreSuccess', false);
|
||||
this.set('restoreFailed', false);
|
||||
|
||||
// If Documize Global Admin we perform system-level restore.
|
||||
// Otherwise it is current tenant backup.
|
||||
let spec = this.get('restoreSpec');
|
||||
if (this.get('session.isGlobalAdmin')) {
|
||||
spec.org = "*";
|
||||
}
|
||||
|
||||
this.get('onRestore')(spec, filedata).then(() => {
|
||||
this.showDone();
|
||||
this.set('buttonLabel', 'Perform Restore');
|
||||
this.set('restoreSuccess', true);
|
||||
}, ()=> {
|
||||
this.showDone();
|
||||
this.set('restorButtonLabel', 'Perform Restore');
|
||||
this.set('restoreFailed', true);
|
||||
});
|
||||
},
|
||||
|
||||
upload(event) {
|
||||
this.set('restoreUploading', true);
|
||||
this.set('restoreUploadReady', false);
|
||||
this.set('restoreFile', null);
|
||||
|
||||
// const reader = new FileReader();
|
||||
const file = event.target.files[0];
|
||||
|
||||
this.set('restoreFile', file);
|
||||
this.set('restoreUploadReady', true);
|
||||
this.set('restoreUploading', false);
|
||||
|
||||
// let imageData;
|
||||
// reader.onload = () => {
|
||||
// imageData = reader.result;
|
||||
// this.set('restoreFile', imageData);
|
||||
// this.set('restoreUploadReady', true);
|
||||
// this.set('restoreUploading', false);
|
||||
// };
|
||||
|
||||
// if (file) {
|
||||
// reader.readAsDataURL(file);
|
||||
// }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue