Port Tablespace node to react. Fixes #6644.

This commit is contained in:
Akshay Joshi
2021-07-27 19:19:30 +05:30
parent d9cfbf592e
commit 39765903d4
6 changed files with 308 additions and 80 deletions

View File

@@ -11,6 +11,7 @@ import gettext from 'sources/gettext';
import _ from 'lodash';
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
import { getNodeAjaxOptions, getNodeListByName } from '../../../../static/js/node_ajax';
import { isEmptyString } from '../../../../../static/js/validators';
export function getNodeVariableSchema(nodeObj, treeNodeInfo, itemNodeData, hasDatabase, hasRole) {
let keys = ['name', 'value'];
@@ -81,7 +82,7 @@ export default class VariableSchema extends BaseUISchema {
case 'integer':
return 'int';
case 'real':
return 'number';
return 'numeric';
case 'string':
return 'text';
default:
@@ -107,11 +108,10 @@ export default class VariableSchema extends BaseUISchema {
optionsLoaded: (options)=>{obj.setVarTypes(options);},
controlProps: { allowClear: false },
}),
noEmpty: true,
},
{
id: 'value', label: gettext('Value'), type: 'text',
noEmpty: true, deps: ['name'],
deps: ['name'],
depChange: (state, changeSource)=>{
if(changeSource == 'name') {
return {...state
@@ -136,4 +136,21 @@ export default class VariableSchema extends BaseUISchema {
},
];
}
validate(state, setError) {
if (isEmptyString(state.name)) {
setError('name', gettext('Please select a parameter name.'));
return true;
} else {
setError('name', null);
}
if (isEmptyString(state.value)) {
setError('value', gettext('Please enter a value for the parameter.'));
return true;
} else {
setError('value', null);
}
}
}

View File

@@ -7,6 +7,11 @@
//
//////////////////////////////////////////////////////////////
import { getNodeListByName } from '../../../../../static/js/node_ajax';
import { getNodePrivilegeRoleSchema } from '../../../static/js/privilege.ui';
import { getNodeVariableSchema } from '../../../static/js/variable.ui';
import TablespaceSchema from './tablespace.ui';
define('pgadmin.node.tablespace', [
'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'backbone',
'sources/pgadmin', 'pgadmin.browser', 'pgadmin.alertifyjs',
@@ -318,18 +323,22 @@ define('pgadmin.node.tablespace', [
Alertify.move_objects_dlg(true).resizeTo(pgBrowser.stdW.md,pgBrowser.stdH.md);
},
},
getSchema: function(treeNodeInfo, itemNodeData) {
return new TablespaceSchema(
()=>getNodeVariableSchema(this, treeNodeInfo, itemNodeData, false, false),
(privileges)=>getNodePrivilegeRoleSchema(this, treeNodeInfo, itemNodeData, privileges),
{
role: ()=>getNodeListByName('role', treeNodeInfo, itemNodeData),
},
{
spcuser: pgBrowser.serverInfo[treeNodeInfo.server._id].user.name,
}
);
},
model: pgBrowser.Node.Model.extend({
idAttribute: 'oid',
defaults: {
name: undefined,
owner: undefined,
is_sys_obj: undefined,
comment: undefined,
spclocation: undefined,
spcoptions: [],
spcacl: [],
seclabels:[],
},
// Default values!
initialize: function(attrs, args) {
@@ -342,73 +351,19 @@ define('pgadmin.node.tablespace', [
pgBrowser.Node.Model.prototype.initialize.apply(this, arguments);
},
schema: [{
id: 'name', label: gettext('Name'), cell: 'string',
type: 'text',
},{
id: 'oid', label: gettext('OID'), cell: 'string',
type: 'text', mode: ['properties'],
},{
id: 'spclocation', label: gettext('Location'), cell: 'string',
group: gettext('Definition'), type: 'text', mode: ['properties', 'edit','create'],
readonly: function(m) {
// To disabled it in edit mode,
// We'll check if model is new if yes then disabled it
return !m.isNew();
schema: [
{
id: 'name', label: gettext('Name'), cell: 'string',
type: 'text',
}, {
id: 'spcuser', label: gettext('Owner'), cell: 'string',
type: 'text', control: 'node-list-by-name', node: 'role',
select2: {allowClear: false},
}, {
id: 'description', label: gettext('Comment'), cell: 'string',
type: 'multiline',
},
},{
id: 'spcuser', label: gettext('Owner'), cell: 'string',
type: 'text', control: 'node-list-by-name', node: 'role',
select2: {allowClear: false},
},{
id: 'acl', label: gettext('Privileges'), type: 'text',
group: gettext('Security'), mode: ['properties'],
},{
id: 'is_sys_obj', label: gettext('System tablespace?'),
cell:'boolean', type: 'switch', mode: ['properties'],
},{
id: 'description', label: gettext('Comment'), cell: 'string',
type: 'multiline',
},{
id: 'spcoptions', label: '', type: 'collection',
group: gettext('Parameters'), control: 'variable-collection',
model: pgBrowser.Node.VariableModel,
mode: ['edit', 'create'], canAdd: true, canEdit: false,
canDelete: true,
},{
id: 'spcacl', label: gettext('Privileges'), type: 'collection',
group: gettext('Security'), control: 'unique-col-collection',
model: pgBrowser.Node.PrivilegeRoleModel.extend({privileges: ['C']}),
mode: ['edit', 'create'], canAdd: true, canDelete: true,
uniqueCol : ['grantee'],
columns: ['grantee', 'grantor', 'privileges'],
},{
id: 'seclabels', label: gettext('Security labels'),
model: pgBrowser.SecLabelModel, editable: false, type: 'collection',
group: gettext('Security'), mode: ['edit', 'create'],
min_version: 90200, canAdd: true,
canEdit: false, canDelete: true, control: 'unique-col-collection',
},
],
validate: function() {
var msg;
if (_.isUndefined(this.get('name'))
|| String(this.get('name')).replace(/^\s+|\s+$/g, '') == '') {
msg = gettext('Name cannot be empty.');
this.errorModel.set('name', msg);
} else if (this.isNew() &&
(_.isUndefined(this.get('spclocation'))
|| String(this.get('spclocation')).replace(/^\s+|\s+$/g, '') == '')) {
msg = gettext('Location cannot be empty.');
this.errorModel.set('spclocation', msg);
this.errorModel.unset('name');
} else {
this.errorModel.unset('name');
this.errorModel.unset('spclocation');
}
return null;
},
}),
});

View File

@@ -0,0 +1,91 @@
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import gettext from 'sources/gettext';
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
import SecLabelSchema from '../../../static/js/sec_label.ui';
export default class TablespaceSchema extends BaseUISchema {
constructor(getVariableSchema, getPrivilegeRoleSchema, fieldOptions={}, initValues) {
super({
name: undefined,
owner: undefined,
is_sys_obj: undefined,
comment: undefined,
spclocation: undefined,
spcoptions: [],
spcacl: [],
seclabels:[],
...initValues,
});
this.getPrivilegeRoleSchema = getPrivilegeRoleSchema;
this.getVariableSchema = getVariableSchema;
this.fieldOptions = {
role: [],
...fieldOptions,
};
}
get idAttribute() {
return 'oid';
}
get baseFields() {
let obj = this;
return [
{
id: 'name', label: gettext('Name'), cell: 'text',
type: 'text', mode: ['properties', 'create', 'edit'],
noEmpty: true,
}, {
id: 'oid', label: gettext('OID'), cell: 'text',
type: 'text', mode: ['properties'],
}, {
id: 'spcuser', label: gettext('Owner'), cell: 'text',
editable: false, type: 'select', options: this.fieldOptions.role,
controlProps: { allowClear: false }
}, {
id: 'is_sys_obj', label: gettext('System tablespace?'),
cell:'boolean', type: 'switch', mode: ['properties'],
}, {
id: 'description', label: gettext('Comment'), cell: 'text',
type: 'multiline',
}, {
id: 'spclocation', label: gettext('Location'),
group: gettext('Definition'), type: 'text',
mode: ['properties', 'edit','create'],
readonly: function(state) {return !obj.isNew(state); },
noEmpty: true,
}, {
id: 'acl', label: gettext('Privileges'), type: 'text',
group: gettext('Security'), mode: ['properties'],
}, {
id: 'spcoptions', label: '', type: 'collection',
schema: this.getVariableSchema(),
editable: false,
group: gettext('Parameters'), mode: ['edit', 'create'],
canAdd: true, canEdit: false, canDelete: true,
}, {
id: 'spcacl', label: gettext('Privileges'), type: 'collection',
group: gettext('Security'),
schema: this.getPrivilegeRoleSchema(['C']),
mode: ['edit', 'create'], uniqueCol : ['grantee'],
canAdd: true, canDelete: true,
}, {
id: 'seclabels', label: gettext('Security labels'), type: 'collection',
editable: false, group: gettext('Security'),
schema: new SecLabelSchema(),
mode: ['edit', 'create'],
min_version: 90200,
uniqueCol : ['provider'],
canAdd: true, canEdit: false, canDelete: true,
}
];
}
}