Merge branch 'master' into websocket
Conflicts: public/app/core/core.ts
This commit is contained in:
+16
-3
@@ -1,8 +1,11 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
//"github.com/grafana/grafana/pkg/log"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
@@ -17,9 +20,10 @@ func GetDataSources(c *middleware.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
result := make([]*dtos.DataSource, len(query.Result))
|
||||
for i, ds := range query.Result {
|
||||
result[i] = &dtos.DataSource{
|
||||
result := make(dtos.DataSourceList, 0)
|
||||
for _, ds := range query.Result {
|
||||
|
||||
dsItem := dtos.DataSource{
|
||||
Id: ds.Id,
|
||||
OrgId: ds.OrgId,
|
||||
Name: ds.Name,
|
||||
@@ -32,8 +36,17 @@ func GetDataSources(c *middleware.Context) {
|
||||
BasicAuth: ds.BasicAuth,
|
||||
IsDefault: ds.IsDefault,
|
||||
}
|
||||
|
||||
if plugin, exists := plugins.DataSources[ds.Type]; exists {
|
||||
dsItem.TypeLogoUrl = plugin.Info.Logos.Small
|
||||
} else {
|
||||
dsItem.TypeLogoUrl = "public/img/plugin-default-logo_dark.svg"
|
||||
}
|
||||
|
||||
result = append(result, dsItem)
|
||||
}
|
||||
|
||||
sort.Sort(result)
|
||||
c.JSON(200, result)
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ type DataSource struct {
|
||||
OrgId int64 `json:"orgId"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
TypeLogoUrl string `json:"typeLogoUrl"`
|
||||
Access m.DsAccess `json:"access"`
|
||||
Url string `json:"url"`
|
||||
Password string `json:"password"`
|
||||
@@ -75,6 +76,20 @@ type DataSource struct {
|
||||
JsonData *simplejson.Json `json:"jsonData,omitempty"`
|
||||
}
|
||||
|
||||
type DataSourceList []DataSource
|
||||
|
||||
func (slice DataSourceList) Len() int {
|
||||
return len(slice)
|
||||
}
|
||||
|
||||
func (slice DataSourceList) Less(i, j int) bool {
|
||||
return slice[i].Name < slice[j].Name
|
||||
}
|
||||
|
||||
func (slice DataSourceList) Swap(i, j int) {
|
||||
slice[i], slice[j] = slice[j], slice[i]
|
||||
}
|
||||
|
||||
type MetricQueryResultDto struct {
|
||||
Data []MetricQueryResultDataDto `json:"data"`
|
||||
}
|
||||
|
||||
@@ -26,6 +26,20 @@ type PluginListItem struct {
|
||||
Info *plugins.PluginInfo `json:"info"`
|
||||
}
|
||||
|
||||
type PluginList []PluginListItem
|
||||
|
||||
func (slice PluginList) Len() int {
|
||||
return len(slice)
|
||||
}
|
||||
|
||||
func (slice PluginList) Less(i, j int) bool {
|
||||
return slice[i].Name < slice[j].Name
|
||||
}
|
||||
|
||||
func (slice PluginList) Swap(i, j int) {
|
||||
slice[i], slice[j] = slice[j], slice[i]
|
||||
}
|
||||
|
||||
type ImportDashboardCommand struct {
|
||||
PluginId string `json:"pluginId"`
|
||||
Path string `json:"path"`
|
||||
|
||||
+5
-2
@@ -1,6 +1,8 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
@@ -19,7 +21,7 @@ func GetPluginList(c *middleware.Context) Response {
|
||||
return ApiError(500, "Failed to get list of plugins", err)
|
||||
}
|
||||
|
||||
result := make([]*dtos.PluginListItem, 0)
|
||||
result := make(dtos.PluginList, 0)
|
||||
for _, pluginDef := range plugins.Plugins {
|
||||
// filter out app sub plugins
|
||||
if embeddedFilter == "0" && pluginDef.IncludedInAppId != "" {
|
||||
@@ -31,7 +33,7 @@ func GetPluginList(c *middleware.Context) Response {
|
||||
continue
|
||||
}
|
||||
|
||||
listItem := &dtos.PluginListItem{
|
||||
listItem := dtos.PluginListItem{
|
||||
Id: pluginDef.Id,
|
||||
Name: pluginDef.Name,
|
||||
Type: pluginDef.Type,
|
||||
@@ -58,6 +60,7 @@ func GetPluginList(c *middleware.Context) Response {
|
||||
result = append(result, listItem)
|
||||
}
|
||||
|
||||
sort.Sort(result)
|
||||
return Json(200, result)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/fatih/color"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
|
||||
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
|
||||
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
||||
@@ -53,12 +54,6 @@ func installCommand(c CommandLine) error {
|
||||
pluginToInstall := c.Args().First()
|
||||
version := c.Args().Get(1)
|
||||
|
||||
if version == "" {
|
||||
log.Infof("version: latest\n")
|
||||
} else {
|
||||
log.Infof("version: %v\n", version)
|
||||
}
|
||||
|
||||
return InstallPlugin(pluginToInstall, version, c)
|
||||
}
|
||||
|
||||
@@ -86,13 +81,14 @@ func InstallPlugin(pluginName, version string, c CommandLine) error {
|
||||
log.Infof("installing %v @ %v\n", plugin.Id, version)
|
||||
log.Infof("from url: %v\n", downloadURL)
|
||||
log.Infof("into: %v\n", pluginFolder)
|
||||
log.Info("\n")
|
||||
|
||||
err = downloadFile(plugin.Id, pluginFolder, downloadURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("Installed %v successfully ✔\n", plugin.Id)
|
||||
log.Infof("%s Installed %s successfully \n", color.GreenString("✔"), plugin.Id)
|
||||
|
||||
/* Enable once we need support for downloading depedencies
|
||||
res, _ := s.ReadPlugin(pluginFolder, pluginName)
|
||||
|
||||
@@ -3,6 +3,7 @@ package commands
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/fatih/color"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
|
||||
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
|
||||
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
||||
@@ -42,7 +43,7 @@ func lsCommand(c CommandLine) error {
|
||||
}
|
||||
|
||||
for _, plugin := range plugins {
|
||||
log.Infof("%s @ %s \n", plugin.Id, plugin.Info.Version)
|
||||
log.Infof("%s %s %s \n", plugin.Id, color.YellowString("@"), plugin.Info.Version)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -3,9 +3,9 @@ package plugins
|
||||
import (
|
||||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
@@ -14,10 +14,9 @@ type FrontendPluginBase struct {
|
||||
}
|
||||
|
||||
func (fp *FrontendPluginBase) initFrontendPlugin() {
|
||||
if fp.StaticRoot != "" {
|
||||
fp.StaticRootAbs = filepath.Join(fp.PluginDir, fp.StaticRoot)
|
||||
if isInternalPlugin(fp.PluginDir) {
|
||||
StaticRoutes = append(StaticRoutes, &PluginStaticRoute{
|
||||
Directory: fp.StaticRootAbs,
|
||||
Directory: fp.PluginDir,
|
||||
PluginId: fp.Id,
|
||||
})
|
||||
}
|
||||
@@ -41,7 +40,7 @@ func getPluginLogoUrl(path, baseUrl string) string {
|
||||
}
|
||||
|
||||
func (fp *FrontendPluginBase) setPathsBasedOnApp(app *AppPlugin) {
|
||||
appSubPath := strings.Replace(fp.PluginDir, app.StaticRootAbs, "", 1)
|
||||
appSubPath := strings.Replace(fp.PluginDir, app.PluginDir, "", 1)
|
||||
fp.IncludedInAppId = app.Id
|
||||
fp.BaseUrl = app.BaseUrl
|
||||
fp.Module = util.JoinUrlFragments("plugins/"+app.Id, appSubPath) + "/module"
|
||||
@@ -49,7 +48,7 @@ func (fp *FrontendPluginBase) setPathsBasedOnApp(app *AppPlugin) {
|
||||
|
||||
func (fp *FrontendPluginBase) handleModuleDefaults() {
|
||||
|
||||
if fp.StaticRoot != "" {
|
||||
if isInternalPlugin(fp.PluginDir) {
|
||||
fp.Module = path.Join("plugins", fp.Id, "module")
|
||||
fp.BaseUrl = path.Join("public/plugins", fp.Id)
|
||||
return
|
||||
@@ -59,6 +58,10 @@ func (fp *FrontendPluginBase) handleModuleDefaults() {
|
||||
fp.BaseUrl = path.Join("public/app/plugins", fp.Type, fp.Id)
|
||||
}
|
||||
|
||||
func isInternalPlugin(pluginDir string) bool {
|
||||
return !strings.Contains(pluginDir, setting.StaticRootPath)
|
||||
}
|
||||
|
||||
func evalRelativePluginUrlPath(pathStr string, baseUrl string) string {
|
||||
if pathStr == "" {
|
||||
return ""
|
||||
|
||||
+8
-10
@@ -30,16 +30,14 @@ type PluginLoader interface {
|
||||
}
|
||||
|
||||
type PluginBase struct {
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Id string `json:"id"`
|
||||
Info PluginInfo `json:"info"`
|
||||
Dependencies PluginDependencies `json:"dependencies"`
|
||||
Includes []*PluginInclude `json:"includes"`
|
||||
Module string `json:"module"`
|
||||
BaseUrl string `json:"baseUrl"`
|
||||
StaticRoot string `json:"staticRoot"`
|
||||
StaticRootAbs string `json:"-"`
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Id string `json:"id"`
|
||||
Info PluginInfo `json:"info"`
|
||||
Dependencies PluginDependencies `json:"dependencies"`
|
||||
Includes []*PluginInclude `json:"includes"`
|
||||
Module string `json:"module"`
|
||||
BaseUrl string `json:"baseUrl"`
|
||||
|
||||
IncludedInAppId string `json:"-"`
|
||||
PluginDir string `json:"-"`
|
||||
|
||||
@@ -69,6 +69,7 @@ func AddDataSource(cmd *m.AddDataSourceCommand) error {
|
||||
BasicAuth: cmd.BasicAuth,
|
||||
BasicAuthUser: cmd.BasicAuthUser,
|
||||
BasicAuthPassword: cmd.BasicAuthPassword,
|
||||
WithCredentials: cmd.WithCredentials,
|
||||
JsonData: cmd.JsonData,
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
|
||||
Reference in New Issue
Block a user