composer allows blueprints to be passed, and app-add-wizard preview button takes you to composer
previously "preview" button just reset the dialog; this also gives slightly more interesting examples Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/2d75ed5c Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/2d75ed5c Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/2d75ed5c Branch: refs/heads/master Commit: 2d75ed5cdfae618af20d1a87246ea989ccca5289 Parents: 1e17eee Author: Alex Heneveld <alex.henev...@cloudsoftcorp.com> Authored: Thu Feb 11 01:38:25 2016 +0000 Committer: Alex Heneveld <alex.henev...@cloudsoftcorp.com> Committed: Thu Feb 11 17:44:11 2016 +0000 ---------------------------------------------------------------------- .../assets/js/model/catalog-application.js | 1 - src/main/webapp/assets/js/router.js | 8 +-- .../assets/js/view/application-add-wizard.js | 46 +++++++++------ src/main/webapp/assets/js/view/catalog.js | 3 +- src/main/webapp/assets/js/view/editor.js | 60 ++++++++++++++++---- src/main/webapp/assets/tpl/editor/page.html | 2 +- 6 files changed, 87 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/2d75ed5c/src/main/webapp/assets/js/model/catalog-application.js ---------------------------------------------------------------------- diff --git a/src/main/webapp/assets/js/model/catalog-application.js b/src/main/webapp/assets/js/model/catalog-application.js index f1a15eb..43f28b4 100644 --- a/src/main/webapp/assets/js/model/catalog-application.js +++ b/src/main/webapp/assets/js/model/catalog-application.js @@ -51,7 +51,6 @@ define(["underscore", "backbone"], function (_, Backbone) { }, getId: function(id){ return this.find(function(model) { - console.info("model", model, model.get('id') === id); return model.get('id') === id; }); } http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/2d75ed5c/src/main/webapp/assets/js/router.js ---------------------------------------------------------------------- diff --git a/src/main/webapp/assets/js/router.js b/src/main/webapp/assets/js/router.js index 54874a9..1d6dae4 100644 --- a/src/main/webapp/assets/js/router.js +++ b/src/main/webapp/assets/js/router.js @@ -123,7 +123,7 @@ define([ routes:{ 'v1/home/*trail':'homePage', //'v1/editor/*trail':'editorPage', - 'v1/editor(/)(:type)(/)(:typeId)':'editorPage', + 'v1/editor(/)(:type)(/)(:typeId)(/:content)':'editorPage', 'v1/applications/:app/entities/*trail':'applicationsPage', 'v1/applications/*trail':'applicationsPage', 'v1/applications':'applicationsPage', @@ -179,13 +179,13 @@ define([ } }, error: render}); }, - editorPage: function (type, typeId) { - console.log("editorPage", type, typeId); + editorPage: function (type, typeId, content) { var editorView = new EditorView({ collection: this.applications, appRouter: this, type: type, - typeId: typeId + typeId: typeId, + content: content }); this.showView("#application-content", editorView); $(".nav1").removeClass("active"); http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/2d75ed5c/src/main/webapp/assets/js/view/application-add-wizard.js ---------------------------------------------------------------------- diff --git a/src/main/webapp/assets/js/view/application-add-wizard.js b/src/main/webapp/assets/js/view/application-add-wizard.js index 344d6a0..ffdee6d 100644 --- a/src/main/webapp/assets/js/view/application-add-wizard.js +++ b/src/main/webapp/assets/js/view/application-add-wizard.js @@ -266,6 +266,7 @@ define([ nextStep:function () { if (this.currentStep == 0) { if (this.currentView.validate()) { + this.isTemplate = false; var yaml = (this.currentView && this.currentView.selectedTemplate && this.currentView.selectedTemplate.yaml); if (yaml) { try { @@ -283,16 +284,15 @@ define([ } } } - yaml = (hasLocation ? true : false); + this.isTemplate = (hasLocation ? true : false); } catch (e) { log("Warning: could not parse yaml template") log(yaml); - yaml = false; } } - if (yaml) { - // it's a yaml catalog template which includes a location, show the yaml tab navigate to editor - this.currentView.redirectToEditorTab(this.currentView.selectedTemplate.id); + if (this.isTemplate) { + // it's a yaml catalog *template* (because it includes a location); go to composer + this.redirectToEditorTabToDeployId(this.currentView.selectedTemplate.id); } else { // it's a java catalog template or yaml template without a location, go to wizard this.currentStep += 1; @@ -307,12 +307,16 @@ define([ }, previewStep:function () { if (this.currentView.validate()) { - this.currentStep = 0; - var that = this; - this.renderCurrentStep(function callback(view) { + var yaml; + if (this.model.mode == "yaml") { + yaml = this.model.yaml; + } else { // Drop any "None" locations. - that.model.spec.pruneLocations(); - }); + this.model.spec.pruneLocations(); + yaml = JsYaml.safeDump(oldSpecToCamp(this.model.spec.toJSON())); + } + + this.redirectToEditorTabToDeployYaml(yaml); } else { // call to validate should showFailure } @@ -323,7 +327,20 @@ define([ } else { // call to validate should showFailure } - } + }, + + redirectToEditorTabToDeployId: function(catalogId){ + this.redirectTo("/v1/editor/app/"+ (typeof catalogId === 'string' ? catalogId : '')); + }, + redirectToEditorTabToDeployYaml: function(yaml){ + this.redirectTo("/v1/editor/app/_/"+encodeURIComponent(yaml)); + }, + redirectTo: function(url){ + var $modal = $('.add-app #modal-container .modal'); + $modal.modal('hide'); + $modal.fadeTo(500,1); + Backbone.history.navigate(url, {trigger: true}); + }, }) // Note: this does not restore values on a back click; setting type and entity type+name is easy, @@ -432,11 +449,8 @@ define([ $("ul#app-add-wizard-create-tab").find("a[href='#yamlTab']").tab('show'); $("#yaml_code").focus(); }, - redirectToEditorTab: function(catalogId){ - var $modal = $('.add-app #modal-container .modal'); - $modal.modal('hide'); - $modal.fadeTo(500,1); - Backbone.history.navigate("/v1/editor/app/"+ (typeof catalogId === 'string' ? catalogId : '') ,{trigger: true}); + redirectToEditorTab: function() { + this.redirectToEditorTabToDeployId(); }, applyFilter: function(e) { var filter = $(e.currentTarget).val().toLowerCase() http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/2d75ed5c/src/main/webapp/assets/js/view/catalog.js ---------------------------------------------------------------------- diff --git a/src/main/webapp/assets/js/view/catalog.js b/src/main/webapp/assets/js/view/catalog.js index 90e89ca..eb9effd 100644 --- a/src/main/webapp/assets/js/view/catalog.js +++ b/src/main/webapp/assets/js/view/catalog.js @@ -170,7 +170,8 @@ define([ Backbone.history.navigate("/v1/catalog/new/" + type); this.$("#catalog-add-form").html(this.contextView.$el); }else{ - Backbone.history.navigate('/v1/editor/catalog/'+ type, {trigger: true}); + // go to composer + Backbone.history.navigate('/v1/editor/catalog/', {trigger: true}); } } }); http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/2d75ed5c/src/main/webapp/assets/js/view/editor.js ---------------------------------------------------------------------- diff --git a/src/main/webapp/assets/js/view/editor.js b/src/main/webapp/assets/js/view/editor.js index 4746b33..baf534f 100644 --- a/src/main/webapp/assets/js/view/editor.js +++ b/src/main/webapp/assets/js/view/editor.js @@ -27,9 +27,28 @@ define([ "handlebars", "bootstrap" ], function (_, $, Backbone, CatalogApplication, jsYaml, CodeMirror, EditorHtml) { - var _DEFAULT_BLUEPRINT = 'name: Empty Software Process\nlocation: localhost\nservices:\n- type: org.apache.brooklyn.entity.software.base.EmptySoftwareProcess'; - var _DEFAULT_CATALOG = 'brooklyn.catalog:\n version: 0.0.1\n items:\n - id: example\n description: This is an example catalog application\n ' + - 'itemType: template\n item:\n name: Empty Software Process\n services:\n - type: org.apache.brooklyn.entity.software.base.EmptySoftwareProcess'; + var _DEFAULT_BLUEPRINT = + 'name: Sample Blueprint\n'+ + 'description: runs `sleep` for sixty seconds then stops triggering ON_FIRE in Brooklyn\n'+ + 'location: localhost\n'+ + 'services:\n'+ + '- type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess\n'+ + ' launch.command: |\n'+ + ' echo hello world\n'+ + ' nohup sleep 60 &\n'+ + ' echo $! > ${PID_FILE:-pid.txt}\n'; + var _DEFAULT_CATALOG = + 'brooklyn.catalog:\n'+ + ' version: 0.0.1\n'+ + ' items:\n'+ + ' - id: example\n'+ + ' description: This is an example catalog application\n'+ + ' itemType: template\n'+ + ' item:\n'+ + ' name: Sample Blueprint Template\n'+ + ' services:\n'+ + ' - type: <your service here>\n'+ + ' location: <your cloud here>\n'; var EditorView = Backbone.View.extend({ tagName:"div", @@ -60,14 +79,35 @@ define([ refreshEditor: function() { var cm = this.editor; if (typeof(cm) !== "undefined") { - if(this.options.type && this.options.type === 'catalog'){ - cm.getDoc().setValue(_DEFAULT_CATALOG); - }else{ - //assume blueprint - var item = this.options.catalog.getId(this.options.typeId); - cm.getDoc().setValue((item ? item['attributes']['planYaml'] : _DEFAULT_BLUEPRINT )); + var itemText; + if (this.options.typeId === '_') { + // _ indicates a literal is being supplied + itemText = this.options.content; + } else { + if (this.options.content) { + console.log('ignoring content when typeId is not _; given:', this.options.type, this.options.typeId, this.options.content); + } + if (this.options.typeId) { + var item = this.options.catalog.getId(this.options.typeId); + if (item) itemText = item['attributes']['planYaml']; + if (!itemText) { + itemText = '# unknown type - this is an example blueprint that would reference it\n'+ + 'services:\n- type: '+this.options.typeId+'\n'; + + } + } + } + if (!itemText) { + if (this.options.type === 'catalog') { + itemText = _DEFAULT_CATALOG; + } else { + itemText = _DEFAULT_BLUEPRINT; + } } - cm.focus(); + cm.getDoc().setValue(itemText); + //better not to focus as focussing puts the cursor at the beginning which is odd + //and cmd-shift-[ and tab are intercepted so user can't navigate + // cm.focus(); cm.refresh(); } http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/2d75ed5c/src/main/webapp/assets/tpl/editor/page.html ---------------------------------------------------------------------- diff --git a/src/main/webapp/assets/tpl/editor/page.html b/src/main/webapp/assets/tpl/editor/page.html index 44c5d9d..9a37fe0 100644 --- a/src/main/webapp/assets/tpl/editor/page.html +++ b/src/main/webapp/assets/tpl/editor/page.html @@ -36,7 +36,7 @@ under the License. <div class="composer-toolbar"> <!-- the toolbar --> </div> - <textarea id="yaml_code" placeholder="no details available" mode="yaml" class="code-textarea" style="height:760px; width:98%"></textarea> + <textarea id="yaml_code" placeholder="<enter blueprint yaml here>" mode="yaml" class="code-textarea" style="height:760px; width:98%"></textarea> </div> </div> </div>