2018-10-04 21:04:31 +01:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
|
|
|
// This software (Documize Community Edition) is licensed under
|
|
|
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
|
|
|
//
|
|
|
|
// You can operate outside the AGPL restrictions by purchasing
|
|
|
|
// Documize Enterprise Edition and obtaining a commercial license
|
|
|
|
// by contacting <sales@documize.com>.
|
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
2018-10-12 17:54:30 +01:00
|
|
|
import $ from 'jquery';
|
2018-10-04 21:04:31 +01:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import Notifier from '../../mixins/notifier';
|
|
|
|
import Component from '@ember/component';
|
|
|
|
|
|
|
|
export default Component.extend(Notifier, {
|
|
|
|
appMeta: service(),
|
|
|
|
browserSvc: service('browser'),
|
2018-10-12 17:54:30 +01:00
|
|
|
buttonLabel: 'Start Backup',
|
2018-10-10 15:13:09 +01:00
|
|
|
backupSpec: null,
|
|
|
|
backupFilename: '',
|
|
|
|
backupError: false,
|
2018-10-12 17:54:30 +01:00
|
|
|
backupSuccess: false,
|
|
|
|
restoreSpec: null,
|
|
|
|
restoreButtonLabel: 'Perform Restore',
|
|
|
|
restoreUploading: false,
|
|
|
|
restoreUploadReady: false,
|
2018-10-10 15:13:09 +01:00
|
|
|
|
|
|
|
didReceiveAttrs() {
|
2018-10-12 17:54:30 +01:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2018-10-10 15:13:09 +01:00
|
|
|
this.set('backupSpec', {
|
2018-10-12 17:54:30 +01:00
|
|
|
retain: true,
|
2018-10-11 16:19:11 +01:00
|
|
|
org: this.get('appMeta.orgId')
|
2018-10-10 15:13:09 +01:00
|
|
|
});
|
2018-10-12 17:54:30 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
},
|
2018-10-04 21:04:31 +01:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
onBackup() {
|
|
|
|
this.showWait();
|
|
|
|
this.set('buttonLabel', 'Please wait, backup running...');
|
2018-10-10 15:13:09 +01:00
|
|
|
this.set('backupFilename', '');
|
|
|
|
this.set('backupSuccess', false);
|
2018-10-12 17:54:30 +01:00
|
|
|
this.set('backupFailed', false);
|
2018-10-04 21:04:31 +01:00
|
|
|
|
2018-10-12 17:54:30 +01:00
|
|
|
// 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) => {
|
2018-10-04 21:04:31 +01:00
|
|
|
this.showDone();
|
2018-10-12 17:54:30 +01:00
|
|
|
this.set('buttonLabel', 'Start Backup');
|
2018-10-10 15:13:09 +01:00
|
|
|
this.set('backupSuccess', true);
|
|
|
|
this.set('backupFilename', filename);
|
|
|
|
}, ()=> {
|
2018-10-12 17:54:30 +01:00
|
|
|
this.showDone();
|
2018-10-10 15:13:09 +01:00
|
|
|
this.set('buttonLabel', 'Run Backup');
|
|
|
|
this.set('backupFailed', true);
|
2018-10-04 21:04:31 +01:00
|
|
|
});
|
2018-10-12 17:54:30 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
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);
|
|
|
|
// }
|
2018-10-04 21:04:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|