From fc54c01f01dc9e5136b65d8e477cfa2458d24043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 11 Mar 2016 12:31:56 +0100 Subject: [PATCH] feat(plugins): more work on plugin dashboard install, #4298 --- pkg/api/dtos/plugins.go | 7 +-- pkg/plugins/dashboard_installer.go | 3 +- pkg/plugins/dashboards.go | 6 ++- public/app/core/routes/routes.ts | 6 +-- public/app/features/dashboard/all.js | 1 - public/app/features/datasources/all.js | 4 -- public/app/features/org/all.js | 1 - public/app/features/plugins/all.ts | 9 ++-- .../edit_ctrl.ts => plugins/ds_edit_ctrl.ts} | 2 +- .../list_ctrl.ts => plugins/ds_list_ctrl.ts} | 0 .../plugins/import_list/import_list.html | 37 ++++++++++++++++ .../import_list/import_list.ts | 44 +++++-------------- .../partials/ds_edit.html} | 0 .../partials/ds_http_settings.html} | 0 .../partials/ds_list.html} | 0 .../partials/{edit.html => plugin_edit.html} | 0 .../partials/{list.html => plugin_list.html} | 0 .../partials/{page.html => plugin_page.html} | 0 .../{edit_ctrl.ts => plugin_edit_ctrl.ts} | 0 .../{list_ctrl.ts => plugin_list_ctrl.ts} | 0 .../{page_ctrl.ts => plugin_page_ctrl.ts} | 0 .../graphite/dashboards/carbon_stats.json | 2 +- .../plugins/datasource/graphite/plugin.json | 3 +- 23 files changed, 70 insertions(+), 55 deletions(-) delete mode 100644 public/app/features/datasources/all.js rename public/app/features/{datasources/edit_ctrl.ts => plugins/ds_edit_ctrl.ts} (97%) rename public/app/features/{datasources/list_ctrl.ts => plugins/ds_list_ctrl.ts} (100%) create mode 100644 public/app/features/plugins/import_list/import_list.html rename public/app/features/{dashboard => plugins}/import_list/import_list.ts (56%) rename public/app/features/{datasources/partials/edit.html => plugins/partials/ds_edit.html} (100%) rename public/app/features/{datasources/partials/http_settings.html => plugins/partials/ds_http_settings.html} (100%) rename public/app/features/{datasources/partials/list.html => plugins/partials/ds_list.html} (100%) rename public/app/features/plugins/partials/{edit.html => plugin_edit.html} (100%) rename public/app/features/plugins/partials/{list.html => plugin_list.html} (100%) rename public/app/features/plugins/partials/{page.html => plugin_page.html} (100%) rename public/app/features/plugins/{edit_ctrl.ts => plugin_edit_ctrl.ts} (100%) rename public/app/features/plugins/{list_ctrl.ts => plugin_list_ctrl.ts} (100%) rename public/app/features/plugins/{page_ctrl.ts => plugin_page_ctrl.ts} (100%) diff --git a/pkg/api/dtos/plugins.go b/pkg/api/dtos/plugins.go index 144b9b09755..5f3dac76296 100644 --- a/pkg/api/dtos/plugins.go +++ b/pkg/api/dtos/plugins.go @@ -27,7 +27,8 @@ type PluginListItem struct { } type InstallPluginDashboardCmd struct { - PluginId string `json:"pluginId"` - Path string `json:"path"` - Inputs map[string]interface{} `json:"inputs"` + PluginId string `json:"pluginId"` + Path string `json:"path"` + Reinstall bool `json:"reinstall"` + Inputs map[string]interface{} `json:"inputs"` } diff --git a/pkg/plugins/dashboard_installer.go b/pkg/plugins/dashboard_installer.go index 9f52b518d70..279ab209989 100644 --- a/pkg/plugins/dashboard_installer.go +++ b/pkg/plugins/dashboard_installer.go @@ -48,8 +48,9 @@ func InstallPluginDashboard(cmd *InstallPluginDashboardCommand) error { Title: dashboard.Title, Path: cmd.Path, Revision: dashboard.GetString("revision", "1.0"), - InstalledURI: "db/" + saveCmd.Result.Slug, + InstalledUri: "db/" + saveCmd.Result.Slug, InstalledRevision: dashboard.GetString("revision", "1.0"), + Installed: true, } return nil diff --git a/pkg/plugins/dashboards.go b/pkg/plugins/dashboards.go index 9acb64cec1b..1697ad808f2 100644 --- a/pkg/plugins/dashboards.go +++ b/pkg/plugins/dashboards.go @@ -12,7 +12,8 @@ import ( type PluginDashboardInfoDTO struct { PluginId string `json:"pluginId"` Title string `json:"title"` - InstalledURI string `json:"installedURI"` + Installed bool `json:"installed"` + InstalledUri string `json:"installedUri"` InstalledRevision string `json:"installedRevision"` Revision string `json:"revision"` Description string `json:"description"` @@ -83,7 +84,8 @@ func getDashboardImportStatus(orgId int64, plugin *PluginBase, path string) (*Pl return nil, err } } else { - res.InstalledURI = "db/" + query.Result.Slug + res.Installed = true + res.InstalledUri = "db/" + query.Result.Slug res.InstalledRevision = query.Result.GetString("revision", "1.0") } diff --git a/public/app/core/routes/routes.ts b/public/app/core/routes/routes.ts index 91ef4cd8b25..5ec55c311e5 100644 --- a/public/app/core/routes/routes.ts +++ b/public/app/core/routes/routes.ts @@ -52,19 +52,19 @@ function setupAngularRoutes($routeProvider, $locationProvider) { templateUrl: 'public/app/features/datasources/partials/list.html', controller : 'DataSourcesCtrl', controllerAs: 'ctrl', - resolve: loadOrgBundle, + resolve: loadPluginsBundle, }) .when('/datasources/edit/:id', { templateUrl: 'public/app/features/datasources/partials/edit.html', controller : 'DataSourceEditCtrl', controllerAs: 'ctrl', - resolve: loadOrgBundle, + resolve: loadPluginsBundle, }) .when('/datasources/new', { templateUrl: 'public/app/features/datasources/partials/edit.html', controller : 'DataSourceEditCtrl', controllerAs: 'ctrl', - resolve: loadOrgBundle, + resolve: loadPluginsBundle, }) .when('/org', { templateUrl: 'public/app/features/org/partials/orgDetails.html', diff --git a/public/app/features/dashboard/all.js b/public/app/features/dashboard/all.js index b96f6693324..d110019add6 100644 --- a/public/app/features/dashboard/all.js +++ b/public/app/features/dashboard/all.js @@ -13,7 +13,6 @@ define([ './timeSrv', './unsavedChangesSrv', './timepicker/timepicker', - './import_list/import_list', './graphiteImportCtrl', './dynamicDashboardSrv', './importCtrl', diff --git a/public/app/features/datasources/all.js b/public/app/features/datasources/all.js deleted file mode 100644 index b181fd475c2..00000000000 --- a/public/app/features/datasources/all.js +++ /dev/null @@ -1,4 +0,0 @@ -define([ - './list_ctrl', - './edit_ctrl', -], function () {}); diff --git a/public/app/features/org/all.js b/public/app/features/org/all.js index cebd0dd1def..e04634d709a 100644 --- a/public/app/features/org/all.js +++ b/public/app/features/org/all.js @@ -4,5 +4,4 @@ define([ './userInviteCtrl', './orgApiKeysCtrl', './orgDetailsCtrl', - '../datasources/all', ], function () {}); diff --git a/public/app/features/plugins/all.ts b/public/app/features/plugins/all.ts index 9d54165e56b..346fb2b30ef 100644 --- a/public/app/features/plugins/all.ts +++ b/public/app/features/plugins/all.ts @@ -1,3 +1,6 @@ -import './edit_ctrl'; -import './page_ctrl'; -import './list_ctrl'; +import './plugin_edit_ctrl'; +import './plugin_page_ctrl'; +import './plugin_list_ctrl'; +import './import_list/import_list'; +import './ds_edit_ctrl'; +import './ds_list_ctrl'; diff --git a/public/app/features/datasources/edit_ctrl.ts b/public/app/features/plugins/ds_edit_ctrl.ts similarity index 97% rename from public/app/features/datasources/edit_ctrl.ts rename to public/app/features/plugins/ds_edit_ctrl.ts index 3ad74c628ab..1e07b3a814a 100644 --- a/public/app/features/datasources/edit_ctrl.ts +++ b/public/app/features/plugins/ds_edit_ctrl.ts @@ -140,6 +140,6 @@ coreModule.controller('DataSourceEditCtrl', DataSourceEditCtrl); coreModule.directive('datasourceHttpSettings', function() { return { scope: {current: "="}, - templateUrl: 'public/app/features/datasources/partials/http_settings.html' + templateUrl: 'public/app/features/plugins/partials/ds_http_settings.html' }; }); diff --git a/public/app/features/datasources/list_ctrl.ts b/public/app/features/plugins/ds_list_ctrl.ts similarity index 100% rename from public/app/features/datasources/list_ctrl.ts rename to public/app/features/plugins/ds_list_ctrl.ts diff --git a/public/app/features/plugins/import_list/import_list.html b/public/app/features/plugins/import_list/import_list.html new file mode 100644 index 00000000000..d6c1bb914ce --- /dev/null +++ b/public/app/features/plugins/import_list/import_list.html @@ -0,0 +1,37 @@ +
+ + + + + + + + + + +
+ + + + {{dash.title}} + + + {{dash.title}} + + + v{{dash.revision}} + + Installed v{{dash.installedRevision}} + + + + +
+
+ diff --git a/public/app/features/dashboard/import_list/import_list.ts b/public/app/features/plugins/import_list/import_list.ts similarity index 56% rename from public/app/features/dashboard/import_list/import_list.ts rename to public/app/features/plugins/import_list/import_list.ts index 7d88d7f9f0a..62145623fa2 100644 --- a/public/app/features/dashboard/import_list/import_list.ts +++ b/public/app/features/plugins/import_list/import_list.ts @@ -4,9 +4,6 @@ import angular from 'angular'; import _ from 'lodash'; import coreModule from 'app/core/core_module'; -class DashboardScriptLoader { -} - export class DashImportListCtrl { dashboards: any[]; plugin: any; @@ -19,50 +16,32 @@ export class DashImportListCtrl { }); } - import(dash) { + import(dash, reinstall) { var installCmd = { pluginId: this.plugin.id, path: dash.path, + reinstall: reinstall, inputs: {} }; this.backendSrv.post(`/api/plugins/dashboards/install`, installCmd).then(res => { - console.log(res); + this.$rootScope.appEvent('alert-success', ['Dashboard Installed', dash.title]); + _.extend(dash, res); }); } + remove(dash) { + this.backendSrv.delete('/api/dashboards/' + dash.installedUri).then(() => { + this.$rootScope.appEvent('alert-success', ['Dashboard Deleted', dash.title]); + dash.installed = false; + }); + } } -var template = ` -
- - - - - - - - - - -
- - - {{dash.title}} - - {{dash.revision}} - - {{dash.installedRevision}} - - -
-
-`; - export function dashboardImportList() { return { restrict: 'E', - template: template, + templateUrl: 'public/app/features/plugins/import_list/import_list.html', controller: DashImportListCtrl, bindToController: true, controllerAs: 'ctrl', @@ -72,7 +51,6 @@ export function dashboardImportList() { }; } - coreModule.directive('dashboardImportList', dashboardImportList); diff --git a/public/app/features/datasources/partials/edit.html b/public/app/features/plugins/partials/ds_edit.html similarity index 100% rename from public/app/features/datasources/partials/edit.html rename to public/app/features/plugins/partials/ds_edit.html diff --git a/public/app/features/datasources/partials/http_settings.html b/public/app/features/plugins/partials/ds_http_settings.html similarity index 100% rename from public/app/features/datasources/partials/http_settings.html rename to public/app/features/plugins/partials/ds_http_settings.html diff --git a/public/app/features/datasources/partials/list.html b/public/app/features/plugins/partials/ds_list.html similarity index 100% rename from public/app/features/datasources/partials/list.html rename to public/app/features/plugins/partials/ds_list.html diff --git a/public/app/features/plugins/partials/edit.html b/public/app/features/plugins/partials/plugin_edit.html similarity index 100% rename from public/app/features/plugins/partials/edit.html rename to public/app/features/plugins/partials/plugin_edit.html diff --git a/public/app/features/plugins/partials/list.html b/public/app/features/plugins/partials/plugin_list.html similarity index 100% rename from public/app/features/plugins/partials/list.html rename to public/app/features/plugins/partials/plugin_list.html diff --git a/public/app/features/plugins/partials/page.html b/public/app/features/plugins/partials/plugin_page.html similarity index 100% rename from public/app/features/plugins/partials/page.html rename to public/app/features/plugins/partials/plugin_page.html diff --git a/public/app/features/plugins/edit_ctrl.ts b/public/app/features/plugins/plugin_edit_ctrl.ts similarity index 100% rename from public/app/features/plugins/edit_ctrl.ts rename to public/app/features/plugins/plugin_edit_ctrl.ts diff --git a/public/app/features/plugins/list_ctrl.ts b/public/app/features/plugins/plugin_list_ctrl.ts similarity index 100% rename from public/app/features/plugins/list_ctrl.ts rename to public/app/features/plugins/plugin_list_ctrl.ts diff --git a/public/app/features/plugins/page_ctrl.ts b/public/app/features/plugins/plugin_page_ctrl.ts similarity index 100% rename from public/app/features/plugins/page_ctrl.ts rename to public/app/features/plugins/plugin_page_ctrl.ts diff --git a/public/app/plugins/datasource/graphite/dashboards/carbon_stats.json b/public/app/plugins/datasource/graphite/dashboards/carbon_stats.json index 642f32b6e6a..ad2c32be759 100644 --- a/public/app/plugins/datasource/graphite/dashboards/carbon_stats.json +++ b/public/app/plugins/datasource/graphite/dashboards/carbon_stats.json @@ -6,7 +6,7 @@ } }, - "title": "Carbon stats", + "title": "Carbon Cache Stats", "version": 1, "rows": [ { diff --git a/public/app/plugins/datasource/graphite/plugin.json b/public/app/plugins/datasource/graphite/plugin.json index c923cb79c4e..f7715f9c5b9 100644 --- a/public/app/plugins/datasource/graphite/plugin.json +++ b/public/app/plugins/datasource/graphite/plugin.json @@ -4,8 +4,7 @@ "id": "graphite", "includes": [ - {"type": "dashboard", "name": "Carbon Overview", "path": "dashboards/carbon_stats.json"}, - {"type": "dashboard", "name": "Carbon Agent Details", "path": "dashboards/carbon_stats.json"} + {"type": "dashboard", "name": "Carbon Cache Stats", "path": "dashboards/carbon_stats.json"} ], "metrics": true,