Router.js 11 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
/**
 * 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([
    'jquery',
    'underscore',
    'backbone',
    'App',
    'utils/Globals',
    'utils/Utils'
], function($, _, Backbone, App, Globals, Utils) {
    var AppRouter = Backbone.Router.extend({
        routes: {
            // Define some URL routes
30 31 32 33 34 35 36 37 38 39 40 41
            '': 'commonAction',
            '!/': 'tagAttributePageLoad',
            '!/tag/tagAttribute/(*name)': 'tagAttributePageLoad',
            '!/taxonomy/detailCatalog/(*url)': 'detailCatalog',
            '!/search/searchResult': 'searchResult',
            '!/detailPage/:id': 'detailPage',
            '!/detailPage/:id': 'detailPage',
            '!/detailPage/:id': 'detailPage',

            '!/tag': 'commonAction',
            '!/taxonomy': 'commonAction',
            '!/search': 'commonAction',
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
            // Default
            '*actions': 'defaultAction'
        },
        initialize: function() {
            this.showRegions();
            this.bindCommonEvents();
            this.listenTo(this, 'route', this.postRouteExecute, this);
            this.globalVent = new Backbone.Wreqr.EventAggregator();
            this.catalogVent = new Backbone.Wreqr.EventAggregator();
            this.tagVent = new Backbone.Wreqr.EventAggregator();
        },
        bindCommonEvents: function() {
            var that = this;
            $('body').on('click', 'li.aboutAtlas', function() {
                that.aboutAtlas();
            });
        },
        aboutAtlas: function() {
            var that = this;
            require([
                'hbs!tmpl/common/aboutAtlas_tmpl',
                'modules/Modal'
            ], function(aboutAtlasTmpl, Modal) {

                var aboutAtlas = Marionette.LayoutView.extend({
                    template: aboutAtlasTmpl,
                    events: {},
                });
                var view = new aboutAtlas();
                var modal = new Modal({
72
                    title: 'Apache Atlas',
73 74 75
                    content: view,
                    okCloses: true,
                    showFooter: true,
76
                    allowCancel: false,
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
                }).open();

                view.on('closeModal', function() {
                    modal.trigger('cancel');
                });

            });
        },
        showRegions: function() {},

        /**
         * @override
         * Execute a route handler with the provided parameters. This is an
         * excellent place to do pre-route setup or post-route cleanup.
         * @param  {Function} callback - route handler
         * @param  {Array}   args - route params
         */
        execute: function(callback, args) {
            this.preRouteExecute();
            if (callback) callback.apply(this, args);
            this.postRouteExecute();
        },
        preRouteExecute: function() {
            // console.log("Pre-Route Change Operations can be performed here !!");
        },
        postRouteExecute: function(name, args) {
            // console.log("Post-Route Change Operations can be performed here !!");
            // console.log("Route changed: ", name);
        },
106
        detailCatalog: function(url) {
107 108
            var that = this;
            require([
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
                'views/business_catalog/BusinessCatalogHeader',
                'views/business_catalog/BusinessCatalogDetailLayoutView',
                'views/business_catalog/SideNavLayoutView',
                'collection/VCatalogList'
            ], function(BusinessCatalogHeader, BusinessCatalogDetailLayoutView, SideNavLayoutView, VCatalogList) {
                this.collection = new VCatalogList();
                this.collection.url = url;
                App.rNHeader.show(new BusinessCatalogHeader({ 'globalVent': that.globalVent, 'url': url, 'collection': this.collection }));
                // App.rSideNav.show(new SideNavLayoutView({ 'globalVent': that.globalVent, 'url': url }));
                if (!App.rSideNav.currentView) {
                    App.rSideNav.show(new SideNavLayoutView({ 'globalVent': that.globalVent, 'url': url }));
                } else {
                    var view = App.rSideNav.currentView.RBusinessCatalogLayoutView.currentView;
                    if (view.dblClick == false && view.singleClick == false && !Globals.saveApplicationState.tabState.stateChanged) {
                        App.rSideNav.currentView.RBusinessCatalogLayoutView.currentView.manualRender(url,true);
                        view.dblClick == false;

                    }/* else if (view.firstManualClick) {
                        view.firstManualClick = false;
                        App.rSideNav.currentView.RBusinessCatalogLayoutView.currentView.manualRender(url);
                    }*/ else if (view.singleClick) {
                        view.singleClick = false;
131
                    }
132 133 134 135 136 137
                    App.rSideNav.currentView.selectTab();
                }
                if (Globals.saveApplicationState.tabState.stateChanged) {
                    Globals.saveApplicationState.tabState.stateChanged = false;
                }
                App.rNContent.show(new BusinessCatalogDetailLayoutView({
138
                    'globalVent': that.globalVent,
139 140
                    'url': url,
                    'collection': this.collection
141
                }));
142
                this.collection.fetch({ reset: true });
143 144
            });
        },
145
        detailPage: function(id) {
146 147 148 149
            var that = this;
            if (id) {
                require([
                    'views/site/Header',
150 151 152 153
                    'views/detail_page/DetailPageLayoutView',
                    'views/business_catalog/SideNavLayoutView',
                    'collection/VEntityList'
                ], function(Header, DetailPageLayoutView, SideNavLayoutView, VEntityList) {
154
                    this.entityCollection = new VEntityList([], {});
155 156 157 158 159 160 161 162
                    App.rNHeader.show(new Header({ 'globalVent': that.globalVent }));
                    if (!App.rSideNav.currentView) {
                        App.rSideNav.show(new SideNavLayoutView({ 'globalVent': that.globalVent }));
                    } else {
                        App.rSideNav.currentView.selectTab();
                    }

                    App.rNContent.show(new DetailPageLayoutView({
163
                        'globalVent': that.globalVent,
164
                        'collection': this.entityCollection,
165 166
                        'id': id,
                    }));
167 168
                    this.entityCollection.url = "/api/atlas/entities/" + id;
                    this.entityCollection.fetch({ reset: true });
169 170 171
                });
            }
        },
172
        tagAttributePageLoad: function(tagName) {
173 174 175
            var that = this;
            require([
                'views/site/Header',
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
                'views/business_catalog/BusinessCatalogLayoutView',
                'views/business_catalog/SideNavLayoutView',
                'views/tag/TagDetailLayoutView',
            ], function(Header, BusinessCatalogLayoutView, SideNavLayoutView, TagDetailLayoutView) {
                App.rNHeader.show(new Header({ 'globalVent': that.globalVent, 'vent': that.catalogVent }));
                if (!App.rSideNav.currentView) {
                    App.rSideNav.show(new SideNavLayoutView({
                        'globalVent': that.globalVent,
                        'tag': tagName
                    }));
                } else {
                    App.rSideNav.currentView.RTagLayoutView.currentView.manualRender(tagName);
                    App.rSideNav.currentView.selectTab();
                }

                if (tagName) {
                    App.rNContent.show(new TagDetailLayoutView({
                        'globalVent': that.globalVent,
                        'tag': tagName
                    }));
                }
            });
        },
        commonAction: function() {
            var that = this;
            require([
                'views/site/Header',
                'views/business_catalog/BusinessCatalogLayoutView',
                'views/business_catalog/SideNavLayoutView',
            ], function(Header, BusinessCatalogLayoutView, SideNavLayoutView) {
                App.rNHeader.show(new Header({ 'globalVent': that.globalVent }));
                if (!App.rSideNav.currentView) {
                    App.rSideNav.show(new SideNavLayoutView({
                        'globalVent': that.globalVent
                    }));
                } else {
                    App.rSideNav.currentView.selectTab();
                    if (Utils.getUrlState.isTagTab()) {
                        App.rSideNav.currentView.RTagLayoutView.currentView.manualRender();
                    } else if (Utils.getUrlState.isTaxonomyTab()) {
                        App.rSideNav.currentView.RBusinessCatalogLayoutView.currentView.manualRender(undefined,true);
                    }
                }
                App.rNContent.$el.html('');
                App.rNContent.destroy();
            });
        },
        searchResult: function() {
            var that = this;
            require([
                'views/site/Header',
                'views/business_catalog/BusinessCatalogLayoutView',
                'views/business_catalog/SideNavLayoutView',
                'views/search/SearchDetailLayoutView'
            ], function(Header, BusinessCatalogLayoutView, SideNavLayoutView, SearchDetailLayoutView) {
                var paramObj = Utils.getUrlState.getQueryParams();
                App.rNHeader.show(new Header({ 'globalVent': that.globalVent, 'vent': that.catalogVent }));
                if (!App.rSideNav.currentView) {
                    App.rSideNav.show(new SideNavLayoutView({
                        'globalVent': that.globalVent,
                        'value': paramObj
                    }));
                } else {
                    App.rSideNav.currentView.RSearchLayoutView.currentView.manualRender(paramObj);
                }
                App.rSideNav.currentView.selectTab();
                App.rNContent.show(new SearchDetailLayoutView({
243
                    'globalVent': that.globalVent,
244
                    'value': paramObj
245 246 247 248 249 250 251 252 253 254
                }));
            });
        },
        defaultAction: function(actions) {
            // We have no matching route, lets just log what the URL was
            console.log('No route:', actions);
        }
    });
    return AppRouter;
});