Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
collection.js128 linesDownload Raw Back to js
1/////////////////////////////////////////////////////////////2//3// pgAdmin 4 - PostgreSQL Tools4//5// Copyright (C) 2013 - 2024, The pgAdmin Development Team6// This software is released under the PostgreSQL Licence7//8//////////////////////////////////////////////////////////////9import _ from 'lodash';10 11define([12  'sources/gettext', 'sources/pgadmin',13  'sources/browser/generate_url',14  'pgadmin.browser.node',15], function(gettext, pgAdmin, generateUrl) {16 17  let pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {};18 19  // It has already been defined.20  // Avoid running this script again.21  if (pgBrowser.Collection)22    return pgBrowser.Collection;23 24  pgBrowser.Collection = function() {/*This is intentional (SonarQube)*/};25 26  _.extend(27    pgBrowser.Collection,28    _.clone(pgBrowser.Node), {29      ///////30      // Initialization function31      // Generally - used to register the menus for this type of node.32      //33      // Also, look at pgAdmin.Browser.add_menus(...) function.34      //35      // Collection will not have 'Properties' menu.36      //37      // NOTE: Override this for each node for initialization purpose38      Init: function() {39        if (this.node_initialized)40          return;41        this.node_initialized = true;42 43        pgAdmin.Browser.add_menus([{44          name: 'refresh', node: this.type, module: this,45          applies: ['object', 'context'], callback: 'refresh',46          priority: 2, label: gettext('Refresh'),47        }]);48 49        // show query tool only in context menu of supported nodes.50        if (pgAdmin.unsupported_nodes && _.indexOf(pgAdmin.unsupported_nodes, this.type) == -1) {51          if ((this.type == 'database' && this.allowConn) || this.type != 'database') {52            pgAdmin.Browser.add_menus([{53              name: 'show_query_tool', node: this.type, module: this,54              applies: ['context'], callback: 'show_query_tool',55              priority: 998, label: gettext('Query Tool'),56            }]);57 58            // show search objects same as query tool59            pgAdmin.Browser.add_menus([{60              name: 'search_objects', node: this.type, module: this,61              applies: ['context'], callback: 'show_search_objects',62              priority: 997, label: gettext('Search Objects...'),63            }]);64 65            // show psql tool same as query tool.66            if(pgAdmin['enable_psql']) {67              pgAdmin.Browser.add_menus([{68                name: 'show_psql_tool', node: this.type, module: this,69                applies: ['context'], callback: 'show_psql_tool',70                priority: 998, label: gettext('PSQL Tool'),71              }]);72            }73          }74        }75      },76 77      hasId: false,78      is_collection: true,79      collection_node: true,80      // A collection will always have a collection of statistics, when the node81      // it represent will have some statistics.82      hasCollectiveStatistics: true,83      canDrop: true,84      canDropCascade: true,85      selectParentNodeOnDelete: false,86      generate_url: function(item, type) {87        /*88         * Using list, and collection functions of a node to get the nodes89         * under the collection, and properties of the collection respectively.90         */91        let opURL = {92            'properties': 'obj',93            'children': 'nodes',94            'drop': 'obj',95          },96          self = this;97        let collectionPickFunction = function (treeInfoValue, treeInfoKey) {98          return (treeInfoKey != self.type);99        };100        let treeInfo = pgBrowser.tree.getTreeNodeHierarchy(item);101        let actionType = type in opURL ? opURL[type] : type;102        return generateUrl.generate_url(103          pgAdmin.Browser.URL, treeInfo, actionType, self.node,104          collectionPickFunction105        );106      },107      show_query_tool: function() {108        if(pgAdmin.Tools.SQLEditor) {109          pgAdmin.Tools.SQLEditor.showQueryTool('', pgAdmin.Browser.tree.selected());110        }111      },112      show_search_objects: function() {113        if(pgAdmin.Tools.SearchObjects) {114          pgAdmin.Tools.SearchObjects.show_search_objects('', pgAdmin.Browser.tree.selected());115        }116      },117      show_psql_tool: function(args) {118        let input = args || {},119          t = pgBrowser.tree,120          i = input.item || t.selected(),121          d = i ? t.itemData(i) : undefined;122        pgBrowser.psql.psql_tool(d, i, true);123      },124    });125 126  return pgBrowser.Collection;127});128 
codekingpro/portable-devtools · Team Ai