mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
refactor: moving routes into core, improved bundle loader
This commit is contained in:
parent
8f45324bce
commit
2b95cd5081
@ -74,7 +74,6 @@ function (angular, $, _, appLevelRequire) {
|
||||
'features/all',
|
||||
'controllers/all',
|
||||
'components/partials',
|
||||
'routes/all',
|
||||
];
|
||||
|
||||
app.boot = function() {
|
||||
|
@ -14,11 +14,12 @@
|
||||
///<amd-dependency path="./directives/tags" />
|
||||
///<amd-dependency path="./directives/topnav" />
|
||||
///<amd-dependency path="./directives/value_select_dropdown" />
|
||||
///<amd-dependency path="./routes/all" />
|
||||
|
||||
export * from './directives/array_join'
|
||||
export * from './directives/give_focus'
|
||||
|
||||
export * from './routes/module_loader'
|
||||
export * from './routes/bundle_loader'
|
||||
export * from './filters/filters'
|
||||
|
||||
|
||||
|
@ -2,4 +2,4 @@
|
||||
|
||||
import angular = require('angular');
|
||||
|
||||
export = angular.module('grafana.core', []);
|
||||
export = angular.module('grafana.core', ['ngRoute']);
|
||||
|
@ -1,15 +1,16 @@
|
||||
define([
|
||||
'angular',
|
||||
'../core/core',
|
||||
'./dashLoadControllers',
|
||||
], function(angular, core) {
|
||||
'../core_module',
|
||||
'./bundle_loader',
|
||||
'./dashboard_loaders',
|
||||
], function(angular, coreModule, BundleLoader) {
|
||||
"use strict";
|
||||
|
||||
var module = angular.module('grafana.routes');
|
||||
|
||||
module.config(function($routeProvider, $locationProvider) {
|
||||
coreModule.config(function($routeProvider, $locationProvider) {
|
||||
$locationProvider.html5Mode(true);
|
||||
|
||||
var loadOrgBundle = new BundleLoader.BundleLoader('features/org/all');
|
||||
|
||||
$routeProvider
|
||||
.when('/', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
@ -42,37 +43,37 @@ define([
|
||||
.when('/datasources', {
|
||||
templateUrl: 'app/features/org/partials/datasources.html',
|
||||
controller : 'DataSourcesCtrl',
|
||||
resolve: new core.ModuleLoader("features/org/all"),
|
||||
resolve: loadOrgBundle,
|
||||
})
|
||||
.when('/datasources/edit/:id', {
|
||||
templateUrl: 'app/features/org/partials/datasourceEdit.html',
|
||||
controller : 'DataSourceEditCtrl',
|
||||
resolve: new core.ModuleLoader("features/org/all"),
|
||||
resolve: loadOrgBundle,
|
||||
})
|
||||
.when('/datasources/new', {
|
||||
templateUrl: 'app/features/org/partials/datasourceEdit.html',
|
||||
controller : 'DataSourceEditCtrl',
|
||||
resolve: new core.ModuleLoader("features/org/all"),
|
||||
resolve: loadOrgBundle,
|
||||
})
|
||||
.when('/org', {
|
||||
templateUrl: 'app/features/org/partials/orgDetails.html',
|
||||
controller : 'OrgDetailsCtrl',
|
||||
resolve: new core.ModuleLoader("features/org/all"),
|
||||
resolve: loadOrgBundle,
|
||||
})
|
||||
.when('/org/new', {
|
||||
templateUrl: 'app/features/org/partials/newOrg.html',
|
||||
controller : 'NewOrgCtrl',
|
||||
resolve: new core.ModuleLoader("features/org/all"),
|
||||
resolve: loadOrgBundle,
|
||||
})
|
||||
.when('/org/users', {
|
||||
templateUrl: 'app/features/org/partials/orgUsers.html',
|
||||
controller : 'OrgUsersCtrl',
|
||||
resolve: new core.ModuleLoader("features/org/all"),
|
||||
resolve: loadOrgBundle,
|
||||
})
|
||||
.when('/org/apikeys', {
|
||||
templateUrl: 'app/features/org/partials/orgApiKeys.html',
|
||||
controller : 'OrgApiKeysCtrl',
|
||||
resolve: new core.ModuleLoader("features/org/all"),
|
||||
resolve: loadOrgBundle,
|
||||
})
|
||||
.when('/profile', {
|
||||
templateUrl: 'app/features/profile/partials/profile.html',
|
23
public/app/core/routes/bundle_loader.ts
Normal file
23
public/app/core/routes/bundle_loader.ts
Normal file
@ -0,0 +1,23 @@
|
||||
///<reference path="../../headers/require/require.d.ts" />
|
||||
|
||||
export class BundleLoader {
|
||||
lazy: any;
|
||||
loadingDefer: any;
|
||||
|
||||
constructor(bundleName) {
|
||||
this.lazy = ["$q", "$route", "$rootScope", ($q, $route, $rootScope) => {
|
||||
if (this.loadingDefer) {
|
||||
return this.loadingDefer.promise;
|
||||
}
|
||||
|
||||
this.loadingDefer = $q.defer();
|
||||
|
||||
require([bundleName], () => {
|
||||
this.loadingDefer.resolve();
|
||||
});
|
||||
|
||||
return this.loadingDefer.promise;
|
||||
}];
|
||||
|
||||
}
|
||||
}
|
@ -1,16 +1,10 @@
|
||||
define([
|
||||
'angular',
|
||||
'lodash',
|
||||
'kbn',
|
||||
'moment',
|
||||
'jquery',
|
||||
'../core_module',
|
||||
],
|
||||
function (angular) {
|
||||
function (coreModule) {
|
||||
"use strict";
|
||||
|
||||
var module = angular.module('grafana.routes');
|
||||
|
||||
module.controller('LoadDashboardCtrl', function($scope, $routeParams, dashboardLoaderSrv, backendSrv) {
|
||||
coreModule.controller('LoadDashboardCtrl', function($scope, $routeParams, dashboardLoaderSrv, backendSrv) {
|
||||
|
||||
if (!$routeParams.slug) {
|
||||
backendSrv.get('/api/dashboards/home').then(function(result) {
|
||||
@ -27,7 +21,7 @@ function (angular) {
|
||||
|
||||
});
|
||||
|
||||
module.controller('DashFromImportCtrl', function($scope, $location, alertSrv) {
|
||||
coreModule.controller('DashFromImportCtrl', function($scope, $location, alertSrv) {
|
||||
if (!window.grafanaImportDashboard) {
|
||||
alertSrv.set('Not found', 'Cannot reload page with unsaved imported dashboard', 'warning', 7000);
|
||||
$location.path('');
|
||||
@ -39,7 +33,7 @@ function (angular) {
|
||||
}, $scope);
|
||||
});
|
||||
|
||||
module.controller('NewDashboardCtrl', function($scope) {
|
||||
coreModule.controller('NewDashboardCtrl', function($scope) {
|
||||
$scope.initDashboard({
|
||||
meta: { canStar: false, canShare: false },
|
||||
dashboard: {
|
@ -1,19 +0,0 @@
|
||||
///<reference path="../../headers/require/require.d.ts" />
|
||||
|
||||
export class ModuleLoader {
|
||||
lazy: any;
|
||||
|
||||
constructor(moduleName) {
|
||||
|
||||
this.lazy = ["$q", "$route", "$rootScope", function($q, $route, $rootScope) {
|
||||
var defered = $q.defer();
|
||||
|
||||
require([moduleName], function () {
|
||||
defered.resolve();
|
||||
});
|
||||
|
||||
return defered.promise;
|
||||
}];
|
||||
|
||||
}
|
||||
}
|
@ -58,7 +58,6 @@ module.exports = function(config,grunt) {
|
||||
'services/all',
|
||||
'features/all',
|
||||
'controllers/all',
|
||||
'routes/all',
|
||||
'components/partials',
|
||||
// bundle the datasources
|
||||
'plugins/datasource/grafana/datasource',
|
||||
|
Loading…
Reference in New Issue
Block a user