Fixed code smell 'Update this function so that its implementation is not identical' reported by SonarQube.

This commit is contained in:
Akshay Joshi 2022-01-25 20:10:31 +05:30
parent 094129e2be
commit 0ce3434631
33 changed files with 603 additions and 1055 deletions

View File

@ -29,6 +29,16 @@ export default class CastSchema extends BaseUISchema {
return 'oid';
}
getCastName(state) {
var srctype = state.srctyp;
var trgtype = state.trgtyp;
if(srctype != undefined && srctype != '' &&
trgtype != undefined && trgtype != '')
return state.name = srctype+'->'+trgtype;
else
return state.name = '';
}
get baseFields() {
let obj = this;
return [{
@ -53,13 +63,7 @@ export default class CastSchema extends BaseUISchema {
* target type are set, if yes then fetch values from both
* controls and generate cast name
*/
var srctype = state.srctyp;
var trgtype = state.trgtyp;
if(srctype != undefined && srctype != '' &&
trgtype != undefined && trgtype != '')
return state.name = srctype+'->'+trgtype;
else
return state.name = '';
return obj.getCastName(state);
},
},
@ -83,13 +87,7 @@ export default class CastSchema extends BaseUISchema {
* target type are set, if yes then fetch values from both
* controls and generate cast name
*/
var srctype = state.srctyp;
var trgtype = state.trgtyp;
if(srctype != undefined && srctype != '' &&
trgtype != undefined && trgtype != '')
return state.name = srctype+'->'+trgtype;
else
return state.name = '';
return obj.getCastName(state);
},
},
/*

View File

@ -66,18 +66,7 @@ export default class FTSParserSchema extends BaseUISchema {
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
return obj.getFilterOptions(state, options);
}
}
};
@ -93,18 +82,7 @@ export default class FTSParserSchema extends BaseUISchema {
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
return obj.getFilterOptions(state, options);
}
}
};
@ -120,18 +98,7 @@ export default class FTSParserSchema extends BaseUISchema {
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
return obj.getFilterOptions(state, options);
}
}
};
@ -147,18 +114,7 @@ export default class FTSParserSchema extends BaseUISchema {
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
return obj.getFilterOptions(state, options);
}
}
};
@ -174,18 +130,7 @@ export default class FTSParserSchema extends BaseUISchema {
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
return obj.getFilterOptions(state, options);
}
}
};

View File

@ -66,18 +66,7 @@ export default class FTSTemplateSchema extends BaseUISchema {
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
return obj.getFilterOptions(state, options);
}
}
};
@ -96,18 +85,7 @@ export default class FTSTemplateSchema extends BaseUISchema {
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
return obj.getFilterOptions(state, options);
}
}
};

View File

@ -147,6 +147,10 @@ export default class ColumnSchema extends BaseUISchema {
return null;
}
attCell(state) {
return { cell: this.attlenRange(state) ? 'int' : '' };
}
get baseFields() {
let obj = this;
@ -281,9 +285,7 @@ export default class ColumnSchema extends BaseUISchema {
id: 'attlen', label: gettext('Length/Precision'),
deps: ['cltype'], type: 'int', group: gettext('Definition'), width: 120, disableResizing: true,
cell: (state)=>{
return {
cell: obj.attlenRange(state) ? 'int' : '',
};
return obj.attCell(state);
},
depChange: (state)=>{
let range = this.attlenRange(state);
@ -311,9 +313,7 @@ export default class ColumnSchema extends BaseUISchema {
id: 'attprecision', label: gettext('Scale'), width: 60, disableResizing: true,
deps: ['cltype'], type: 'int', group: gettext('Definition'),
cell: (state)=>{
return {
cell: obj.attlenRange(state) ? 'int' : '',
};
return obj.attCell(state);
},
depChange: (state)=>{
let range = this.attprecisionRange(state);

View File

@ -8,6 +8,16 @@ import { getNodeAjaxOptions, getNodeListByName } from '../../../../../../../../.
import TableSchema from '../../../../static/js/table.ui';
import Notify from '../../../../../../../../../../static/js/helpers/Notifier';
function getData(data) {
let res = [];
if (data && _.isArray(data)) {
_.each(data, function(d) {
res.push({label: d[0], value: d[1]});
});
}
return res;
}
export function getNodeExclusionConstraintSchema(treeNodeInfo, itemNodeData, pgBrowser, noColumns=false) {
let tableNode = pgBrowser.Nodes['table'];
return new ExclusionConstraintSchema({
@ -17,22 +27,10 @@ export function getNodeExclusionConstraintSchema(treeNodeInfo, itemNodeData, pgB
return (m.label != 'pg_global');
}),
getOperClass: (urlParams)=>getNodeAjaxOptions('get_oper_class', tableNode, treeNodeInfo, itemNodeData, {urlParams: urlParams, useCache:false}, (data)=>{
let res = [];
if (data && _.isArray(data)) {
_.each(data, function(d) {
res.push({label: d[0], value: d[1]});
});
}
return res;
return getData(data);
}),
getOperator: (urlParams)=>getNodeAjaxOptions('get_operator', tableNode, treeNodeInfo, itemNodeData, {urlParams: urlParams, useCache:false}, (data)=>{
let res = [];
if (data && _.isArray(data)) {
_.each(data, function(d) {
res.push({label: d[0], value: d[1]});
});
}
return res;
return getData(data);
}),
}, treeNodeInfo);
}

View File

@ -126,6 +126,49 @@ define('pgadmin.node.primary_key', [
include: [],
},
genResetColOptions: function() {
var self = this;
setTimeout(function () {
self.custom_options();
self.render.apply(self);
}, 50);
},
genCustomOptions: function() {
// We will add all the columns entered by user in table model
var columns = this.model.top.get('columns'),
added_columns_from_tables = [];
if (columns.length > 0) {
_.each(columns.models, function(m) {
var col = m.get('name');
if(!_.isUndefined(col) && !_.isNull(col)) {
added_columns_from_tables.push(
{label: col, value: col, image:'icon-column'}
);
}
});
}
// Set the values in to options so that user can select
this.field.set('options', added_columns_from_tables);
},
checkReadOnly(m) {
// If we are in table edit mode then
if (_.has(m, 'top') && !_.isUndefined(m.top)
&& !m.top.isNew()) {
// If OID is undefined then user is trying to add
// new constraint which should be allowed for Unique
return !_.isUndefined(m.get('oid'));
}
// We can't update columns of existing index constraint.
if (!m.isNew()) {
return true;
}
return false;
},
// Define the schema for the index constraint node
schema: [{
id: 'name', label: gettext('Name'), type: 'text',
@ -294,30 +337,10 @@ define('pgadmin.node.primary_key', [
});
},
resetColOptions: function() {
var self = this;
setTimeout(function () {
self.custom_options();
self.render.apply(self);
}, 50);
this.genResetColOptions();
},
custom_options: function() {
// We will add all the columns entered by user in table model
var columns = this.model.top.get('columns'),
added_columns_from_tables = [];
if (columns.length > 0) {
_.each(columns.models, function(m) {
var col = m.get('name');
if(!_.isUndefined(col) && !_.isNull(col)) {
added_columns_from_tables.push(
{label: col, value: col, image:'icon-column'}
);
}
});
}
// Set the values in to options so that user can select
this.field.set('options', added_columns_from_tables);
this.genCustomOptions();
},
onChange: function() {
var self = this,
@ -412,18 +435,7 @@ define('pgadmin.node.primary_key', [
},
select2:{allowClear:false},
readonly: function(m) {
// If we are in table edit mode then
if (_.has(m, 'top') && !_.isUndefined(m.top)
&& !m.top.isNew()) {
// If OID is undefined then user is trying to add
// new constraint which should be allowed for Unique
return !_.isUndefined(m.get('oid'));
}
// We can't update columns of existing index constraint.
if (!m.isNew()) {
return true;
}
return this.checkReadOnly(m);
},
disabled: function(m) {
// Disable if index is selected.
@ -477,46 +489,15 @@ define('pgadmin.node.primary_key', [
}
},
resetColOptions: function() {
var self = this;
setTimeout(function () {
self.custom_options();
self.render.apply(self);
}, 50);
this.genResetColOptions();
},
custom_options: function() {
// We will add all the columns entered by user in table model
var columns = this.model.top.get('columns'),
added_columns_from_tables = [];
if (columns.length > 0) {
_.each(columns.models, function(m) {
var col = m.get('name');
if(!_.isUndefined(col) && !_.isNull(col)) {
added_columns_from_tables.push(
{label: col, value: col, image:'icon-column'}
);
}
});
}
// Set the values in to options so that user can select
this.field.set('options', added_columns_from_tables);
this.genCustomOptions();
},
}),
deps: ['index'], node: 'column',
readonly: function(m) {
// If we are in table edit mode then
if (_.has(m, 'top') && !_.isUndefined(m.top)
&& !m.top.isNew()) {
// If OID is undefined then user is trying to add
// new constraint which should be allowed for Unique
return !_.isUndefined(m.get('oid'));
}
// We can't update columns of existing index constraint.
if (!m.isNew()) {
return true;
}
return this.checkReadOnly(m);
},
disabled: function(m) {
// Disable if index is selected.
@ -596,18 +577,7 @@ define('pgadmin.node.primary_key', [
id: 'condeferrable', label: gettext('Deferrable?'),
type: 'switch', group: gettext('Definition'), deps: ['index'],
readonly: function(m) {
// If we are in table edit mode then
if (_.has(m, 'top') && !_.isUndefined(m.top)
&& !m.top.isNew()) {
// If OID is undefined then user is trying to add
// new constraint which should allowed for Unique
return !_.isUndefined(m.get('oid'));
}
// We can't update condeferrable of existing index constraint.
if (!m.isNew()) {
return true;
}
return this.checkReadOnly(m);
},
disabled: function(m) {
// Disable if index is selected.
@ -627,18 +597,7 @@ define('pgadmin.node.primary_key', [
type: 'switch', group: gettext('Definition'),
deps: ['condeferrable'],
readonly: function(m) {
// If we are in table edit mode then
if (_.has(m, 'top') && !_.isUndefined(m.top)
&& !m.top.isNew()) {
// If OID is undefined then user is trying to add
// new constraint which should allowed for Unique
return !_.isUndefined(m.get('oid'));
}
// We can't update condeferred of existing index constraint.
if (!m.isNew()) {
return true;
}
return this.checkReadOnly(m);
},
disabled: function(m) {
// Disable if condeferred is false or unselected.

View File

@ -158,9 +158,7 @@ export default class PrimaryKeySchema extends BaseUISchema {
},
deps: ['index'],
readonly: function(state) {
if(!obj.isNew(state)) {
return true;
}
return obj.isReadOnly(state);
},
disabled: function(state) {
// Disable if index is selected.
@ -225,10 +223,7 @@ export default class PrimaryKeySchema extends BaseUISchema {
id: 'condeferrable', label: gettext('Deferrable?'),
type: 'switch', group: gettext('Definition'), deps: ['index'],
readonly: function(state) {
if(!obj.isNew(state)) {
return true;
}
return false;
return obj.isReadOnly(state);
},
disabled: function(state) {
// Disable if index is selected.
@ -246,10 +241,7 @@ export default class PrimaryKeySchema extends BaseUISchema {
type: 'switch', group: gettext('Definition'),
deps: ['condeferrable'],
readonly: function(state) {
if(!obj.isNew(state)) {
return true;
}
return false;
return obj.isReadOnly(state);
},
disabled: function(state) {
// Disable if index is selected.

View File

@ -130,9 +130,7 @@ export default class UniqueConstraintSchema extends BaseUISchema {
}), group: gettext('Definition'),
editable: false,
readonly: function(state) {
if(!obj.isNew(state)) {
return true;
}
return obj.isReadOnly(state);
},
disabled: function(state) {
// Disable if index is selected.
@ -161,9 +159,7 @@ export default class UniqueConstraintSchema extends BaseUISchema {
},
deps: ['index'],
readonly: function(state) {
if(!obj.isNew(state)) {
return true;
}
return obj.isReadOnly(state);
},
disabled: function(state) {
// Disable if index is selected.
@ -228,10 +224,7 @@ export default class UniqueConstraintSchema extends BaseUISchema {
id: 'condeferrable', label: gettext('Deferrable?'),
type: 'switch', group: gettext('Definition'), deps: ['index'],
readonly: function(state) {
if(!obj.isNew(state)) {
return true;
}
return false;
return obj.isReadOnly(state);
},
disabled: function(state) {
// Disable if index is selected.
@ -249,10 +242,7 @@ export default class UniqueConstraintSchema extends BaseUISchema {
type: 'switch', group: gettext('Definition'),
deps: ['condeferrable'],
readonly: function(state) {
if(!obj.isNew(state)) {
return true;
}
return false;
return obj.isReadOnly(state);
},
disabled: function(state) {
// Disable if index is selected.

View File

@ -75,6 +75,19 @@ export class ColumnSchema extends BaseUISchema {
this.op_class_types = options;
}
isEditable(state) {
let topObj = this._top;
if(this.inSchemaWithModelCheck(state)) {
return false;
} else if (topObj._sessData && topObj._sessData.amname === 'btree') {
state.is_sort_nulls_applicable = true;
return true;
} else {
state.is_sort_nulls_applicable = false;
}
return false;
}
get baseFields() {
let columnSchemaObj = this;
return [
@ -161,31 +174,13 @@ export class ColumnSchema extends BaseUISchema {
}
},
editable: function(state) {
let topObj = columnSchemaObj._top;
if(columnSchemaObj.inSchemaWithModelCheck(state)) {
return false;
} else if (topObj._sessData && topObj._sessData.amname === 'btree') {
state.is_sort_nulls_applicable = true;
return true;
} else {
state.is_sort_nulls_applicable = false;
return false;
}
return columnSchemaObj.isEditable(state);
},
deps: ['amname'],
},{
id: 'nulls', label: gettext('NULLs'),
editable: function(state) {
let topObj = columnSchemaObj._top;
if(columnSchemaObj.inSchemaWithModelCheck(state)) {
return false;
} else if (topObj._sessData && topObj._sessData.amname === 'btree') {
state.is_sort_nulls_applicable = true;
return true;
} else {
state.is_sort_nulls_applicable = false;
return false;
}
return columnSchemaObj.isEditable(state);
},
deps: ['amname', 'sort_order'],
type:'select', cell: 'select',
@ -237,6 +232,39 @@ export default class IndexSchema extends BaseUISchema {
return 'oid';
}
getColumns() {
return {
type: 'select',
options: this.fieldOptions.columnList,
optionsLoaded: (options) => { this.fieldOptions.columnList = options; },
controlProps: {
allowClear: false,
multiple: true,
placeholder: gettext('Select the column(s)'),
width: 'style',
filter: (options) => {
let res = [];
if (options && _.isArray(options)) {
_.each(options, function(d) {
if(d.label != '')
res.push({label: d.label, value: d.value, image:'icon-column'});
});
}
return res;
}
}
};
}
isVisible() {
if(!_.isUndefined(this.node_info) && !_.isUndefined(this.node_info.server)
&& !_.isUndefined(this.node_info.server.version) &&
this.node_info.server.version >= 110000)
return true;
return false;
}
get baseFields() {
let indexSchemaObj = this;
return [
@ -324,35 +352,10 @@ export default class IndexSchema extends BaseUISchema {
return !indexSchemaObj.isNew(state);
},
type: () => {
return {
type: 'select',
options: indexSchemaObj.fieldOptions.columnList,
optionsLoaded: (options) => { indexSchemaObj.fieldOptions.columnList = options; },
controlProps: {
allowClear: false,
multiple: true,
placeholder: gettext('Select the column(s)'),
width: 'style',
filter: (options) => {
let res = [];
if (options && _.isArray(options)) {
_.each(options, function(d) {
if(d.label != '')
res.push({label: d.label, value: d.value, image:'icon-column'});
});
}
return res;
}
}
};
return indexSchemaObj.getColumns();
},
visible: function() {
if(!_.isUndefined(this.node_info) && !_.isUndefined(this.node_info.server)
&& !_.isUndefined(this.node_info.server.version) &&
this.node_info.server.version >= 110000)
return true;
return false;
return indexSchemaObj.isVisible();
},
node:'column',
},{
@ -416,27 +419,7 @@ export default class IndexSchema extends BaseUISchema {
}, {
id: 'include', label: gettext('Include columns'),
type: () => {
return {
type: 'select',
options: indexSchemaObj.fieldOptions.columnList,
optionsLoaded: (options) => { indexSchemaObj.fieldOptions.columnList = options; },
controlProps: {
allowClear: false,
multiple: true,
placeholder: gettext('Select the column(s)'),
width: 'style',
filter: (options) => {
let res = [];
if (options && _.isArray(options)) {
_.each(options, function(d) {
if(d.label != '')
res.push({label: d.label, value: d.value, image:'icon-column'});
});
}
return res;
}
}
};
return indexSchemaObj.getColumns();
},
group: gettext('Definition'),
editable: false,
@ -446,12 +429,7 @@ export default class IndexSchema extends BaseUISchema {
return !indexSchemaObj.isNew(state);
},
visible: function() {
if(!_.isUndefined(this.node_info) && !_.isUndefined(this.node_info.server)
&& !_.isUndefined(this.node_info.server.version) &&
this.node_info.server.version >= 110000)
return true;
return false;
return indexSchemaObj.isVisible();
},
node:'column',
},{

View File

@ -127,6 +127,21 @@ function(
encodeURIComponent(info['partition']._id)
);
},
on_done: function(res, data, t, i) {
if (res.success == 1) {
Notify.success(res.info);
t.removeIcon(i);
data.icon = 'icon-partition';
t.addIcon(i, {icon: data.icon});
t.unload(i);
t.setInode(i);
t.deselect(i);
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
}
},
canDrop: SchemaChildTreeNode.isTreeItemOfChildOfSchema,
canDropCascade: SchemaChildTreeNode.isTreeItemOfChildOfSchema,
callbacks: {
@ -197,35 +212,22 @@ function(
Notify.confirm(
gettext('Truncate Table'),
gettext('Are you sure you want to truncate table %s?', d.label),
function (e) {
if (e) {
var data = d;
$.ajax({
url: obj.generate_url(i, 'truncate' , d, true),
type:'PUT',
data: params,
dataType: 'json',
function () {
var data = d;
$.ajax({
url: obj.generate_url(i, 'truncate' , d, true),
type:'PUT',
data: params,
dataType: 'json',
})
.done(function(res) {
obj.on_done(res, data, t, i);
})
.done(function(res) {
if (res.success == 1) {
Notify.success(res.info);
t.removeIcon(i);
data.icon = 'icon-partition';
t.addIcon(i, {icon: data.icon});
t.unload(i);
t.setInode(i);
t.deselect(i);
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
}
})
.fail(function(xhr, status, error) {
Notify.pgRespErrorNotify(xhr, error);
t.unload(i);
});
}},
.fail(function(xhr, status, error) {
Notify.pgRespErrorNotify(xhr, error);
t.unload(i);
});
},
);
},
reset_table_stats: function(args) {
@ -241,33 +243,19 @@ function(
Notify.confirm(
gettext('Reset statistics'),
gettext('Are you sure you want to reset the statistics for table "%s"?', d._label),
function (e) {
if (e) {
var data = d;
$.ajax({
url: obj.generate_url(i, 'reset' , d, true),
type:'DELETE',
function () {
var data = d;
$.ajax({
url: obj.generate_url(i, 'reset' , d, true),
type:'DELETE',
})
.done(function(res) {
obj.on_done(res, data, t, i);
})
.done(function(res) {
if (res.success == 1) {
Notify.success(res.info);
t.removeIcon(i);
data.icon = 'icon-partition';
t.addIcon(i, {icon: data.icon});
t.unload(i);
t.setInode(i);
t.deselect(i);
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
}
})
.fail(function(xhr, status, error) {
Notify.pgRespErrorNotify(xhr, error);
t.unload(i);
});
}
.fail(function(xhr, status, error) {
Notify.pgRespErrorNotify(xhr, error);
t.unload(i);
});
},
function() {/*This is intentional (SonarQube)*/}
);
@ -285,32 +273,30 @@ function(
Notify.confirm(
gettext('Detach Partition'),
gettext('Are you sure you want to detach the partition %s?', d._label),
function (e) {
if (e) {
$.ajax({
url: obj.generate_url(i, 'detach' , d, true),
type:'PUT',
})
.done(function(res) {
if (res.success == 1) {
Notify.success(res.info);
var n = t.next(i);
function () {
$.ajax({
url: obj.generate_url(i, 'detach' , d, true),
type:'PUT',
})
.done(function(res) {
if (res.success == 1) {
Notify.success(res.info);
var n = t.next(i);
if (!n) {
n = t.prev(i);
if (!n) {
n = t.prev(i);
if (!n) {
n = t.parent(i);
}
}
t.remove(i);
if (n) {
t.select(n);
n = t.parent(i);
}
}
})
.fail(function(xhr, status, error) {
Notify.pgRespErrorNotify(xhr, error);
});
}
t.remove(i);
if (n) {
t.select(n);
}
}
})
.fail(function(xhr, status, error) {
Notify.pgRespErrorNotify(xhr, error);
});
},
function() {/*This is intentional (SonarQube)*/}
);

View File

@ -18,6 +18,13 @@ export class PartitionKeysSchema extends BaseUISchema {
this.columns = columns;
}
isEditable(state) {
if(state.key_type == 'expression') {
return false;
}
return true;
}
get baseFields() {
let obj = this;
return [{
@ -47,10 +54,7 @@ export class PartitionKeysSchema extends BaseUISchema {
}
}),
editable: function(state) {
if(state.key_type == 'expression') {
return false;
}
return true;
return obj.isEditable(state);
},
},{
id: 'expression', label: gettext('Expression'), type:'text',
@ -73,10 +77,7 @@ export class PartitionKeysSchema extends BaseUISchema {
type: 'select', group: gettext('partition'), deps:['key_type'],
options: obj.getCollations, mode: ['create', 'properties', 'edit'],
editable: function(state) {
if(state.key_type == 'expression') {
return false;
}
return true;
return obj.isEditable(state);
},
disabled: ()=>{return !(obj.isNew()); },
},
@ -84,10 +85,7 @@ export class PartitionKeysSchema extends BaseUISchema {
id: 'op_class', label: gettext('Operator class'), cell: 'select',
type: 'select', group: gettext('partition'), deps:['key_type'],
editable: function(state) {
if(state.key_type == 'expression') {
return false;
}
return true;
return obj.isEditable(state);
},
disabled: ()=>{return !(obj.isNew()); },
options: obj.getOperatorClass, mode: ['create', 'properties', 'edit'],
@ -137,6 +135,22 @@ export class PartitionsSchema extends BaseUISchema {
this.subPartitionsObj.changeColumnOptions(columns);
}
isEditable(state, type) {
if(this.top && this.top.sessData.partition_type == type && this.isNew(state)
&& state.is_default !== true) {
return true;
}
return false;
}
isDisable(state, type) {
if(this.top && this.top.sessData.partition_type == type && this.isNew(state)
&& state.is_default !== true) {
return false;
}
return true;
}
get baseFields() {
let obj = this;
return [{
@ -223,68 +237,37 @@ export class PartitionsSchema extends BaseUISchema {
id: 'values_from', label: gettext('From'), type:'text', cell: 'text',
deps: ['is_default'],
editable: function(state) {
if(obj.top && obj.top.sessData.partition_type == 'range' && obj.isNew(state)
&& state.is_default !== true) {
return true;
}
return false;
return obj.isEditable(state, 'range');
},
disabled: function(state) {
if(obj.top && obj.top.sessData.partition_type == 'range' && obj.isNew(state)
&& state.is_default !== true) {
return false;
}
return true;
},
return obj.isDisable(state, 'range');
}
},
{
id: 'values_to', label: gettext('To'), type:'text', cell: 'text',
deps: ['is_default'],
editable: function(state) {
if(obj.top && obj.top.sessData.partition_type == 'range' && obj.isNew(state)
&& state.is_default !== true) {
return true;
}
return false;
return obj.isEditable(state, 'range');
},
disabled: function(state) {
if(obj.top && obj.top.sessData.partition_type == 'range' && obj.isNew(state)
&& state.is_default !== true) {
return false;
}
return true;
return obj.isDisable(state, 'range');
},
},{
id: 'values_in', label: gettext('In'), type:'text', cell: 'text',
deps: ['is_default'],
editable: function(state) {
if(obj.top && obj.top.sessData.partition_type == 'list' && obj.isNew(state)
&& state.is_default !== true) {
return true;
}
return false;
return obj.isEditable(state, 'list');
},
readonly: function(state) {
if(obj.top && obj.top.sessData.partition_type == 'list' && obj.isNew(state)
&& state.is_default !== true) {
return false;
}
return true;
return obj.isDisable(state, 'list');
},
},{
id: 'values_modulus', label: gettext('Modulus'), type:'int', cell: 'int',
editable: function(state) {
if(obj.top && obj.top.sessData.partition_type == 'hash' && obj.isNew(state)) {
return true;
}
return false;
return obj.isEditable(state, 'hash');
},
disabled: function(state) {
if(obj.top && obj.top.sessData.partition_type == 'hash' && obj.isNew(state)
&& state.is_default !== true) {
return false;
}
return true;
return obj.isDisable(state, 'hash');
},
},{
id: 'values_remainder', label: gettext('Remainder'), type:'int', cell: 'int',

View File

@ -97,6 +97,13 @@ export class ConstraintsSchema extends BaseUISchema {
return _.some(_.map(state.columns, 'name'));
}
canAdd(state) {
if (state.is_partitioned && this.top.getServerVersion() < 110000) {
return false;
}
return true;
}
get baseFields() {
let obj = this;
return [{
@ -108,10 +115,7 @@ export class ConstraintsSchema extends BaseUISchema {
columns : ['name', 'columns'],
disabled: this.inCatalog,
canAdd: function(state) {
if (state.is_partitioned && obj.top.getServerVersion() < 110000) {
return false;
}
return true;
return obj.canAdd(state);
},
canAddRow: function(state) {
return ((state.primary_key||[]).length < 1 && obj.anyColumnAdded(state));
@ -137,10 +141,7 @@ export class ConstraintsSchema extends BaseUISchema {
group: gettext('Foreign Key'), mode: ['edit', 'create'],
canEdit: true, canDelete: true, deps:['is_partitioned', 'columns'],
canAdd: function(state) {
if (state.is_partitioned && obj.top.getServerVersion() < 110000) {
return false;
}
return true;
return obj.canAdd(state);
},
columns : ['name', 'columns','references_table_name'],
disabled: this.inCatalog,
@ -172,10 +173,7 @@ export class ConstraintsSchema extends BaseUISchema {
columns : ['name', 'columns'],
disabled: this.inCatalog,
canAdd: function(state) {
if (state.is_partitioned && obj.top.getServerVersion() < 110000) {
return false;
}
return true;
return obj.canAdd(state);
},
canAddRow: obj.anyColumnAdded,
depChange: (state)=>{
@ -194,10 +192,7 @@ export class ConstraintsSchema extends BaseUISchema {
columns : ['name', 'columns', 'constraint'],
disabled: this.inCatalog,
canAdd: function(state) {
if (state.is_partitioned && obj.top.getServerVersion() < 110000) {
return false;
}
return true;
return obj.canAdd(state);
},
canAddRow: obj.anyColumnAdded,
depChange: (state)=>{

View File

@ -188,6 +188,13 @@ export default class TriggerSchema extends BaseUISchema {
return flag;
}
isDisable(state) {
if(!state.is_constraint_trigger) {
return true;
}
return false;
}
get baseFields() {
let obj = this;
return [{
@ -301,10 +308,7 @@ export default class TriggerSchema extends BaseUISchema {
}
},
disabled: (state) => {
if(!state.is_constraint_trigger) {
return true;
}
return false;
return obj.isDisable(state);
}
},{
id: 'tginitdeferred', label: gettext('Deferred?'),
@ -331,10 +335,7 @@ export default class TriggerSchema extends BaseUISchema {
}
},
disabled: (state) => {
if(!state.is_constraint_trigger) {
return true;
}
return false;
return obj.isDisable(state);
}
},{
id: 'tfunction', label: gettext('Trigger function'),

View File

@ -145,6 +145,13 @@ function getDataTypeSchema(nodeObj, treeNodeInfo, itemNodeData) {
);
}
function isVisible(state, type) {
if(state.typtype === type) {
return true;
}
return false;
}
class EnumerationSchema extends BaseUISchema {
constructor() {
@ -249,18 +256,7 @@ class RangeSchema extends BaseUISchema {
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
return obj.getFilterOptions(state, options);
}
}
};
@ -277,18 +273,7 @@ class RangeSchema extends BaseUISchema {
placeholder: '',
width: '100%',
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
return obj.getFilterOptions(state, options);
}
}
};
@ -336,18 +321,7 @@ class RangeSchema extends BaseUISchema {
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
return obj.getFilterOptions(state, options);
}
}
};
@ -377,18 +351,7 @@ class RangeSchema extends BaseUISchema {
controlProps: {
allowClear: true,
filter: (options) => {
let res = [];
if (state) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
return obj.getFilterOptions(state, options);
}
}
};
@ -479,6 +442,33 @@ class ExternalSchema extends BaseUISchema {
return result;
}
filterFunctionOptions(state, options) {
let res = [];
if (state && this.isNew(state)) {
res = this.external_func_combo(options);
} else {
res = options;
}
return res;
}
getFunctionType(state) {
let obj = this;
return {
type: 'select',
options: obj.fieldOptions.externalFunctionsList,
optionsLoaded: (options) => { obj.fieldOptions.externalFunctionsList = options; },
controlProps: {
allowClear: true,
placeholder: '',
width: '100%',
filter: (options) => {
return obj.filterFunctionOptions(state, options);
}
}
};
}
get baseFields() {
var obj = this;
return [{
@ -491,50 +481,14 @@ class ExternalSchema extends BaseUISchema {
return !obj.isNew(state);
},
type: (state) => {
return {
type: 'select',
options: obj.fieldOptions.externalFunctionsList,
optionsLoaded: (options) => { obj.fieldOptions.externalFunctionsList = options; },
controlProps: {
allowClear: true,
placeholder: '',
width: '100%',
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
res = obj.external_func_combo(options);
} else {
res = options;
}
return res;
}
}
};
return obj.getFunctionType(state);
},
}, {
id: 'typoutput', label: gettext('Output function'),
mode: ['properties', 'create', 'edit'],
group: gettext('Required'),
type: (state) => {
return {
type: 'select',
options: obj.fieldOptions.externalFunctionsList,
optionsLoaded: (options) => { obj.fieldOptions.externalFunctionsList = options; },
controlProps: {
allowClear: true,
placeholder: '',
width: '100%',
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
res = obj.external_func_combo(options);
} else {
res = options;
}
return res;
}
}
};
return obj.getFunctionType(state);
},
readonly: function (state) {
return !obj.isNew(state);
@ -586,13 +540,7 @@ class ExternalSchema extends BaseUISchema {
placeholder: '',
width: '100%',
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
res = obj.external_func_combo(options);
} else {
res = options;
}
return res;
return obj.filterFunctionOptions(state, options);
}
}
};
@ -705,25 +653,7 @@ class ExternalSchema extends BaseUISchema {
id: 'typanalyze', label: gettext('Analyze function'),
group: gettext('Optional-1'),
type: (state) => {
return {
type: 'select',
options: obj.fieldOptions.externalFunctionsList,
optionsLoaded: (options) => { obj.fieldOptions.externalFunctionsList = options; },
controlProps: {
allowClear: true,
placeholder: '',
width: '100%',
filter: (options) => {
let res = [];
if (state && obj.isNew(state)) {
res = obj.external_func_combo(options);
} else {
res = options;
}
return res;
}
}
};
return obj.getFunctionType(state);
},
mode: ['properties', 'create','edit'],
disabled: () => obj.inCatalog(),
@ -908,6 +838,14 @@ class CompositeSchema extends BaseUISchema {
return 'oid';
}
onTypeChange(state, changeSource) {
if(_.isArray(changeSource) && changeSource[2] == 'type') {
return {...state
, value: null
};
}
}
get baseFields() {
var obj = this;
return [{
@ -970,11 +908,7 @@ class CompositeSchema extends BaseUISchema {
id: 'precision', label: gettext('Scale'), deps: ['type'],
type: 'text', disabled: false, cell: 'int',
depChange: (state, changeSource)=>{
if(_.isArray(changeSource) && changeSource[2] == 'type') {
return {...state
, value: null
};
}
return obj.onTypeChange(state, changeSource);
},
editable: (state) => {
// We will store type from selected from combobox
@ -1003,11 +937,7 @@ class CompositeSchema extends BaseUISchema {
}, {
id: 'collation', label: gettext('Collation'), type: 'text',
depChange: (state, changeSource)=>{
if(_.isArray(changeSource) && changeSource[2] == 'type') {
return {...state
, value: null
};
}
return obj.onTypeChange(state, changeSource);
},
cell: ()=>({
cell: 'select', options: obj.fieldOptions.collations,
@ -1138,9 +1068,7 @@ class DataTypeSchema extends BaseUISchema {
readonly: function (state) {
return !dataTypeObj.isNew(state);
},
visible: function (state) {
return state.typtype === 'V';
}
visible: (state) => isVisible(state, 'V'),
},{
// Note: There are ambiguities in the PG catalogs and docs between
// precision and scale. In the UI, we try to follow the docs as
@ -1155,9 +1083,7 @@ class DataTypeSchema extends BaseUISchema {
readonly: function (state) {
return !dataTypeObj.isNew(state);
},
visible: function (state) {
return state.typtype === 'N';
},
visible: (state) => isVisible(state, 'N'),
disabled: function(state) {
var of_type = state.type,
@ -1217,9 +1143,7 @@ class DataTypeSchema extends BaseUISchema {
return !dataTypeObj.isNew(state);
},
cell: 'int',
visible: function (state) {
return state.typtype === 'N';
},
visible: (state) => isVisible(state, 'N'),
disabled: function(state) {
var of_type = state.type,
flag = true;
@ -1416,9 +1340,7 @@ export default class TypeSchema extends BaseUISchema {
state.composite.splice(0, state.composite.length);
}
},
visible: (state) => {
return state.typtype === 'c';
},
visible: (state) => isVisible(state, 'c'),
},
{
id: 'enum', label: gettext('Enumeration type'),
@ -1437,9 +1359,7 @@ export default class TypeSchema extends BaseUISchema {
disabled: () => obj.inCatalog(),
deps: ['typtype'],
uniqueCol : ['label'],
visible: function(state) {
return state.typtype === 'e';
},
visible: (state) => isVisible(state, 'e'),
}, {
type: 'nested-fieldset',
group: gettext('Definition'),
@ -1456,9 +1376,7 @@ export default class TypeSchema extends BaseUISchema {
group: gettext('Definition'),
label: '',
mode: ['edit', 'create'],
visible: (state) => {
return state.typtype && state.typtype === 'r';
},
visible: (state) => isVisible(state, 'r'),
deps: ['typtype'],
schema: obj.getRangeSchema(),
}, {
@ -1466,9 +1384,7 @@ export default class TypeSchema extends BaseUISchema {
group: gettext('Definition'),
label: gettext('External Type'), deps: ['typtype'],
mode: ['create', 'edit'], tabPanelExtraClasses:'inline-tab-panel-padded',
visible: function(state) {
return state.typtype === 'b';
},
visible: (state) => isVisible(state, 'b'),
schema: obj.getExternalSchema(),
},
{
@ -1480,99 +1396,54 @@ export default class TypeSchema extends BaseUISchema {
id: 'member_list', label: gettext('Members'), cell: 'string',
type: 'text', mode: ['properties'], group: gettext('Definition'),
disabled: () => obj.inCatalog(),
visible: function(state) {
if(state.typtype === 'c') {
return true;
}
return false;
},
visible: (state) => isVisible(state, 'c'),
},{
id: 'enum_list', label: gettext('Labels'), cell: 'string',
type: 'text', mode: ['properties'], group: gettext('Definition'),
disabled: () => obj.inCatalog(),
visible: function(state) {
if(state.typtype === 'e') {
return true;
}
return false;
},
visible: (state) => isVisible(state, 'e'),
},
{
id: 'typname', label: gettext('SubType'), cell: 'string',
type: 'text', mode: ['properties'], group: gettext('Definition'),
disabled: () => obj.inCatalog(),
visible: function(state) {
if(state.typtype === 'r') {
return true;
}
return false;
},
visible: (state) => isVisible(state, 'r'),
},
{
id: 'opcname', label: gettext('Subtype operator class'), cell: 'string',
type: 'text', mode: ['properties'], group: gettext('Definition'),
disabled: () => obj.inCatalog(),
visible: function(state) {
if(state.typtype === 'r') {
return true;
}
return false;
},
visible: (state) => isVisible(state, 'r'),
},
{
id: 'collname', label: gettext('Collation'), cell: 'string',
type: 'text', mode: ['properties'], group: gettext('Definition'),
disabled: () => obj.inCatalog(),
visible: function(state) {
if(state.typtype === 'r') {
return true;
}
return false;
},
visible: (state) => isVisible(state, 'r'),
},
{
id: 'rngcanonical', label: gettext('Canonical function'), cell: 'string',
type: 'text', mode: ['properties'], group: gettext('Definition'),
disabled: () => obj.inCatalog(),
visible: function(state) {
if(state.typtype === 'r') {
return true;
}
return false;
},
visible: (state) => isVisible(state, 'r'),
},
{
id: 'rngsubdiff', label: gettext('Subtype diff function'), cell: 'string',
type: 'text', mode: ['properties'], group: gettext('Definition'),
disabled: () => obj.inCatalog(),
visible: function(state) {
if(state.typtype === 'r') {
return true;
}
return false;
},
visible: (state) => isVisible(state, 'r'),
},
{
id: 'typinput', label: gettext('Input function'), cell: 'string',
type: 'text', mode: ['properties'], group: gettext('Definition'),
disabled: () => obj.inCatalog(),
visible: function(state) {
if(state.typtype === 'b') {
return true;
}
return false;
},
visible: (state) => isVisible(state, 'b'),
},
{
id: 'typoutput', label: gettext('Output function'), cell: 'string',
type: 'text', mode: ['properties'], group: gettext('Definition'),
disabled: () => obj.inCatalog(),
visible: function(state) {
if(state.typtype === 'b') {
return true;
}
return false;
},
visible: (state) => isVisible(state, 'b'),
},
{
id: 'type', label: gettext('Data Type'), cell: 'string',
@ -1589,34 +1460,19 @@ export default class TypeSchema extends BaseUISchema {
id: 'tlength', label: gettext('Length/Precision'), cell: 'string',
type: 'text', mode: ['properties'], group: gettext('Definition'),
disabled: () => obj.inCatalog(),
visible: function(state) {
if(state.typtype === 'N') {
return true;
}
return false;
}
visible: (state) => isVisible(state, 'N'),
},
{
id: 'precision', label: gettext('Scale'), cell: 'string',
type: 'text', mode: ['properties'], group: gettext('Definition'),
disabled: () => obj.inCatalog(),
visible: function(state) {
if(state.typtype === 'N') {
return true;
}
return false;
}
visible: (state) => isVisible(state, 'N'),
},
{
id: 'maxsize', label: gettext('Size'), cell: 'string',
type: 'text', mode: ['properties'], group: gettext('Definition'),
disabled: () => obj.inCatalog(),
visible: function(state) {
if(state.typtype === 'V') {
return true;
}
return false;
}
visible: (state) => isVisible(state, 'V'),
},
{
id: 'type_acl', label: gettext('Privileges'), cell: 'string',

View File

@ -313,6 +313,10 @@ define('pgadmin.node.database', [
},
},
getSchema: function(treeNodeInfo, itemNodeData) {
let c_types = ()=>getNodeAjaxOptions('get_ctypes', this, treeNodeInfo, itemNodeData, {
cacheLevel: 'server',
});
return new DatabaseSchema(
()=>getNodeVariableSchema(this, treeNodeInfo, itemNodeData, false, true),
(privileges)=>getNodePrivilegeRoleSchema(this, treeNodeInfo, itemNodeData, privileges),
@ -339,14 +343,8 @@ define('pgadmin.node.database', [
()=>getNodeListByName('tablespace', treeNodeInfo, itemNodeData, {}, (m)=>{
return (m.label != 'pg_global');
}),
datcollate:
()=>getNodeAjaxOptions('get_ctypes', this, treeNodeInfo, itemNodeData, {
cacheLevel: 'server',
}),
datctype:
()=>getNodeAjaxOptions('get_ctypes', this, treeNodeInfo, itemNodeData, {
cacheLevel: 'server',
}),
datcollate: c_types,
datctype: c_types,
},
{
datowner: pgBrowser.serverInfo[treeNodeInfo.server._id].user.name,

View File

@ -584,6 +584,20 @@ define('pgadmin.node.server', [
return false;
},
on_done: function(res, t, i) {
if (res.success == 1) {
Notify.success(res.info);
t.itemData(i).wal_pause=res.data.wal_pause;
t.unload(i);
t.setInode(i);
t.deselect(i);
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
}
},
/* Pause WAL Replay */
pause_wal_replay: function(args) {
var input = args || {},
@ -601,17 +615,7 @@ define('pgadmin.node.server', [
dataType: 'json',
})
.done(function(res) {
if (res.success == 1) {
Notify.success(res.info);
t.itemData(i).wal_pause=res.data.wal_pause;
t.unload(i);
t.setInode(i);
t.deselect(i);
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
}
obj.on_done(res, t, i);
})
.fail(function(xhr, status, error) {
Notify.pgRespErrorNotify(xhr, error);
@ -636,17 +640,7 @@ define('pgadmin.node.server', [
dataType: 'json',
})
.done(function(res) {
if (res.success == 1) {
Notify.success(res.info);
t.itemData(i).wal_pause=res.data.wal_pause;
t.unload(i);
t.setInode(i);
t.deselect(i);
// Fetch updated data from server
setTimeout(function() {
t.select(i);
}, 10);
}
obj.on_done(res, t, i);
})
.fail(function(xhr, status, error) {
Notify.pgRespErrorNotify(xhr, error);

View File

@ -532,6 +532,22 @@ define('pgadmin.browser.node', [
return new_panel;
},
onEventResizeEnded: function() {
var $container = this.$container.find('.obj_properties').first(),
v = $container.data('obj-view');
if (v && v.model && v.model) {
v.model.trigger(
'pg-browser-resized', {
'view': v,
'panel': this,
'container': $container,
});
}
},
registerUtilityPanel: function() {
var w = pgBrowser.docker,
p = w.findPanels('utility_props');
@ -540,20 +556,7 @@ define('pgadmin.browser.node', [
return;
var events = {};
events[wcDocker.EVENT.RESIZE_ENDED] = function() {
var $container = this.$container.find('.obj_properties').first(),
v = $container.data('obj-view');
if (v && v.model && v.model) {
v.model.trigger(
'pg-browser-resized', {
'view': v,
'panel': this,
'container': $container,
});
}
};
events[wcDocker.EVENT.RESIZE_ENDED] = this.onEventResizeEnded;
p = new pgBrowser.Panel({
name: 'utility_props',
@ -579,20 +582,7 @@ define('pgadmin.browser.node', [
return;
var events = {};
events[wcDocker.EVENT.RESIZE_ENDED] = function() {
var $container = this.$container.find('.obj_properties').first(),
v = $container.data('obj-view');
if (v && v.model && v.model) {
v.model.trigger(
'pg-browser-resized', {
'view': v,
'panel': this,
'container': $container,
});
}
};
events[wcDocker.EVENT.RESIZE_ENDED] = this.onEventResizeEnded;
p = new pgBrowser.Panel({
name: 'node_props',

View File

@ -218,6 +218,30 @@ define([
}
};
var filterRows = function(self, filter, rows, node) {
var res = [];
_.each(rows, function(r) {
if (filter(r)) {
var l = (_.isFunction(node['node_label']) ?
(node['node_label']).apply(node, [r, self.model, self]) :
r.label),
image = (_.isFunction(node['node_image']) ?
(node['node_image']).apply(
node, [r, self.model, self]
) :
(node['node_image'] || ('icon-' + node.type)));
res.push({
'value': r._id,
'image': image,
'label': l,
});
}
});
return res;
};
var NodeListByIdControl = Backform.NodeListByIdControl = NodeAjaxOptionsControl.extend({
controlClassName: 'pgadmin-node-select form-control',
defaults: _.extend({}, NodeAjaxOptionsControl.prototype.defaults, {
@ -226,33 +250,12 @@ define([
transform: function(rows) {
var self = this,
node = self.field.get('schema_node'),
res = [],
filter = self.field.get('filter') || function() {
return true;
};
filter = filter.bind(self);
_.each(rows, function(r) {
if (filter(r)) {
var l = (_.isFunction(node['node_label']) ?
(node['node_label']).apply(node, [r, self.model, self]) :
r.label),
image = (_.isFunction(node['node_image']) ?
(node['node_image']).apply(
node, [r, self.model, self]
) :
(node['node_image'] || ('icon-' + node.type)));
res.push({
'value': r._id,
'image': image,
'label': l,
});
}
});
return res;
return filterRows(self, filter, rows, node);
},
select2: {
allowClear: true,
@ -473,42 +476,23 @@ define([
},
});
var transformFunc = function(rows, control) {
var self = control || this,
node = self.column.get('schema_node'),
filter = self.column.get('filter') || function() {
return true;
};
filter = filter.bind(self);
return filterRows(self, filter, rows, node);
};
Backgrid.Extension.NodeListByIdCell = NodeAjaxOptionsCell.extend({
controlClassName: 'pgadmin-node-select backgrid-cell',
defaults: _.extend({}, NodeAjaxOptionsCell.prototype.defaults, {
url: 'nodes',
filter: undefined,
transform: function(rows, control) {
var self = control || this,
node = self.column.get('schema_node'),
res = [],
filter = self.column.get('filter') || function() {
return true;
};
filter = filter.bind(self);
_.each(rows, function(r) {
if (filter(r)) {
var l = (_.isFunction(node['node_label']) ?
(node['node_label']).apply(node, [r, self.model, self]) :
r.label),
image = (_.isFunction(node['node_image']) ?
(node['node_image']).apply(
node, [r, self.model, self]
) :
(node['node_image'] || ('icon-' + node.type)));
res.push({
'value': r._id,
'image': image,
'label': l,
});
}
});
return res;
},
transform: transformFunc,
select2: {
placeholder: gettext('Select an item...'),
width: 'style',
@ -523,37 +507,7 @@ define([
defaults: _.extend({}, NodeAjaxOptionsCell.prototype.defaults, {
url: 'nodes',
filter: undefined,
transform: function(rows, control) {
var self = control || this,
node = self.column.get('schema_node'),
res = [],
filter = self.column.get('filter') || function() {
return true;
};
filter = filter.bind(self);
_.each(rows, function(r) {
if (filter(r)) {
var l = (_.isFunction(node['node_label']) ?
(node['node_label']).apply(node, [r, self.model, self]) :
r.label),
image = (_.isFunction(node['node_image']) ?
(node['node_image']).apply(
node, [r, self.model, self]
) :
(node['node_image'] || ('icon-' + node.type)));
res.push({
'value': r.label,
'image': image,
'label': l,
});
}
});
return res;
},
transform: transformFunc,
select2: {
placeholder: gettext('Select an item...'),
width: 'style',

View File

@ -35,6 +35,16 @@ export function getNodeView(nodeType, treeNodeInfo, actionType, itemNodeData, fo
let warnOnCloseFlag = true;
const confirmOnCloseReset = pgAdmin.Browser.get_preferences_for_module('browser').confirm_on_properties_close;
let onError = (err)=> {
if(err.response){
console.error('error resp', err.response);
} else if(err.request){
console.error('error req', err.request);
} else if(err.message){
console.error('error msg', err.message);
}
};
/* Called when dialog is opened in edit mode, promise required */
let initData = ()=>new Promise((resolve, reject)=>{
api.get(url(false))
@ -42,13 +52,7 @@ export function getNodeView(nodeType, treeNodeInfo, actionType, itemNodeData, fo
resolve(res.data);
})
.catch((err)=>{
if(err.response){
console.error('error resp', err.response);
} else if(err.request){
console.error('error req', err.request);
} else if(err.message){
console.error('error msg', err.message);
}
onError(err);
reject(err);
});
});
@ -80,13 +84,7 @@ export function getNodeView(nodeType, treeNodeInfo, actionType, itemNodeData, fo
}).then((res)=>{
resolve(res.data.data);
}).catch((err)=>{
if(err.response){
console.error('error resp', err.response);
} else if(err.request){
console.error('error req', err.request);
} else if(err.message){
console.error('error msg', err.message);
}
onError(err);
reject(err);
});
});

View File

@ -133,7 +133,6 @@ define(
pgBrowser.Events.on('pgadmin-browser:tree:selected', () => {
if(myPanel.isVisible()) {
removePanelView($container[0]);
getPanelView(
pgBrowser.tree,
$container[0],

View File

@ -239,19 +239,7 @@ define('pgadmin.dashboard', [
$(div).html(data);
})
.fail(function(xhr, error) {
Notify.pgNotifier(
error, xhr,
gettext('An error occurred whilst loading the dashboard.'),
function(msg) {
if(msg === 'CRYPTKEY_SET') {
ajaxHook();
} else {
$(div).html(
'<div class="pg-panel-message" role="alert">' + gettext('An error occurred whilst loading the dashboard.') + '</div>'
);
}
}
);
self.onFail(xhr, error, div, ajaxHook);
});
};
$(div).html(
@ -266,6 +254,22 @@ define('pgadmin.dashboard', [
}
},
onFail: function(xhr, error, div, ajaxHook) {
Notify.pgNotifier(
error, xhr,
gettext('An error occurred whilst loading the dashboard.'),
function(msg) {
if(msg === 'CRYPTKEY_SET') {
ajaxHook();
} else {
$(div).html(
'<div class="pg-panel-message" role="alert">' + gettext('An error occurred whilst loading the dashboard.') + '</div>'
);
}
}
);
},
// Handle Server Disconnect
object_disconnected: function() {
let item = pgBrowser.tree.selected(),
@ -358,19 +362,7 @@ define('pgadmin.dashboard', [
self.init_dashboard();
})
.fail(function(xhr, error) {
Notify.pgNotifier(
error, xhr,
gettext('An error occurred whilst loading the dashboard.'),
function(msg) {
if(msg === 'CRYPTKEY_SET') {
ajaxHook();
} else {
$(div).html(
'<div class="pg-panel-message" role="alert">' + gettext('An error occurred whilst loading the dashboard.') + '</div>'
);
}
}
);
self.onFail(xhr, error, div, ajaxHook);
});
};
$(div).html(
@ -631,6 +623,16 @@ define('pgadmin.dashboard', [
}
}
},
renderTab: function(e, tab_grid_map) {
let prevGrid = tab_grid_map[$(e.relatedTarget).attr('aria-controls')];
$(prevGrid).data('filtertext', $('#txtGridSearch').val());
let currGrid = tab_grid_map[$(e.target).attr('aria-controls')];
$('#txtGridSearch').val($(currGrid).data('filtertext'));
pgAdmin.Dashboard.render_grid_data(currGrid);
},
reflectPreferencesServer: function() {
var self = this;
var $dashboardContainer = $('.dashboard-container');
@ -895,12 +897,7 @@ define('pgadmin.dashboard', [
// (Re)render the appropriate tab
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
let prevGrid = tab_grid_map[$(e.relatedTarget).attr('aria-controls')];
$(prevGrid).data('filtertext', $('#txtGridSearch').val());
let currGrid = tab_grid_map[$(e.target).attr('aria-controls')];
$('#txtGridSearch').val($(currGrid).data('filtertext'));
pgAdmin.Dashboard.render_grid_data(currGrid);
self.renderTab(e, tab_grid_map);
});
$('#btn_refresh').off('click').on('click', () => {
@ -1123,12 +1120,7 @@ define('pgadmin.dashboard', [
// (Re)render the appropriate tab
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
let prevGrid = tab_grid_map[$(e.relatedTarget).attr('aria-controls')];
$(prevGrid).data('filtertext', $('#txtGridSearch').val());
let currGrid = tab_grid_map[$(e.target).attr('aria-controls')];
$('#txtGridSearch').val($(currGrid).data('filtertext'));
pgAdmin.Dashboard.render_grid_data(currGrid);
self.renderTab(e, tab_grid_map);
});
$('#btn_refresh').off('click').on('click', () => {

View File

@ -19,8 +19,20 @@ let StatisticsModel = Backbone.Model.extend({
Summary: {},
},
explainToolTip: function(key, value, tooltip) {
key = _.escape(key);
value = _.escape(value);
tooltip.append(`
<tr>
<td class="label explain-tooltip"> ${key}</td>
<td class="label explain-tooltip-val">${value}</td>
</tr>
`);
},
set_statistics: function(toolTipContainer) {
var jit_stats = this.get('JIT'),
var self= this,
jit_stats = this.get('JIT'),
triggers_stats = this.get('Triggers'),
summary = this.get('Summary');
@ -40,14 +52,7 @@ let StatisticsModel = Backbone.Model.extend({
if (Object.keys(jit_stats).length > 0){
tooltip.append('<tr><td colspan="2" class="label explain-tooltip">' + gettext('JIT:') + '</td></tr>');
_.each(jit_stats, function(value, key) {
key = _.escape(key);
value = _.escape(value);
tooltip.append(`
<tr>
<td class="label explain-tooltip"> ${key}</td>
<td class="label explain-tooltip-val">${value}</td>
</tr>
`);
self.explainToolTip(key, value, tooltip);
});
}
@ -93,14 +98,7 @@ let StatisticsModel = Backbone.Model.extend({
if (Object.keys(summary).length > 0){
tooltip.append('<tr><td colspan="2" class="label explain-tooltip">' + gettext('Summary:') + '</td></tr>');
_.each(summary, function(value, key) {
key = _.escape(key);
value = _.escape(value);
tooltip.append(`
<tr>
<td class="label explain-tooltip"> ${key}</td>
<td class="label explain-tooltip-val">${value}</td>
</tr>
`);
self.explainToolTip(key, value, tooltip);
});
}

View File

@ -355,7 +355,7 @@ export default function DataGridView({
disableResizing: false,
sortable: true,
...widthParms,
Cell: ({cellValue, row, ...other}) => {
Cell: ({value, row, ...other}) => {
/* Make sure to take the latest field info from schema */
field = _.find(schemaRef.current.fields, (f)=>f.id==field.id) || field;
@ -365,7 +365,7 @@ export default function DataGridView({
console.error('cell is required ', field);
}
return <MappedCellControl rowIndex={row.index} value={cellValue}
return <MappedCellControl rowIndex={row.index} value={value}
row={row.original} {...field}
readonly={!editable}
disabled={false}
@ -385,7 +385,6 @@ export default function DataGridView({
colInfo.Cell.propTypes = {
row: PropTypes.object.isRequired,
value: PropTypes.any,
cellValue: PropTypes.any,
onCellChange: PropTypes.func,
};
return colInfo;

View File

@ -145,6 +145,14 @@ export default class BaseUISchema {
return false;
}
/* Check readonly on the basis of new state */
isReadOnly(state) {
if(!this.isNew(state)) {
return true;
}
return false;
}
/* Get the server version */
getServerVersion() {
if(!_.isUndefined(this.nodeInfo) && !_.isUndefined(this.nodeInfo.server)
@ -152,4 +160,21 @@ export default class BaseUISchema {
return this.nodeInfo.server.version;
}
}
/* Get the filter options */
getFilterOptions(state, options) {
// Function is used to populate the filter options.
let res = [];
if (state && this.isNew(state)) {
options.forEach((option) => {
if(option && option.label == '') {
return;
}
res.push({ label: option.label, value: option.value });
});
} else {
res = options;
}
return res;
}
}

View File

@ -426,11 +426,6 @@ export function registerDetachEvent(panel){
style: 'z-index: 1200'
});
});
panel.on(wcDocker.EVENT.ORDER_CHANGED, function() {
$((this.$container)[0].ownerDocument).find('.wcIFrameFloating').attr({
style: 'z-index: 1200'
});
});
panel.on(wcDocker.EVENT.ORDER_CHANGED, function() {
var docker = this.docker(this._panel);
var dockerPos = docker.$container.offset();
@ -442,5 +437,8 @@ export function registerDetachEvent(panel){
$((this.$container)[0].ownerDocument).find('.wcIFrameFloating').css('left', pos.left - dockerPos.left);
$((this.$container)[0].ownerDocument).find('.wcIFrameFloating').css('width', width);
$((this.$container)[0].ownerDocument).find('.wcIFrameFloating').find('.wcIFrameFloating').css('height', height);
$((this.$container)[0].ownerDocument).find('.wcIFrameFloating').attr({
style: 'z-index: 1200'
});
});
}

View File

@ -193,6 +193,12 @@ export function getSaveOptSchema(fieldOptions) {
return new SaveOptSchema(fieldOptions);
}
function isVisible () {
if (!_.isUndefined(this.backupType) && this.backupType === 'server')
return false;
return true;
}
export class QueryOptionSchema extends BaseUISchema {
constructor(fieldOptions={}, initValues={}) {
super({
@ -465,11 +471,7 @@ export default class BackupSchema extends BaseUISchema {
disabled: function(state) {
return (state.format === 'tar');
},
visible: function() {
if (!_.isUndefined(obj.backupType) && obj.backupType === 'server')
return false;
return true;
},
visible: isVisible,
}, {
id: 'encoding',
label: gettext('Encoding'),
@ -491,11 +493,7 @@ export default class BackupSchema extends BaseUISchema {
disabled: function(state) {
return (state.format !== 'directory');
},
visible: function() {
if (!_.isUndefined(obj.backupType) && obj.backupType === 'server')
return false;
return true;
},
visible: isVisible,
}, {
id: 'role',
label: gettext('Role name'),
@ -517,11 +515,7 @@ export default class BackupSchema extends BaseUISchema {
label: gettext('Sections'),
group: gettext('Data/Objects'),
schema:new getSectionSchema(),
visible: function() {
if (!_.isUndefined(obj.backupType) && obj.backupType === 'server')
return false;
return true;
},
visible: isVisible,
}, {
type: 'nested-fieldset',
label: gettext('Type of objects'),

View File

@ -119,23 +119,23 @@ export function launchDataGrid(datagrid, transId, gridUrl, queryToolTitle, sURL)
}
}
function setPanelTitle(panel, value) {
if(value) {
$('#' + panel.$title.index() + ' div:first').addClass('wcPanelTab-dynamic');
} else {
$('#' + panel.$title.index() + ' div:first').removeClass('wcPanelTab-dynamic');
}
}
export function _set_dynamic_tab(pgBrowser, value){
var datagrid_panels = pgBrowser.docker.findPanels('frm_datagrid');
datagrid_panels.forEach(panel => {
if(value) {
$('#' + panel.$title.index() + ' div:first').addClass('wcPanelTab-dynamic');
} else {
$('#' + panel.$title.index() + ' div:first').removeClass('wcPanelTab-dynamic');
}
setPanelTitle(panel, value);
});
var debugger_panels = pgBrowser.docker.findPanels('frm_debugger');
debugger_panels.forEach(panel => {
if(value) {
$('#' + panel.$title.index() + ' div:first').addClass('wcPanelTab-dynamic');
} else {
$('#' + panel.$title.index() + ' div:first').removeClass('wcPanelTab-dynamic');
}
setPanelTitle(panel, value);
});
}

View File

@ -300,6 +300,17 @@ define([
});
},
onFail: function(xhr) {
try {
var err = JSON.parse(xhr.responseText);
if (err.success == 0) {
Notify.alert(gettext('Debugger Error'), err.errormsg);
}
} catch (e) {
console.warn(e.stack || e);
}
},
check_func_debuggable: function(args, item) {
var t = pgBrowser.tree,
i = item || t.selected(),
@ -321,17 +332,28 @@ define([
self.start_global_debugger(args, item, res.data.trans_id);
})
.fail(function(xhr) {
try {
var err = JSON.parse(xhr.responseText);
if (err.success == 0) {
Notify.alert(gettext('Debugger Error'), err.errormsg);
}
} catch (e) {
console.warn(e.stack || e);
}
self.onFail(xhr);
});
},
panel_rename_event: function(panel_data, panel, treeInfo) {
Alertify.prompt('', panel_data.$titleText[0].textContent,
// We will execute this function when user clicks on the OK button
function(evt, value) {
if(value) {
// Remove the leading and trailing white spaces.
value = value.trim();
let preferences = pgBrowser.get_preferences_for_module('browser');
var name = debuggerUtils.getAppropriateLabel(treeInfo);
debuggerUtils.setDebuggerTitle(panel, preferences, name, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
}
},
// We will execute this function when user clicks on the Cancel
// button. Do nothing just close it.
function(evt) { evt.cancel = false; }
).set({'title': gettext('Rename Panel')});
},
//Callback function when user start the indirect debugging ( Listen to another session to invoke the target )
start_global_debugger: function(args, item, trans_id) {
// Initialize the target and create asynchronous connection and unique transaction ID
@ -465,21 +487,7 @@ define([
// Panel Rename event
panel.on(wcDocker.EVENT.RENAME, function(panel_data) {
Alertify.prompt('', panel_data.$titleText[0].textContent,
// We will execute this function when user clicks on the OK button
function(evt, value) {
if(value) {
// Remove the leading and trailing white spaces.
value = value.trim();
let preferences = pgBrowser.get_preferences_for_module('browser');
var name = debuggerUtils.getAppropriateLabel(treeInfo);
debuggerUtils.setDebuggerTitle(panel, preferences, name, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
}
},
// We will execute this function when user clicks on the Cancel
// button. Do nothing just close it.
function(evt) { evt.cancel = false; }
).set({'title': gettext('Rename Panel')});
self.panel_rename_event(panel_data, panel, treeInfo);
});
}
})
@ -639,21 +647,7 @@ define([
// Panel Rename event
panel.on(wcDocker.EVENT.RENAME, function(panel_data) {
Alertify.prompt('', panel_data.$titleText[0].textContent,
// We will execute this function when user clicks on the OK button
function(evt, value) {
if(value) {
// Remove the leading and trailing white spaces.
value = value.trim();
let preferences = pgBrowser.get_preferences_for_module('browser');
var name = debuggerUtils.getAppropriateLabel(treeInfo);
debuggerUtils.setDebuggerTitle(panel, preferences, name, treeInfo.schema.label, treeInfo.database.label, value, pgBrowser);
}
},
// We will execute this function when user clicks on the Cancel
// button. Do nothing just close it.
function(evt) { evt.cancel = false; }
).set({'title': gettext('Rename Panel')});
self.panel_rename_event(panel_data, panel, treeInfo);
});
}
})
@ -666,14 +660,7 @@ define([
}
})
.fail(function(xhr) {
try {
var err = JSON.parse(xhr.responseText);
if (err.success == 0) {
Notify.alert(gettext('Debugger Error'), err.errormsg);
}
} catch (e) {
console.warn(e.stack || e);
}
self.onFail(xhr);
});
},
};

View File

@ -536,14 +536,7 @@ define([
// Execution completed so disable the buttons other than
// "Continue/Start" button because user can still
// start the same execution again.
setTimeout(function() {
self.enable('stop', false);
self.enable('step_over', false);
self.enable('step_into', false);
self.enable('toggle_breakpoint', false);
self.enable('clear_all_breakpoints', false);
self.enable('continue', true);
}, 500);
setTimeout(self.disable_toolbar_buttons(), 500);
// Stop further polling
pgTools.DirectDebug.is_polling_required = false;
@ -570,14 +563,7 @@ define([
// Execution completed so disable the buttons other than
// "Continue/Start" button because user can still
// start the same execution again.
setTimeout(function() {
self.enable('stop', false);
self.enable('step_over', false);
self.enable('step_into', false);
self.enable('toggle_breakpoint', false);
self.enable('clear_all_breakpoints', false);
self.enable('continue', true);
}, 500);
setTimeout(self.disable_toolbar_buttons(), 500);
// Stop further pooling
pgTools.DirectDebug.is_polling_required = false;

View File

@ -23,17 +23,22 @@ export class VacuumSchema extends BaseUISchema {
return 'op';
}
isDisabled(state) {
if(state?.op) {
return (state.op != 'VACUUM');
} else {
return false;
}
}
get baseFields() {
let obj = this;
return [{
id: 'vacuum_full',
group: gettext('Vacuum'),
disabled: function(state) {
if(state?.op) {
return (state.op != 'VACUUM');
} else {
return false;
}
return obj.isDisabled(state);
},
type: 'switch',
label: gettext('FULL'),
@ -42,11 +47,7 @@ export class VacuumSchema extends BaseUISchema {
id: 'vacuum_freeze',
deps: ['op'],
disabled: function(state) {
if(state?.op) {
return (state.op != 'VACUUM');
} else {
return false;
}
return obj.isDisabled(state);
},
type: 'switch',
label: gettext('FREEZE'),
@ -56,11 +57,7 @@ export class VacuumSchema extends BaseUISchema {
deps: ['op'],
type: 'switch',
disabled: function(state) {
if(state?.op) {
return (state.op != 'VACUUM');
} else {
return false;
}
return obj.isDisabled(state);
},
label: gettext('ANALYZE'),
group: gettext('Vacuum'),

View File

@ -27,6 +27,14 @@ export class RestoreSectionSchema extends BaseUISchema {
return 'id';
}
isDisabled(state) {
return this.selectedNodeType !== 'function' &&
this.selectedNodeType !== 'table' &&
this.selectedNodeType !== 'trigger' &&
this.selectedNodeType !== 'trigger_function' &&
(state.only_data || state.only_schema);
}
get baseFields() {
let obj = this;
return [{
@ -36,10 +44,7 @@ export class RestoreSectionSchema extends BaseUISchema {
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);
return obj.isDisabled(state);
},
}, {
id: 'data',
@ -48,11 +53,7 @@ export class RestoreSectionSchema extends BaseUISchema {
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);
return obj.isDisabled(state);
},
}, {
id: 'post_data',
@ -61,11 +62,7 @@ export class RestoreSectionSchema extends BaseUISchema {
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);
return obj.isDisabled(state);
},
}];
}

View File

@ -632,6 +632,16 @@ export default class SchemaDiffUI {
}
}
transformFunc(data) {
let group_template_options = [];
for (let key in data) {
if (data.hasOwnProperty(key)) {
group_template_options.push({'group': key, 'optval': data[key]});
}
}
return group_template_options;
}
render() {
let self = this;
let panel = self.docker.findPanels('schema_diff_header_panel')[0];
@ -645,13 +655,7 @@ export default class SchemaDiffUI {
name: 'source_sid', label: false,
control: SchemaDiffSelect2Control,
transform: function(data) {
let group_template_options = [];
for (let key in data) {
if (data.hasOwnProperty(key)) {
group_template_options.push({'group': key, 'optval': data[key]});
}
}
return group_template_options;
return self.transformFunc(data);
},
url: url_for('schema_diff.servers'),
select2: {
@ -729,13 +733,7 @@ export default class SchemaDiffUI {
name: 'target_sid', label: false,
control: SchemaDiffSelect2Control,
transform: function(data) {
let group_template_options = [];
for (let key in data) {
if (data.hasOwnProperty(key)) {
group_template_options.push({'group': key, 'optval': data[key]});
}
}
return group_template_options;
return self.transformFunc(data);
},
group: 'target',
url: url_for('schema_diff.servers'),

View File

@ -192,6 +192,13 @@ define([
alertify.PgaLogin(title, url).resizeTo(pgBrowser.stdW.md, pgBrowser.stdH.md);
},
is_editable: function(m) {
if (m instanceof Backbone.Collection) {
return true;
}
return (m.get('id') != userInfo['id']);
},
// Callback to draw User Management Dialog.
show_users: function() {
if (!userInfo['is_admin']) return;
@ -310,10 +317,7 @@ define([
return options;
},
editable: function(m) {
if (m instanceof Backbone.Collection) {
return true;
}
return (m.get('id') != userInfo['id']);
return self.is_editable(m);
},
}, {
id: 'active',
@ -323,10 +327,7 @@ define([
cellHeaderClasses: 'width_percent_10',
sortable: false,
editable: function(m) {
if (m instanceof Backbone.Collection) {
return true;
}
return (m.get('id') != userInfo['id']);
return self.is_editable(m);
},
}, {
id: 'newPassword',
@ -519,29 +520,13 @@ define([
}
}
} else {
if (!!this.get('username') && this.collection.nonFilter.where({
if (!!this.get('username') && (this.collection.nonFilter.where({
'username': this.get('username'), 'auth_source': LDAP,
}).length > 1) {
errmsg = gettext('The username %s already exists.',
this.get('username')
);
this.errorModel.set('username', errmsg);
return errmsg;
}
else if (!!this.get('username') && this.collection.nonFilter.where({
}).length > 1) || (this.collection.nonFilter.where({
'username': this.get('username'), 'auth_source': KERBEROS,
}).length > 1) {
errmsg = gettext('The username %s already exists.',
this.get('username')
);
this.errorModel.set('username', errmsg);
return errmsg;
}
else if (!!this.get('username') && this.collection.nonFilter.where({
}).length > 1) || (this.collection.nonFilter.where({
'username': this.get('username'), 'auth_source': OAUTH2,
}).length > 1) {
}).length > 1)) {
errmsg = gettext('The username %s already exists.',
this.get('username')
);