Re: [pgadmin-hackers] Tree reload & panel close issue after saving new node on server [pgadmin4]

2016-04-01 Thread Ashesh Vashi
Thanks - committed!

--

Thanks & Regards,

Ashesh Vashi
EnterpriseDB INDIA: Enterprise PostgreSQL Company



*http://www.linkedin.com/in/asheshvashi*


On Thu, Mar 31, 2016 at 1:34 PM, Harshal Dhumal <
harshal.dhu...@enterprisedb.com> wrote:

> Hi,
>
> PFA patch for node.js
>
> Issues fixed:
>
> 1] Reload node collection when server doesn't send node data for newly
> created node.
> 2] Close create panel either when collection node matches with newly
> create node type  or *collection node type matches with newly created
> node's collection type.*
>
>
>
>
>
> --
> *Harshal Dhumal*
> *Software Engineer *
>
>
>
> EenterpriseDB 
>
>
> --
> Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>
>


[pgadmin-hackers] Tree reload & panel close issue after saving new node on server [pgadmin4]

2016-03-31 Thread Harshal Dhumal
Hi,

PFA patch for node.js

Issues fixed:

1] Reload node collection when server doesn't send node data for newly
created node.
2] Close create panel either when collection node matches with newly create
node type  or *collection node type matches with newly created node's
collection type.*





-- 
*Harshal Dhumal*
*Software Engineer *



EenterpriseDB 
diff --git a/web/pgadmin/browser/templates/browser/js/node.js b/web/pgadmin/browser/templates/browser/js/node.js
index 5d6ec86..bb683ee 100644
--- a/web/pgadmin/browser/templates/browser/js/node.js
+++ b/web/pgadmin/browser/templates/browser/js/node.js
@@ -847,7 +847,7 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) {
 },
 saveNewNode = function() {
   /* TODO:: Create new tree node for this */
-  if (view.model.tnode) {
+  if (view.model.tnode && '_id' in view.model.tnode) {
 var d = _.extend({}, view.model.tnode),
   func = function(i) {
 setTimeout(function() {
@@ -888,7 +888,8 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) {
   if (data && data._type && data._type in pgBrowser.Nodes) {
 node = pgBrowser.Nodes[data._type];
 
-if (node && node.node && node.node == that.type) {
+if (node && ((node.node && node.node == that.type) ||
+node.type == that.collection_type)) {
   found = true;
   if (tree.wasLoad(j)) {
 tree.append(j, {
@@ -979,6 +980,48 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) {
 }
   });
 }
+  } else {
+  /*
+   * Sometime we don't get node in response even though it's saved
+   * on server. In such case just reload the collection to get newly
+   * created nodes.
+   */
+
+   var children = tree.children(item, false, false),
+openNode = function(item, animation){
+  tree.open(item, {
+success: function (item, options){
+  setTimeout(function() {
+closePanel();
+  }, 0);
+},
+fail: function (item, options){
+},
+unanimated: animation
+  });
+};
+
+if (children) {
+  _.each(children, function(child) {
+var $child = $(child);
+var data = tree.itemData($child)
+  if (data._type == that.collection_type){
+// We found collection which need to reload.
+if (tree.wasLoad($child)) {
+  tree.unload($child, {
+success: function (item, options){
+  openNode(item, true);
+},
+fail: function (item, options){
+},
+unanimated: true
+  });
+} else {
+  openNode($child, false);
+}
+  }
+  });
+}
   }
 },
 editInNewPanel = function() {

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