main.js 12.8 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.
 */

require.config({
    /* starting point for application */
21 22 23
    'hbs': {
        'disableI18n': true, // This disables the i18n helper and doesn't require the json i18n files (e.g. en_us.json)
        'helperPathCallback': // Callback to determine the path to look for helpers
24
            function(name) { // ('/template/helpers/'+name by default)
25 26
                return 'modules/Helpers';
            },
27 28
        'templateExtension': 'html', // Set the extension automatically appended to templates
        'compileOptions': {} // options object which is passed to Handlebars compiler
29
    },
30
    'urlArgs': "bust=" + getBustValue(),
31 32 33 34 35 36 37
    /**
     * Requested as soon as the loader has processed the configuration. It does
     * not block any other require() calls from starting their requests for
     * modules, it is just a way to specify some modules to load asynchronously
     * as part of a config block.
     * @type {Array} An array of dependencies to load.
     */
38
    'deps': ['marionette'],
39 40 41 42 43 44

    /**
     * The number of seconds to wait before giving up on loading a script.
     * @default 7 seconds
     * @type {Number}
     */
45
    'waitSeconds': 0,
46

47

48 49 50 51
    'shim': {
        'backbone': {
            'deps': ['underscore', 'jquery'],
            'exports': 'Backbone'
52
        },
53
        'jquery-ui': {
54
            'deps': ['jquery']
55
        },
56 57 58
        'asBreadcrumbs': {
            'deps': ['jquery'],
            'exports': 'asBreadcrumbs'
59
        },
60 61 62
        'bootstrap': {
            'deps': ['jquery'],
            'exports': 'jquery'
63
        },
64 65
        'underscore': {
            'exports': '_'
66
        },
67 68
        'marionette': {
            'deps': ['backbone']
69
        },
70 71 72
        'backgrid': {
            'deps': ['backbone'],
            'exports': 'Backgrid'
73 74
        },
        'backgrid-paginator': {
75
            'deps': ['backbone', 'backgrid']
76 77
        },
        'backgrid-filter': {
78
            'deps': ['backbone', 'backgrid']
79 80
        },
        'backgrid-orderable': {
81
            'deps': ['backbone', 'backgrid'],
82 83
        },
        'backgrid-sizeable': {
84
            'deps': ['backbone', 'backgrid'],
85
        },
86
        'backgrid-select-all': {
87
            'deps': ['backbone', 'backgrid']
88
        },
89 90 91
        'backgrid-columnmanager': {
            'deps': ['backbone', 'backgrid'],
        },
92 93
        'hbs': {
            'deps': ['underscore', 'handlebars']
94
        },
95 96
        'd3': {
            'exports': ['d3']
97 98
        },
        'd3-tip': {
99 100
            'deps': ['d3'],
            'exports': ['d3-tip']
101
        },
102 103 104
        'dagreD3': {
            'deps': ['d3'],
            'exports': ['dagreD3']
105
        },
106 107 108 109 110
        'pnotify': {
            'exports': ['pnotify']
        },
        'jquery-placeholder': {
            'deps': ['jquery']
111 112 113 114 115 116
        },
        'query-builder': {
            'deps': ['jquery']
        },
        'daterangepicker': {
            'deps': ['jquery', 'moment']
117
        },
118 119
        'moment-timezone': {
            'deps': ['moment']
120
        },
121 122
        'moment': {
            'exports': ['moment']
123
        },
124 125 126 127 128 129
        'nvd3': {
            'deps': ['d3']
        },
        'sparkline': {
            'deps': ['jquery'],
            'exports': ['sparkline']
130 131 132
        },
        'jstree': {
            'deps': ['jquery']
133 134 135
        },
        'jquery-steps': {
            'deps': ['jquery']
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
        }
    },

    paths: {
        'jquery': 'libs/jquery/js/jquery.min',
        'underscore': 'libs/underscore/underscore-min',
        'bootstrap': 'libs/bootstrap/js/bootstrap.min',
        'backbone': 'libs/backbone/backbone-min',
        'backbone.babysitter': 'libs/backbone.babysitter/lib/backbone.babysitter.min',
        'marionette': 'libs/backbone-marionette/backbone.marionette.min',
        'backbone.paginator': 'libs/backbone-paginator/backbone.paginator.min',
        'backbone.wreqr': 'libs/backbone-wreqr/backbone.wreqr.min',
        'backgrid': 'libs/backgrid/js/backgrid',
        'backgrid-filter': 'libs/backgrid-filter/js/backgrid-filter.min',
        'backgrid-orderable': 'libs/backgrid-orderable-columns/js/backgrid-orderable-columns',
        'backgrid-paginator': 'libs/backgrid-paginator/js/backgrid-paginator.min',
        'backgrid-sizeable': 'libs/backgrid-sizeable-columns/js/backgrid-sizeable-columns',
153
        'backgrid-columnmanager': 'external_lib/backgrid-columnmanager/js/Backgrid.ColumnManager',
154 155 156 157 158
        'asBreadcrumbs': 'libs/jquery-asBreadcrumbs/js/jquery-asBreadcrumbs.min',
        'd3': 'libs/d3/d3.min',
        'd3-tip': 'libs/d3/index',
        'tmpl': 'templates',
        'requirejs.text': 'libs/requirejs-text/text',
159 160 161
        'handlebars': 'external_lib/require-handlebars-plugin/js/handlebars',
        'hbs': 'external_lib/require-handlebars-plugin/js/hbs',
        'i18nprecompile': 'external_lib/require-handlebars-plugin/js/i18nprecompile',
162
        'dagreD3': 'libs/dagre-d3/dagre-d3.min',
163
        'select2': 'libs/select2/select2.full.min',
164
        'backgrid-select-all': 'libs/backgrid-select-all/backgrid-select-all.min',
165
        'moment': 'libs/moment/js/moment.min',
166
        'moment-timezone': 'libs/moment-timezone/moment-timezone-with-data.min',
167
        'jquery-ui': 'external_lib/jquery-ui/jquery-ui.min',
168 169 170
        'pnotify': 'external_lib/pnotify/pnotify.custom.min',
        'pnotify.buttons': 'external_lib/pnotify/pnotify.custom.min',
        'pnotify.confirm': 'external_lib/pnotify/pnotify.custom.min',
171
        'jquery-placeholder': 'libs/jquery-placeholder/js/jquery.placeholder',
172 173
        'platform': 'libs/platform/platform',
        'query-builder': 'libs/jQueryQueryBuilder/js/query-builder.standalone.min',
174 175
        'daterangepicker': 'libs/bootstrap-daterangepicker/js/daterangepicker',
        'nvd3': 'libs/nvd3/nv.d3.min',
176
        'sparkline': 'libs/sparkline/jquery.sparkline.min',
177
        'table-dragger': 'libs/table-dragger/table-dragger',
178
        'jstree': 'libs/jstree/jstree.min',
179 180
        'jquery-steps': 'libs/jquery-steps/jquery.steps.min',
        'dropzone': 'libs/dropzone/js/dropzone-amd-module'
181 182 183 184 185 186 187 188
    },

    /**
     * If set to true, an error will be thrown if a script loads that does not
     * call define() or have a shim exports string value that can be checked.
     * To get timely, correct error triggers in IE, force a define/shim export.
     * @type {Boolean}
     */
189
    'enforceDefine': false
190 191 192 193
});

require(['App',
    'router/Router',
194
    'utils/Helper',
195 196
    'utils/CommonViewFunction',
    'utils/Globals',
197
    'utils/UrlLinks',
198
    'collection/VEntityList',
199
    'collection/VTagList',
200
    'utils/Enums',
201 202
    'utils/Overrides',
    'bootstrap',
203
    'd3',
204
    'select2'
205
], function(App, Router, Helper, CommonViewFunction, Globals, UrlLinks, VEntityList, VTagList, Enums) {
206
    var that = this;
207 208
    this.asyncFetchCounter = 7 + (Enums.addOnEntities.length + 1);
    // entity
209
    this.entityDefCollection = new VEntityList();
210
    this.entityDefCollection.url = UrlLinks.entitiesDefApiUrl();
211
    // typeHeaders
212 213
    this.typeHeaders = new VTagList();
    this.typeHeaders.url = UrlLinks.typesApiUrl();
214
    // enum
215 216 217
    this.enumDefCollection = new VTagList();
    this.enumDefCollection.url = UrlLinks.enumDefApiUrl();
    this.enumDefCollection.modelAttrName = "enumDefs";
218
    // classfication
219
    this.classificationDefCollection = new VTagList();
220
    // metric
221 222 223
    this.metricCollection = new VTagList();
    this.metricCollection.url = UrlLinks.metricsApiUrl();
    this.metricCollection.modelAttrName = "data";
224 225 226 227
    // businessMetadata
    this.businessMetadataDefCollection = new VEntityList();
    this.businessMetadataDefCollection.url = UrlLinks.businessMetadataDefApiUrl();
    this.businessMetadataDefCollection.modelAttrName = "businessMetadataDefs";
228 229

    App.appRouter = new Router({
230
        entityDefCollection: this.entityDefCollection,
231
        typeHeaders: this.typeHeaders,
232
        enumDefCollection: this.enumDefCollection,
233
        classificationDefCollection: this.classificationDefCollection,
234 235
        metricCollection: this.metricCollection,
        businessMetadataDefCollection: this.businessMetadataDefCollection
236 237 238 239 240 241 242
    });

    var startApp = function() {
        if (that.asyncFetchCounter === 0) {
            App.start();
        }
    };
243
    CommonViewFunction.userDataFetch({
244
        url: UrlLinks.sessionApiUrl(),
245
        callback: function(response) {
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
            if (response) {
                if (response.userName) {
                    Globals.userLogedIn.status = true;
                    Globals.userLogedIn.response = response;
                }
                if (response['atlas.entity.create.allowed'] !== undefined) {
                    Globals.entityCreate = response['atlas.entity.create.allowed'];
                }
                if (response['atlas.entity.update.allowed'] !== undefined) {
                    Globals.entityUpdate = response['atlas.entity.update.allowed'];
                }
                if (response['atlas.ui.editable.entity.types'] !== undefined) {
                    var entityTypeList = response['atlas.ui.editable.entity.types'].trim().split(",");
                    if (entityTypeList.length) {
                        if (entityTypeList[0] === "*") {
                            Globals.entityTypeConfList = [];
                        } else if (entityTypeList.length > 0) {
                            Globals.entityTypeConfList = entityTypeList;
                        }
265 266
                    }
                }
267 268 269
                if (response['atlas.ui.default.version'] !== undefined) {
                    Globals.DEFAULT_UI = response['atlas.ui.default.version'];
                }
270
            }
271 272 273 274
            --that.asyncFetchCounter;
            startApp();
        }
    });
275 276
    this.entityDefCollection.fetch({
        complete: function() {
277 278 279 280
            that.entityDefCollection.fullCollection.comparator = function(model) {
                return model.get('name').toLowerCase();
            };
            that.entityDefCollection.fullCollection.sort({ silent: true });
281 282 283 284 285
            --that.asyncFetchCounter;
            startApp();
        }
    });
    this.typeHeaders.fetch({
286
        complete: function() {
287 288 289 290
            that.typeHeaders.fullCollection.comparator = function(model) {
                return model.get('name').toLowerCase();
            }
            that.typeHeaders.fullCollection.sort({ silent: true });
291 292
            --that.asyncFetchCounter;
            startApp();
293 294
        }
    });
295 296
    this.enumDefCollection.fetch({
        complete: function() {
297 298 299 300
            that.enumDefCollection.fullCollection.comparator = function(model) {
                return model.get('name').toLowerCase();
            };
            that.enumDefCollection.fullCollection.sort({ silent: true });
301 302 303 304
            --that.asyncFetchCounter;
            startApp();
        }
    });
305 306
    this.classificationDefCollection.fetch({
        complete: function() {
307 308 309 310
            that.classificationDefCollection.fullCollection.comparator = function(model) {
                return model.get('name').toLowerCase();
            };
            that.classificationDefCollection.fullCollection.sort({ silent: true });
311 312 313 314
            --that.asyncFetchCounter;
            startApp();
        }
    });
315

316
    this.metricCollection.fetch({
317 318 319 320 321
        complete: function() {
            --that.asyncFetchCounter;
            startApp();
        }
    });
322

323 324 325 326 327 328 329 330 331 332 333
    this.businessMetadataDefCollection.fetch({
        complete: function() {
            that.businessMetadataDefCollection.fullCollection.comparator = function(model) {
                return model.get('name').toLowerCase();
            };
            that.businessMetadataDefCollection.fullCollection.sort({ silent: true });
            --that.asyncFetchCounter;
            startApp();
        }
    });

334 335 336 337 338 339 340
    CommonViewFunction.fetchRootEntityAttributes({
        url: UrlLinks.rootEntityDefUrl(Enums.addOnEntities[0]),
        entity: Enums.addOnEntities,
        callback: function() {
            --that.asyncFetchCounter;
            startApp();
        }
341 342 343
    });

    CommonViewFunction.fetchRootClassificationAttributes({
344
        url: UrlLinks.rootClassificationDefUrl(Enums.addOnClassification[0]),
345
        classification: Enums.addOnClassification,
346 347 348 349 350
        callback: function() {
            --that.asyncFetchCounter;
            startApp();
        }
    });
351
});