From b53371de8a2feb20d8b5f829e0ad08bb3cbc1d6b Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Mon, 24 Mar 2014 13:00:29 -0400
Subject: [PATCH] Added details page for TPS connections.

A new page has been added to view TPS connection details. The properties
are displayed in a table which provides pagination and search
functionality. Currently the page is read-only. The edit functionality
will be added separately later.

Previously the ConnectionData had a problem with JSON mapping because it
incorrectly included a PropertyNames attribute. To fix the problem the
class has been modified to require explicit JAXB mapping by setting the
@XmlAccessorType to NONE.

Ticket #654
---
 .../certsrv/tps/connection/ConnectionData.java     |  3 +
 .../tps-tomcat/shared/webapps/tps/js/connection.js | 43 ++++++++++--
 .../shared/webapps/tps/ui/connection.html          | 77 ++++++++++++++++++++++
 base/tps-tomcat/shared/webapps/tps/ui/index.html   |  2 +-
 4 files changed, 120 insertions(+), 5 deletions(-)
 create mode 100644 base/tps-tomcat/shared/webapps/tps/ui/connection.html

diff --git a/base/common/src/com/netscape/certsrv/tps/connection/ConnectionData.java b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionData.java
index 50b0f6b519f738444fe1b761d586b72388a4f6fe..3ab71c75d458af06637701fdb8f3abb26378742e 100644
--- a/base/common/src/com/netscape/certsrv/tps/connection/ConnectionData.java
+++ b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionData.java
@@ -29,6 +29,8 @@ import java.util.Map;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
@@ -42,6 +44,7 @@ import org.jboss.resteasy.plugins.providers.atom.Link;
  * @author Endi S. Dewata
  */
 @XmlRootElement(name="Connection")
+@XmlAccessorType(XmlAccessType.NONE)
 public class ConnectionData {
 
     public static Marshaller marshaller;
diff --git a/base/tps-tomcat/shared/webapps/tps/js/connection.js b/base/tps-tomcat/shared/webapps/tps/js/connection.js
index 53eb12f3b799bb86a67603cd0b8e97b87195dd95..fc89595282d1fee656312d0042329152287f12ea 100644
--- a/base/tps-tomcat/shared/webapps/tps/js/connection.js
+++ b/base/tps-tomcat/shared/webapps/tps/js/connection.js
@@ -24,7 +24,8 @@ var ConnectionModel = Model.extend({
     parseResponse: function(response) {
         return {
             id: response.id,
-            status: response.Status
+            status: response.Status,
+            properties: response.Properties.Property
         };
     },
     parseXML: function(data) {
@@ -124,7 +125,39 @@ var ConnectionDialog = Dialog.extend({
     }
 });
 
-var ConnectionPage = Page.extend({
+var ConnectionsTable = Table.extend({
+    initialize: function(options) {
+        var self = this;
+        ConnectionsTable.__super__.initialize.call(self, options);
+        self.url = options.url;
+        self.container = options.container;
+    },
+    open: function(item) {
+        var self = this;
+
+        // load entry properties
+        item.model.fetch({
+            success: function(model, response, options) {
+                self.container.load(self.url, function(response, status, xhr) {
+                    $("h1 span[name='id']", self.container).text(model.id);
+
+                    var fields = $("div[name='connection']", self.container);
+                    $("input[name='id']", fields).val(model.id);
+                    $("input[name='status']", fields).val(model.get("status"));
+
+                    var properties = new PropertiesTable({
+                        el: $("table[name='connection-properties']"),
+                        properties: model.get("properties"),
+                        pageSize: 10
+                    });
+                    properties.render();
+                });
+            }
+        });
+    }
+});
+
+var ConnectionsPage = Page.extend({
     load: function(container) {
         var editDialog = new ConnectionDialog({
             el: $("#connection-dialog"),
@@ -132,10 +165,12 @@ var ConnectionPage = Page.extend({
             readonly: ["id", "status"]
         });
 
-        var table = new Table({
+        var table = new ConnectionsTable({
+            url: "connection.html",
             el: $("table[name='connections']"),
             collection: new ConnectionCollection(),
-            editDialog: editDialog
+            editDialog: editDialog,
+            container: container
         });
         table.render();
     }
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/connection.html b/base/tps-tomcat/shared/webapps/tps/ui/connection.html
new file mode 100644
index 0000000000000000000000000000000000000000..823f28fdd584083e11819b020a57cddb9c8f89e5
--- /dev/null
+++ b/base/tps-tomcat/shared/webapps/tps/ui/connection.html
@@ -0,0 +1,77 @@
+<!-- --- BEGIN COPYRIGHT BLOCK ---
+     This program is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published by
+     the Free Software Foundation; version 2 of the License.
+
+     This program is distributed in the hope that it will be useful,
+     but WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+     GNU General Public License for more details.
+
+     You should have received a copy of the GNU General Public License along
+     with this program; if not, write to the Free Software Foundation, Inc.,
+     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+     Copyright (C) 2014 Red Hat, Inc.
+     All rights reserved.
+     --- END COPYRIGHT BLOCK --- -->
+<h1>Connection <span name="id"></span></h1>
+
+<div name="connection" class="pki-fields">
+<fieldset>
+    <label>Connection ID</label>
+    <input name="id" readonly>
+    <br>
+    <label>Status</label>
+    <input name="status" readonly>
+    <br>
+</fieldset>
+</div>
+
+<h2>Properties</h2>
+
+<table name="connection-properties">
+<thead>
+    <tr>
+         <th class="pki-table-actions" colspan="3">
+             <span name="search">
+                 <input name="search" type="text" placeholder="Search...">
+             </span>
+             <span name="actions">
+             </span>
+         </th>
+    </tr>
+    <tr>
+        <th class="pki-select-column"><input id="connection_selectall" type="checkbox"><label for="connection_selectall">&nbsp;</label></th>
+        <th class="pki-property-name-column">Name</th>
+        <th>Value</th>
+    </tr>
+</thead>
+<tbody>
+    <tr>
+        <td class="pki-select-column"><input id="connection_select" type="checkbox"><label for="connection_select">&nbsp;</label></td>
+        <td name="id" class="pki-property-name-column"><a href="connection.html">&nbsp;</a></td>
+        <td name="status">&nbsp;</td>
+    </tr>
+</tbody>
+<tfoot>
+    <tr>
+         <th class="pki-table-actions" colspan="3">
+             <span name="info">
+                 Total: <span name="totalEntries">0</span> entries
+             </span>
+             <span name="page-controls">
+                 <ul class="pagination">
+                     <li><a href="#" name="first"><span class="i fa fa-angle-double-left"></span></a></li>
+                     <li><a href="#" name="prev"><span class="i fa fa-angle-left"></span></a></li>
+                     <li><a href="#" name="next"><span class="i fa fa-angle-right"></span></a></li>
+                     <li><a href="#" name="last"><span class="i fa fa-angle-double-right"></span></a></li>
+                 </ul>
+             </span>
+             <span name="page-jump">
+                 Page <input name="page" type="text" value="1"> of <span name="totalPages">1</span>
+             </span>
+         </th>
+    </tr>
+</tfoot>
+</table>
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/index.html b/base/tps-tomcat/shared/webapps/tps/ui/index.html
index 2cfee922890417d1139ccf0747b182d665f30420..85c4dcc11b38eb230dc07907f7ed512858cddd64 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/index.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/index.html
@@ -45,7 +45,7 @@ $(function() {
             activities: new ActivityPage({ url: "activities.html" }),
             authenticators: new AuthenticatorPage({ url: "authenticators.html" }),
             certs: new CertificatePage({ url: "certs.html" }),
-            connections: new ConnectionPage({ url: "connections.html" }),
+            connections: new ConnectionsPage({ url: "connections.html" }),
             groups: new GroupPage({ url: "groups.html" }),
             profiles: new ProfilesPage({ url: "profiles.html" }),
             selftests: new SelfTestPage({ url: "selftests.html" }),
-- 
1.8.4.2

