public inbox for [email protected]  
help / color / mirror / Atom feed
From: Surinder Kumar <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: Control for displaying "auto vacuum" fields into grid
Date: Fri, 18 Mar 2016 16:07:36 +0530
Message-ID: <CAM5-9D9Nwm2SKkaRpWpMy=95RhKO+qm1O9TvhXE8dmCiUFe1Cw@mail.gmail.com> (raw)
List-Unsubscribe:  <mailto:[email protected]?body=unsub%20pgadmin-hackers>

Hi,

PFA control for displaying auto vacuum fields into grid. This control is
common for
Materialized View Node and Table Node.

*Usage:*

{
  id: 'vacuum_table', label: '{{ _("Vacuum Table") }}',
  model: VacuumTableModel, editable: false, type: 'collection',
  canEdit: true, group: '{{ _("Table") }}',
  mode: ['edit', 'create'], url: 'get_vacuum_defaults',
  control: Backform.VacuumCollectionControl.extend({
    grid_columns :[
      {
        name: 'label', label: '{{ _("Label") }}',
        cell: 'string', editable: false
      },
      {
        name: 'value', label: '{{ _("Value") }}',
        cellFunction: cellFunction, editable: function(m) {
          if(m.handler.has('autovacuum_enabled')) {
            return m.handler.get('autovacuum_enabled');
          }
          return !m.handler.isNew();
        }
      },
      {
        name: 'setting', label: '{{ _("Default value") }}',
        cellFunction: cellFunction, editable: false
      }
    ]
  }),


When using this control, provide following parameters in schema:
*1. model*
2. *url - *to fetch default values for auto vacuum fields.
3. *grid columns - *Name of the columns to display in the grid.


Please review the patch.



Thanks
Surinder Kumar


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [application/octet-stream] vacuum_collection_control.patch (3.2K, 3-vacuum_collection_control.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schema/js/schema.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schema/js/schema.js
index 352da1f..88e3731 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schema/js/schema.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schema/js/schema.js
@@ -4,6 +4,86 @@ define(
         'pgadmin.browser.collection',
         'pgadmin.browser.server.privilege'],
 function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
+
+    var VacuumCollectionControl = Backform.VacuumCollectionControl =
+      Backform.Control.extend({
+
+      grid_columns:undefined,
+
+      initialize: function() {
+        Backform.Control.prototype.initialize.apply(this, arguments);
+        var self = this,
+            m = this.model;
+            url = self.field.get('url');
+
+        if (url && m.isNew()) {
+          var node = self.field.get('node'),
+              node_data = self.field.get('node_data'),
+              node_info = self.field.get('node_info'),
+              full_url = node.generate_url.apply(
+                node, [
+                  null, url, node_data, true, node_info
+                ]),
+              data;
+          m.trigger('pgadmin-view:fetching', m, self.field);
+
+          // fetch default values for autovacuum fields
+          $.ajax({
+            async: false,
+            url: full_url,
+            success: function (res) {
+              data = res;
+            },
+            error: function() {
+              m.trigger('pgadmin-view:fetch:error', m, self.field);
+            }
+          });
+          m.trigger('pgadmin-view:fetched', m, self.field);
+
+          // Add fetched models into collection
+          if (data && _.isArray(data)) {
+            m.get(self.field.get('name')).reset(data, {silent: true});
+          }
+        }
+      },
+
+      render: function() {
+        var self = this,
+            m = this.model,
+            attributes = self.field.attributes;
+
+        // remove grid
+        if(self.grid) {
+          self.grid.remove();
+          delete self.grid;
+          self.grid = undefined;
+        }
+
+        self.$el.empty();
+
+        var gridHeader = _.template([
+            '<div class="subnode-header">',
+            '  <label class="control-label col-sm-4"><%-label%></label>',
+            '</div>'].join("\n")),
+            gridBody = $('<div class="pgadmin-control-group backgrid form-group col-xs-12 object subnode"></div>').append(
+                gridHeader(attributes)
+                );
+
+        // Initialize a new Grid instance
+        var grid = self.grid = new Backgrid.Grid({
+          columns: self.grid_columns,
+          collection: self.model.get(self.field.get('name')),
+          className: "backgrid table-bordered"
+        });
+
+        // render grid
+        self.$el.append($(gridBody).append(grid.render().$el));
+
+        return self;
+      }
+    });
+
+
    // Extend the browser's collection class for SecurityLabel control
     var SecurityModel = Backform.SecurityModel = pgAdmin.Browser.Node.Model.extend({
     defaults: {


view thread (8+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: Control for displaying "auto vacuum" fields into grid
  In-Reply-To: <CAM5-9D9Nwm2SKkaRpWpMy=95RhKO+qm1O9TvhXE8dmCiUFe1Cw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox