You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2014/07/11 06:14:13 UTC
[06/10] Merge remote-tracking branch 'upstream/master' into
feature/jsgui-catalog
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/jsgui/src/main/webapp/assets/css/base.css
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/jsgui/src/main/webapp/assets/js/router.js
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/jsgui/src/main/webapp/assets/js/view/catalog.js
----------------------------------------------------------------------
diff --cc usage/jsgui/src/main/webapp/assets/js/view/catalog.js
index 85fe1a5,71a8162..6f8d059
--- a/usage/jsgui/src/main/webapp/assets/js/view/catalog.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/catalog.js
@@@ -1,203 -1,38 +1,221 @@@
+ /*
+ * 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.
+ */
define([
- "underscore", "jquery", "backbone", "model/location", "formatJson",
- "text!tpl/catalog/page.html",
+ "underscore", "jquery", "backbone", "formatJson",
+ "model/location", "model/entity",
+ "view/catalog-add-location-modal",
+ "text!tpl/catalog/page.html",
+ "text!tpl/catalog/details-entity.html",
"text!tpl/catalog/details-generic.html",
- "text!tpl/catalog/nav-entry.html",
-
- "view/catalog-details-location",
- "view/catalog-add-location-modal",
-
+ "text!tpl/catalog/nav-entry.html",
+ "text!tpl/catalog/details-location.html",
+
"bootstrap", "jquery-form"
-], function (_, $, Backbone, Location, FormatJSON,
- CatalogPageHtml,
- DetailsGenericHtml,
- EntryHtml,
- DetailsLocationView,
- AddLocationModalView
- ) {
+], function(_, $, Backbone, FormatJSON, Location, Entity, AddLocationModalView,
+ CatalogPageHtml, DetailsEntityHtml, DetailsGenericHtml, EntryHtml, LocationDetailsHtml) {
+
+ // Holds the currently active details type, e.g. applications, policies
+ var activeDetails;
+
+ // TODO: Loading item's details should perform page navigation
+ var DetailsView = Backbone.View.extend({
+
+ events: {
+ "click .delete": "deleteItem"
+ },
+
+ initialize: function() {
+ _.bindAll(this);
+ },
+
+ render: function(extraMessage) {
+ this.$el.html("<div class='catalog-details'>" +
+ "<h3>Select an entry on the left</h3>" +
+ (extraMessage ? extraMessage : "") +
+ "</div>");
+ },
+
+ show: function(model, template) {
+ // Keep the previously open section open between items
+ var open = this.$(".in").attr("id");
+ var newHtml = $(template({model: model}));
+ $(newHtml).find("#"+open).addClass("in");
+ this.$el.html(newHtml);
+
+ // rewire events. previous callbacks are removed automatically.
+ this.delegateEvents()
+ },
+
+ showDetailsFor: function(model, template) {
+ this.activeModel = model;
+ var that = this;
+ // Load the view with currently available data and refresh once the load is complete.
+ // Only refreshes the view if the model changes and the user hasn't selected another
+ // item while the load was executing.
+ this.show(model, template);
+ model.on("change", function() {
+ if (that.activeModel.cid === model.cid) {
+ that.show(model, template);
+ }
+ });
+ model.fetch()
+ .fail(function(xhr, textStatus, errorThrown) {
+ console.log("error loading", model.id, ":", errorThrown);
+ if (that.activeModel.cid === model.cid) {
+ model.error = true;
+ that.show(model, template);
+ }
+ })
+ // Runs after the change event fires, or after the xhr completes
+ .always(function () {
+ model.off("change");
+ });
+ },
+
+ deleteItem: function(event) {
+ // Could use wait flag to block removal of model from collection
+ // until server confirms deletion and success handler to perform
+ // removal. Useful if delete fails for e.g. lack of entitlement.
+ this.activeModel.destroy();
+ var displayName = $(event.currentTarget).data("name");
+ this.render(displayName ? "Deleted " + displayName : "");
+ }
+ });
+
+ var Catalog = Backbone.Collection.extend({
+ initialize: function(models, options) {
+ this.name = options["name"];
+ if (!this.name) {
+ throw new Error("Catalog collection must know its name");
+ }
+ _.bindAll(this);
+ },
+ url: function() {
+ return "/v1/catalog/" + this.name;
+ }
+ });
+
+ var accordionBodyTemplate = _.template(
+ "<div class='accordion-head capitalized'><%= name %></div>" +
+ "<div class='accordion-body' style='display: <%= display %>'></div>");
+
+ /** Use to fill single accordion view list. */
+ var AccordionItemView = Backbone.View.extend({
+ tag: "div",
+ className: "accordion-item",
+ events: {
+ 'click .accordion-head': 'toggle',
+ 'click .accordion-nav-row': 'showDetails'
+ },
+
+ initialize: function() {
+ _.bindAll(this);
+ this.name = this.options.name;
+ if (!this.name) {
+ throw new Error("Name should have been given for accordion entry");
+ }
+
+ // Generic templates
+ this.template = _.template(this.options.template || EntryHtml);
+ this.detailsTemplate = _.template(this.options.detailsTemplate || DetailsGenericHtml);
+
+ // Returns template applied to function arguments. Alter if collection altered.
+ // Will be run in the context of the AccordionItemView.
+ this.templateArgs = this.options.templateArgs || function(model, index) {
+ return {type: model.get("type"), id: model.get("id")};
+ };
+
+ // undefined argument is used for existing model items
+ var collectionModel = this.options.model || Backbone.Model;
+ this.collection = this.options.collection || new Catalog(undefined, {
+ name: this.name,
+ model: collectionModel
+ });
+ // Refreshes entries list when the collection is synced with the server or
+ // any of its members are destroyed.
+ this.collection
+ .on("sync", this.renderEntries)
+ .on("destroy", this.renderEntries);
+ this.refresh();
+ },
+
+ beforeClose: function() {
+ this.collection.off();
+ },
+
+ render: function() {
+ this.$el.html(accordionBodyTemplate({
+ name: this.name,
+ display: this.options.autoOpen ? "block" : "none"
+ }));
+ this.renderEntries();
+ return this;
+ },
+
+ renderEntries: function() {
+ var templater = function(model, index) {
+ var args = _.extend({cid: model.cid}, this.templateArgs(model));
+ return this.template(args);
+ };
+ var elements = this.collection.map(templater, this);
+ this.$(".accordion-body")
+ .empty()
+ .append(elements.join(''));
+ // Rehighlight active model
+ if (this.activeCid && activeDetails === this.name) {
+ $(".accordion-nav-row").removeClass("active");
+ this.setActiveItem(this.$("[data-cid='"+this.activeCid+"'"));
+ }
+ },
+
+ refresh: function() {
+ this.collection.fetch();
+ },
+
+ setActiveItem: function($element) {
+ $(".accordion-nav-row").removeClass("active");
+ $element.addClass("active");
+ activeDetails = this.name;
+ },
+
+ showDetails: function(event) {
+ var $event = $(event.currentTarget);
+ if (!$event.hasClass("active")) {
+ this.setActiveItem($event);
+ var cid = this.activeCid = $(event.currentTarget).data("cid");
+ var model = this.collection.get(cid);
+ this.options.details.showDetailsFor(model, this.detailsTemplate);
+ }
+ },
+
+ toggle: function() {
+ var body = this.$(".accordion-body");
+ var hidden = this.hidden = body.css("display") == "none";
+ if (hidden) {
+ this.$el.addClass('active');
+ body.removeClass("hide").slideDown('fast');
+ } else {
+ this.$el.removeClass('active');
+ body.slideUp('fast')
+ }
+ }
+ });
var CatalogResourceView = Backbone.View.extend({
tagName:"div",
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/jsgui/src/main/webapp/assets/tpl/catalog/details-location.html
----------------------------------------------------------------------
diff --cc usage/jsgui/src/main/webapp/assets/tpl/catalog/details-location.html
index a9474fc,c91e3e7..4d93207
--- a/usage/jsgui/src/main/webapp/assets/tpl/catalog/details-location.html
+++ b/usage/jsgui/src/main/webapp/assets/tpl/catalog/details-location.html
@@@ -1,13 -1,33 +1,31 @@@
-
+ <!--
+ 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.
+ -->
+<div class="catalog-details">
-<div class="catalog-details-location">
+ <h3><%= model.getPrettyName() %></h3>
-<% if ((typeof title !== 'undefined') && (title.length > 0)) { %>
- <div class="float-right"><button id="<%= id %>" class="btn btn-danger delete-location">Delete</button></div>
-
- <h3><%= title %></h3>
-<% } %>
+ <div class="float-right">
+ <button data-name="<%= model.getPrettyName() %>" class="btn btn-danger delete">Delete</button>
+ </div>
-<% if (typeof config === 'undefined') { %>
- <i>Loading...</i>
+<% if (!model.get("config") || _.isEmpty(model.get("config"))) { %>
+ <em>No special configuration</em>
<% } else { %>
<br/>
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/jsgui/src/main/webapp/assets/tpl/catalog/nav-entry.html
----------------------------------------------------------------------
diff --cc usage/jsgui/src/main/webapp/assets/tpl/catalog/nav-entry.html
index 02f0242,d30dde3..922f254
--- a/usage/jsgui/src/main/webapp/assets/tpl/catalog/nav-entry.html
+++ b/usage/jsgui/src/main/webapp/assets/tpl/catalog/nav-entry.html
@@@ -1,1 -1,21 +1,19 @@@
-
+ <!--
+ 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.
+ -->
-
-<div id="<%= id %>" class="accordion-nav-row"><%= type %></div>
+<div data-cid="<%= cid %>" class="accordion-nav-row"><%= type %></div>
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/jsgui/src/main/webapp/assets/tpl/catalog/page.html
----------------------------------------------------------------------
diff --cc usage/jsgui/src/main/webapp/assets/tpl/catalog/page.html
index 0a375a9,096667e..c15802d
--- a/usage/jsgui/src/main/webapp/assets/tpl/catalog/page.html
+++ b/usage/jsgui/src/main/webapp/assets/tpl/catalog/page.html
@@@ -1,27 -1,84 +1,47 @@@
+
+ <!--
+ 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.
+ -->
+
<!-- Catalog page template -->
-<div id="catalog-resource">
-<div class="row row-fluid">
- <div class="span4" id="accord">
- <div class="navbar_top">
- <h3>Catalog</h3>
- <div class="apps-tree-toolbar">
- <i id="add-new-thing" class="icon-br-plus-sign handy" />
-
- <i class="icon-br-refresh refresh handy" />
+<div id="catalog-resource">
+ <div class="row row-fluid">
+ <div class="span4" id="accord">
+ <div class="navbar_top">
+ <h3>Catalog</h3>
+
+ <div class="apps-tree-toolbar">
+ <i class="icon-br-refresh refresh handy"/>
+ </div>
+ </div>
+ <div class="navbar_main_wrapper">
+ <div id="accordion-empty-to-create-info-message" class="label-message hide">
+ <div class="label-important full-width">ERROR</div>
+ No category selected.
+ Select the category of the item type you wish to add.
+ </div>
+ <div class="catalog-accordion-parent catalog-accordion-wrapper"></div>
</div>
</div>
- <div class="navbar_main_wrapper">
-
-<div id="accordion-empty-to-create-info-message" class="label-message hide">
- <div class="label-important full-width">ERROR</div>
- No category selected.
- Select the category of the item type you wish to add.
-</div>
-
-<div class="catalog-accordion-wrapper">
-<div id="applications" class="accordion-item">
- <div class="accordion-head">
- Applications
- </div>
- <div class="accordion-body hide"></div>
-</div>
-<div id="entities" class="accordion-item">
- <div class="accordion-head">
- Entities
- </div>
- <div class="accordion-body hide"></div>
-</div>
-<div id="policies" class="accordion-item">
- <div class="accordion-head">
- Policies
+ <div class="span8" id="details"></div>
</div>
- <div class="accordion-body hide"></div>
</div>
-<div id="locations" class="accordion-item">
- <div class="accordion-head">
- Locations
- </div>
- <div class="accordion-body hide"></div>
-</div>
-
-</div>
- </div>
-
- </div>
- <div class="span8" id="details">
- <div id="details-empty" class="catalog-details hide">
- <i>Nothing selected</i>
- </div>
- <div id="details-applications" class="catalog-details hide"/>
- <div id="details-entities" class="catalog-details hide"/>
- <div id="details-policies" class="catalog-details hide"/>
- <div id="details-locations" class="catalog-details hide"/>
- </div>
-</div></div>
<div class="modal hide fade" id="new-entity-modal">
<form class="form-vertical" id="new-entity-form">
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/api/CatalogApi.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/domain/ApplicationSpec.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/domain/ApplicationSummary.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogItemSummary.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/domain/ConfigSummary.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/domain/EffectorSummary.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/domain/EntitySpec.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/domain/EntitySummary.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSpec.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSummary.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/domain/PolicySummary.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/domain/SensorSummary.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/domain/TaskSummary.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-api/src/main/java/brooklyn/rest/domain/UsageStatistic.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-server/src/main/java/brooklyn/rest/resources/CatalogResource.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-server/src/main/java/brooklyn/rest/resources/EffectorResource.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-server/src/main/java/brooklyn/rest/resources/LocationResource.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1a8427dc/usage/rest-server/src/main/java/brooklyn/rest/resources/PolicyResource.java
----------------------------------------------------------------------