mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Port Restore dialog to React. Fixes #7018
This commit is contained in:
committed by
Akshay Joshi
parent
262dcdcf54
commit
603d91be0e
@@ -7,16 +7,18 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import { getNodeListByName } from '../../../../browser/static/js/node_ajax';
|
||||
import {getUtilityView} from '../../../../browser/static/js/utility_view';
|
||||
import Notify from '../../../../static/js/helpers/Notifier';
|
||||
import getApiInstance from 'sources/api_instance';
|
||||
import {retrieveAncestorOfTypeServer} from 'sources/tree/tree_utils';
|
||||
import RestoreSchema, {getRestoreSaveOptSchema, getRestoreQueryOptionSchema, getRestoreDisableOptionSchema, getRestoreMiscellaneousSchema, getRestoreTypeObjSchema, getRestoreSectionSchema} from './restore.ui';
|
||||
|
||||
define('tools.restore', [
|
||||
'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'backbone',
|
||||
'pgadmin.alertifyjs', 'pgadmin.browser',
|
||||
'pgadmin.backgrid', 'pgadmin.backform', 'sources/utils',
|
||||
'tools/restore/static/js/menu_utils',
|
||||
'sources/nodes/supported_database_node',
|
||||
'tools/restore/static/js/restore_dialog',
|
||||
'sources/gettext', 'sources/url_for', 'pgadmin.browser',
|
||||
'tools/restore/static/js/menu_utils', 'sources/nodes/supported_database_node',
|
||||
], function(
|
||||
gettext, url_for, $, _, Backbone, alertify, pgBrowser, Backgrid, Backform,
|
||||
commonUtils, menuUtils, supportedNodes, restoreDialog
|
||||
gettext, url_for, pgBrowser, menuUtils, supportedNodes
|
||||
) {
|
||||
|
||||
// if module is already initialized, refer to that.
|
||||
@@ -24,360 +26,6 @@ define('tools.restore', [
|
||||
return pgBrowser.Restore;
|
||||
}
|
||||
|
||||
//Restore Model (Objects like Database/Schema/Table)
|
||||
var RestoreObjectModel = Backbone.Model.extend({
|
||||
idAttribute: 'id',
|
||||
defaults: {
|
||||
custom: false,
|
||||
file: undefined,
|
||||
role: undefined,
|
||||
format: 'custom',
|
||||
verbose: true,
|
||||
blobs: true,
|
||||
encoding: undefined,
|
||||
database: undefined,
|
||||
schemas: undefined,
|
||||
tables: undefined,
|
||||
functions: undefined,
|
||||
triggers: undefined,
|
||||
trigger_funcs: undefined,
|
||||
indexes: undefined,
|
||||
},
|
||||
|
||||
// Default values!
|
||||
initialize: function(attrs) {
|
||||
// Set default options according to node type selection by user
|
||||
var node_type = attrs.node_data.type;
|
||||
|
||||
if (node_type) {
|
||||
// Only_Schema option
|
||||
if (node_type === 'function' || node_type === 'index' ||
|
||||
node_type === 'trigger') {
|
||||
this.set({
|
||||
'only_schema': true,
|
||||
}, {
|
||||
silent: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Only_Data option
|
||||
if (node_type === 'table') {
|
||||
this.set({
|
||||
'only_data': true,
|
||||
}, {
|
||||
silent: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Clean option
|
||||
if (node_type === 'function' || node_type === 'trigger_function') {
|
||||
this.set({
|
||||
'clean': true,
|
||||
}, {
|
||||
silent: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
Backbone.Model.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
schema: [{
|
||||
id: 'format',
|
||||
label: gettext('Format'),
|
||||
type: 'text',
|
||||
disabled: false,
|
||||
control: 'select2',
|
||||
select2: {
|
||||
allowClear: false,
|
||||
width: '100%',
|
||||
},
|
||||
options: [{
|
||||
label: gettext('Custom or tar'),
|
||||
value: 'custom',
|
||||
},
|
||||
{
|
||||
label: gettext('Directory'),
|
||||
value: 'directory',
|
||||
},
|
||||
],
|
||||
}, {
|
||||
id: 'file',
|
||||
label: gettext('Filename'),
|
||||
type: 'text',
|
||||
disabled: false,
|
||||
control: Backform.FileControl.extend({
|
||||
render: function() {
|
||||
var attributes = this.model.toJSON();
|
||||
if (attributes.format == 'directory') {
|
||||
this.field.attributes.dialog_type = 'select_folder';
|
||||
}
|
||||
else {
|
||||
this.field.attributes.dialog_type = 'select_file';
|
||||
}
|
||||
|
||||
Backform.InputControl.prototype.render.apply(this, arguments);
|
||||
return this;
|
||||
},
|
||||
}),
|
||||
dialog_type: 'select_file',
|
||||
supp_types: ['*', 'backup', 'sql', 'patch'],
|
||||
deps: ['format'],
|
||||
}, {
|
||||
id: 'no_of_jobs',
|
||||
label: gettext('Number of jobs'),
|
||||
type: 'int',
|
||||
}, {
|
||||
id: 'role',
|
||||
label: gettext('Role name'),
|
||||
control: 'node-list-by-name',
|
||||
node: 'role',
|
||||
select2: {
|
||||
allowClear: false,
|
||||
},
|
||||
}, {
|
||||
type: 'nested',
|
||||
control: 'fieldset',
|
||||
label: gettext('Sections'),
|
||||
group: gettext('Restore options'),
|
||||
contentClass: 'row',
|
||||
schema: [{
|
||||
id: 'pre_data',
|
||||
label: gettext('Pre-data'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
group: gettext('Sections'),
|
||||
deps: ['only_data', 'only_schema'],
|
||||
disabled: function(m) {
|
||||
return this.node.type !== 'function' && this.node.type !== 'table' &&
|
||||
this.node.type !== 'trigger' &&
|
||||
this.node.type !== 'trigger_function' &&
|
||||
(m.get('only_data') || m.get('only_schema'));
|
||||
},
|
||||
}, {
|
||||
id: 'data',
|
||||
label: gettext('Data'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
group: gettext('Sections'),
|
||||
deps: ['only_data', 'only_schema'],
|
||||
disabled: function(m) {
|
||||
return this.node.type !== 'function' && this.node.type !== 'table' &&
|
||||
this.node.type !== 'trigger' &&
|
||||
this.node.type !== 'trigger_function' &&
|
||||
(m.get('only_data') || m.get('only_schema'));
|
||||
},
|
||||
}, {
|
||||
id: 'post_data',
|
||||
label: gettext('Post-data'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
group: gettext('Sections'),
|
||||
deps: ['only_data', 'only_schema'],
|
||||
disabled: function(m) {
|
||||
return this.node.type !== 'function' && this.node.type !== 'table' &&
|
||||
this.node.type !== 'trigger' &&
|
||||
this.node.type !== 'trigger_function' &&
|
||||
(m.get('only_data') || m.get('only_schema'));
|
||||
},
|
||||
}],
|
||||
}, {
|
||||
type: 'nested',
|
||||
control: 'fieldset',
|
||||
label: gettext('Type of objects'),
|
||||
group: gettext('Restore options'),
|
||||
contentClass: 'row',
|
||||
schema: [{
|
||||
id: 'only_data',
|
||||
label: gettext('Only data'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
group: gettext('Type of objects'),
|
||||
deps: ['pre_data', 'data', 'post_data', 'only_schema'],
|
||||
disabled: function(m) {
|
||||
return (this.node.type !== 'database' && this.node.type !== 'schema') ||
|
||||
(m.get('pre_data') ||
|
||||
m.get('data') ||
|
||||
m.get('post_data') ||
|
||||
m.get('only_schema')
|
||||
);
|
||||
},
|
||||
}, {
|
||||
id: 'only_schema',
|
||||
label: gettext('Only schema'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
group: gettext('Type of objects'),
|
||||
deps: ['pre_data', 'data', 'post_data', 'only_data'],
|
||||
disabled: function(m) {
|
||||
return (this.node.type !== 'database' && this.node.type !== 'schema') ||
|
||||
(m.get('pre_data') ||
|
||||
m.get('data') ||
|
||||
m.get('post_data') ||
|
||||
m.get('only_data')
|
||||
);
|
||||
},
|
||||
}],
|
||||
}, {
|
||||
type: 'nested',
|
||||
control: 'fieldset',
|
||||
label: gettext('Do not save'),
|
||||
group: gettext('Restore options'),
|
||||
contentClass: 'row',
|
||||
schema: [{
|
||||
id: 'dns_owner',
|
||||
label: gettext('Owner'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
disabled: false,
|
||||
group: gettext('Do not save'),
|
||||
}, {
|
||||
id: 'dns_privilege',
|
||||
label: gettext('Privilege'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
disabled: false,
|
||||
group: gettext('Do not save'),
|
||||
}, {
|
||||
id: 'dns_tablespace',
|
||||
label: gettext('Tablespace'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
disabled: false,
|
||||
group: gettext('Do not save'),
|
||||
}, {
|
||||
id: 'no_comments',
|
||||
label: gettext('Comments'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
disabled: false,
|
||||
group: gettext('Do not save'),
|
||||
visible: function() {
|
||||
var t = pgBrowser.tree,
|
||||
i = t.selected(),
|
||||
d = i ? t.itemData(i) : undefined,
|
||||
s = _.isUndefined(d) ? undefined : pgBrowser.tree.getTreeNodeHierarchy(i)['server'];
|
||||
|
||||
return _.isUndefined(s) ? false : s.version >= 110000;
|
||||
},
|
||||
}],
|
||||
}, {
|
||||
type: 'nested',
|
||||
control: 'fieldset',
|
||||
label: gettext('Queries'),
|
||||
group: gettext('Restore options'),
|
||||
contentClass: 'row',
|
||||
schema: [{
|
||||
id: 'include_create_database',
|
||||
label: gettext('Include CREATE DATABASE statement'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
disabled: false,
|
||||
group: gettext('Queries'),
|
||||
}, {
|
||||
id: 'clean',
|
||||
label: gettext('Clean before restore'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
group: gettext('Queries'),
|
||||
disabled: function() {
|
||||
return this.node.type === 'function' ||
|
||||
this.node.type === 'trigger_function';
|
||||
},
|
||||
}, {
|
||||
id: 'single_transaction',
|
||||
label: gettext('Single transaction'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
disabled: false,
|
||||
group: gettext('Queries'),
|
||||
}],
|
||||
}, {
|
||||
type: 'nested',
|
||||
control: 'fieldset',
|
||||
label: gettext('Disable'),
|
||||
group: gettext('Restore options'),
|
||||
contentClass: 'row',
|
||||
schema: [{
|
||||
id: 'disable_trigger',
|
||||
label: gettext('Trigger'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
group: gettext('Disable'),
|
||||
}, {
|
||||
id: 'no_data_fail_table',
|
||||
label: gettext('No data for Failed Tables'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
disabled: false,
|
||||
group: gettext('Disable'),
|
||||
}],
|
||||
}, {
|
||||
type: 'nested',
|
||||
control: 'fieldset',
|
||||
label: gettext('Miscellaneous / Behavior'),
|
||||
group: gettext('Restore options'),
|
||||
contentClass: 'row',
|
||||
schema: [{
|
||||
id: 'verbose',
|
||||
label: gettext('Verbose messages'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
disabled: false,
|
||||
group: gettext('Miscellaneous / Behavior'),
|
||||
}, {
|
||||
id: 'use_set_session_auth',
|
||||
label: gettext('Use SET SESSION AUTHORIZATION'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
disabled: false,
|
||||
group: gettext('Miscellaneous / Behavior'),
|
||||
}, {
|
||||
id: 'exit_on_error',
|
||||
label: gettext('Exit on error'),
|
||||
type: 'switch',
|
||||
extraToggleClasses: 'pg-el-sm-6',
|
||||
controlLabelClassName: 'control-label pg-el-sm-5 pg-el-12',
|
||||
controlsClassName: 'pgadmin-controls pg-el-sm-7 pg-el-12',
|
||||
disabled: false,
|
||||
group: gettext('Miscellaneous / Behavior'),
|
||||
}],
|
||||
}],
|
||||
validate: function() {
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
// Create an Object Restore of pgBrowser class
|
||||
pgBrowser.Restore = {
|
||||
init: function() {
|
||||
@@ -391,7 +39,7 @@ define('tools.restore', [
|
||||
name: 'restore_object',
|
||||
module: this,
|
||||
applies: ['tools'],
|
||||
callback: 'restore_objects',
|
||||
callback: 'restoreObjects',
|
||||
priority: 2,
|
||||
label: gettext('Restore...'),
|
||||
icon: 'fa fa-upload',
|
||||
@@ -410,8 +58,8 @@ define('tools.restore', [
|
||||
node: menuUtils.restoreSupportedNodes[idx],
|
||||
module: this,
|
||||
applies: ['context'],
|
||||
callback: 'restore_objects',
|
||||
priority: 13,
|
||||
callback: 'restoreObjects',
|
||||
priority: 2,
|
||||
label: gettext('Restore...'),
|
||||
icon: 'fa fa-upload',
|
||||
enable: supportedNodes.enabled.bind(
|
||||
@@ -423,12 +71,109 @@ define('tools.restore', [
|
||||
pgBrowser.add_menus(menus);
|
||||
return this;
|
||||
},
|
||||
// Callback to draw Backup Dialog for objects
|
||||
restore_objects: function(action, treeItem) {
|
||||
let dialog = new restoreDialog.RestoreDialog(
|
||||
pgBrowser, $, alertify, RestoreObjectModel
|
||||
getUISchema: function(treeItem) {
|
||||
let treeNodeInfo = pgBrowser.tree.getTreeNodeHierarchy(treeItem);
|
||||
const selectedNode = pgBrowser.tree.selected();
|
||||
let itemNodeData = pgBrowser.tree.findNodeByDomElement(selectedNode).getData();
|
||||
|
||||
return new RestoreSchema(
|
||||
()=>getRestoreSectionSchema({selectedNodeType: itemNodeData._type}),
|
||||
()=>getRestoreTypeObjSchema({selectedNodeType: itemNodeData._type}),
|
||||
()=>getRestoreSaveOptSchema({nodeInfo: treeNodeInfo}),
|
||||
()=>getRestoreQueryOptionSchema({nodeInfo: treeNodeInfo}),
|
||||
()=>getRestoreDisableOptionSchema({nodeInfo: treeNodeInfo}),
|
||||
()=>getRestoreMiscellaneousSchema({nodeInfo: treeNodeInfo}),
|
||||
{
|
||||
role: ()=>getNodeListByName('role', treeNodeInfo, itemNodeData)
|
||||
},
|
||||
treeNodeInfo,
|
||||
pgBrowser
|
||||
);
|
||||
dialog.draw(action, treeItem, pgBrowser.stdW.calc(pgBrowser.stdW.md), pgBrowser.stdH.calc(pgBrowser.stdH.md));
|
||||
},
|
||||
saveCallBack: function(data, dialog) {
|
||||
if(data.errormsg) {
|
||||
Notify.alert(
|
||||
gettext('Utility not found'),
|
||||
gettext(data.errormsg)
|
||||
);
|
||||
} else {
|
||||
pgBrowser.Events.trigger('pgadmin-bgprocess:created', dialog);
|
||||
}
|
||||
},
|
||||
setExtraParameters: function(treeInfo, nodeData) {
|
||||
var extraData = {};
|
||||
extraData['database'] = treeInfo.database._label;
|
||||
|
||||
if('schema' in treeInfo) {
|
||||
extraData['schemas'] = treeInfo.schema._label;
|
||||
}
|
||||
|
||||
if('table' in treeInfo) {
|
||||
extraData['tables'] = [nodeData._label];
|
||||
}
|
||||
|
||||
if('function' in treeInfo) {
|
||||
extraData['functions'] = [nodeData._label];
|
||||
}
|
||||
return extraData;
|
||||
},
|
||||
url_for_utility_exists: function(id){
|
||||
return url_for('restore.utility_exists', {
|
||||
'sid': id,
|
||||
});
|
||||
},
|
||||
restoreObjects: function(action, treeItem) {
|
||||
var that = this,
|
||||
tree = pgBrowser.tree,
|
||||
i = treeItem || tree.selected(),
|
||||
data = i ? tree.itemData(i) : undefined,
|
||||
treeNodeInfo = pgBrowser.tree.getTreeNodeHierarchy(treeItem);
|
||||
|
||||
const serverInformation = retrieveAncestorOfTypeServer(pgBrowser, treeItem, gettext('Restore Error')),
|
||||
sid = serverInformation._type == 'database' ? serverInformation._pid : serverInformation._id,
|
||||
api = getApiInstance(),
|
||||
utility_exists_url = that.url_for_utility_exists(sid);
|
||||
|
||||
return api({
|
||||
url: utility_exists_url,
|
||||
method: 'GET'
|
||||
}).then((res)=>{
|
||||
if (!res.data.success) {
|
||||
Notify.alert(
|
||||
gettext('Utility not found'),
|
||||
gettext(res.data.errormsg)
|
||||
);
|
||||
return;
|
||||
}
|
||||
pgBrowser.Node.registerUtilityPanel();
|
||||
var panel = pgBrowser.Node.addUtilityPanel(),
|
||||
j = panel.$container.find('.obj_properties').first();
|
||||
|
||||
var schema = that.getUISchema(treeItem);
|
||||
panel.title(gettext(`Restore (${pgBrowser.Nodes[data._type].label}: ${data.label})`));
|
||||
panel.focus();
|
||||
|
||||
let urlShortcut = 'restore.create_job',
|
||||
baseUrl = url_for(urlShortcut, {
|
||||
'sid': sid,
|
||||
}),
|
||||
extraData = that.setExtraParameters(treeNodeInfo, data);
|
||||
|
||||
var sqlHelpUrl = 'restore.html',
|
||||
helpUrl = url_for('help.static', {
|
||||
'filename': 'restore_dialog.html',
|
||||
});
|
||||
|
||||
getUtilityView(
|
||||
schema, treeNodeInfo, 'select', 'dialog', j[0], panel, that.saveCallBack, extraData, 'Restore', baseUrl, sqlHelpUrl, helpUrl);
|
||||
|
||||
}).catch(()=>{
|
||||
Notify.alert(
|
||||
gettext('Utility not found'),
|
||||
gettext('Failed to fetch Utility information')
|
||||
);
|
||||
return;
|
||||
});
|
||||
},
|
||||
};
|
||||
return pgBrowser.Restore;
|
||||
|
||||
460
web/pgadmin/tools/restore/static/js/restore.ui.js
Normal file
460
web/pgadmin/tools/restore/static/js/restore.ui.js
Normal file
@@ -0,0 +1,460 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
|
||||
import gettext from 'sources/gettext';
|
||||
import { isEmptyString } from 'sources/validators';
|
||||
|
||||
export class RestoreSectionSchema extends BaseUISchema {
|
||||
constructor(fieldOptions={}) {
|
||||
super();
|
||||
|
||||
this.fieldOptions = {
|
||||
selectedNodeType: undefined,
|
||||
...fieldOptions,
|
||||
};
|
||||
|
||||
this.selectedNodeType = this.fieldOptions.selectedNodeType;
|
||||
}
|
||||
|
||||
get idAttribute() {
|
||||
return 'id';
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
let obj = this;
|
||||
return [{
|
||||
id: 'pre_data',
|
||||
label: gettext('Pre-data'),
|
||||
type: 'switch',
|
||||
group: gettext('Sections'),
|
||||
deps: ['only_data', 'only_schema'],
|
||||
disabled: function(state) {
|
||||
return obj.selectedNodeType !== 'function' && obj.selectedNodeType !== 'table' &&
|
||||
obj.selectedNodeType !== 'trigger' &&
|
||||
obj.selectedNodeType !== 'trigger_function' &&
|
||||
(state.only_data || state.only_schema);
|
||||
},
|
||||
}, {
|
||||
id: 'data',
|
||||
label: gettext('Data'),
|
||||
type: 'switch',
|
||||
group: gettext('Sections'),
|
||||
deps: ['only_data', 'only_schema'],
|
||||
disabled: function(state) {
|
||||
return obj.selectedNodeType !== 'function' &&
|
||||
obj.selectedNodeType !== 'table' &&
|
||||
obj.selectedNodeType !== 'trigger' &&
|
||||
obj.selectedNodeType !== 'trigger_function' &&
|
||||
(state.only_data || state.only_schema);
|
||||
},
|
||||
}, {
|
||||
id: 'post_data',
|
||||
label: gettext('Post-data'),
|
||||
type: 'switch',
|
||||
group: gettext('Sections'),
|
||||
deps: ['only_data', 'only_schema'],
|
||||
disabled: function(state) {
|
||||
return obj.selectedNodeType !== 'function' &&
|
||||
obj.selectedNodeType !== 'table' &&
|
||||
obj.selectedNodeType !== 'trigger' &&
|
||||
obj.selectedNodeType !== 'trigger_function' &&
|
||||
(state.only_data || state.only_schema);
|
||||
},
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
export function getRestoreSectionSchema(fieldOptions) {
|
||||
return new RestoreSectionSchema(fieldOptions);
|
||||
}
|
||||
|
||||
export class RestoreTypeObjSchema extends BaseUISchema {
|
||||
constructor(fieldOptions={}) {
|
||||
super();
|
||||
|
||||
this.fieldOptions = {
|
||||
selectedNodeType: undefined,
|
||||
...fieldOptions,
|
||||
};
|
||||
|
||||
this.selectedNodeType = this.fieldOptions.selectedNodeType;
|
||||
}
|
||||
|
||||
get idAttribute() {
|
||||
return 'id';
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
let obj = this;
|
||||
return [{
|
||||
id: 'only_data',
|
||||
label: gettext('Only data'),
|
||||
type: 'switch',
|
||||
group: gettext('Type of objects'),
|
||||
deps: ['pre_data', 'data', 'post_data', 'only_schema'],
|
||||
disabled: function(state) {
|
||||
return (obj.selectedNodeType !== 'database' && obj.selectedNodeType !== 'schema') ||
|
||||
(state.pre_data ||
|
||||
state.data ||
|
||||
state.post_data ||
|
||||
state.only_schema
|
||||
);
|
||||
},
|
||||
}, {
|
||||
id: 'only_schema',
|
||||
label: gettext('Only schema'),
|
||||
type: 'switch',
|
||||
group: gettext('Type of objects'),
|
||||
deps: ['pre_data', 'data', 'post_data', 'only_data'],
|
||||
disabled: function(state) {
|
||||
return (obj.selectedNodeType !== 'database' && obj.selectedNodeType !== 'schema') ||
|
||||
(state.pre_data ||
|
||||
state.data ||
|
||||
state.post_data ||
|
||||
state.only_data
|
||||
);
|
||||
},
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
export function getRestoreTypeObjSchema(fieldOptions) {
|
||||
return new RestoreTypeObjSchema(fieldOptions);
|
||||
}
|
||||
|
||||
export class RestoreSaveOptSchema extends BaseUISchema {
|
||||
constructor(fieldOptions={}, initValues) {
|
||||
super({
|
||||
id: null,
|
||||
...initValues,
|
||||
});
|
||||
|
||||
this.fieldOptions = {
|
||||
nodeInfo: null,
|
||||
...fieldOptions,
|
||||
};
|
||||
}
|
||||
|
||||
get idAttribute() {
|
||||
return 'id';
|
||||
}
|
||||
|
||||
|
||||
get baseFields() {
|
||||
let obj = this;
|
||||
return [{
|
||||
id: 'dns_owner',
|
||||
label: gettext('Owner'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Do not save'),
|
||||
}, {
|
||||
id: 'dns_privilege',
|
||||
label: gettext('Privilege'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Do not save'),
|
||||
}, {
|
||||
id: 'dns_tablespace',
|
||||
label: gettext('Tablespace'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Do not save'),
|
||||
}, {
|
||||
id: 'no_comments',
|
||||
label: gettext('Comments'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Do not save'),
|
||||
visible: function() {
|
||||
var serverInfo = obj.fieldOptions.nodeInfo;
|
||||
return !_.isUndefined(serverInfo) && serverInfo.version >= 110000 ? true : false;
|
||||
},
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
export function getRestoreSaveOptSchema(fieldOptions) {
|
||||
return new RestoreSaveOptSchema(fieldOptions);
|
||||
}
|
||||
|
||||
export class RestoreQueryOptionSchema extends BaseUISchema {
|
||||
constructor(fieldOptions={}, initValues) {
|
||||
super({
|
||||
id: null,
|
||||
...initValues,
|
||||
});
|
||||
|
||||
this.fieldOptions = {
|
||||
nodeInfo: null,
|
||||
backupType: null,
|
||||
...fieldOptions,
|
||||
};
|
||||
|
||||
this.selectedNodeType = this.fieldOptions.selectedNodeType;
|
||||
}
|
||||
|
||||
get idAttribute() {
|
||||
return 'id';
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
let obj = this;
|
||||
return [{
|
||||
id: 'include_create_database',
|
||||
label: gettext('Include CREATE DATABASE statement'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Queries')
|
||||
}, {
|
||||
id: 'clean',
|
||||
label: gettext('Clean before restore'),
|
||||
type: 'switch',
|
||||
group: gettext('Queries'),
|
||||
disabled: function() {
|
||||
return obj.selectedNodeType === 'function'
|
||||
|| obj.selectedNodeType === 'trigger_function';
|
||||
},
|
||||
}, {
|
||||
id: 'single_transaction',
|
||||
label: gettext('Single transaction'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Queries'),
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
export function getRestoreQueryOptionSchema(fieldOptions) {
|
||||
return new RestoreQueryOptionSchema(fieldOptions);
|
||||
}
|
||||
|
||||
export class RestoreDisableOptionSchema extends BaseUISchema {
|
||||
constructor(fieldOptions={}, initValues) {
|
||||
super({
|
||||
id: null,
|
||||
...initValues,
|
||||
});
|
||||
|
||||
this.fieldOptions = {
|
||||
nodeInfo: null,
|
||||
...fieldOptions,
|
||||
};
|
||||
}
|
||||
|
||||
get idAttribute() {
|
||||
return 'id';
|
||||
}
|
||||
|
||||
|
||||
get baseFields() {
|
||||
return [{
|
||||
id: 'disable_trigger',
|
||||
label: gettext('Trigger'),
|
||||
type: 'switch',
|
||||
disable: false,
|
||||
group: gettext('Disable')
|
||||
}, {
|
||||
id: 'no_data_fail_table',
|
||||
label: gettext('No data for Failed Tables'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Disable'),
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
export function getRestoreDisableOptionSchema(fieldOptions) {
|
||||
return new RestoreDisableOptionSchema(fieldOptions);
|
||||
}
|
||||
|
||||
export class RestoreMiscellaneousSchema extends BaseUISchema {
|
||||
constructor(fieldOptions={}, initValues) {
|
||||
super({
|
||||
id: null,
|
||||
verbose: true,
|
||||
...initValues,
|
||||
});
|
||||
|
||||
this.fieldOptions = {
|
||||
nodeInfo: null,
|
||||
...fieldOptions,
|
||||
};
|
||||
}
|
||||
|
||||
get idAttribute() {
|
||||
return 'id';
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
return [{
|
||||
id: 'verbose',
|
||||
label: gettext('Verbose messages'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Miscellaneous / Behavior'),
|
||||
}, {
|
||||
id: 'use_set_session_auth',
|
||||
label: gettext('Use SET SESSION AUTHORIZATION'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Miscellaneous / Behavior'),
|
||||
}, {
|
||||
id: 'exit_on_error',
|
||||
label: gettext('Exit on error'),
|
||||
type: 'switch',
|
||||
disabled: false,
|
||||
group: gettext('Miscellaneous / Behavior'),
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
export function getRestoreMiscellaneousSchema(fieldOptions) {
|
||||
return new RestoreMiscellaneousSchema(fieldOptions);
|
||||
}
|
||||
|
||||
//Restore Schema
|
||||
export default class RestoreSchema extends BaseUISchema {
|
||||
|
||||
constructor(getRestoreSectionSchema, getRestoreTypeObjSchema, getRestoreSaveOptSchema, getRestoreQueryOptionSchema, getRestoreDisableOptionSchema, getRestoreMiscellaneousSchema, fieldOptions = {}, treeNodeInfo, pgBrowser) {
|
||||
super({
|
||||
custom: false,
|
||||
file: undefined,
|
||||
role: undefined,
|
||||
format: 'custom',
|
||||
verbose: true,
|
||||
blobs: true,
|
||||
encoding: undefined,
|
||||
database: undefined,
|
||||
schemas: undefined,
|
||||
tables: undefined,
|
||||
functions: undefined,
|
||||
triggers: undefined,
|
||||
trigger_funcs: undefined,
|
||||
indexes: undefined
|
||||
});
|
||||
|
||||
this.fieldOptions = {
|
||||
encoding: null,
|
||||
role: null,
|
||||
...fieldOptions,
|
||||
};
|
||||
|
||||
this.getSectionSchema = getRestoreSectionSchema;
|
||||
this.getRestoreTypeObjSchema = getRestoreTypeObjSchema;
|
||||
this.getRestoreSaveOptSchema = getRestoreSaveOptSchema;
|
||||
this.getRestoreQueryOptionSchema = getRestoreQueryOptionSchema;
|
||||
this.getRestoreDisableOptionSchema = getRestoreDisableOptionSchema;
|
||||
this.getRestoreMiscellaneousSchema = getRestoreMiscellaneousSchema;
|
||||
this.treeNodeInfo = treeNodeInfo;
|
||||
this.pgBrowser = pgBrowser;
|
||||
}
|
||||
|
||||
get idAttribute() {
|
||||
return 'id';
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
var obj = this;
|
||||
return [{
|
||||
id: 'format',
|
||||
label: gettext('Format'),
|
||||
disabled: false,type: 'select',
|
||||
controlProps: { allowClear: false, width: '100%' },
|
||||
options: [{
|
||||
label: gettext('Custom or tar'),
|
||||
value: 'custom',
|
||||
},
|
||||
{
|
||||
label: gettext('Directory'),
|
||||
value: 'directory',
|
||||
}],
|
||||
}, {
|
||||
id: 'file',
|
||||
label: gettext('Filename'),
|
||||
type: (state) => {
|
||||
return {
|
||||
type: 'file',
|
||||
controlProps: {
|
||||
dialogType: state.format == 'directory' ? 'select_folder' : 'select_file',
|
||||
supportedTypes: ['*', 'backup', 'sql', 'patch'],
|
||||
dialogTitle: 'Select file',
|
||||
}
|
||||
};
|
||||
},
|
||||
disabled: false,
|
||||
deps: ['format']
|
||||
}, {
|
||||
id: 'no_of_jobs',
|
||||
label: gettext('Number of jobs'),
|
||||
type: 'int',
|
||||
}, {
|
||||
id: 'role',
|
||||
label: gettext('Role name'),
|
||||
node: 'role',
|
||||
type: 'select',
|
||||
options: obj.fieldOptions.role,
|
||||
controlProps: {
|
||||
allowClear: false,
|
||||
},
|
||||
}, {
|
||||
type: 'nested-fieldset',
|
||||
label: gettext('Sections'),
|
||||
group: gettext('Restore options'),
|
||||
schema:obj.getSectionSchema(),
|
||||
visible: true
|
||||
}, {
|
||||
type: 'nested-fieldset',
|
||||
label: gettext('Type of objects'),
|
||||
group: gettext('Restore options'),
|
||||
schema:obj.getRestoreTypeObjSchema(),
|
||||
visible: true
|
||||
}, {
|
||||
type: 'nested-fieldset',
|
||||
label: gettext('Do not save'),
|
||||
group: gettext('Restore options'),
|
||||
schema:obj.getRestoreSaveOptSchema(),
|
||||
visible: true
|
||||
}, {
|
||||
type: 'nested-fieldset',
|
||||
label: gettext('Queries'),
|
||||
group: gettext('Restore options'),
|
||||
schema:obj.getRestoreQueryOptionSchema(),
|
||||
visible: true
|
||||
}, {
|
||||
type: 'nested-fieldset',
|
||||
label: gettext('Disable'),
|
||||
group: gettext('Restore options'),
|
||||
schema:obj.getRestoreDisableOptionSchema(),
|
||||
visible: true
|
||||
}, {
|
||||
type: 'nested-fieldset',
|
||||
label: gettext('Miscellaneous / Behavior'),
|
||||
group: gettext('Restore options'),
|
||||
schema:obj.getRestoreMiscellaneousSchema(),
|
||||
visible: true
|
||||
}];
|
||||
}
|
||||
|
||||
validate(state, setError) {
|
||||
if (isEmptyString(state.service)) {
|
||||
let errmsg = null;
|
||||
/* events validation*/
|
||||
if (!state.file) {
|
||||
errmsg = gettext('Please provide a filename.');
|
||||
setError('file', errmsg);
|
||||
return true;
|
||||
} else {
|
||||
errmsg = null;
|
||||
setError('file', errmsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import gettext from '../../../../static/js/gettext';
|
||||
import Backform from '../../../../static/js/backform.pgadmin';
|
||||
import {Dialog} from '../../../../static/js/alertify/dialog';
|
||||
import url_for from 'sources/url_for';
|
||||
import axios from 'axios/index';
|
||||
import {retrieveAncestorOfTypeServer} from 'sources/tree/tree_utils';
|
||||
import {hasBinariesConfiguration} from 'sources/utils';
|
||||
import Notify from '../../../../static/js/helpers/Notifier';
|
||||
|
||||
export class RestoreDialog extends Dialog {
|
||||
constructor(pgBrowser, $, alertify, RestoreModel, backform = Backform) {
|
||||
super(gettext('Restore Error'),
|
||||
'<div class=\'restore_dialog\'></div>',
|
||||
pgBrowser, $, alertify, RestoreModel, backform);
|
||||
}
|
||||
|
||||
url_for_utility_exists(id){
|
||||
return url_for('restore.utility_exists', {
|
||||
'sid': id,
|
||||
});
|
||||
}
|
||||
|
||||
draw(action, aciTreeItem, width, height) {
|
||||
const serverInformation = retrieveAncestorOfTypeServer(this.pgBrowser, aciTreeItem, gettext('Restore Error'));
|
||||
if (!serverInformation) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasBinariesConfiguration(this.pgBrowser, serverInformation)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var sid = serverInformation._type == 'database' ? serverInformation._pid : serverInformation._id;
|
||||
const baseUrl = this.url_for_utility_exists(sid);
|
||||
// Check pg_restore utility exists or not.
|
||||
let that = this;
|
||||
axios.get(
|
||||
baseUrl
|
||||
).then(function(res) {
|
||||
if (!res.data.success) {
|
||||
Notify.alert(
|
||||
gettext('Utility not found'),
|
||||
res.data.errormsg
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!that.canExecuteOnCurrentDatabase(aciTreeItem)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let aciTreeItem1 = aciTreeItem || that.pgBrowser.tree.selected();
|
||||
let item = that.pgBrowser.tree.findNodeByDomElement(aciTreeItem1);
|
||||
const data = item.getData();
|
||||
const node = that.pgBrowser.Nodes[data._type];
|
||||
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
let title = gettext('Restore (%s: %s)', node.label, data.label);
|
||||
that.createOrGetDialog(title, 'restore');
|
||||
that.alertify.pg_restore(title, aciTreeItem1, data, node)
|
||||
.resizeTo(width, height);
|
||||
}).catch(function() {
|
||||
Notify.alert(
|
||||
gettext('Utility not found'),
|
||||
gettext('Failed to fetch Utility information')
|
||||
);
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
dialogName() {
|
||||
return 'pg_restore';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,293 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import axios from 'axios/index';
|
||||
import _ from 'underscore';
|
||||
import gettext from '../../../../static/js/gettext';
|
||||
import url_for from '../../../../static/js/url_for';
|
||||
import {DialogWrapper} from '../../../../static/js/alertify/dialog_wrapper';
|
||||
import Notify from '../../../../static/js/helpers/Notifier';
|
||||
|
||||
export class RestoreDialogWrapper extends DialogWrapper {
|
||||
constructor(dialogContainerSelector, dialogTitle, typeOfDialog,
|
||||
jquery, pgBrowser, alertify, dialogModel, backform) {
|
||||
super(dialogContainerSelector, dialogTitle, jquery,
|
||||
pgBrowser, alertify, dialogModel, backform);
|
||||
}
|
||||
|
||||
main(title, item, data, node) {
|
||||
this.set('title', title);
|
||||
this.setting('pg_node', node);
|
||||
this.setting('pg_item', item);
|
||||
this.setting('pg_item_data', data);
|
||||
}
|
||||
|
||||
setup() {
|
||||
return {
|
||||
buttons: [{
|
||||
text: '',
|
||||
className: 'btn btn-primary-icon pull-left fa fa-info pg-alertify-icon-button',
|
||||
attrs: {
|
||||
name: 'object_help',
|
||||
type: 'button',
|
||||
url: 'backup.html',
|
||||
label: gettext('Restore'),
|
||||
'aria-label': gettext('Object Help'),
|
||||
},
|
||||
}, {
|
||||
text: '',
|
||||
key: 112,
|
||||
className: 'btn btn-primary-icon pull-left fa fa-question pg-alertify-icon-button',
|
||||
attrs: {
|
||||
name: 'dialog_help',
|
||||
type: 'button',
|
||||
label: gettext('Restore'),
|
||||
'aria-label': gettext('Help'),
|
||||
url: url_for('help.static', {
|
||||
'filename': 'restore_dialog.html',
|
||||
}),
|
||||
},
|
||||
}, {
|
||||
text: gettext('Cancel'),
|
||||
key: 27,
|
||||
className: 'btn btn-secondary fa fa-lg fa-times pg-alertify-button',
|
||||
restore: false,
|
||||
'data-btn-name': 'cancel',
|
||||
}, {
|
||||
text: gettext('Restore'),
|
||||
key: 13,
|
||||
className: 'btn btn-primary fa fa-upload pg-alertify-button',
|
||||
restore: true,
|
||||
'data-btn-name': 'restore',
|
||||
}],
|
||||
// Set options for dialog
|
||||
options: {
|
||||
title: this.dialogTitle,
|
||||
//disable both padding and overflow control.
|
||||
padding: !1,
|
||||
overflow: !1,
|
||||
model: 0,
|
||||
resizable: true,
|
||||
maximizable: true,
|
||||
pinnable: false,
|
||||
closableByDimmer: false,
|
||||
modal: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
prepare() {
|
||||
this.disableRestoreButton();
|
||||
|
||||
const $container = this.jquery(this.dialogContainerSelector);
|
||||
const selectedTreeNode = this.getSelectedNode();
|
||||
const selectedTreeNodeData = this.getSelectedNodeData(selectedTreeNode);
|
||||
if (!selectedTreeNodeData) {
|
||||
return;
|
||||
}
|
||||
|
||||
const node = this.pgBrowser.Nodes[selectedTreeNodeData._type];
|
||||
const treeInfo = this.pgBrowser.tree.getTreeNodeHierarchy(selectedTreeNode);
|
||||
const dialog = this.createDialog(node, treeInfo, $container);
|
||||
this.addAlertifyClassToRestoreNodeChildNodes();
|
||||
dialog.render();
|
||||
const statusBar = this.jquery(
|
||||
'<div class=\'pg-prop-status-bar pg-prop-status-bar-absolute pg-el-xs-12 d-none\'>' +
|
||||
' <div class="error-in-footer"> ' +
|
||||
' <div class="d-flex px-2 py-1"> ' +
|
||||
' <div class="pr-2"> ' +
|
||||
' <i class="fa fa-exclamation-triangle text-danger" aria-hidden="true"></i> ' +
|
||||
' </div> ' +
|
||||
' <div class="alert-text" role="alert"></div> ' +
|
||||
' <div class="ml-auto close-error-bar"> ' +
|
||||
' <a aria-label="' + gettext('Close error bar') + '" class="close-error fa fa-times text-danger"></a> ' +
|
||||
' </div> ' +
|
||||
' </div> ' +
|
||||
' </div> ' +
|
||||
'</div>').appendTo($container);
|
||||
|
||||
this.elements.content.appendChild($container.get(0));
|
||||
|
||||
this.focusOnDialog(this);
|
||||
this.setListenersForFilenameChanges(statusBar);
|
||||
}
|
||||
|
||||
callback(event) {
|
||||
const selectedTreeNode = this.getSelectedNode();
|
||||
const selectedTreeNodeData = this.getSelectedNodeData(selectedTreeNode);
|
||||
const node = selectedTreeNodeData && this.pgBrowser.Nodes[selectedTreeNodeData._type];
|
||||
|
||||
if (this.wasHelpButtonPressed(event)) {
|
||||
event.cancel = true;
|
||||
this.pgBrowser.showHelp(
|
||||
event.button.element.name,
|
||||
event.button.element.getAttribute('url'),
|
||||
node,
|
||||
selectedTreeNode.getHtmlIdentifier()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.wasRestoreButtonPressed(event)) {
|
||||
|
||||
if (!selectedTreeNodeData)
|
||||
return;
|
||||
|
||||
const serverIdentifier = this.retrieveServerIdentifier(node, selectedTreeNode);
|
||||
|
||||
const dialogWrapper = this;
|
||||
let urlShortcut = 'restore.create_job';
|
||||
|
||||
const baseUrl = url_for(urlShortcut, {
|
||||
'sid': serverIdentifier,
|
||||
});
|
||||
|
||||
const treeInfo = this.pgBrowser.tree.getTreeNodeHierarchy(selectedTreeNode);
|
||||
|
||||
this.setExtraParameters(selectedTreeNode, treeInfo);
|
||||
|
||||
axios.post(
|
||||
baseUrl,
|
||||
this.view.model.toJSON()
|
||||
).then(function (res) {
|
||||
if (res.data.success) {
|
||||
Notify.success(gettext('Restore job created.'), 5);
|
||||
dialogWrapper.pgBrowser.Events.trigger('pgadmin-bgprocess:created', dialogWrapper);
|
||||
} else {
|
||||
Notify.alert(
|
||||
gettext('Restore job creation failed.'),
|
||||
res.data.errormsg
|
||||
);
|
||||
}
|
||||
}).catch(function (error) {
|
||||
try {
|
||||
const err = error.response.data;
|
||||
Notify.alert(
|
||||
gettext('Restore job failed.'),
|
||||
err.errormsg
|
||||
);
|
||||
} catch (e) {
|
||||
console.warn(e.stack || e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
addAlertifyClassToRestoreNodeChildNodes() {
|
||||
this.jquery(this.elements.body.childNodes[0]).addClass(
|
||||
'alertify_tools_dialog_properties obj_properties'
|
||||
);
|
||||
}
|
||||
|
||||
getSelectedNode() {
|
||||
const tree = this.pgBrowser.tree;
|
||||
const selectedNode = tree.selected();
|
||||
if (selectedNode) {
|
||||
return tree.findNodeByDomElement(selectedNode);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
disableRestoreButton() {
|
||||
this.__internal.buttons[3].element.disabled = true;
|
||||
}
|
||||
|
||||
enableRestoreButton() {
|
||||
this.__internal.buttons[3].element.disabled = false;
|
||||
}
|
||||
|
||||
createDialog(node, treeInfo, $container) {
|
||||
const newModel = new this.dialogModel({
|
||||
node_data: node,
|
||||
}, {
|
||||
node_info: treeInfo,
|
||||
});
|
||||
const fields = this.backform.generateViewSchema(
|
||||
treeInfo, newModel, 'create', node, treeInfo.server, true
|
||||
);
|
||||
|
||||
return this.view = new this.backform.Dialog({
|
||||
el: $container,
|
||||
model: newModel,
|
||||
schema: fields,
|
||||
});
|
||||
}
|
||||
|
||||
retrieveServerIdentifier(node, selectedTreeNode) {
|
||||
const treeInfo = this.pgBrowser.tree.getTreeNodeHierarchy(selectedTreeNode);
|
||||
return treeInfo.server._id;
|
||||
}
|
||||
|
||||
setListenersForFilenameChanges(statusBar) {
|
||||
const self = this;
|
||||
|
||||
this.view.model.on('change', function () {
|
||||
const ctx = this;
|
||||
var errmsg;
|
||||
|
||||
const showError = function(errorField, errormsg) {
|
||||
ctx.errorModel.set(errorField, errormsg);
|
||||
statusBar.removeClass('d-none');
|
||||
statusBar.find('.alert-text').html(errormsg);
|
||||
self.elements.dialog.querySelector('.close-error').addEventListener('click', ()=>{
|
||||
statusBar.addClass('d-none');
|
||||
ctx.errorModel.set(errorField, errormsg);
|
||||
});
|
||||
};
|
||||
|
||||
if (!_.isUndefined(this.get('file')) && this.get('file') !== '') {
|
||||
this.errorModel.clear();
|
||||
statusBar.addClass('d-none');
|
||||
self.enableRestoreButton();
|
||||
} else {
|
||||
self.disableRestoreButton();
|
||||
errmsg = gettext('Please provide a filename');
|
||||
showError('file', errmsg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setExtraParameters(selectedTreeNode, treeInfo) {
|
||||
this.view.model.set('database', treeInfo.database._label);
|
||||
if (!this.view.model.get('custom')) {
|
||||
const nodeData = selectedTreeNode.getData();
|
||||
|
||||
switch (nodeData._type) {
|
||||
case 'schema':
|
||||
this.view.model.set('schemas', [nodeData._label]);
|
||||
break;
|
||||
case 'table':
|
||||
this.view.model.set('schemas', [treeInfo.schema._label]);
|
||||
this.view.model.set('tables', [nodeData._label]);
|
||||
break;
|
||||
case 'function':
|
||||
this.view.model.set('schemas', [treeInfo.schema._label]);
|
||||
this.view.model.set('functions', [nodeData._label]);
|
||||
break;
|
||||
case 'index':
|
||||
this.view.model.set('schemas', [treeInfo.schema._label]);
|
||||
this.view.model.set('indexes', [nodeData._label]);
|
||||
break;
|
||||
case 'trigger':
|
||||
this.view.model.set('schemas', [treeInfo.schema._label]);
|
||||
this.view.model.set('triggers', [nodeData._label]);
|
||||
break;
|
||||
case 'trigger_func':
|
||||
this.view.model.set('schemas', [treeInfo.schema._label]);
|
||||
this.view.model.set('trigger_funcs', [nodeData._label]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wasRestoreButtonPressed(event) {
|
||||
return event.button['data-btn-name'] === 'restore';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user