mirror of
https://github.com/grafana/grafana.git
synced 2025-01-02 12:17:01 -06:00
Fixed so that scripted dashboards and json file based dashboards works as in 1.x, Closes #1548
This commit is contained in:
parent
6850a4d25d
commit
56c83cefe9
12
build.go
12
build.go
@ -73,7 +73,8 @@ func main() {
|
||||
test("./pkg/...")
|
||||
|
||||
case "package":
|
||||
checkCleanTree()
|
||||
clean()
|
||||
//verifyGitRepoIsClean()
|
||||
test("./pkg/...")
|
||||
build(".", []string{})
|
||||
buildFrontend()
|
||||
@ -83,6 +84,7 @@ func main() {
|
||||
buildFrontend()
|
||||
|
||||
case "clean":
|
||||
clean()
|
||||
|
||||
default:
|
||||
log.Fatalf("Unknown command %q", cmd)
|
||||
@ -173,7 +175,7 @@ chown -R -L grafana:grafana $GRAFANA_LOG_DIR
|
||||
ioutil.WriteFile(path, []byte(content), 0644)
|
||||
}
|
||||
|
||||
func checkCleanTree() {
|
||||
func verifyGitRepoIsClean() {
|
||||
rs, err := runError("git", "ls-files", "--modified")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to check if git tree was clean, %v, %v\n", string(rs), err)
|
||||
@ -184,7 +186,7 @@ func checkCleanTree() {
|
||||
log.Fatalf("Git repository has modified files, aborting")
|
||||
}
|
||||
|
||||
log.Fatalf("Git repository is clean")
|
||||
log.Println("Git repository is clean")
|
||||
}
|
||||
|
||||
func ensureGoPath() {
|
||||
@ -264,7 +266,9 @@ func rmr(paths ...string) {
|
||||
|
||||
func clean() {
|
||||
rmr("bin", "Godeps/_workspace/pkg", "Godeps/_workspace/bin")
|
||||
rmr(filepath.Join(os.Getenv("GOPATH"), fmt.Sprintf("pkg/%s_%s/github.com/grafana-pro", goos, goarch)))
|
||||
rmr("dist")
|
||||
rmr("tmp")
|
||||
rmr(filepath.Join(os.Getenv("GOPATH"), fmt.Sprintf("pkg/%s_%s/github.com/grafan", goos, goarch)))
|
||||
}
|
||||
|
||||
func setBuildEnv() {
|
||||
|
@ -93,8 +93,7 @@ function (angular, $, _, appLevelRequire) {
|
||||
'directives/all',
|
||||
'filters/all',
|
||||
'components/partials',
|
||||
'routes/standalone/all',
|
||||
'routes/backend/all',
|
||||
'routes/all',
|
||||
];
|
||||
|
||||
app.boot = function() {
|
||||
|
@ -1,106 +0,0 @@
|
||||
define([
|
||||
'angular',
|
||||
'./dashboard',
|
||||
], 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 : 'DashFromDBProvider',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.when('/dashboard/db/:slug', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromDBProvider',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.when('/dashboard/import/:file', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromImportCtrl',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.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',
|
||||
})
|
||||
.when('/dashboard/solo/:slug/', {
|
||||
templateUrl: 'app/features/panel/partials/soloPanel.html',
|
||||
controller : 'SoloPanelCtrl',
|
||||
})
|
||||
.otherwise({
|
||||
templateUrl: 'app/partials/error.html',
|
||||
controller: 'ErrorCtrl'
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@ -1,52 +0,0 @@
|
||||
define([
|
||||
'angular',
|
||||
'store',
|
||||
],
|
||||
function (angular) {
|
||||
"use strict";
|
||||
|
||||
var module = angular.module('grafana.routes');
|
||||
|
||||
module.controller('DashFromDBProvider', 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('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);
|
||||
});
|
||||
|
||||
});
|
@ -1,24 +0,0 @@
|
||||
define([
|
||||
'angular',
|
||||
'config',
|
||||
'store',
|
||||
'./fromDB',
|
||||
'./fromFile',
|
||||
'./fromScript',
|
||||
],
|
||||
function (angular, config, store) {
|
||||
'use strict';
|
||||
|
||||
var module = angular.module('grafana.routes.standalone');
|
||||
|
||||
module.config(function($routeProvider) {
|
||||
$routeProvider
|
||||
.otherwise({ redirectTo: config.default_route })
|
||||
.when('/', {
|
||||
redirectTo: function() {
|
||||
return store.get('grafanaDashboardDefault') || config.default_route;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@ -1,59 +0,0 @@
|
||||
define([
|
||||
'angular',
|
||||
],
|
||||
function (angular) {
|
||||
"use strict";
|
||||
|
||||
var module = angular.module('grafana.routes.standalone');
|
||||
|
||||
module.config(function($routeProvider) {
|
||||
$routeProvider
|
||||
.when('/dashboard/db/:id', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromDBProvider',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.when('/dashboard/elasticsearch/:id', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromDBProvider',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.when('/dashboard/temp/:id', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromDBProvider',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.when('/dashboard/import/:id', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromImportCtrl',
|
||||
reloadOnSearch: false,
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
module.controller('DashFromDBProvider', function($scope, $rootScope, datasourceSrv, $routeParams) {
|
||||
|
||||
var db = datasourceSrv.getGrafanaDB();
|
||||
var isTemp = window.location.href.indexOf('dashboard/temp') !== -1;
|
||||
|
||||
db.getDashboard($routeParams.id, isTemp)
|
||||
.then(function(dashboard) {
|
||||
$scope.initDashboard(dashboard, $scope);
|
||||
}).then(null, function(error) {
|
||||
$scope.initDashboard({ title: 'Grafana'}, $scope);
|
||||
$scope.appEvent('alert-error', ['Dashboard load failed', error]);
|
||||
});
|
||||
});
|
||||
|
||||
module.controller('DashFromImportCtrl', function($scope, $location) {
|
||||
|
||||
if (!window.grafanaImportDashboard) {
|
||||
$scope.appEvent('alert-warning', ['Dashboard load failed', 'Cannot reload unsaved imported dashboard']);
|
||||
$location.path('');
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.initDashboard(window.grafanaImportDashboard, $scope);
|
||||
});
|
||||
|
||||
});
|
@ -1,71 +0,0 @@
|
||||
define([
|
||||
'angular',
|
||||
'jquery',
|
||||
'config',
|
||||
'lodash'
|
||||
],
|
||||
function (angular, $, config, _) {
|
||||
"use strict";
|
||||
|
||||
var module = angular.module('grafana.routes.standalone');
|
||||
|
||||
module.config(function($routeProvider) {
|
||||
$routeProvider
|
||||
.when('/dashboard/file/:jsonFile', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromFileProvider',
|
||||
reloadOnSearch: false,
|
||||
})
|
||||
.when('/dashboard/new', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromFileProvider',
|
||||
reloadOnSearch: false,
|
||||
newDashboard: true,
|
||||
});
|
||||
});
|
||||
|
||||
module.controller('DashFromFileProvider', function($scope, $rootScope, $http, $routeParams, $route) {
|
||||
|
||||
var renderTemplate = function(json,params) {
|
||||
var _r;
|
||||
_.templateSettings = {interpolate : /\{\{(.+?)\}\}/g};
|
||||
var template = _.template(json);
|
||||
var rendered = template({ARGS:params});
|
||||
try {
|
||||
_r = angular.fromJson(rendered);
|
||||
} catch(e) {
|
||||
_r = false;
|
||||
}
|
||||
return _r;
|
||||
};
|
||||
|
||||
var file_load = function(file) {
|
||||
return $http({
|
||||
url: "/dashboards/"+file.replace(/\.(?!json)/,"/")+'?' + new Date().getTime(),
|
||||
method: "GET",
|
||||
transformResponse: function(response) {
|
||||
return renderTemplate(response,$routeParams);
|
||||
}
|
||||
}).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;
|
||||
});
|
||||
};
|
||||
|
||||
var fileToLoad = $routeParams.jsonFile;
|
||||
if ($route.current.newDashboard) {
|
||||
fileToLoad = 'empty.json';
|
||||
}
|
||||
|
||||
file_load(fileToLoad).then(function(result) {
|
||||
$scope.initDashboard({meta: {}, model: result}, $scope);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
@ -1,68 +0,0 @@
|
||||
define([
|
||||
'angular',
|
||||
'jquery',
|
||||
'config',
|
||||
'lodash',
|
||||
'kbn',
|
||||
'moment'
|
||||
],
|
||||
function (angular, $, config, _, kbn, moment) {
|
||||
"use strict";
|
||||
|
||||
var module = angular.module('grafana.routes.standalone');
|
||||
|
||||
module.config(function($routeProvider) {
|
||||
$routeProvider
|
||||
.when('/dashboard/script/:jsFile', {
|
||||
templateUrl: 'app/partials/dashboard.html',
|
||||
controller : 'DashFromScriptProvider',
|
||||
reloadOnSearch: false,
|
||||
});
|
||||
});
|
||||
|
||||
module.controller('DashFromScriptProvider', 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 = 'app/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(result.data, $scope);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user