From 3849b5962792eb72ba315ccd9a4a1f1086a3ed7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 11 Apr 2016 17:16:52 -0400 Subject: [PATCH] feat(updates): changed to new api --- pkg/plugins/update_checker.go | 42 ++++++---- public/app/plugins/panel/dashlist/module.js | 91 --------------------- 2 files changed, 24 insertions(+), 109 deletions(-) delete mode 100644 public/app/plugins/panel/dashlist/module.js diff --git a/pkg/plugins/update_checker.go b/pkg/plugins/update_checker.go index 6d3626fff16..b619310a918 100644 --- a/pkg/plugins/update_checker.go +++ b/pkg/plugins/update_checker.go @@ -11,16 +11,8 @@ import ( "github.com/grafana/grafana/pkg/setting" ) -type GrafanaNetPlugins struct { - Plugins []GrafanaNetPlugin `json:"plugins"` -} - type GrafanaNetPlugin struct { - Id string `json:"id"` - Versions []GrafanaNetPluginVersion `json:"versions"` -} - -type GrafanaNetPluginVersion struct { + Slug string `json:"slug"` Version string `json:"version"` } @@ -43,11 +35,27 @@ func StartPluginUpdateChecker() { } } +func getAllExternalPluginSlugs() string { + str := "" + + for _, plug := range Plugins { + if plug.IsCorePlugin { + continue + } + + str += plug.Id + "," + } + + return str +} + func checkForUpdates() { log.Trace("Checking for updates") client := http.Client{Timeout: time.Duration(5 * time.Second)} - resp, err := client.Get("https://grafana.net/api/plugins/repo") + + pluginSlugs := getAllExternalPluginSlugs() + resp, err := client.Get("https://grafana.net/api/plugins/versioncheck?slugIn=" + pluginSlugs + "&grafanaVersion=" + setting.BuildVersion) if err != nil { log.Trace("Failed to get plugins repo from grafana.net, %v", err.Error()) @@ -62,20 +70,18 @@ func checkForUpdates() { return } - var data GrafanaNetPlugins - err = json.Unmarshal(body, &data) + gNetPlugins := []GrafanaNetPlugin{} + err = json.Unmarshal(body, &gNetPlugins) if err != nil { log.Trace("Failed to unmarshal plugin repo, reading response from grafana.net, %v", err.Error()) return } for _, plug := range Plugins { - for _, gplug := range data.Plugins { - if gplug.Id == plug.Id { - if len(gplug.Versions) > 0 { - plug.GrafanaNetVersion = gplug.Versions[0].Version - plug.GrafanaNetHasUpdate = plug.Info.Version != plug.GrafanaNetVersion - } + for _, gplug := range gNetPlugins { + if gplug.Slug == plug.Id { + plug.GrafanaNetVersion = gplug.Version + plug.GrafanaNetHasUpdate = plug.Info.Version != plug.GrafanaNetVersion } } } diff --git a/public/app/plugins/panel/dashlist/module.js b/public/app/plugins/panel/dashlist/module.js deleted file mode 100644 index 5bc42c505fd..00000000000 --- a/public/app/plugins/panel/dashlist/module.js +++ /dev/null @@ -1,91 +0,0 @@ -/// -"use strict"; -var __extends = (this && this.__extends) || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); -}; -var lodash_1 = require('lodash'); -var sdk_1 = require('app/plugins/sdk'); -var impression_store_1 = require('app/features/dashboard/impression_store'); -// Set and populate defaults -var panelDefaults = { - mode: 'starred', - query: '', - limit: 10, - tags: [], - recent: false, - search: false, - starred: true -}; -var DashListCtrl = (function (_super) { - __extends(DashListCtrl, _super); - /** @ngInject */ - function DashListCtrl($scope, $injector, backendSrv) { - _super.call(this, $scope, $injector); - this.backendSrv = backendSrv; - lodash_1["default"].defaults(this.panel, panelDefaults); - if (this.panel.tag) { - this.panel.tags = [this.panel.tag]; - delete this.panel.tag; - } - this.events.on('refresh', this.onRefresh.bind(this)); - this.events.on('init-edit-mode', this.onInitEditMode.bind(this)); - } - DashListCtrl.prototype.onInitEditMode = function () { - this.editorTabIndex = 1; - this.modes = ['starred', 'search', 'recently viewed']; - this.addEditorTab('Options', 'public/app/plugins/panel/dashlist/editor.html'); - }; - DashListCtrl.prototype.onRefresh = function () { - var promises = []; - if (this.panel.recent) { - promises.push(this.getRecentDashboards()); - } - if (this.panel.starred) { - promises.push(this.getStarred()); - } - if (this.panel.search) { - promises.push(this.getSearch()); - } - return Promise.all(promises) - .then(this.renderingCompleted.bind(this)); - }; - DashListCtrl.prototype.getSearch = function () { - var _this = this; - var params = { - limit: this.panel.limit, - query: this.panel.query, - tag: this.panel.tags - }; - return this.backendSrv.search(params).then(function (result) { - _this.dashList = result; - _this.renderingCompleted(); - }); - }; - DashListCtrl.prototype.getStarred = function () { - var _this = this; - var params = { limit: this.panel.limit, starred: "true" }; - return this.backendSrv.search(params).then(function (result) { - _this.dashList = result; - _this.renderingCompleted(); - }); - }; - DashListCtrl.prototype.getRecentDashboards = function () { - var _this = this; - var dashIds = lodash_1["default"].first(impression_store_1.impressions.getDashboardOpened(), this.panel.limit); - return this.backendSrv.search({ dashboardIds: dashIds, limit: this.panel.limit }).then(function (result) { - _this.dashList = dashIds.map(function (orderId) { - return lodash_1["default"].find(result, function (dashboard) { - return dashboard.id === orderId; - }); - }).filter(function (el) { - return el !== undefined; - }); - }); - }; - DashListCtrl.templateUrl = 'module.html'; - return DashListCtrl; -}(sdk_1.PanelCtrl)); -exports.DashListCtrl = DashListCtrl; -exports.PanelCtrl = DashListCtrl;