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';
|
2018-10-15 18:59:21 +01:00
|
|
|
import Modal from '../../mixins/modal';
|
2018-10-04 21:04:31 +01:00
|
|
|
import Component from '@ember/component';
|
|
|
|
|
2018-10-15 18:59:21 +01:00
|
|
|
export default Component.extend(Notifier, Modal, {
|
2018-10-04 21:04:31 +01:00
|
|
|
appMeta: service(),
|
2018-10-17 14:27:40 +01:00
|
|
|
router: service(),
|
2018-10-04 21:04:31 +01:00
|
|
|
browserSvc: service('browser'),
|
2018-10-17 14:27:40 +01:00
|
|
|
backupLabel: 'Backup',
|
|
|
|
backupSystemLabel: 'System Backup',
|
2018-10-10 15:13:09 +01:00
|
|
|
backupSpec: null,
|
|
|
|
backupFilename: '',
|
|
|
|
backupError: false,
|
2018-10-12 17:54:30 +01:00
|
|
|
backupSuccess: false,
|
2018-10-17 14:27:40 +01:00
|
|
|
backupRunning: false,
|
2018-10-12 17:54:30 +01:00
|
|
|
restoreSpec: null,
|
2018-10-15 18:59:21 +01:00
|
|
|
restoreButtonLabel: 'Restore',
|
2018-10-12 17:54:30 +01:00
|
|
|
restoreUploadReady: false,
|
2018-10-15 18:59:21 +01:00
|
|
|
confirmRestore: '',
|
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);
|
2018-10-15 18:59:21 +01:00
|
|
|
this.set('confirmRestore', '');
|
2018-10-17 14:27:40 +01:00
|
|
|
|
|
|
|
this.set('backupType', { Tenant: true, System: false });
|
2018-10-12 17:54:30 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-10-17 14:27:40 +01:00
|
|
|
doBackup() {
|
|
|
|
this.set('backupFilename', '');
|
|
|
|
this.set('backupSuccess', false);
|
|
|
|
this.set('backupFailed', false);
|
|
|
|
this.set('backupRunning', true);
|
|
|
|
|
|
|
|
let spec = this.get('backupSpec');
|
|
|
|
|
|
|
|
this.get('onBackup')(spec).then((filename) => {
|
2018-12-05 13:44:10 +00:00
|
|
|
this.notifySuccess('Completed');
|
2018-10-17 14:27:40 +01:00
|
|
|
this.set('backupLabel', 'Start Backup');
|
|
|
|
this.set('backupSuccess', true);
|
|
|
|
this.set('backupFilename', filename);
|
|
|
|
this.set('backupRunning', false);
|
|
|
|
}, ()=> {
|
2018-12-05 13:44:10 +00:00
|
|
|
this.notifyError('Failed');
|
2018-10-17 14:27:40 +01:00
|
|
|
this.set('backupLabel', 'Run Backup');
|
|
|
|
this.set('backupFailed', true);
|
|
|
|
this.set('backupRunning', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-10-04 21:04:31 +01:00
|
|
|
actions: {
|
|
|
|
onBackup() {
|
2018-10-17 14:27:40 +01:00
|
|
|
// We perform tenant level backup.
|
|
|
|
this.set('backupSpec.org', this.get('appMeta.orgId'));
|
2018-10-04 21:04:31 +01:00
|
|
|
|
2018-10-17 14:27:40 +01:00
|
|
|
this.doBackup();
|
|
|
|
},
|
2018-10-12 17:54:30 +01:00
|
|
|
|
2018-10-17 14:27:40 +01:00
|
|
|
onSystemBackup() {
|
|
|
|
// We perform system-level backup.
|
|
|
|
this.set('backupSpec.org', '*');
|
|
|
|
|
|
|
|
this.doBackup();
|
2018-10-12 17:54:30 +01:00
|
|
|
},
|
|
|
|
|
2018-10-15 18:59:21 +01:00
|
|
|
onShowRestoreModal() {
|
|
|
|
this.modalOpen("#confirm-restore-modal", {"show": true}, '#confirm-restore');
|
|
|
|
},
|
|
|
|
|
|
|
|
onRestore(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
let typed = this.get('confirmRestore');
|
|
|
|
typed = typed.toLowerCase();
|
|
|
|
|
|
|
|
if (typed !== 'restore' || typed === '') {
|
|
|
|
$("#confirm-restore").addClass("is-invalid").focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set('confirmRestore', '');
|
|
|
|
$("#confirm-restore").removeClass("is-invalid");
|
|
|
|
|
|
|
|
this.modalClose('#confirm-restore-modal');
|
|
|
|
|
2018-10-12 17:54:30 +01:00
|
|
|
// 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.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(() => {
|
2018-12-05 13:44:10 +00:00
|
|
|
this.notifySuccess('Completed');
|
2018-10-17 14:27:40 +01:00
|
|
|
this.set('backupLabel', 'Restore');
|
|
|
|
this.set('restoreSuccess', true);
|
|
|
|
this.get('router').transitionTo('auth.logout');
|
2018-10-12 17:54:30 +01:00
|
|
|
}, ()=> {
|
2018-12-05 13:44:10 +00:00
|
|
|
this.notifyError('Failed');
|
2018-10-17 14:27:40 +01:00
|
|
|
this.set('restorbackupLabel', 'Restore');
|
2018-10-12 17:54:30 +01:00
|
|
|
this.set('restoreFailed', true);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
upload(event) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2018-10-15 18:59:21 +01:00
|
|
|
|
|
|
|
// {{#ui/ui-checkbox selected=restoreSpec.recreateUsers}}
|
|
|
|
// Recreate user accounts — users, groups, permissions
|
|
|
|
// {{/ui/ui-checkbox}}
|