Commit 3849b596 by Torkel Ödegaard

feat(updates): changed to new api

parent 31441f0b
......@@ -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,23 +70,21 @@ 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
for _, gplug := range gNetPlugins {
if gplug.Slug == plug.Id {
plug.GrafanaNetVersion = gplug.Version
plug.GrafanaNetHasUpdate = plug.Info.Version != plug.GrafanaNetVersion
}
}
}
}
resp2, err := client.Get("https://raw.githubusercontent.com/grafana/grafana/master/latest.json")
if err != nil {
......
///<reference path="../../../headers/common.d.ts" />
"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;
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