public inbox for [email protected]  
help / color / mirror / Atom feed
From: Murtuza Zabuawala <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: PATCH: To fix JSON array handling (pgAdmin4)
Date: Wed, 21 Sep 2016 16:13:27 +0530
Message-ID: <CAKKotZTO2001ka4TBq6wnWtY0RkMr5=Db3XSSyB-Adhhwh4OVg@mail.gmail.com> (raw)
List-Unsubscribe:  <mailto:[email protected]?body=unsub%20pgadmin-hackers>

Hi,

PFA patch to fix the issue where SlickGrid was not displaying nested JSON
data properly.
This patch fixes: RM#1713 & RM#1404

*Issue:*
Nested JSON data was not handled properly.


--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
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] RM_1713.patch (2.8K, 3-RM_1713.patch)
  download | inline diff:
diff --git a/web/pgadmin/static/js/slickgrid/slick.pgadmin.editors.js b/web/pgadmin/static/js/slickgrid/slick.pgadmin.editors.js
index 6f2984a..05fbb91 100644
--- a/web/pgadmin/static/js/slickgrid/slick.pgadmin.editors.js
+++ b/web/pgadmin/static/js/slickgrid/slick.pgadmin.editors.js
@@ -230,6 +230,16 @@
       var data = defaultValue = item[args.column.field];
       if (typeof data === "object" && !Array.isArray(data)) {
         data = JSON.stringify(data);
+      } else if (Array.isArray(data)) {
+        var temp = [];
+        $.each(data, function(i, val) {
+          if (typeof val === "object") {
+            temp.push(JSON.stringify(val));
+          } else {
+            temp.push(val)
+          }
+        });
+        data = "[" + temp.join() + "]";
       }
       $input.val(data);
       $input.select();
@@ -466,6 +476,16 @@
       var data = defaultValue = item[args.column.field];
       if (typeof data === "object" && !Array.isArray(data)) {
         data = JSON.stringify(data);
+      } else if (Array.isArray(data)) {
+        var temp = [];
+        $.each(data, function(i, val) {
+          if (typeof val === "object") {
+            temp.push(JSON.stringify(val));
+          } else {
+            temp.push(val)
+          }
+        });
+        data = "[" + temp.join() + "]";
       }
       $input.val(data);
       $input.select();
diff --git a/web/pgadmin/static/js/slickgrid/slick.pgadmin.formatters.js b/web/pgadmin/static/js/slickgrid/slick.pgadmin.formatters.js
index b131657..3b4aa3c 100644
--- a/web/pgadmin/static/js/slickgrid/slick.pgadmin.formatters.js
+++ b/web/pgadmin/static/js/slickgrid/slick.pgadmin.formatters.js
@@ -24,6 +24,16 @@
       // Stringify only if it's json object
       if (typeof value === "object" && !Array.isArray(value)) {
         return JSON.stringify(value);
+      } else if (Array.isArray(value)) {
+        var temp = [];
+        $.each(value, function(i, val) {
+          if (typeof val === "object") {
+            temp.push(JSON.stringify(val));
+          } else {
+            temp.push(val)
+          }
+        });
+        return "[" + temp.join() + "]"
       } else {
         return value;
       }
diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
index 74502c7..f7cf0ab 100644
--- a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
@@ -1790,7 +1790,7 @@ define(
                  */
               var explain_data_array = [];
               if(
-                data.result && data.result.length > 1 &&
+                data.result && data.result.length >= 1 &&
                   data.result[0] && data.result[0].hasOwnProperty(
                     'QUERY PLAN'
                   ) && _.isObject(data.result[0]['QUERY PLAN'])


view thread (2+ 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: PATCH: To fix JSON array handling (pgAdmin4)
  In-Reply-To: <CAKKotZTO2001ka4TBq6wnWtY0RkMr5=Db3XSSyB-Adhhwh4OVg@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