CreateAuditTableLayoutView.js 9.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/**
 * 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',
    'hbs!tmpl/audit/CreateAuditTableLayoutView_tmpl',
    'utils/Enums',
    'utils/CommonViewFunction',
    'utils/Utils'
], function(require, Backbone, CreateAuditTableLayoutViewTmpl, Enums, CommonViewFunction, Utils) {
    'use strict';

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

            template: CreateAuditTableLayoutViewTmpl,

            /** Layout sub regions */
            regions: {},

            /** ui selector cache */
            ui: {
                auditValue: "[data-id='auditValue']",
41
                name: "[data-id='name']",
42 43 44
                noData: "[data-id='noData']",
                tableAudit: "[data-id='tableAudit']",
                auditHeaderValue: "[data-id='auditHeaderValue']",
45 46 47 48 49 50 51 52 53 54 55 56 57
                attributeDetails: "[data-id='attributeDetails']",
                attributeCard: "[data-id='attribute-card']",
                labelsDetailsTable: "[data-id='labelsDetails']",
                labelCard: "[data-id='label-card']",
                customAttributeDetails: "[data-id='customAttributeDetails']",
                customAttrCard: "[data-id='custom-attr-card']",
                relationShipAttributeDetails: "[data-id='relationShipAttributeDetails']",
                relationshipAttrCard: "[data-id='relationship-attr-card']",
                attributeDetailCard: "[data-id='attributeDetail-card']",
                detailsAttribute: "[data-id='detailsAttribute']",
                panelAttrHeading: "[data-id='panel-attr-heading']",
                nameUpdate: "[data-id='name-update']"

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
            },
            /** ui events hash */
            events: function() {
                var events = {};
                return events;
            },
            /**
             * intialize a new CreateAuditTableLayoutView Layout
             * @constructs
             */
            initialize: function(options) {
                _.extend(this, _.pick(options, 'guid', 'entityModel', 'action', 'entity', 'entityName', 'attributeDefs'));
            },
            bindEvents: function() {},
            onRender: function() {
                this.auditTableGenerate();
            },
75 76 77 78 79 80 81 82 83
            createTableWithValues: function(tableDetails) {
                var attrTable = CommonViewFunction.propertyTable({
                    scope: this,
                    valueObject: tableDetails
                });
                return attrTable;

            },
            updateName: function(name) {
84
                this.ui.name.html("<span>Name: </span><span>" + name + "</span>");
85 86 87 88
            },
            noDetailsShow: function() {
                this.ui.noData.removeClass('hide');
            },
89 90 91 92
            auditTableGenerate: function() {
                var that = this,
                    table = "";
                var detailObj = this.entityModel.get('details');
93 94 95 96 97 98 99 100 101
                if (detailObj) {
                    if (detailObj.search(':') >= 0) {
                        var parseDetailsObject = detailObj.split(':'),
                            type = "",
                            auditData = "";
                        if (parseDetailsObject.length > 1) {
                            type = parseDetailsObject[0];
                            parseDetailsObject.shift();
                            auditData = parseDetailsObject.join(":");
102
                        }
103 104 105 106 107
                        if (auditData.search('{') === -1) {
                            if (type.trim() === "Added labels" || type.trim() === "Deleted labels") {
                                this.updateName(auditData.trim().split(" ").join(","));
                            } else {
                                this.updateName(auditData);
108 109
                            }
                        } else {
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
                            try {
                                parseDetailsObject = JSON.parse(auditData);
                                var skipAttribute = parseDetailsObject.typeName ? "guid" : null,
                                    name = Utils.getName(parseDetailsObject, null, skipAttribute);
                                if (name == "-") {
                                    name = _.escape(parseDetailsObject.typeName);
                                }
                                var name = ((name ? name : this.entityName));
                                that.updateName(name);
                                if (parseDetailsObject) {
                                    var attributesDetails = parseDetailsObject.attributes,
                                        customAttr = parseDetailsObject.customAttributes,
                                        labelsDetails = parseDetailsObject.labels,
                                        relationshipAttributes = parseDetailsObject.relationshipAttributes;
                                    if (attributesDetails) {
                                        that.ui.attributeDetails.removeClass('hide');
                                        that.action.indexOf("Classification") === -1 ? that.ui.panelAttrHeading.html("Technical properties ") : that.ui.panelAttrHeading.html("Properties ");
                                        var attrTable = that.createTableWithValues(attributesDetails);
                                        that.ui.attributeCard.html(
                                            attrTable);
                                    }
                                    if (!_.isEmpty(customAttr)) {
                                        that.ui.customAttributeDetails.removeClass('hide');
                                        var customAttrTable = that.createTableWithValues(customAttr);
                                        that.ui.customAttrCard.html(
                                            customAttrTable);
                                    }
                                    if (!_.isEmpty(labelsDetails)) {
                                        this.ui.labelsDetailsTable.removeClass('hide');
                                        var labelsTable = '';
                                        _.each(labelsDetails, function(value, key, list) {
                                            labelsTable += "<label class='label badge-default'>" + value + "</label>";
                                        });
                                        that.ui.labelCard.html(
                                            labelsTable);
                                    }
                                    if (!_.isEmpty(relationshipAttributes)) {
                                        that.ui.relationShipAttributeDetails.removeClass('hide');
                                        var relationshipAttrTable = that.createTableWithValues(relationshipAttributes);
                                        that.ui.relationshipAttrCard.html(
                                            relationshipAttrTable);
                                    }
                                    if (!attributesDetails && !customAttr && !labelsDetails && !relationshipAttributes) {
                                        that.ui.detailsAttribute.removeClass('hide');
                                        var attrDetailTable = that.createTableWithValues(parseDetailsObject);
                                        that.ui.attributeDetailCard.html(
                                            attrDetailTable);
                                    }
                                } else {
                                    that.noDetailsShow();
                                }
                            } catch (err) {
                                if (_.isArray(parseDetailsObject)) {
                                    var name = _.escape(parseDetailsObject[0]);
                                }
                                that.updateName(name);
                                that.noDetailsShow();
                            }
168
                        }
169 170
                    } else if (detailObj == "Deleted entity" || detailObj == "Purged entity") {
                        this.entityName ? this.updateName(this.entityName) : (this.ui.name.hide() && this.ui.noData.removeClass("hide"));
171 172
                    }
                }
173
            }
174 175 176
        });
    return CreateAuditTableLayoutView;
});