Commit 9e892bdd by Torkel Ödegaard

More work on restoring features after moving to plugin model for datasources, #1276 #1472

parent 109dd324
package api
import (
"errors"
"fmt"
"strconv"
"github.com/grafana/grafana/pkg/bus"
......@@ -41,7 +43,7 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
meta, exists := plugins.DataSources[ds.Type]
if !exists {
//return nil, errors.New(fmt.Sprintf("Could not find plugin definition for data source: %v", ds.Type))
return nil, errors.New(fmt.Sprintf("Could not find plugin definition for data source: %v", ds.Type))
}
dsMap["meta"] = meta
......@@ -75,9 +77,14 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
}
// add grafana backend data source
grafanaDatasourceMeta, _ := plugins.DataSources["grafana"]
datasources["grafana"] = map[string]interface{}{
"type": "grafana",
"grafanaDB": true,
"type": "grafana",
"meta": grafanaDatasourceMeta,
}
if defaultDatasource == "" {
defaultDatasource = "grafana"
}
jsonObj := map[string]interface{}{
......
......@@ -2,16 +2,10 @@ define([
'./panellinkeditor/module',
'./annotations/annotationsSrv',
'./templating/templateSrv',
// './graphite/datasource',
// './influxdb/datasource',
// './influxdb_08/datasource',
// './opentsdb/datasource',
// './elasticsearch/datasource',
'./dashboard/all',
'./panel/all',
'./profile/profileCtrl',
'./profile/changePasswordCtrl',
'./org/all',
'./admin/all',
'./grafanaDatasource/datasource',
], function () {});
......@@ -6,16 +6,14 @@ define([
'store',
'filesaver'
],
function (angular, _, moment, config, store) {
function (angular, _, moment) {
'use strict';
var module = angular.module('grafana.controllers');
module.controller('DashboardNavCtrl', function($scope, $rootScope, alertSrv, $location, playlistSrv, datasourceSrv, timeSrv) {
module.controller('DashboardNavCtrl', function($scope, $rootScope, alertSrv, $location, playlistSrv, backendSrv, timeSrv) {
$scope.init = function() {
$scope.db = datasourceSrv.getGrafanaDB();
$scope.onAppEvent('save-dashboard', $scope.saveDashboard);
$scope.onAppEvent('delete-dashboard', $scope.deleteDashboard);
......@@ -24,16 +22,6 @@ function (angular, _, moment, config, store) {
});
};
$scope.set_default = function() {
store.set('grafanaDashboardDefault', $location.path());
alertSrv.set('Home Set','This page has been set as your default dashboard','success',5000);
};
$scope.purge_default = function() {
store.delete('grafanaDashboardDefault');
alertSrv.set('Local Default Clear','Your default dashboard has been reset to the default','success', 5000);
};
$scope.openEditView = function(editview) {
var search = _.extend($location.search(), {editview: editview});
$location.search(search);
......@@ -41,12 +29,12 @@ function (angular, _, moment, config, store) {
$scope.starDashboard = function() {
if ($scope.dashboardMeta.isStarred) {
$scope.db.unstarDashboard($scope.dashboard.id).then(function() {
$scope.dashboardMeta.isStarred = false;
backendSrv.delete('/api/user/stars/dashboard/' + $scope.dashboard.id).then(function() {
$scope.dashboardMeta.isStarred = true;
});
}
else {
$scope.db.starDashboard($scope.dashboard.id).then(function() {
backendSrv.post('/api/user/stars/dashboard/' + $scope.dashboard.id).then(function() {
$scope.dashboardMeta.isStarred = true;
});
}
......@@ -59,12 +47,6 @@ function (angular, _, moment, config, store) {
});
};
$scope.passwordCache = function(pwd) {
if (!window.sessionStorage) { return null; }
if (!pwd) { return window.sessionStorage["grafanaAdminPassword"]; }
window.sessionStorage["grafanaAdminPassword"] = pwd;
};
$scope.openSearch = function() {
$scope.appEvent('show-dash-search');
};
......@@ -75,20 +57,18 @@ function (angular, _, moment, config, store) {
$scope.saveDashboard = function() {
var clone = angular.copy($scope.dashboard);
$scope.db.saveDashboard(clone)
.then(function(result) {
$scope.appEvent('alert-success', ['Dashboard saved', 'Saved as ' + result.title]);
if (result.url !== $location.path()) {
$location.search({});
$location.path(result.url);
}
backendSrv.saveDashboard(clone).then(function(data) {
$scope.appEvent('dashboard-saved', $scope.dashboard);
$scope.appEvent('dashboard-saved', $scope.dashboard);
var dashboardUrl = '/dashboard/db/' + data.slug;
}, function(err) {
$scope.appEvent('alert-error', ['Save failed', err]);
});
if (dashboardUrl !== $location.path()) {
$location.url(dashboardUrl);
}
$scope.appEvent('alert-success', ['Dashboard saved', 'Saved as ' + clone.title]);
});
};
$scope.deleteDashboard = function() {
......@@ -102,10 +82,9 @@ function (angular, _, moment, config, store) {
};
$scope.deleteDashboardConfirmed = function() {
$scope.db.deleteDashboard($scope.dashboardMeta.slug).then(function() {
backendSrv.delete('/api/dashboards/db/' + $scope.dashboardMeta.slug).then(function() {
$scope.appEvent('alert-success', ['Dashboard Deleted', $scope.dashboard.title + ' has been deleted']);
}, function(err) {
$scope.appEvent('alert-error', ['Deleted failed', err]);
$location.url('/');
});
};
......@@ -149,21 +128,6 @@ function (angular, _, moment, config, store) {
$scope.appEvent('show-json-editor', { object: $scope.dashboard });
};
$scope.openSaveDropdown = function() {
$scope.isFavorite = playlistSrv.isCurrentFavorite($scope.dashboard);
$scope.saveDropdownOpened = true;
};
$scope.markAsFavorite = function() {
playlistSrv.markAsFavorite($scope.dashboard);
$scope.isFavorite = true;
};
$scope.removeAsFavorite = function() {
playlistSrv.removeAsFavorite($scope.dashboard);
$scope.isFavorite = false;
};
$scope.stopPlaylist = function() {
playlistSrv.stop(1);
};
......
......@@ -18,35 +18,33 @@ function (angular, _) {
$scope.infoText = '';
$scope.importing = false;
_.each(datasourceSrv.getAll(), function(ds) {
if (ds.type === 'influxdb' || ds.type === 'elasticsearch') {
$scope.sourceName = ds.name;
$scope.datasources.push(ds.name);
} else if (ds.type === 'grafana') {
$scope.datasources.push(ds.name);
_.each(datasourceSrv.getAll(), function(ds, key) {
if (ds.type === 'influxdb_08' || ds.type === 'elasticsearch') {
$scope.sourceName = key;
$scope.datasources.push(key);
}
});
};
$scope.startImport = function() {
$scope.sourceDs = datasourceSrv.get($scope.sourceName);
$scope.destDs = datasourceSrv.get($scope.destName);
datasourceSrv.get($scope.sourceName).then(function(ds) {
$scope.dashboardSource = ds;
$scope.dashboardSource.searchDashboards('title:').then(function(results) {
$scope.dashboards = results.dashboards;
$scope.sourceDs.searchDashboards('title:').then(function(results) {
$scope.dashboards = results.dashboards;
if ($scope.dashboards.length === 0) {
$scope.infoText = 'No dashboards found';
return;
}
if ($scope.dashboards.length === 0) {
$scope.infoText = 'No dashboards found';
return;
}
$scope.importing = true;
$scope.imported = [];
$scope.next();
}, function(err) {
var resp = err.message || err.statusText || 'Unknown error';
var message = "Failed to load dashboards from selected data source, response from server was: " + resp;
$scope.appEvent('alert-error', ['Import failed', message]);
$scope.importing = true;
$scope.imported = [];
$scope.next();
}, function(err) {
var resp = err.message || err.statusText || 'Unknown error';
var message = "Failed to load dashboards from selected data source, response from server was: " + resp;
$scope.appEvent('alert-error', ['Import failed', message]);
});
});
};
......@@ -65,12 +63,13 @@ function (angular, _) {
$scope.imported.push(infoObj);
$scope.infoText = "Importing " + $scope.imported.length + '/' + ($scope.imported.length + $scope.dashboards.length);
$scope.sourceDs.getDashboard(dash.id).then(function(loadedDash) {
$scope.destDs.saveDashboard(loadedDash).then(function() {
$scope.dashboardSource.getDashboard(dash.id).then(function(loadedDash) {
backendSrv.saveDashboard(loadedDash).then(function() {
infoObj.info = "Done!";
$scope.next();
}, function(err) {
infoObj.info = "Error: " + err;
err.isHandled = true;
infoObj.info = "Error: " + (err.data || { message: 'Unknown' }).message;
$scope.next();
});
});
......
......@@ -8,7 +8,7 @@
<div class="page">
<h2>
Import file
<span><tip>Load dashboard JSON layout from file</tip></span>
<em style="font-size: 14px;padding-left: 10px;"> <i class="fa fa-info-circle"></i> Load dashboard from local .json file</em>
</h2>
<div class="editor-row">
......@@ -21,7 +21,10 @@
</div>
</div>
<h2>Migrate dashboards</h2>
<h2>
Migrate dashboards
<em style="font-size: 14px;padding-left: 10px;"><i class="fa fa-info-circle"></i> Import dashboards from Elasticsearch or InfluxDB</em>
</h2>
<div class="tight-form last">
<ul class="tight-form-list">
......@@ -32,14 +35,7 @@
<select type="text" ng-model="sourceName" class="input-medium tight-form-input" ng-options="f for f in datasources">
</select>
</li>
<li class="tight-form-item">
<strong>Destination</strong>
</li>
<li>
<select type="text" ng-model="destName" class="input-medium tight-form-input" ng-options="f for f in datasources">
</select>
</li>
<li>
<li style="float: right">
<button class="btn btn-success tight-form-btn" ng-click="startImport()">Import</button>
</li>
<div class="clearfix"></div>
......
......@@ -6,7 +6,7 @@ function (angular) {
var module = angular.module('grafana.controllers');
module.controller('OrgDetailsCtrl', function($scope, $http, backendSrv) {
module.controller('OrgDetailsCtrl', function($scope, $http, backendSrv, contextSrv) {
$scope.init = function() {
$scope.getOrgInfo();
......@@ -15,6 +15,7 @@ function (angular) {
$scope.getOrgInfo = function() {
backendSrv.get('/api/org').then(function(org) {
$scope.org = org;
contextSrv.user.orgName = org.name;
});
};
......
......@@ -100,6 +100,9 @@ function (angular, _, config) {
datasourceSrv.get($scope.panel.datasource).then(function(datasource) {
$scope.datasource = datasource;
return $scope.refreshData($scope.datasource);
}, function(err) {
$scope.panelMeta.loading = false;
$scope.panelMeta.error = err.message;
});
};
......
{
"pluginType": "datasource",
"name": "Grafana (for testing)",
"type": "grafana",
"serviceName": "GrafanaDatasource",
"module": "plugins/datasource/grafana/datasource",
"partials": {
"query": "app/plugins/datasource/grafana/partials/query.editor.html"
},
"metrics": true
}
{
"pluginType": "datasource",
"name": "InfluxDB 0.9.x",
"type": "influxdb",
"serviceName": "InfluxDatasource",
"module": "plugins/datasource/influxdb/datasource",
"partials": {
"config": "app/plugins/datasource/influxdb/partials/config.html",
"query": "app/plugins/datasource/influxdb/partials/query.editor.html",
"annotations": "app/plugins/datasource/influxdb/partials/query.editor.html"
},
"metrics": true,
"annotations": true
}
{
"pluginType": "datasource",
"name": "OpenTSDB",
"type": "opentsdb",
"serviceName": "OpenTSDBDatasource",
"module": "plugins/datasource/opentsdb/datasource",
"partials": {
"config": "app/plugins/datasource/opentsdb/partials/config.html",
"query": "app/plugins/datasource/opentsdb/partials/query.editor.html"
},
"metrics": true
}
......@@ -90,10 +90,6 @@ function (angular, _, kbn) {
function validateTarget(target) {
var errs = {};
if (!target.metric) {
errs.metric = "You must supply a metric name.";
}
if (target.shouldDownsample) {
try {
if (target.downsampleInterval) {
......
......@@ -77,5 +77,9 @@ function (angular, _, config) {
});
};
this.saveDashboard = function(dash) {
return this.post('/api/dashboards/db/', {dashboard: dash});
};
});
});
......@@ -11,8 +11,6 @@ function (angular, _, config) {
module.service('datasourceSrv', function($q, $injector, $rootScope) {
var self = this;
this.grafanaDB = new ($injector.get("GrafanaDatasource"));
this.init = function(dsSettingList) {
config.datasources = dsSettingList;
......@@ -45,6 +43,10 @@ function (angular, _, config) {
this.loadDatasource = function(name) {
var dsConfig = config.datasources[name];
if (!dsConfig) {
return $q.reject({message: "Datasource named " + name + " was not found"});
}
var deferred = $q.defer();
var pluginDef = dsConfig.meta;
......@@ -62,7 +64,7 @@ function (angular, _, config) {
};
this.getAll = function() {
return this.datasources;
return config.datasources;
};
this.getAnnotationSources = function() {
......@@ -73,10 +75,6 @@ function (angular, _, config) {
return this.metricSources;
};
this.getGrafanaDB = function() {
return this.grafanaDB;
};
this.init(config.datasources);
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment