From 8ad9923f081a888f01661520fa5e0dfcf4433bd0 Mon Sep 17 00:00:00 2001 From: Thomas Bouron Date: Thu, 10 Mar 2016 15:24:53 +0000 Subject: [PATCH 01/11] Add first draft of the location wizard --- src/main/webapp/assets/css/base.css | 31 ++ src/main/webapp/assets/js/view/home.js | 25 +- .../webapp/assets/js/view/location-wizard.js | 497 ++++++++++++++++++ .../webapp/assets/tpl/home/summaries.html | 3 +- .../location-configuration.html | 20 + .../location-provisioning.html | 30 ++ .../tpl/location-wizard/location-type.html | 40 ++ .../assets/tpl/location-wizard/modal.html | 36 ++ 8 files changed, 679 insertions(+), 3 deletions(-) create mode 100644 src/main/webapp/assets/js/view/location-wizard.js create mode 100644 src/main/webapp/assets/tpl/location-wizard/location-configuration.html create mode 100644 src/main/webapp/assets/tpl/location-wizard/location-provisioning.html create mode 100644 src/main/webapp/assets/tpl/location-wizard/location-type.html create mode 100644 src/main/webapp/assets/tpl/location-wizard/modal.html diff --git a/src/main/webapp/assets/css/base.css b/src/main/webapp/assets/css/base.css index a80f35b47..be100e2c8 100644 --- a/src/main/webapp/assets/css/base.css +++ b/src/main/webapp/assets/css/base.css @@ -1486,3 +1486,34 @@ textarea.param-value { color: transparent; text-shadow: 0 0 5px rgba(0,0,0,0.5); } + +/* Location wizard */ +.location-type { + width: 160px; + height: 200px; + float: left; + text-align: center; + border: 3px solid #EEE; + position: relative; + margin: 4px; +} +.location-type:hover { + border-color: #CCC; +} +.location-type.selected { + border-color: #793; +} +.location-type div { + position: absolute; + top: 50%; + transform: translateY(-50%); + width: 150px; + padding: 5px; +} +.location-type .fa { + font-size: 60px; + margin-bottom: 20px; +} +.location-type .location-type-title { + font-size: 30px; +} diff --git a/src/main/webapp/assets/js/view/home.js b/src/main/webapp/assets/js/view/home.js index ae2ba3a99..375e670c5 100644 --- a/src/main/webapp/assets/js/view/home.js +++ b/src/main/webapp/assets/js/view/home.js @@ -24,6 +24,7 @@ define([ "jquery", "underscore", "backbone", "view/viewutils", "view/application-add-wizard", + "view/location-wizard", "view/ha-summary", "model/location", "text!tpl/home/applications.html", @@ -31,7 +32,7 @@ define([ "text!tpl/home/app-entry.html", "bootstrap", "brooklyn-utils" ], function ($, _, Backbone, ViewUtils, - AppAddWizard, HASummary, Location, + AppAddWizard, LocationWizard , HASummary, Location, ApplicationsHtml, HomeSummariesHtml, AppEntryHtml) { var HomeView = Backbone.View.extend({ @@ -40,7 +41,8 @@ define([ 'click #add-new-application':'createApplication', 'click #reload-brooklyn-properties': 'reloadBrooklynProperties', 'click #clear-ha-node-records': 'clearHaNodeRecords', - 'click .addApplication':'createApplication' + 'click .addApplication':'createApplication', + 'click .addLocation': 'createLocation' }, initialize:function () { @@ -153,6 +155,25 @@ define([ } }, + createLocation:function () { + if (this._modal) { + this._modal.close() + } + var that = this; + if (this.options.offline || (this.options.cautionOverlay && this.options.cautionOverlay.warningActive)) { + // don't show wizard + } else { + var wizard = new LocationWizard(); + this._modal = wizard; + this.$(".add-app #modal-container").html(wizard.render().el); + this.$(".add-app #modal-container .modal") + .on("hidden",function () { + wizard.close(); + that.options.locations.fetch({reset:true}); + }).modal('show'); + } + }, + reloadBrooklynProperties: function() { var self = this; // indicate submitted diff --git a/src/main/webapp/assets/js/view/location-wizard.js b/src/main/webapp/assets/js/view/location-wizard.js new file mode 100644 index 000000000..0e9cacb57 --- /dev/null +++ b/src/main/webapp/assets/js/view/location-wizard.js @@ -0,0 +1,497 @@ +/* + * 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', 'backbone', 'jquery', 'brooklyn-utils', 'model/location', + 'text!tpl/location-wizard/modal.html', + 'text!tpl/location-wizard/location-type.html', + 'text!tpl/location-wizard/location-configuration.html', + 'text!tpl/location-wizard/location-provisioning.html', + 'text!tpl/app-add-wizard/edit-config-entry.html', +], function(_, Backbone, $, Util, Location, ModalHtml, LocationTypeHtml, LocationConfigurationHtml, LocationProvisioningHtml, EditConfigEntryHtml) { + var Wizard = Backbone.View.extend({ + className:'modal hide fade', + template: _.template(ModalHtml), + events: { + 'click .location-wizard-previous': 'previousStep', + 'click .location-wizard-next': 'nextStep', + 'click .location-wizard-inject': 'inject', + 'click .location-wizard-save': 'save', + 'click .location-wizard-save-and-reset': 'saveAndReset' + }, + + initialize: function () { + this.type = ''; + this.step = 0; + this.location = new Location.Model; + + this.steps = [ + { + title: 'No locations defined', + subtitle: 'You currently have no location to deploy applications to' + }, + { + title: 'Location type', + subtitle: 'Select the location type you want to add', + view: new LocationType({wizard: this}) + }, + { + title: '<%= type %> Location - Configuration', + subtitle: 'Required information about your location', + view: new LocationConfiguration({wizard: this}) + }, + { + title: '<%= type %> Location - Provisioning', + subtitle: 'Provisioning information about your location', + view: new LocationProvisioning({wizard: this}), + actions: [ + { + label: 'Inject in YAML', + class: 'location-wizard-inject' + }, + { + label: 'Save and add another', + class: 'location-wizard-save-and-reset' + }, + { + label: 'Save', + class: 'location-wizard-save' + } + ] + } + ]; + }, + + render: function() { + this.$el.html(this.template({})); + + this.renderStep(); + + return this; + }, + + renderStep: function() { + var step = this.steps[this.step]; + + this.$('.location-wizard-title').html(_.template(step.title)({type: this.capitalize(this.type)})); + this.$('.location-wizard-subtitle').html(_.template(step.subtitle)({type: this.type})); + + if (_.isObject(step.view)) { + this.$('.modal-body').html(step.view.render().el); + } + + // Render prev / next buttons + var prev = this.$('.location-wizard-previous'); + var next = this.$('.location-wizard-next'); + if (this.step == 0) { + prev.hide(); + } else { + prev.show(); + } + if (this.step == this.steps.length - 1) { + next.hide(); + } else { + next.show(); + } + this.$('.trail').html('Step ' + (this.step + 1) + ' of ' + this.steps.length); + + // Render actions buttons + var actionContainer = this.$('.location-wizard-actions').empty(); + if (_.isArray(step.actions)) { + _.each(step.actions, function(element, index, list) { + actionContainer.append($('