mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(updates): changed to new api
This commit is contained in:
parent
31441f0b43
commit
3849b59627
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,91 +0,0 @@
|
||||
///<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;
|
Loading…
Reference in New Issue
Block a user