Router.js 10.3 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
            '': 'commonAction',
            '!/': 'tagAttributePageLoad',
            '!/tag/tagAttribute/(*name)': 'tagAttributePageLoad',
            '!/taxonomy/detailCatalog/(*url)': 'detailCatalog',
            '!/search/searchResult': 'searchResult',
            '!/detailPage/:id': 'detailPage',
            '!/tag': 'commonAction',
            '!/taxonomy': 'commonAction',
            '!/search': 'commonAction',
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
            // 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',
60 61 62 63
                'modules/Modal',
                'views/common/aboutAtlas',
            ], function(aboutAtlasTmpl, Modal, aboutAtlasView) {
                var view = new aboutAtlasView();
64
                var modal = new Modal({
65
                    title: 'Apache Atlas',
66 67 68
                    content: view,
                    okCloses: true,
                    showFooter: true,
69
                    allowCancel: false,
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
                }).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);
        },
99
        detailCatalog: function(url) {
100 101
            var that = this;
            require([
102 103 104 105 106
                'views/business_catalog/BusinessCatalogHeader',
                'views/business_catalog/BusinessCatalogDetailLayoutView',
                'views/business_catalog/SideNavLayoutView',
                'collection/VCatalogList'
            ], function(BusinessCatalogHeader, BusinessCatalogDetailLayoutView, SideNavLayoutView, VCatalogList) {
107
                var paramObj = Utils.getUrlState.getQueryParams();
108 109 110 111 112 113
                this.collection = new VCatalogList();
                this.collection.url = url;
                App.rNHeader.show(new BusinessCatalogHeader({ 'globalVent': that.globalVent, 'url': url, 'collection': this.collection }));
                if (!App.rSideNav.currentView) {
                    App.rSideNav.show(new SideNavLayoutView({ 'globalVent': that.globalVent, 'url': url }));
                } else {
114
                    App.rSideNav.currentView.RBusinessCatalogLayoutView.currentView.manualRender("/" + url);
115 116 117
                    App.rSideNav.currentView.selectTab();
                }
                App.rNContent.show(new BusinessCatalogDetailLayoutView({
118
                    'globalVent': that.globalVent,
119 120
                    'url': url,
                    'collection': this.collection
121
                }));
122
                this.collection.fetch({ reset: true });
123 124
            });
        },
125
        detailPage: function(id) {
126 127 128 129
            var that = this;
            if (id) {
                require([
                    'views/site/Header',
130 131 132 133
                    'views/detail_page/DetailPageLayoutView',
                    'views/business_catalog/SideNavLayoutView',
                    'collection/VEntityList'
                ], function(Header, DetailPageLayoutView, SideNavLayoutView, VEntityList) {
134
                    this.entityCollection = new VEntityList([], {});
135 136 137 138 139 140 141 142
                    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({
143
                        'globalVent': that.globalVent,
144
                        'collection': this.entityCollection,
145 146
                        'id': id,
                    }));
147 148
                    this.entityCollection.url = "/api/atlas/entities/" + id;
                    this.entityCollection.fetch({ reset: true });
149 150 151
                });
            }
        },
152
        tagAttributePageLoad: function(tagName) {
153 154 155
            var that = this;
            require([
                'views/site/Header',
156 157 158 159 160 161 162 163 164 165 166
                '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 {
167

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
                    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()) {
197
                        App.rSideNav.currentView.RBusinessCatalogLayoutView.currentView.manualRender(undefined, true);
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
                    }
                }
                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({
224
                    'globalVent': that.globalVent,
225
                    'value': paramObj
226 227 228 229 230
                }));
            });
        },
        defaultAction: function(actions) {
            // We have no matching route, lets just log what the URL was
231 232 233 234 235 236 237 238
            Utils.setUrl({
                url: '#!/taxonomy',
                mergeBrowserUrl: false,
                updateTabState: function() {
                    return { taxonomyUrl: this.url, stateChanged: false };
                },
                trigger: true
            });
239 240 241 242 243
            console.log('No route:', actions);
        }
    });
    return AppRouter;
});