brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [16/19] git commit: sort locations by display name, ignoring case (and sorting numbers as numbers); and tidy how catalog items are displayed
Date Tue, 09 Sep 2014 22:49:19 GMT
sort locations by display name, ignoring case (and sorting numbers as numbers); and tidy how
catalog items are displayed


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/f19ef81b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/f19ef81b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/f19ef81b

Branch: refs/heads/master
Commit: f19ef81b76a90a682b06f34e42f6c7deea6057b3
Parents: bcb5828
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Mon Sep 8 22:42:25 2014 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Sep 9 12:24:12 2014 +0100

----------------------------------------------------------------------
 usage/jsgui/src/main/webapp/assets/css/base.css |  3 ++
 .../src/main/webapp/assets/js/model/location.js |  1 -
 .../assets/tpl/catalog/details-entity.html      | 17 +++++----
 .../java/brooklyn/rest/domain/HasConfig.java    | 28 +++++++++++++++
 .../java/brooklyn/rest/domain/LocationSpec.java |  2 +-
 .../rest/domain/SummaryComparators.java         | 36 +++++++++++++++++++-
 .../rest/resources/LocationResource.java        |  3 +-
 7 files changed, 79 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f19ef81b/usage/jsgui/src/main/webapp/assets/css/base.css
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/css/base.css b/usage/jsgui/src/main/webapp/assets/css/base.css
index 057f4fe..611d8fe 100644
--- a/usage/jsgui/src/main/webapp/assets/css/base.css
+++ b/usage/jsgui/src/main/webapp/assets/css/base.css
@@ -1093,6 +1093,9 @@ tr.app-add-wizard-config-entry {
     border-bottom-left-radius: 5px;
     border-bottom-right-radius: 5px;
 }
+.catalog-details .accordion-body {
+    padding: 0;
+}
 .accordion-head:hover {
     background-color: #E0E4E0;
     cursor: hand; cursor: pointer;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f19ef81b/usage/jsgui/src/main/webapp/assets/js/model/location.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/model/location.js b/usage/jsgui/src/main/webapp/assets/js/model/location.js
index 6d45478..3bb3db2 100644
--- a/usage/jsgui/src/main/webapp/assets/js/model/location.js
+++ b/usage/jsgui/src/main/webapp/assets/js/model/location.js
@@ -75,7 +75,6 @@ define(["underscore", "backbone"], function (_, Backbone) {
 
     Location.Collection = Backbone.Collection.extend({
         model:Location.Model,
-        comparator: "name",
         url:'/v1/locations'
     })
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f19ef81b/usage/jsgui/src/main/webapp/assets/tpl/catalog/details-entity.html
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/tpl/catalog/details-entity.html b/usage/jsgui/src/main/webapp/assets/tpl/catalog/details-entity.html
index 60768d5..f0de1c7 100644
--- a/usage/jsgui/src/main/webapp/assets/tpl/catalog/details-entity.html
+++ b/usage/jsgui/src/main/webapp/assets/tpl/catalog/details-entity.html
@@ -23,6 +23,7 @@ under the License.
     <p><%- model.get("description") %></p>
 
     <div id="catalog-details-accordion" class="accordion">
+      <% if (model.get("planYaml")) { %>
         <div class="accordion-group">
             <div class="accordion-heading">
                 <a class="accordion-toggle" data-toggle="collapse" data-parent="#catalog-details-accordion"
href="#collapseYaml">
@@ -31,14 +32,11 @@ under the License.
             </div>
             <div id="collapseYaml" class="accordion-body collapse">
                 <div class="accordion-inner">
-                    <% if (model.get("planYaml")) { %>
                     <textarea rows="15" readonly><%- model.get("planYaml") %></textarea>
-                    <% } else { %>
-                    <p>No plan</p>
-                    <% } %>
                 </div>
             </div>
         </div>
+      <% } %>
         <% if (viewName != "policies") { %>
         <div class="accordion-group">
             <div class="accordion-heading">
@@ -63,19 +61,22 @@ under the License.
                             'reconfigurable'
                         ]; %>
                         <% _.each(model.get("config"), function(object, index) { %>
+                        <div style="padding-bottom: 12px;">
                         <p><strong><%- object.name %></strong>: <%-
object.description %></p>
+                        <div style="margin-left: 24px;">
                         <table class="table table-striped table-condensed nonDatatables">
                             <tbody>
                             <% _.each(object, function(value, key) { %>
                             <% if (!_.contains(skip, key)) { %>
                             <tr>
                                 <td><%- key %></td>
-                                <td><%- value %></td>
+                                <td><%- typeof value === "string" ? value : JSON.stringify(value)
%></td>
                             </tr>
                             <% } %>
                             <% }); %>
                             </tbody>
-                        </table>
+                        </table></div>
+                        </div>
                         <% }); %>
                     <% } %>
                 </div>
@@ -134,10 +135,12 @@ under the License.
                     <p>No effectors</p>
                 <% } else { %>
                     <% _.each(model.get("effectors"), function(object, index) { %>
+                        <div style="padding-bottom: 12px;">
                         <p><strong><%- object.name %></strong>: <%-
object.description %></p>
                         <% if (!object.parameters || _.isEmpty(object.parameters)) { %>
                             <p>No parameters</p>
                         <% } else { %>
+                            <div style="margin-left: 24px;">
                             <table class="table table-striped table-condensed nonDatatables">
                                 <tbody>
                                     <% _.each(object.parameters, function(parameter, index)
{ %>
@@ -150,7 +153,9 @@ under the License.
                                     <% }); %>
                                 </tbody>
                             </table>
+                            </div>
                         <% } %>
+                        </div>
                     <% }); %>
                 <% } %>
                 </div>

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f19ef81b/usage/rest-api/src/main/java/brooklyn/rest/domain/HasConfig.java
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/HasConfig.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/HasConfig.java
new file mode 100644
index 0000000..14fbfa3
--- /dev/null
+++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/HasConfig.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package brooklyn.rest.domain;
+
+import java.util.Map;
+
+/** Marker interface for summary objects with a name field */
+public interface HasConfig {
+
+    public Map<String, ?> getConfig();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f19ef81b/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSpec.java
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSpec.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSpec.java
index 99a2bd0..c9bbe25 100644
--- a/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSpec.java
+++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSpec.java
@@ -32,7 +32,7 @@ import com.google.common.collect.ImmutableMap;
 
 // FIXME change name, due to confusion with brooklyn.location.LocationSpec <- no need,
as we can kill the class instead soon!
 /** @deprecated since 0.7.0 location spec objects will not be used from the client, instead
pass yaml location spec strings */
-public class LocationSpec implements HasName {
+public class LocationSpec implements HasName, HasConfig {
 
   @JsonSerialize(include=Inclusion.NON_NULL)
   private final String name;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f19ef81b/usage/rest-api/src/main/java/brooklyn/rest/domain/SummaryComparators.java
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/SummaryComparators.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/SummaryComparators.java
index 3b467fe..e5f366d 100644
--- a/usage/rest-api/src/main/java/brooklyn/rest/domain/SummaryComparators.java
+++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/SummaryComparators.java
@@ -20,6 +20,12 @@ package brooklyn.rest.domain;
 
 import java.util.Comparator;
 
+import javax.annotation.Nonnull;
+
+import brooklyn.basic.BrooklynObject;
+import brooklyn.util.text.NaturalOrderComparator;
+import brooklyn.util.text.Strings;
+
 /**
  * Useful comparators for domain objects
  */
@@ -27,11 +33,39 @@ public class SummaryComparators {
     
     private SummaryComparators() {}
     
+    private static NaturalOrderComparator COMPARATOR = new NaturalOrderComparator();
+    
+    @Nonnull
+    static String getDisplayNameOrName(HasName o1) {
+        String n1 = null;
+        if (o1 instanceof BrooklynObject)
+            n1 = ((BrooklynObject)o1).getDisplayName();
+        if (Strings.isEmpty(n1) && o1 instanceof HasConfig && ((HasConfig)o1).getConfig()!=null)
+            n1 = Strings.toString(((HasConfig)o1).getConfig().get("displayName"));
+        // prefer display name if set
+        if (Strings.isEmpty(n1))
+            n1 = o1.getName();
+        if (n1==null) {
+            // put last
+            return "~~~";
+        }
+        return n1;
+    }
+    
+    public static Comparator<HasName> displayNameComparator() {
+        return new Comparator<HasName>() {
+            @Override
+            public int compare(HasName o1, HasName o2) {
+                return COMPARATOR.compare(getDisplayNameOrName(o1).toLowerCase(), getDisplayNameOrName(o2).toLowerCase());
+            }
+        };
+    }
+
     public static Comparator<HasName> nameComparator() {
         return new Comparator<HasName>() {
             @Override
             public int compare(HasName o1, HasName o2) {
-                return o1.getName().compareTo(o2.getName());
+                return COMPARATOR.compare(o1.getName(), o2.getName());
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f19ef81b/usage/rest-server/src/main/java/brooklyn/rest/resources/LocationResource.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/resources/LocationResource.java
b/usage/rest-server/src/main/java/brooklyn/rest/resources/LocationResource.java
index d8a4e40..d4f004c 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/resources/LocationResource.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/resources/LocationResource.java
@@ -19,7 +19,6 @@
 package brooklyn.rest.resources;
 
 import java.net.URI;
-import java.util.Comparator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -80,7 +79,7 @@ public class LocationResource extends AbstractBrooklynRestResource implements
Lo
         return FluentIterable.from(brooklyn().getLocationRegistry().getDefinedLocations().values())
                 .transform(transformer)
                 .filter(LocationSummary.class)
-                .toSortedList(SummaryComparators.nameComparator());
+                .toSortedList(SummaryComparators.displayNameComparator());
     }
 
     // this is here to support the web GUI's circles


Mime
View raw message