support for multi-item catalog yaml adds many tests, and the rest of the features - template and policy and location; and source yaml.
also a few significant REST API changes: * /v1/catalog/create API change returns a map (breaking) * catalog items include more information for entity and policies Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/7eff2068 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/7eff2068 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/7eff2068 Branch: refs/heads/0.7.0-incubating Commit: 7eff2068729bb66bbe559b22e151b0846c786a14 Parents: bca850e Author: Alex Heneveld <[email protected]> Authored: Fri Apr 3 13:29:28 2015 -0400 Committer: Alex Heneveld <[email protected]> Committed: Thu Apr 16 01:25:39 2015 -0500 ---------------------------------------------------------------------- .../src/main/webapp/assets/js/view/catalog.js | 57 ++++++++++++-------- .../assets/tpl/catalog/add-catalog-entry.html | 4 +- .../webapp/assets/tpl/catalog/add-entity.html | 30 ----------- .../webapp/assets/tpl/catalog/add-yaml.html | 30 +++++++++++ 4 files changed, 68 insertions(+), 53 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/7eff2068/usage/jsgui/src/main/webapp/assets/js/view/catalog.js ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/main/webapp/assets/js/view/catalog.js b/usage/jsgui/src/main/webapp/assets/js/view/catalog.js index 6f75136..68b3c6f 100644 --- a/usage/jsgui/src/main/webapp/assets/js/view/catalog.js +++ b/usage/jsgui/src/main/webapp/assets/js/view/catalog.js @@ -24,7 +24,7 @@ define([ "text!tpl/catalog/details-generic.html", "text!tpl/catalog/details-location.html", "text!tpl/catalog/add-catalog-entry.html", - "text!tpl/catalog/add-entity.html", + "text!tpl/catalog/add-yaml.html", "text!tpl/catalog/add-location.html", "text!tpl/catalog/nav-entry.html", @@ -32,7 +32,7 @@ define([ ], function(_, $, Backbone, Brooklyn, Location, Entity, CatalogPageHtml, DetailsEntityHtml, DetailsGenericHtml, LocationDetailsHtml, - AddCatalogEntryHtml, AddEntityHtml, AddLocationHtml, EntryHtml) { + AddCatalogEntryHtml, AddYamlHtml, AddLocationHtml, EntryHtml) { // Holds the currently active details type, e.g. applications, policies. Bit of a workaround // to share the active view with all instances of AccordionItemView, so clicking the 'reload @@ -130,15 +130,21 @@ define([ render: function (initialView) { this.$el.html(this.template()); if (initialView) { + if (initialView == "entity") initialView = "yaml"; + this.$("[data-context='"+initialView+"']").addClass("active"); this.showFormForType(initialView) } return this; }, + clearWithHtml: function(template) { + if (this.contextView) this.contextView.close(); + this.context = undefined; + this.$(".btn").removeClass("active"); + this.$("#catalog-add-form").html(template); + }, beforeClose: function () { - if (this.contextView) { - this.contextView.close(); - } + if (this.contextView) this.contextView.close(); }, showContext: function(event) { var $event = $(event.currentTarget); @@ -152,13 +158,13 @@ define([ }, showFormForType: function (type) { this.context = type; - if (type == "entity") { - this.contextView = newEntityForm(this.options.parent); + if (type == "yaml" || type == "entity") { + this.contextView = newYamlForm(this, this.options.parent); } else if (type == "location") { - this.contextView = newLocationForm(this.options.parent); + this.contextView = newLocationForm(this, this.options.parent); } else if (type !== undefined) { console.log("unknown catalog type " + type); - this.showFormForType("entity"); + this.showFormForType("yaml"); return; } Backbone.history.navigate("/v1/catalog/new/" + type); @@ -166,11 +172,10 @@ define([ } }); - function newEntityForm(parent) { + function newYamlForm(addView, addViewParent) { return new Brooklyn.view.Form({ - template: _.template(AddEntityHtml), + template: _.template(AddYamlHtml), onSubmit: function (model) { - console.log("Submit entity", model.get("yaml")); var submitButton = this.$(".catalog-submit-button"); // "loading" is an indicator to Bootstrap, not a string to display submitButton.button("loading"); @@ -185,9 +190,13 @@ define([ .done(function (data, status, xhr) { // Can extract location of new item with: //model.url = Brooklyn.util.pathOf(xhr.getResponseHeader("Location")); - self.close(); // one of the calls below should draw a different view - parent.loadAccordionItem("entities", data.id); - parent.loadAccordionItem("applications", data.id); + if (_.size(data)==0) { + addView.clearWithHtml( "No items supplied." ); + } else { + addView.clearWithHtml( "Added: "+_.escape(_.keys(data).join(", ")) + + (_.size(data)==1 ? ". Loading..." : "") ); + addViewParent.loadAnyAccordionItem(_.size(data)==1 ? _.keys(data)[0] : undefined); + } }) .fail(function (xhr, status, error) { submitButton.button("reset"); @@ -201,7 +210,7 @@ define([ } // Could adapt to edit existing locations too. - function newLocationForm(parent) { + function newLocationForm(addView, addViewParent) { // Renders with config key list var body = new (Backbone.View.extend({ beforeClose: function() { @@ -235,10 +244,9 @@ define([ submitButton.button("loading"); location.set("config", configKeys); location.save() - .done(function (newModel) { - newModel = new Location.Model(newModel); - self.close(); // the call below should draw a different view - parent.loadAccordionItem("locations", newModel.id); + .done(function (data) { + addView.clearWithHtml( "Added: "+data.id+". Loading..." ); + addViewParent.loadAccordionItem("locations", data.id); }) .fail(function (response) { submitButton.button("reset"); @@ -264,7 +272,7 @@ define([ this.model = model; }, url: function() { - return "/v1/catalog/" + this.name; + return "/v1/catalog/" + this.name+"?allVersions=true"; } }); @@ -509,6 +517,13 @@ define([ this.setDetailsView(newView); }, + loadAnyAccordionItem: function (id) { + this.loadAccordionItem("entities", id); + this.loadAccordionItem("applications", id); + this.loadAccordionItem("policies", id); + this.loadAccordionItem("locations", id); + }, + loadAccordionItem: function (kind, id) { if (!this.accordion[kind]) { console.error("No accordion for: " + kind); http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/7eff2068/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-catalog-entry.html ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-catalog-entry.html b/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-catalog-entry.html index 6bd8c00..238dd77 100644 --- a/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-catalog-entry.html +++ b/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-catalog-entry.html @@ -18,11 +18,11 @@ under the License. --> <div class="catalog-details"> - <h2>Add a new...</h2> + <h2>Add to Catalog</h2> <br/> <div data-toggle="buttons-radio"> - <button class="btn btn-large show-context" data-context="entity">Entity</button> + <button class="btn btn-large show-context" data-context="yaml">YAML</button> <button class="btn btn-large show-context" data-context="location">Location</button> </div> http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/7eff2068/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-entity.html ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-entity.html b/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-entity.html deleted file mode 100644 index 9c64e90..0000000 --- a/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-entity.html +++ /dev/null @@ -1,30 +0,0 @@ -<!-- -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. ---> -<form> - <label for="new-blueprint">Enter blueprint:</label> - <textarea id='new-blueprint' name='yaml' rows='5' cols='15'></textarea> - - <button class='catalog-submit-button btn' data-loading-text='Saving...'>Submit</button> - <p class="catalog-save-error hide"> - <span class="alert-error"> - <strong>Error:</strong><br/> - <span class="catalog-error-message"></span> - </span> - </p> -</form> http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/7eff2068/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-yaml.html ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-yaml.html b/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-yaml.html new file mode 100644 index 0000000..9c64e90 --- /dev/null +++ b/usage/jsgui/src/main/webapp/assets/tpl/catalog/add-yaml.html @@ -0,0 +1,30 @@ +<!-- +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. +--> +<form> + <label for="new-blueprint">Enter blueprint:</label> + <textarea id='new-blueprint' name='yaml' rows='5' cols='15'></textarea> + + <button class='catalog-submit-button btn' data-loading-text='Saving...'>Submit</button> + <p class="catalog-save-error hide"> + <span class="alert-error"> + <strong>Error:</strong><br/> + <span class="catalog-error-message"></span> + </span> + </p> +</form>
