DetailPageLayoutView.js 17.9 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
    'hbs!tmpl/detail_page/DetailPageLayoutView_tmpl',
    'utils/Utils',
23
    'utils/CommonViewFunction',
24
    'utils/Globals',
25 26 27
    'utils/Enums',
    'utils/Messages',
    'utils/UrlLinks'
28
], function(require, Backbone, DetailPageLayoutViewTmpl, Utils, CommonViewFunction, Globals, Enums, Messages, UrlLinks) {
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
                tagClick: '[data-id="tagClick"]',
                title: '[data-id="title"]',
                editButton: '[data-id="editButton"]',
                description: '[data-id="description"]',
                editBox: '[data-id="editBox"]',
                deleteTag: '[data-id="deleteTag"]',
56 57 58 59 60
                backButton: "[data-id='backButton']",
                addTag: '[data-id="addTag"]',
                addTerm: '[data-id="addTerm"]',
                tagList: '[data-id="tagList"]',
                termList: '[data-id="termList"]'
61
            },
62 63
            templateHelpers: function() {
                return {
64 65
                    taxonomy: Globals.taxonomy,
                    entityUpdate: Globals.entityUpdate
66 67
                };
            },
68 69 70
            /** ui events hash */
            events: function() {
                var events = {};
71
                events["click " + this.ui.editButton] = 'onClickEditEntity';
72
                events["click " + this.ui.tagClick] = function(e) {
73
                    if (e.target.nodeName.toLocaleLowerCase() != "i") {
74 75 76 77 78
                        var scope = $(e.currentTarget);
                        if (scope.hasClass('term')) {
                            var url = scope.data('href').split(".").join("/terms/");
                            Globals.saveApplicationState.tabState.stateChanged = false;
                            Utils.setUrl({
79
                                url: '#!/taxonomy/detailCatalog' + UrlLinks.taxonomiesApiUrl() + '/' + url,
80 81 82 83 84 85 86 87 88 89
                                mergeBrowserUrl: false,
                                trigger: true
                            });
                        } else {
                            Utils.setUrl({
                                url: '#!/tag/tagAttribute/' + e.currentTarget.textContent,
                                mergeBrowserUrl: false,
                                trigger: true
                            });
                        }
90 91 92
                    }
                };
                events["click " + this.ui.deleteTag] = 'onClickTagCross';
93 94
                events["click " + this.ui.addTag] = 'onClickAddTagBtn';
                events["click " + this.ui.addTerm] = 'onClickAddTermBtn';
95 96 97
                events['click ' + this.ui.backButton] = function() {
                    Backbone.history.history.back();
                };
98 99 100 101 102 103 104
                return events;
            },
            /**
             * intialize a new DetailPageLayoutView Layout
             * @constructs
             */
            initialize: function(options) {
105
                _.extend(this, _.pick(options, 'globalVent', 'collection', 'vent', 'id'));
106
                this.bindEvents();
107
                this.auditVent = new Backbone.Wreqr.EventAggregator();
108 109
            },
            bindEvents: function() {
110
                var that = this;
111
                this.listenTo(this.collection, 'reset', function() {
112 113 114
                    var collectionJSON = this.collection.first().toJSON();
                    if (collectionJSON && collectionJSON.guid) {
                        var tagGuid = collectionJSON.guid;
115
                        this.readOnly = Enums.entityStateReadOnly[collectionJSON.status];
116
                    } else {
117
                        var tagGuid = this.id;
118
                    }
119 120 121 122 123
                    if (this.readOnly) {
                        this.$el.addClass('readOnly');
                    } else {
                        this.$el.removeClass('readOnly');
                    }
124 125 126 127
                    if (collectionJSON) {
                        if (collectionJSON.attributes) {
                            if (collectionJSON.attributes.name) {
                                this.name = collectionJSON.attributes.name
128
                            }
129 130
                            if (!this.name && collectionJSON.attributes.qualifiedName) {
                                this.name = collectionJSON.attributes.qualifiedName;
131
                            }
132 133 134
                            if (!this.name && collectionJSON.displayText) {
                                this.name = collectionJSON.displayText;
                            }
135 136
                            if (this.name && collectionJSON.typeName) {
                                this.name = this.name + ' (' + collectionJSON.typeName + ')';
137
                            }
138 139
                            if (!this.name && collectionJSON.typeName) {
                                this.name = collectionJSON.typeName;
140 141 142 143
                            }
                            if (!this.name && this.id) {
                                this.name = this.id;
                            }
144
                            this.description = collectionJSON.attributes.description;
145
                            if (this.name) {
146
                                this.ui.title.show();
147
                                var titleName = '<span>' + _.escape(this.name) + '</span>';
148
                                if (this.readOnly) {
149
                                    titleName += '<button title="Deleted" class="btn btn-atlasAction btn-atlas deleteBtn"><i class="fa fa-trash"></i> Deleted</button>';
150 151
                                }
                                this.ui.title.html(titleName);
152
                            } else {
153
                                this.ui.title.hide();
154 155
                            }
                            if (this.description) {
156
                                this.ui.description.show();
157
                                this.ui.description.html('<span>' + _.escape(this.description) + '</span>');
158
                            } else {
159
                                this.ui.description.hide();
160 161
                            }
                        }
162 163
                        if (collectionJSON.classifications) {
                            this.addTagToTerms(collectionJSON.classifications);
164 165
                        } else {
                            this.addTagToTerms([]);
166
                        }
167 168 169 170 171 172 173
                        if (Globals.entityTypeConfList && _.isEmptyArray(Globals.entityTypeConfList)) {
                            this.ui.editButton.show();
                        } else {
                            if (_.contains(Globals.entityTypeConfList, collectionJSON.typeName)) {
                                this.ui.editButton.show();
                            }
                        }
174
                    }
175
                    this.hideLoader();
176
                    this.renderEntityDetailTableLayoutView();
177
                    this.renderAuditTableLayoutView(this.id, collectionJSON.attributes);
178
                    this.renderTagTableLayoutView(tagGuid);
179
                    this.renderTermTableLayoutView(tagGuid);
180 181
                    this.renderLineageLayoutView(this.id);
                    this.renderSchemaLayoutView(this.id);
182
                }, this);
183 184 185 186 187 188 189 190
                this.listenTo(this.collection, 'error', function(model, response) {
                    this.$('.fontLoader').hide();
                    if (response.responseJSON) {
                        Utils.notifyError({
                            content: response.responseJSON.errorMessage || response.responseJSON.error
                        });
                    }
                }, this);
191
            },
192 193
            onRender: function() {
                var that = this;
194 195
                Utils.showTitleLoader(this.$('.page-title .fontLoader'), this.$('.entityDetail'));
                this.$('.fontLoader').show(); // to show tab loader
196 197 198 199 200 201
            },
            fetchCollection: function() {
                this.collection.fetch({ reset: true });
            },
            onClickTagCross: function(e) {
                var tagName = $(e.currentTarget).parent().text(),
202
                    tagOrTerm = $(e.target).data("type"),
203
                    that = this;
204
                if (tagOrTerm === "term") {
205
                    var modal = CommonViewFunction.deleteTagModel({
206
                        msg: "<div class='ellipsis'>Remove: " + "<b>" + _.escape(tagName) + "</b> assignment from" + " " + "<b>" + this.name + "?</b></div>",
207 208 209
                        titleMessage: Messages.removeTerm,
                        buttonText: "Remove"
                    });
210
                } else if (tagOrTerm === "tag") {
211
                    var modal = CommonViewFunction.deleteTagModel({
212
                        msg: "<div class='ellipsis'>Remove: " + "<b>" + _.escape(tagName) + "</b> assignment from" + " " + "<b>" + this.name + "?</b></div>",
213 214 215 216
                        titleMessage: Messages.removeTag,
                        buttonText: "Remove"
                    });
                }
217 218 219 220 221 222 223 224
                if (modal) {
                    modal.on('ok', function() {
                        that.deleteTagData(e, tagOrTerm);
                    });
                    modal.on('closeModal', function() {
                        modal.trigger('cancel');
                    });
                }
225
            },
226
            deleteTagData: function(e, tagOrTerm) {
227 228
                var that = this,
                    tagName = $(e.currentTarget).text();
229
                Utils.showTitleLoader(this.$('.page-title .fontLoader'), this.$('.entityDetail'));
230 231 232
                CommonViewFunction.deleteTag({
                    'tagName': tagName,
                    'guid': that.id,
233
                    'tagOrTerm': tagOrTerm,
234 235 236
                    callback: function() {
                        that.fetchCollection();
                    }
237 238 239
                });
            },
            addTagToTerms: function(tagObject) {
240 241
                var that = this,
                    tagData = "",
242
                    termData = "";
243

244
                _.each(tagObject, function(val) {
245 246 247
                    //var isTerm = Utils.checkTagOrTerm(val);
                    if (val.typeName && val.typeName.split('.').length === 1) {
                        tagData += '<span class="inputTag" data-id="tagClick"><span class="inputValue">' + val.typeName + '</span><i class="fa fa-close" data-id="deleteTag" data-type="tag"></i></span>';
248
                    }
249 250
                    if (val.typeName && val.typeName.split('.').length > 1) {
                        termData += '<span class="inputTag term" data-id="tagClick" data-href="' + val.typeName + '"><span class="inputValue">' + val.typeName + '</span><i class="fa fa-close" data-id="deleteTag" data-type="term"></i></span>';
251
                    }
252
                });
253 254 255 256
                this.ui.tagList.find("span.inputTag").remove();
                this.ui.termList.find("span.inputTag").remove();
                this.ui.tagList.prepend(tagData);
                this.ui.termList.prepend(termData);
257
            },
258 259 260 261 262 263
            hideLoader: function() {
                Utils.hideTitleLoader(this.$('.page-title .fontLoader'), this.$('.entityDetail'));
            },
            showLoader: function() {
                Utils.showTitleLoader(this.$('.page-title .fontLoader'), this.$('.entityDetail'));
            },
264 265 266 267 268 269
            onClickAddTagBtn: function(e) {
                var that = this;
                require(['views/tag/addTagModalView'], function(AddTagModalView) {
                    var view = new AddTagModalView({
                        vent: that.vent,
                        guid: that.id,
270 271 272
                        tagList: _.map(that.collection.first().toJSON().classifications, function(obj) {
                            return obj.typeName;
                        }),
273 274
                        callback: function() {
                            that.fetchCollection();
275 276 277
                        },
                        showLoader: that.showLoader.bind(that),
                        hideLoader: that.hideLoader.bind(that)
278
                    });
279 280 281
                    view.modal.on('ok', function() {
                        Utils.showTitleLoader(that.$('.page-title .fontLoader'), that.$('.entityDetail'));
                    });
282 283
                });
            },
284 285 286 287 288 289 290 291 292
            onClickAddTermBtn: function(e) {
                var that = this;
                require([
                    'views/business_catalog/AddTermToEntityLayoutView',
                ], function(AddTermToEntityLayoutView) {
                    var view = new AddTermToEntityLayoutView({
                        guid: that.id,
                        callback: function() {
                            that.fetchCollection();
293 294 295
                        },
                        showLoader: that.showLoader.bind(that),
                        hideLoader: that.hideLoader.bind(that)
296
                    });
297 298 299
                    view.modal.on('ok', function() {
                        Utils.showTitleLoader(that.$('.page-title .fontLoader'), that.$('.entityDetail'));
                    });
300 301 302
                });

            },
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
            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,
318 319
                        guid: tagGuid,
                        assetName: that.name
320 321 322 323 324 325 326 327 328 329 330 331
                    }));
                });
            },
            renderLineageLayoutView: function(tagGuid) {
                var that = this;
                require(['views/graph/LineageLayoutView'], function(LineageLayoutView) {
                    that.RLineageLayoutView.show(new LineageLayoutView({
                        globalVent: that.globalVent,
                        guid: tagGuid
                    }));
                });
            },
332
            renderSchemaLayoutView: function(tagGuid) {
333 334 335 336
                var that = this;
                require(['views/schema/SchemaLayoutView'], function(SchemaLayoutView) {
                    that.RSchemaTableLayoutView.show(new SchemaLayoutView({
                        globalVent: that.globalVent,
337
                        guid: tagGuid
338 339
                    }));
                });
340
            },
341
            renderAuditTableLayoutView: function(tagGuid, entityObject) {
342 343 344 345
                var that = this;
                require(['views/audit/AuditTableLayoutView'], function(AuditTableLayoutView) {
                    that.RAuditTableLayoutView.show(new AuditTableLayoutView({
                        globalVent: that.globalVent,
346
                        guid: tagGuid,
347 348
                        vent: that.auditVent,
                        entityObject: entityObject
349 350 351
                    }));
                });
            },
352 353 354 355 356 357 358
            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,
359
                        assetName: that.name,
360 361 362
                        term: true
                    }));
                });
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
            },
            onClickEditEntity: function(e) {
                var that = this;
                $(e.currentTarget).blur();
                require([
                    'views/entity/CreateEntityLayoutView'
                ], function(CreateEntityLayoutView) {
                    var view = new CreateEntityLayoutView({
                        guid: that.id,
                        callback: function() {
                            that.fetchCollection();
                        }
                    });

                });
378 379 380 381
            }
        });
    return DetailPageLayoutView;
});