feat(apps): minor progress on app meta data

This commit is contained in:
Torkel Ödegaard
2015-12-22 16:32:17 +01:00
parent d1145ed3fb
commit 41a0995db7
7 changed files with 43 additions and 28 deletions
+17 -22
View File
@@ -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))
}
}
+1
View File
@@ -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"`