brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorbett <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: GUI+REST improvements - yaml spec...
Date Tue, 09 Sep 2014 14:08:05 GMT
Github user sjcorbett commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/156#discussion_r17301900
  
    --- Diff: usage/jsgui/src/main/webapp/assets/js/view/entity-advanced.js ---
    @@ -0,0 +1,175 @@
    +/*
    + * 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.
    +*/
    +/**
    + * Render entity advanced tab.
    + *
    + * @type {*}
    + */
    +define(["underscore", "jquery", "backbone", "brooklyn", "brooklyn-utils", "view/viewutils",
"formatJson",
    +    "text!tpl/apps/advanced.html", "view/entity-config", "view/change-name-invoke", "view/add-child-invoke",
"view/policy-new"
    +], function(_, $, Backbone, Brooklyn, Util, ViewUtils, FormatJSON,
    +        AdvancedHtml, EntityConfigView, ChangeNameInvokeView, AddChildInvokeView, NewPolicyView)
{
    +    var EntityAdvancedView = Backbone.View.extend({
    +        events: {
    +            "click button#change-name": "showChangeNameModal",
    +            "click button#add-child": "showAddChildModal",
    +            "click button#add-new-policy": "showNewPolicyModal",
    +            "click button#reset-problems": "doResetProblems",
    +            "click button#expunge": "confirmExpunge",
    +            "click button#unmanage": "confirmUnmanage",
    +            "click #advanced-tab-error-closer": "closeAdvancedTabError"
    +        },
    +        template: _.template(AdvancedHtml),
    +        initialize:function() {
    +            _.bindAll(this);
    +            this.$el.html(this.template());
    +
    +            this.options.tabView.configView = new EntityConfigView({
    +                model:this.options.model,
    +                tabView:this.options.tabView,
    +            });
    +            this.$("div#advanced-config").html(this.options.tabView.configView.render().el);
    +
    +            this.model.on('change', this.modelChange, this);
    +            this.modelChange();
    +            
    +            ViewUtils.getRepeatedlyWithDelay(this, this.model.get('links').locations,
this.renderLocationData);
    +            ViewUtils.get(this, this.model.get('links').tags, this.renderTags);
    +            
    +            ViewUtils.attachToggler(this.$el);
    +        },
    +        modelChange: function() {
    +            this.$('#entity-name').html(Util.toDisplayString(this.model.get("name")));
    +            ViewUtils.updateTextareaWithData($("#advanced-entity-json", this.$el), FormatJSON(this.model.toJSON()),
true, false, 250, 600);
    +        },
    +        renderLocationData: function(data) {
    +            ViewUtils.updateTextareaWithData($("#advanced-locations", this.$el), FormatJSON(data),
true, false, 250, 600);
    +        },
    +        renderTags: function(data) {
    +            var list = "";
    +            for (tag in data)
    +                list += "<div class='activity-tag-giftlabel'>"+_.escape(JSON.stringify(data[tag]))+"</div>";
    +            if (!list) list = "No tags";
    +            this.$('#advanced-entity-tags').html(list);
    +        },
    +        reload: function() {
    +            this.model.fetch();
    +        },
    +        
    +        showModal: function(modal) {
    +            if (this.activeModal)
    +                this.activeModal.close();
    +            this.activeModal = modal;
    +            Brooklyn.view.showModalWith(modal);
    +        },
    +        showChangeNameModal: function() {
    +            this.showModal(new ChangeNameInvokeView({
    +                entity: this.model,
    +                target:this
    +            }));
    +        },
    +        showAddChildModal: function() {
    +            this.showModal(new AddChildInvokeView({
    +                entity: this.model,
    +                target:this
    +            }));
    +        },
    +        showNewPolicyModal: function () {
    +            this.showModal(new NewPolicyView({
    +                entity: this.model,
    +            }));
    +        },
    +        doResetProblems: function() {
    +            this.post(this.model.get('links').sensors+"/"+"service.notUp.indicators",
{});
    +            this.post(this.model.get('links').sensors+"/"+"service.problems", {});
    +        },
    +        post: function(url, data) {
    +            var self = this;
    +            
    +            $.ajax({
    +                type: "POST",
    +                url: url,
    +                data: JSON.stringify(data),
    +                contentType: "application/json",
    +                success: function() {
    +                    self.reload();
    +                },
    +                error: function(data) {
    +                    self.showAdvancedTabError("Error connecting to Brooklyn server");
    +
    +                    log("ERROR invoking operation");
    +                    log(data);
    +                }
    +            });
    +        },
    +        
    +        confirmExpunge: function () {
    +            var entity = this.model.get("name");
    +            var title = "Confirm the expunging of " + entity;
    +            var q = "<p>Are you certain you want to expunge this entity?</p>"
+
    +                "<p>When possible, Brooklyn will delete all of its resources.</p>"
+
    +                "<p><span class='label label-important'>Important</span>
" +
    +                "<b>This action is irreversible</b></p>";
    +            this.unmanageAndOrExpunge(q, title, true);
    +        },
    +        confirmUnmanage: function () {
    +            var entity = this.model.get("name");
    +            var title = "Confirm the unmanagement of " + entity;
    +            var q = "<p>Are you certain you want to unmanage this entity?</p>"
+
    +            "<p>Its resources will be left running.</p>" +
    +            "<p><span class='label label-important'>Important</span>
" +
    +            "<b>This action is irreversible</b></p>";
    +            this.unmanageAndOrExpunge(q, title, false);
    +        },
    +        unmanageAndOrExpunge: function (question, title, releaseResources) {
    +            var self = this;
    +            Brooklyn.view.requestConfirmation(question, title).done(function() {
    +                return $.ajax({
    +                    type: "POST",
    +                    url: self.model.get("links").expunge + "?release=" + releaseResources
+ "&timeout=0",
    +                    contentType: "application/json"
    +                }).done(function() {
    +                    self.trigger("entity.expunged");
    +                }).fail(function() {
    +                    // (would just be connection error -- with timeout=0 we get a task
even for invalid input)
    +                    self.showAdvancedTabError("Error connecting to Brooklyn server");
    +                    
    +                    log("ERROR unmanaging/expunging");
    +                    log(data);
    +                });
    +            });
    +        },
    +
    +        showAdvancedTabError: function(errorMessage) {
    +            self.$("#advanced-tab-error-message").html(_.escape(errorMessage));
    +            self.$("#advanced-tab-error-section").removeClass("hide");
    +        },
    +        closeAdvancedTabError: function() {
    +            log("close")
    +            self.$("#advanced-tab-error-section").addClass("hide");
    +        },
    +        
    +        beforeClose:function() {
    +            if (this.activeModal)
    +                this.activeModal.close();
    +            this.options.tabView.configView.close();
    --- End diff --
    
    Call `this.model.off()` too.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message