diff --git a/api/apps.go b/api/apps.go index bb980a06..cf6c4f57 100644 --- a/api/apps.go +++ b/api/apps.go @@ -10,6 +10,7 @@ import ( "github.com/gorilla/context" "net/http" "reflect" + "sort" "strings" ) @@ -80,13 +81,10 @@ func appMiddleware(next http.Handler) http.Handler { } func getApps(w http.ResponseWriter, r *http.Request) { + type app struct { - ID string `json:"id"` - Title string `json:"title"` - Icon string `json:"icon"` - Color string `json:"color"` - DarkColor string `json:"dark_color"` - Active bool `json:"active"` + util.App + ID string `json:"id"` } apps := make([]app, 0) @@ -94,15 +92,15 @@ func getApps(w http.ResponseWriter, r *http.Request) { for k, a := range util.Config.Apps { apps = append(apps, app{ - ID: k, - Title: a.Title, - Icon: a.Icon, - Color: a.Color, - DarkColor: a.DarkColor, - Active: a.Active, + App: a, + ID: k, }) } + sort.Slice(apps, func(i, j int) bool { + return apps[i].Priority > apps[j].Priority + }) + helpers.WriteJSON(w, http.StatusOK, apps) } diff --git a/db_lib/ShellApp.go b/db_lib/ShellApp.go index c521a16e..ac32d3b3 100644 --- a/db_lib/ShellApp.go +++ b/db_lib/ShellApp.go @@ -91,15 +91,16 @@ func (t *ShellApp) makeShellCmd(args []string, environmentVars *[]string) *exec. command = "powershell" appArgs = []string{"-File"} default: + command = string(t.App) } - if app, ok := util.Config.Apps[string(t.App)]; ok && app.AppPath != "" { - command = app.AppPath + if app, ok := util.Config.Apps[string(t.App)]; ok { + if app.AppPath != "" { + command = app.AppPath + } if app.AppArgs != nil { appArgs = app.AppArgs } - } else { - command = string(t.App) } return t.makeCmd(command, append(appArgs, args...), environmentVars) diff --git a/util/App.go b/util/App.go index b7e20478..10608053 100644 --- a/util/App.go +++ b/util/App.go @@ -2,7 +2,7 @@ package util type App struct { Active bool `json:"active"` - Order int `json:"order"` + Priority int `json:"priority"` Title string `json:"title"` Icon string `json:"icon"` Color string `json:"color"` diff --git a/util/config.go b/util/config.go index a226acd4..5c6e9d34 100644 --- a/util/config.go +++ b/util/config.go @@ -252,14 +252,7 @@ func ConfigInit(configPath string) { fmt.Println("Loading config") Config = &ConfigType{} - Config.Apps = map[string]App{ - "ansible": {}, - "terraform": {}, - "tofu": {}, - "bash": {}, - "powershell": {}, - "python": {}, - } + Config.Apps = map[string]App{} loadConfigFile(configPath) loadConfigEnvironment() @@ -811,16 +804,26 @@ func (conf *ConfigType) GenerateSecrets() { conf.AccessKeyEncryption = base64.StdEncoding.EncodeToString(accessKeyEncryption) } -func LookupDefaultApps() { - appCommands := map[string]string{ - "ansible": "ansible-playbook", - "terraform": "terraform", - "tofu": "tofu", - "bash": "bash", - } +var appCommands = map[string]string{ + "ansible": "ansible-playbook", + "terraform": "terraform", + "tofu": "tofu", + "bash": "bash", +} - for app, cmd := range appCommands { - if _, ok := Config.Apps[app]; ok { +var appPriorities = map[string]int{ + "ansible": 1000, + "terraform": 900, + "tofu": 800, + "bash": 700, + "powershell": 600, + "python": 500, +} + +func LookupDefaultApps() { + + for appID, cmd := range appCommands { + if _, ok := Config.Apps[appID]; ok { continue } @@ -834,10 +837,18 @@ func LookupDefaultApps() { Config.Apps = make(map[string]App) } - Config.Apps[app] = App{ + Config.Apps[appID] = App{ Active: true, } } + + for k, v := range appPriorities { + app, _ := Config.Apps[k] + if app.Priority <= 0 { + app.Priority = v + } + Config.Apps[k] = app + } } func PrintDebug() { diff --git a/web/src/components/AppForm.vue b/web/src/components/AppForm.vue index ed262547..79dd47e8 100644 --- a/web/src/components/AppForm.vue +++ b/web/src/components/AppForm.vue @@ -23,27 +23,28 @@ + +