DetailPageLayoutView.js 16.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**
 * 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(['require',
    'backbone',
21 22 23 24
    'hbs!tmpl/detail_page/DetailPageLayoutView_tmpl',
    'utils/Utils',
    'collection/VTagList',
    'models/VEntity',
25
    'utils/CommonViewFunction',
26 27 28
    'utils/Globals',
    'utils/Messages'
], function(require, Backbone, DetailPageLayoutViewTmpl, Utils, VTagList, VEntity, CommonViewFunction, Globals, Messages) {
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    'use strict';

    var DetailPageLayoutView = Backbone.Marionette.LayoutView.extend(
        /** @lends DetailPageLayoutView */
        {
            _viewName: 'DetailPageLayoutView',

            template: DetailPageLayoutViewTmpl,

            /** Layout sub regions */
            regions: {
                REntityDetailTableLayoutView: "#r_entityDetailTableLayoutView",
                RSchemaTableLayoutView: "#r_schemaTableLayoutView",
                RTagTableLayoutView: "#r_tagTableLayoutView",
                RLineageLayoutView: "#r_lineageLayoutView",
44
                RAuditTableLayoutView: "#r_auditTableLayoutView",
45 46
                RTermTableLayoutView: "#r_termTableLayoutView"

47 48
            },
            /** ui selector cache */
49
            ui: {
50 51 52 53 54 55 56 57 58 59 60 61
                tagClick: '[data-id="tagClick"]',
                title: '[data-id="title"]',
                editButton: '[data-id="editButton"]',
                cancelButton: '[data-id="cancelButton"]',
                publishButton: '[data-id="publishButton"]',
                description: '[data-id="description"]',
                descriptionTextArea: '[data-id="descriptionTextArea"]',
                editBox: '[data-id="editBox"]',
                createDate: '[data-id="createDate"]',
                updateDate: '[data-id="updateDate"]',
                createdUser: '[data-id="createdUser"]',
                deleteTag: '[data-id="deleteTag"]',
62 63 64 65 66
                backButton: "[data-id='backButton']",
                addTag: '[data-id="addTag"]',
                addTerm: '[data-id="addTerm"]',
                tagList: '[data-id="tagList"]',
                termList: '[data-id="termList"]'
67
            },
68 69 70 71 72
            templateHelpers: function() {
                return {
                    taxonomy: Globals.taxonomy
                };
            },
73 74 75
            /** ui events hash */
            events: function() {
                var events = {};
76 77 78 79 80 81 82 83 84 85
                events["click " + this.ui.editButton] = function() {
                    this.ui.editButton.hide();
                    this.ui.description.hide();
                    this.ui.editBox.show();
                    this.ui.descriptionTextArea.focus();
                    if (this.descriptionPresent) {
                        this.ui.descriptionTextArea.val(this.ui.description.text());
                    }
                };
                events["click " + this.ui.tagClick] = function(e) {
86
                    if (e.target.nodeName.toLocaleLowerCase() != "i") {
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
                        var scope = $(e.currentTarget);
                        if (scope.hasClass('term')) {
                            var url = scope.data('href').split(".").join("/terms/");
                            Globals.saveApplicationState.tabState.stateChanged = false;
                            Utils.setUrl({
                                url: '#!/taxonomy/detailCatalog/api/atlas/v1/taxonomies/' + url,
                                mergeBrowserUrl: false,
                                trigger: true
                            });
                        } else {
                            Utils.setUrl({
                                url: '#!/tag/tagAttribute/' + e.currentTarget.textContent,
                                mergeBrowserUrl: false,
                                trigger: true
                            });
                        }
103 104 105 106 107
                    }
                };
                // events["click " + this.ui.publishButton] = 'onPublishButtonClick';
                events["click " + this.ui.cancelButton] = 'onCancelButtonClick';
                events["click " + this.ui.deleteTag] = 'onClickTagCross';
108 109
                events["click " + this.ui.addTag] = 'onClickAddTagBtn';
                events["click " + this.ui.addTerm] = 'onClickAddTermBtn';
110 111 112
                events['click ' + this.ui.backButton] = function() {
                    Backbone.history.history.back();
                };
113 114 115 116 117 118 119
                return events;
            },
            /**
             * intialize a new DetailPageLayoutView Layout
             * @constructs
             */
            initialize: function(options) {
120
                _.extend(this, _.pick(options, 'globalVent', 'collection', 'vent', 'id'));
121 122 123
                this.bindEvents();
            },
            bindEvents: function() {
124
                var that = this;
125
                this.listenTo(this.collection, 'reset', function() {
126

127 128 129
                    var collectionJSON = this.collection.toJSON();
                    if (collectionJSON[0].id && collectionJSON[0].id.id) {
                        var tagGuid = collectionJSON[0].id.id;
130 131 132 133 134 135
                        this.readOnly = Globals.entityStateReadOnly[collectionJSON[0].id.state];
                    }
                    if (this.readOnly) {
                        this.$el.addClass('readOnly');
                    } else {
                        this.$el.removeClass('readOnly');
136 137 138
                    }
                    if (collectionJSON && collectionJSON.length) {
                        if (collectionJSON[0].values) {
139 140 141 142 143 144 145 146 147 148 149 150
                            if (collectionJSON[0].values.name) {
                                this.name = collectionJSON[0].values.name;
                            }
                            if (!this.name && collectionJSON[0].values.qualifiedName) {
                                this.name = collectionJSON[0].values.qualifiedName;
                            }
                            if (!this.name && collectionJSON[0].typeName) {
                                this.name = collectionJSON[0].typeName;
                            }
                            if (!this.name && this.id) {
                                this.name = this.id;
                            }
151 152
                            this.description = collectionJSON[0].values.description;
                            if (this.name) {
153
                                this.ui.title.show();
154 155 156 157 158
                                var titleName = '<span>' + this.name + '</span>';
                                if (this.readOnly) {
                                    titleName += '<button title="Deleted" class="btn btn-atlasAction btn-atlas deleteBtn"><i class="fa fa-trash"></i> Deleted</button>'
                                }
                                this.ui.title.html(titleName);
159
                            } else {
160
                                this.ui.title.hide();
161 162
                            }
                            if (this.description) {
163 164
                                this.ui.description.show();
                                this.ui.description.html('<span>' + this.description + '</span>');
165
                            } else {
166
                                this.ui.description.hide();
167 168
                            }
                        }
169 170 171 172
                        if (collectionJSON[0].traits) {
                            this.tagElement = _.keys(collectionJSON[0].traits);
                            this.addTagToTerms(this.tagElement);
                        }
173
                    }
174

175 176 177
                    this.renderEntityDetailTableLayoutView();
                    this.renderTagTableLayoutView(tagGuid);
                    this.renderLineageLayoutView(tagGuid);
178
                    this.renderSchemaLayoutView(tagGuid);
179
                    this.renderAuditTableLayoutView(tagGuid);
180
                    this.renderTermTableLayoutView(tagGuid);
181 182
                }, this);
            },
183 184 185 186 187 188 189 190 191 192 193 194 195 196
            onRender: function() {
                var that = this;
                this.ui.editBox.hide();
            },
            fetchCollection: function() {
                this.collection.fetch({ reset: true });
            },
            onCancelButtonClick: function() {
                this.ui.description.show();
                this.ui.editButton.show();
                this.ui.editBox.hide();
            },
            onClickTagCross: function(e) {
                var tagName = $(e.currentTarget).parent().text(),
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
                    that = this;
                var tagOrTerm = Utils.checkTagOrTerm(tagName);
                if (tagOrTerm.term) {
                    var modal = CommonViewFunction.deleteTagModel({
                        msg: "<div class='ellipsis'>Remove: " + "<b>" + tagName + "</b> assignment from" + " " + "<b>" + this.name + "?</b></div>",
                        titleMessage: Messages.removeTerm,
                        buttonText: "Remove"
                    });
                } else {
                    var modal = CommonViewFunction.deleteTagModel({
                        msg: "<div class='ellipsis'>Remove: " + "<b>" + tagName + "</b> assignment from" + " " + "<b>" + this.name + "?</b></div>",
                        titleMessage: Messages.removeTag,
                        buttonText: "Remove"
                    });
                }
212 213 214 215 216 217 218 219 220 221 222 223 224
                modal.on('ok', function() {
                    that.deleteTagData(e);
                });
                modal.on('closeModal', function() {
                    modal.trigger('cancel');
                });
            },
            deleteTagData: function(e) {
                var that = this,
                    tagName = $(e.currentTarget).text();
                CommonViewFunction.deleteTag({
                    'tagName': tagName,
                    'guid': that.id,
225 226 227
                    callback: function() {
                        that.fetchCollection();
                    }
228 229 230
                });
            },
            addTagToTerms: function(tagObject) {
231 232
                var that = this,
                    tagData = "",
233
                    termData = "";
234

235
                _.each(tagObject, function(val) {
236 237
                    var isTerm = Utils.checkTagOrTerm(val);
                    if (!isTerm.term) {
238
                        tagData += '<span class="inputTag" data-id="tagClick"><span class="inputValue">' + val + '</span><i class="fa fa-close" data-id="deleteTag"></i></span>';
239 240
                    }
                    if (isTerm.term) {
241
                        termData += '<span class="inputTag term" data-id="tagClick" data-href="' + val + '"><span class="inputValue">' + val + '</span><i class="fa fa-close" data-id="deleteTag"></i></span>';
242
                    }
243

244
                });
245 246 247 248
                this.ui.tagList.find("span.inputTag").remove();
                this.ui.termList.find("span.inputTag").remove();
                this.ui.tagList.prepend(tagData);
                this.ui.termList.prepend(termData);
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
            },
            saveTagFromList: function(ref) {
                var that = this;
                this.entityModel = new VEntity();
                var tagName = ref.text();
                var json = {
                    "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$_Struct",
                    "typeName": tagName,
                    "values": {}
                };
                this.entityModel.saveEntity(this.id, {
                    data: JSON.stringify(json),
                    success: function(data) {
                        that.fetchCollection();
                    },
                    error: function(error, data, status) {
                        if (error && error.responseText) {
                            var data = JSON.parse(error.responseText);
                        }
                    },
                    complete: function() {}
                });
            },
            onClickAddTagBtn: function(e) {
                var that = this;
                require(['views/tag/addTagModalView'], function(AddTagModalView) {
                    var view = new AddTagModalView({
                        vent: that.vent,
                        guid: that.id,
278 279 280
                        callback: function() {
                            that.fetchCollection();
                        }
281 282 283 284 285 286
                    });
                    /*view.saveTagData = function() {
                    override saveTagData function 
                    }*/
                });
            },
287 288 289 290 291 292 293 294 295 296 297 298 299 300
            onClickAddTermBtn: function(e) {
                var that = this;
                require([
                    'views/business_catalog/AddTermToEntityLayoutView',
                ], function(AddTermToEntityLayoutView) {
                    var view = new AddTermToEntityLayoutView({
                        guid: that.id,
                        callback: function() {
                            that.fetchCollection();
                        }
                    });
                });

            },
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
            renderEntityDetailTableLayoutView: function() {
                var that = this;
                require(['views/entity/EntityDetailTableLayoutView'], function(EntityDetailTableLayoutView) {
                    that.REntityDetailTableLayoutView.show(new EntityDetailTableLayoutView({
                        globalVent: that.globalVent,
                        collection: that.collection
                    }));
                });
            },
            renderTagTableLayoutView: function(tagGuid) {
                var that = this;
                require(['views/tag/TagDetailTableLayoutView'], function(TagDetailTableLayoutView) {
                    that.RTagTableLayoutView.show(new TagDetailTableLayoutView({
                        globalVent: that.globalVent,
                        collection: that.collection,
316 317
                        guid: tagGuid,
                        assetName: that.name
318 319 320 321 322 323 324 325 326 327 328 329
                    }));
                });
            },
            renderLineageLayoutView: function(tagGuid) {
                var that = this;
                require(['views/graph/LineageLayoutView'], function(LineageLayoutView) {
                    that.RLineageLayoutView.show(new LineageLayoutView({
                        globalVent: that.globalVent,
                        guid: tagGuid
                    }));
                });
            },
330
            renderSchemaLayoutView: function(tagGuid) {
331 332 333 334
                var that = this;
                require(['views/schema/SchemaLayoutView'], function(SchemaLayoutView) {
                    that.RSchemaTableLayoutView.show(new SchemaLayoutView({
                        globalVent: that.globalVent,
335
                        guid: tagGuid
336 337
                    }));
                });
338
            },
339 340 341 342 343 344 345 346 347
            renderAuditTableLayoutView: function(tagGuid) {
                var that = this;
                require(['views/audit/AuditTableLayoutView'], function(AuditTableLayoutView) {
                    that.RAuditTableLayoutView.show(new AuditTableLayoutView({
                        globalVent: that.globalVent,
                        guid: tagGuid
                    }));
                });
            },
348 349 350 351 352 353 354
            renderTermTableLayoutView: function(tagGuid) {
                var that = this;
                require(['views/tag/TagDetailTableLayoutView'], function(TagDetailTableLayoutView) {
                    that.RTermTableLayoutView.show(new TagDetailTableLayoutView({
                        globalVent: that.globalVent,
                        collection: that.collection,
                        guid: tagGuid,
355
                        assetName: that.name,
356 357 358
                        term: true
                    }));
                });
359 360 361 362
            }
        });
    return DetailPageLayoutView;
});