DetailPageLayoutView.js 16.6 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
                            if (collectionJSON[0].values.name) {
                                this.name = collectionJSON[0].values.name;
                            }
                            if (!this.name && collectionJSON[0].values.qualifiedName) {
                                this.name = collectionJSON[0].values.qualifiedName;
                            }
145 146 147
                            if (this.name && collectionJSON[0].typeName) {
                                this.name = this.name + ' (' + collectionJSON[0].typeName + ')';
                            }
148 149 150
                            if (!this.name && collectionJSON[0].typeName) {
                                this.name = collectionJSON[0].typeName;
                            }
151

152 153 154
                            if (!this.name && this.id) {
                                this.name = this.id;
                            }
155 156
                            this.description = collectionJSON[0].values.description;
                            if (this.name) {
157
                                this.ui.title.show();
158 159
                                var titleName = '<span>' + this.name + '</span>';
                                if (this.readOnly) {
160
                                    titleName += '<button title="Deleted" class="btn btn-atlasAction btn-atlas deleteBtn"><i class="fa fa-trash"></i> Deleted</button>';
161 162
                                }
                                this.ui.title.html(titleName);
163
                            } else {
164
                                this.ui.title.hide();
165 166
                            }
                            if (this.description) {
167 168
                                this.ui.description.show();
                                this.ui.description.html('<span>' + this.description + '</span>');
169
                            } else {
170
                                this.ui.description.hide();
171 172
                            }
                        }
173
                        if (collectionJSON[0].traits) {
174
                            this.addTagToTerms(collectionJSON[0].traits);
175
                        }
176
                    }
177

178 179 180
                    this.renderEntityDetailTableLayoutView();
                    this.renderTagTableLayoutView(tagGuid);
                    this.renderLineageLayoutView(tagGuid);
181
                    this.renderSchemaLayoutView(tagGuid);
182
                    this.renderAuditTableLayoutView(tagGuid);
183
                    this.renderTermTableLayoutView(tagGuid);
184 185
                }, this);
            },
186 187 188 189 190 191 192 193 194 195 196 197 198 199
            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(),
200
                    tagOrTerm = $(e.target).data("type"),
201
                    that = this;
202
                if (tagOrTerm === "term") {
203 204 205 206 207
                    var modal = CommonViewFunction.deleteTagModel({
                        msg: "<div class='ellipsis'>Remove: " + "<b>" + tagName + "</b> assignment from" + " " + "<b>" + this.name + "?</b></div>",
                        titleMessage: Messages.removeTerm,
                        buttonText: "Remove"
                    });
208
                } else if (tagOrTerm === "tag") {
209 210 211 212 213 214
                    var modal = CommonViewFunction.deleteTagModel({
                        msg: "<div class='ellipsis'>Remove: " + "<b>" + tagName + "</b> assignment from" + " " + "<b>" + this.name + "?</b></div>",
                        titleMessage: Messages.removeTag,
                        buttonText: "Remove"
                    });
                }
215 216 217 218 219 220 221 222
                if (modal) {
                    modal.on('ok', function() {
                        that.deleteTagData(e, tagOrTerm);
                    });
                    modal.on('closeModal', function() {
                        modal.trigger('cancel');
                    });
                }
223
            },
224
            deleteTagData: function(e, tagOrTerm) {
225 226 227 228 229
                var that = this,
                    tagName = $(e.currentTarget).text();
                CommonViewFunction.deleteTag({
                    'tagName': tagName,
                    'guid': that.id,
230
                    'tagOrTerm': tagOrTerm,
231 232 233
                    callback: function() {
                        that.fetchCollection();
                    }
234 235 236
                });
            },
            addTagToTerms: function(tagObject) {
237 238
                var that = this,
                    tagData = "",
239
                    termData = "";
240

241
                _.each(tagObject, function(val) {
242
                    var isTerm = Utils.checkTagOrTerm(val);
243 244
                    if (isTerm.tag) {
                        tagData += '<span class="inputTag" data-id="tagClick"><span class="inputValue">' + isTerm.fullName + '</span><i class="fa fa-close" data-id="deleteTag" data-type="tag"></i></span>';
245 246
                    }
                    if (isTerm.term) {
247
                        termData += '<span class="inputTag term" data-id="tagClick" data-href="' + isTerm.fullName + '"><span class="inputValue">' + isTerm.fullName + '</span><i class="fa fa-close" data-id="deleteTag" data-type="term"></i></span>';
248
                    }
249
                });
250 251 252 253
                this.ui.tagList.find("span.inputTag").remove();
                this.ui.termList.find("span.inputTag").remove();
                this.ui.tagList.prepend(tagData);
                this.ui.termList.prepend(termData);
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
            },
            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,
283 284 285
                        callback: function() {
                            that.fetchCollection();
                        }
286 287 288 289 290 291
                    });
                    /*view.saveTagData = function() {
                    override saveTagData function 
                    }*/
                });
            },
292 293 294 295 296 297 298 299 300 301 302 303 304 305
            onClickAddTermBtn: function(e) {
                var that = this;
                require([
                    'views/business_catalog/AddTermToEntityLayoutView',
                ], function(AddTermToEntityLayoutView) {
                    var view = new AddTermToEntityLayoutView({
                        guid: that.id,
                        callback: function() {
                            that.fetchCollection();
                        }
                    });
                });

            },
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
            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,
321 322
                        guid: tagGuid,
                        assetName: that.name
323 324 325 326 327 328 329 330 331 332 333 334
                    }));
                });
            },
            renderLineageLayoutView: function(tagGuid) {
                var that = this;
                require(['views/graph/LineageLayoutView'], function(LineageLayoutView) {
                    that.RLineageLayoutView.show(new LineageLayoutView({
                        globalVent: that.globalVent,
                        guid: tagGuid
                    }));
                });
            },
335
            renderSchemaLayoutView: function(tagGuid) {
336 337 338 339
                var that = this;
                require(['views/schema/SchemaLayoutView'], function(SchemaLayoutView) {
                    that.RSchemaTableLayoutView.show(new SchemaLayoutView({
                        globalVent: that.globalVent,
340
                        guid: tagGuid
341 342
                    }));
                });
343
            },
344 345 346 347 348 349 350 351 352
            renderAuditTableLayoutView: function(tagGuid) {
                var that = this;
                require(['views/audit/AuditTableLayoutView'], function(AuditTableLayoutView) {
                    that.RAuditTableLayoutView.show(new AuditTableLayoutView({
                        globalVent: that.globalVent,
                        guid: tagGuid
                    }));
                });
            },
353 354 355 356 357 358 359
            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,
360
                        assetName: that.name,
361 362 363
                        term: true
                    }));
                });
364 365 366 367
            }
        });
    return DetailPageLayoutView;
});