Added support to view trigger function under the respective trigger node. Fixes #2519

This commit is contained in:
Akshay Joshi
2020-10-12 13:49:54 +05:30
parent 365ec0ba9f
commit 556278dbc5
9 changed files with 148 additions and 15 deletions

View File

@@ -404,7 +404,7 @@ define('pgadmin.browser', [
// Create the object menu dynamically
if (item && obj.menus['object'] && obj.menus['object'][d._type]) {
pgAdmin.Browser.MenuCreator(
$obj_mnu, obj.menus['object'][d._type], obj.menu_categories, d, item
obj.Nodes, $obj_mnu, obj.menus['object'][d._type], obj.menu_categories, d, item
);
} else {
// Create a dummy 'no object seleted' menu
@@ -503,7 +503,7 @@ define('pgadmin.browser', [
context_menu = {};
pgAdmin.Browser.MenuCreator(
$div, menus, obj.menu_categories, d, item, context_menu
obj.Nodes, $div, menus, obj.menu_categories, d, item, context_menu
);
return {
@@ -877,7 +877,7 @@ define('pgadmin.browser', [
$dropdown.empty();
if (pgAdmin.Browser.MenuCreator(
$dropdown, obj.menus[o.menu], obj.menu_categories
obj.Nodes, $dropdown, obj.menus[o.menu], obj.menu_categories
)) {
$mnu.removeClass('d-none');
}

View File

@@ -8,8 +8,8 @@
//////////////////////////////////////////////////////////////
define([
'underscore', 'sources/pgadmin', 'jquery', 'sources/utils',
], function(_, pgAdmin, $, pgadminUtils) {
'underscore', 'sources/pgadmin', 'jquery', 'sources/utils', 'sources/gettext',
], function(_, pgAdmin, $, pgadminUtils, gettext) {
'use strict';
pgAdmin.Browser = pgAdmin.Browser || {};
@@ -274,20 +274,38 @@ define([
* menu-items.
*
* Arguments:
* 1. jQuery Element on which you may want to created the menus
* 2. list of menu-items
* 3. categories - metadata information about the categories, based on which
* 1. nodes_obj - Nodes object contains each node object.
* 2. jQuery Element on which you may want to created the menus
* 3. list of menu-items
* 4. categories - metadata information about the categories, based on which
* the submenu (menu-group) will be created (if any).
* 4. d - Data object for the selected browser tree item.
* 5. item - The selected browser tree item
* 6. menu_items - A empty object on which the context menu for the given
* 5. d - Data object for the selected browser tree item.
* 6. item - The selected browser tree item
* 7. menu_items - A empty object on which the context menu for the given
* list of menu-items.
*
* Returns if any menu generated for the given input.
*/
pgAdmin.Browser.MenuCreator = function(
$mnu, menus, categories, d, item, menu_items
nodes_obj, $mnu, menus, categories, d, item, menu_items
) {
let showMenu = true;
/* We check showMenu function is defined by the respective node, if it is
* defined then call the function which will return true or false.
*/
if (d && nodes_obj[d._type] && !_.isUndefined(nodes_obj[d._type].showMenu))
showMenu = nodes_obj[d._type].showMenu(d, item);
if (!showMenu) {
menu_items = menu_items || {};
menu_items[_.uniqueId('ctx_')+ '1_1_ms'] = {
disabled : true,
name: gettext('No menu available for this object.'),
};
return;
}
var groups = {
'common': [],
},

View File

@@ -132,6 +132,10 @@ define('pgadmin.browser.node', [
'action': 'edit',
},
icon: 'fa fa-edit',
enable: _.isFunction(self.canEdit) ?
function() {
return !!(self.canEdit.apply(self, arguments));
} : (!!self.canEdit),
}]);
}
@@ -1233,7 +1237,7 @@ define('pgadmin.browser.node', [
tooltip: gettext('Edit'),
extraClasses: ['btn', 'btn-primary', 'pull-right', 'm-1'],
icon: 'fa fa-sm fa-pencil-alt',
disabled: !that.canEdit,
disabled: _.isFunction(that.canEdit) ? !that.canEdit.apply(that, [d, i]) : !that.canEdit,
register: function(btn) {
btn.on('click',() => {
onEdit();