From 41a0995db7f4858a1518df9e68b64d99826208c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 22 Dec 2015 16:32:17 +0100 Subject: [PATCH] feat(apps): minor progress on app meta data --- pkg/api/app_plugin.go | 39 ++++++++----------- pkg/api/dtos/app_plugin.go | 1 + pkg/plugins/models.go | 19 +++++++++ public/app/features/org/app_edit_ctrl.ts | 5 ++- public/app/features/org/app_srv.ts | 2 +- .../app/features/org/partials/app_list.html | 2 +- .../plugins/datasource/graphite/plugin.json | 3 +- 7 files changed, 43 insertions(+), 28 deletions(-) diff --git a/pkg/api/app_plugin.go b/pkg/api/app_plugin.go index 6bc0e5a4933..860334e362e 100644 --- a/pkg/api/app_plugin.go +++ b/pkg/api/app_plugin.go @@ -15,36 +15,31 @@ func GetAppPlugins(c *middleware.Context) Response { return ApiError(500, "Failed to list Plugin Bundles", err) } - installedAppsMap := make(map[string]*dtos.AppPlugin) - for t, a := range plugins.Apps { - installedAppsMap[t] = &dtos.AppPlugin{ - Type: a.Type, - Enabled: a.Enabled, - Pinned: a.Pinned, - Module: a.Module, - JsonData: make(map[string]interface{}), + translateToDto := func(app *plugins.AppPlugin) *dtos.AppPlugin { + return &dtos.AppPlugin{ + Name: app.Name, + Type: app.Type, + Enabled: app.Enabled, + Pinned: app.Pinned, + Module: app.Module, } } seenApps := make(map[string]bool) - result := make([]*dtos.AppPlugin, 0) - for _, b := range query.Result { - if def, ok := installedAppsMap[b.Type]; ok { - result = append(result, &dtos.AppPlugin{ - Type: b.Type, - Enabled: b.Enabled, - Pinned: b.Pinned, - Module: def.Module, - JsonData: b.JsonData, - }) - seenApps[b.Type] = true + for _, orgApp := range query.Result { + if def, ok := plugins.Apps[orgApp.Type]; ok { + pluginDto := translateToDto(def) + pluginDto.Enabled = orgApp.Enabled + pluginDto.JsonData = orgApp.JsonData + result = append(result, pluginDto) + seenApps[orgApp.Type] = true } } - for t, a := range installedAppsMap { - if _, ok := seenApps[t]; !ok { - result = append(result, a) + for _, app := range plugins.Apps { + if _, ok := seenApps[app.Type]; !ok { + result = append(result, translateToDto(app)) } } diff --git a/pkg/api/dtos/app_plugin.go b/pkg/api/dtos/app_plugin.go index 741b17ab383..029989008b5 100644 --- a/pkg/api/dtos/app_plugin.go +++ b/pkg/api/dtos/app_plugin.go @@ -1,6 +1,7 @@ package dtos type AppPlugin struct { + Name string `json:"name"` Type string `json:"type"` Enabled bool `json:"enabled"` Pinned bool `json:"pinned"` diff --git a/pkg/plugins/models.go b/pkg/plugins/models.go index 15e48409144..0db825b56cf 100644 --- a/pkg/plugins/models.go +++ b/pkg/plugins/models.go @@ -4,6 +4,23 @@ import ( "github.com/grafana/grafana/pkg/models" ) +type PluginInfo struct { + Author PluginAuthor `json:"author"` + Description string `json:"description"` + Homepage string `json:"homepage"` + Logos PluginLogos `json:"logos"` +} + +type PluginAuthor struct { + Name string `json:"name"` + Url string `json:"url"` +} + +type PluginLogos struct { + Small string `json:"small"` + Large string `json:"large"` +} + type DataSourcePlugin struct { Type string `json:"type"` Name string `json:"name"` @@ -61,12 +78,14 @@ type ApiPlugin struct { type AppPlugin struct { Type string `json:"type"` + Name string `json:"name"` Enabled bool `json:"enabled"` Pinned bool `json:"pinned"` Module string `json:"module"` Css *AppPluginCss `json:"css"` Page *AppPluginPage `json:"page"` PublicContent *PublicContent `json:"public"` + Info *PluginInfo `json:"info"` } type EnabledPlugins struct { diff --git a/public/app/features/org/app_edit_ctrl.ts b/public/app/features/org/app_edit_ctrl.ts index ad7db2970e2..7c4553ac332 100644 --- a/public/app/features/org/app_edit_ctrl.ts +++ b/public/app/features/org/app_edit_ctrl.ts @@ -1,8 +1,8 @@ /// -import config = require('app/core/config'); +import config from 'app/core/config'; import angular from 'angular'; -import * as _ from 'lodash'; +import _ from 'lodash'; export class AppEditCtrl { appModel: any; @@ -25,3 +25,4 @@ export class AppEditCtrl { } angular.module('grafana.controllers').controller('AppEditCtrl', AppEditCtrl); + diff --git a/public/app/features/org/app_srv.ts b/public/app/features/org/app_srv.ts index 6d712301b90..0f937e601bc 100644 --- a/public/app/features/org/app_srv.ts +++ b/public/app/features/org/app_srv.ts @@ -1,6 +1,6 @@ /// -import config = require('app/core/config'); +import _ from 'lodash'; import angular from 'angular'; export class AppSrv { diff --git a/public/app/features/org/partials/app_list.html b/public/app/features/org/partials/app_list.html index 79afd4a03fe..ea992a46a92 100644 --- a/public/app/features/org/partials/app_list.html +++ b/public/app/features/org/partials/app_list.html @@ -23,7 +23,7 @@ - Litmus{{app.type}} + {{app.name}} Dashboards: 1 diff --git a/public/app/plugins/datasource/graphite/plugin.json b/public/app/plugins/datasource/graphite/plugin.json index b170cc708f1..0a94404533d 100644 --- a/public/app/plugins/datasource/graphite/plugin.json +++ b/public/app/plugins/datasource/graphite/plugin.json @@ -1,10 +1,9 @@ { "pluginType": "datasource", "name": "Graphite", - "type": "graphite", - "serviceName": "GraphiteDatasource", + "serviceName": "GraphiteDatasource", "module": "app/plugins/datasource/graphite/datasource", "partials": {