mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Renamed src directory to public
This commit is contained in:
124
public/app/routes/all.js
Normal file
124
public/app/routes/all.js
Normal file
@@ -0,0 +1,124 @@
|
||||
define([
|
||||
'angular',
|
||||
'./dashLoadControllers',
|
||||
], function(angular) {
|
||||
"use strict";
|
||||
|
||||
var module = angular.module('grafana.routes');
|
||||
|
||||
module.config(function($routeProvider, $locationProvider) {
|
||||
$locationProvider.html5Mode(true);
|
||||
|
||||
$routeProvider
|
||||
.when('/', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromDBCtrl',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.when('/dashboard/db/:slug', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromDBCtrl',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.when('/dashboard/file/:jsonFile', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromFileCtrl',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.when('/dashboard/script/:jsFile', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromScriptCtrl',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.when('/dashboard/import/:file', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromImportCtrl',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.when('/dashboard/snapshot/:key', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromSnapshotCtrl',
|
||||
})
|
||||
.when('/dashboard/solo/db/:slug', {
|
||||
templateUrl: 'app/features/panel/partials/soloPanel.html',
|
||||
controller : 'SoloPanelCtrl',
|
||||
})
|
||||
.when('/dashboard/solo/snapshot/:key', {
|
||||
templateUrl: 'app/features/panel/partials/soloPanel.html',
|
||||
controller : 'SoloPanelCtrl',
|
||||
})
|
||||
.when('/dashboard/new', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'NewDashboardCtrl',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.when('/dashboard/import', {
|
||||
templateUrl: 'app/features/dashboard/partials/import.html',
|
||||
controller : 'DashboardImportCtrl',
|
||||
})
|
||||
.when('/datasources', {
|
||||
templateUrl: 'app/features/org/partials/datasources.html',
|
||||
controller : 'DataSourcesCtrl',
|
||||
})
|
||||
.when('/datasources/edit/:id', {
|
||||
templateUrl: 'app/features/org/partials/datasourceEdit.html',
|
||||
controller : 'DataSourceEditCtrl',
|
||||
})
|
||||
.when('/datasources/new', {
|
||||
templateUrl: 'app/features/org/partials/datasourceEdit.html',
|
||||
controller : 'DataSourceEditCtrl',
|
||||
})
|
||||
.when('/org', {
|
||||
templateUrl: 'app/features/org/partials/orgDetails.html',
|
||||
controller : 'OrgDetailsCtrl',
|
||||
})
|
||||
.when('/org/new', {
|
||||
templateUrl: 'app/features/org/partials/newOrg.html',
|
||||
controller : 'NewOrgCtrl',
|
||||
})
|
||||
.when('/org/users', {
|
||||
templateUrl: 'app/features/org/partials/orgUsers.html',
|
||||
controller : 'OrgUsersCtrl',
|
||||
})
|
||||
.when('/org/apikeys', {
|
||||
templateUrl: 'app/features/org/partials/orgApiKeys.html',
|
||||
controller : 'OrgApiKeysCtrl',
|
||||
})
|
||||
.when('/profile', {
|
||||
templateUrl: 'app/features/profile/partials/profile.html',
|
||||
controller : 'ProfileCtrl',
|
||||
})
|
||||
.when('/profile/password', {
|
||||
templateUrl: 'app/features/profile/partials/password.html',
|
||||
controller : 'ChangePasswordCtrl',
|
||||
})
|
||||
.when('/admin/settings', {
|
||||
templateUrl: 'app/features/admin/partials/settings.html',
|
||||
controller : 'AdminSettingsCtrl',
|
||||
})
|
||||
.when('/admin/users', {
|
||||
templateUrl: 'app/features/admin/partials/users.html',
|
||||
controller : 'AdminUsersCtrl',
|
||||
})
|
||||
.when('/admin/users/create', {
|
||||
templateUrl: 'app/features/admin/partials/new_user.html',
|
||||
controller : 'AdminEditUserCtrl',
|
||||
})
|
||||
.when('/admin/users/edit/:id', {
|
||||
templateUrl: 'app/features/admin/partials/edit_user.html',
|
||||
controller : 'AdminEditUserCtrl',
|
||||
})
|
||||
.when('/admin/orgs', {
|
||||
templateUrl: 'app/features/admin/partials/orgs.html',
|
||||
})
|
||||
.when('/login', {
|
||||
templateUrl: 'app/partials/login.html',
|
||||
controller : 'LoginCtrl',
|
||||
})
|
||||
.otherwise({
|
||||
templateUrl: 'app/partials/error.html',
|
||||
controller: 'ErrorCtrl'
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
134
public/app/routes/dashLoadControllers.js
Normal file
134
public/app/routes/dashLoadControllers.js
Normal file
@@ -0,0 +1,134 @@
|
||||
define([
|
||||
'angular',
|
||||
'lodash',
|
||||
'kbn',
|
||||
'moment',
|
||||
'jquery',
|
||||
],
|
||||
function (angular, _, kbn, moment, $) {
|
||||
"use strict";
|
||||
|
||||
var module = angular.module('grafana.routes');
|
||||
|
||||
module.controller('DashFromDBCtrl', function($scope, $routeParams, backendSrv) {
|
||||
|
||||
if (!$routeParams.slug) {
|
||||
backendSrv.get('/api/dashboards/home').then(function(result) {
|
||||
$scope.initDashboard(result, $scope);
|
||||
},function() {
|
||||
$scope.initDashboard({}, $scope);
|
||||
$scope.appEvent('alert-error', ['Load dashboard failed', '']);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return backendSrv.getDashboard($routeParams.slug).then(function(result) {
|
||||
$scope.initDashboard(result, $scope);
|
||||
}, function() {
|
||||
$scope.initDashboard({
|
||||
meta: {},
|
||||
model: { title: 'Not found' }
|
||||
}, $scope);
|
||||
});
|
||||
});
|
||||
|
||||
module.controller('DashFromSnapshotCtrl', function($scope, $routeParams, backendSrv) {
|
||||
backendSrv.get('/api/snapshots/' + $routeParams.key).then(function(result) {
|
||||
$scope.initDashboard(result, $scope);
|
||||
},function() {
|
||||
$scope.initDashboard({meta: {isSnapshot: true}, model: {title: 'Snapshot not found'}}, $scope);
|
||||
});
|
||||
});
|
||||
|
||||
module.controller('DashFromImportCtrl', function($scope, $location, alertSrv) {
|
||||
if (!window.grafanaImportDashboard) {
|
||||
alertSrv.set('Not found', 'Cannot reload page with unsaved imported dashboard', 'warning', 7000);
|
||||
$location.path('');
|
||||
return;
|
||||
}
|
||||
$scope.initDashboard({ meta: {}, model: window.grafanaImportDashboard }, $scope);
|
||||
});
|
||||
|
||||
module.controller('NewDashboardCtrl', function($scope) {
|
||||
$scope.initDashboard({
|
||||
meta: {},
|
||||
model: {
|
||||
title: "New dashboard",
|
||||
rows: [{ height: '250px', panels:[] }]
|
||||
},
|
||||
}, $scope);
|
||||
});
|
||||
|
||||
module.controller('DashFromFileCtrl', function($scope, $rootScope, $http, $routeParams) {
|
||||
|
||||
var file_load = function(file) {
|
||||
return $http({
|
||||
url: "public/dashboards/"+file.replace(/\.(?!json)/,"/")+'?' + new Date().getTime(),
|
||||
method: "GET",
|
||||
transformResponse: function(response) {
|
||||
return angular.fromJson(response);
|
||||
}
|
||||
}).then(function(result) {
|
||||
if(!result) {
|
||||
return false;
|
||||
}
|
||||
return result.data;
|
||||
},function() {
|
||||
$scope.appEvent('alert-error', ["Dashboard load failed", "Could not load <i>dashboards/"+file+"</i>. Please make sure it exists"]);
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
file_load($routeParams.jsonFile).then(function(result) {
|
||||
$scope.initDashboard({meta: {}, model: result}, $scope);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
module.controller('DashFromScriptCtrl', function($scope, $rootScope, $http, $routeParams, $q, dashboardSrv, datasourceSrv, $timeout) {
|
||||
|
||||
var execute_script = function(result) {
|
||||
var services = {
|
||||
dashboardSrv: dashboardSrv,
|
||||
datasourceSrv: datasourceSrv,
|
||||
$q: $q,
|
||||
};
|
||||
|
||||
/*jshint -W054 */
|
||||
var script_func = new Function('ARGS','kbn','_','moment','window','document','$','jQuery', 'services', result.data);
|
||||
var script_result = script_func($routeParams, kbn, _ , moment, window, document, $, $, services);
|
||||
|
||||
// Handle async dashboard scripts
|
||||
if (_.isFunction(script_result)) {
|
||||
var deferred = $q.defer();
|
||||
script_result(function(dashboard) {
|
||||
$timeout(function() {
|
||||
deferred.resolve({ data: dashboard });
|
||||
});
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
return { data: script_result };
|
||||
};
|
||||
|
||||
var script_load = function(file) {
|
||||
var url = 'public/dashboards/'+file.replace(/\.(?!js)/,"/") + '?' + new Date().getTime();
|
||||
|
||||
return $http({ url: url, method: "GET" })
|
||||
.then(execute_script)
|
||||
.then(null,function(err) {
|
||||
console.log('Script dashboard error '+ err);
|
||||
$scope.appEvent('alert-error', ["Script Error", "Please make sure it exists and returns a valid dashboard"]);
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
script_load($routeParams.jsFile).then(function(result) {
|
||||
$scope.initDashboard({meta: {}, model: result.data}, $scope);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user