feat(apps): add priority

This commit is contained in:
fiftin 2024-07-22 16:51:29 +05:00
parent 83b8aad3e2
commit de0eda9fb9
No known key found for this signature in database
GPG Key ID: 044381366A5D4731
8 changed files with 72 additions and 54 deletions

View File

@ -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)
}

View File

@ -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)

View File

@ -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"`

View File

@ -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() {

View File

@ -23,27 +23,28 @@
<v-text-field
v-model="item.icon"
:label="$t('Icon')"
:rules="[v => !!v || $t('icon_required')]"
required
:disabled="formSaving"
></v-text-field>
<v-text-field
v-model="item.title"
:label="$t('name')"
:rules="[v => !!v || $t('name_required')]"
required
:disabled="formSaving"
></v-text-field>
<v-text-field
v-model="item.path"
:label="$t('Path')"
:rules="[v => !!v || $t('path_required')]"
required
:disabled="formSaving"
></v-text-field>
<v-text-field
type="number"
v-model.number="item.priority"
:label="$t('Priority')"
:disabled="formSaving"
></v-text-field>
<ArgsPicker style="margin-top: -10px;" :vars="item.args" @change="setArgs"/>
<v-checkbox

View File

@ -38,36 +38,36 @@ export default {
},
getAppColor(id) {
if (APP_ICONS[id]) {
return this.$vuetify.theme.dark ? APP_ICONS[id].darkColor : APP_ICONS[id].color;
if (this.appsMixin.apps[id]?.color) {
return this.appsMixin.apps[id].color || 'gray';
}
if (this.appsMixin.apps[id]) {
return this.appsMixin.apps[id].color || 'gray';
if (APP_ICONS[id]) {
return this.$vuetify.theme.dark ? APP_ICONS[id].darkColor : APP_ICONS[id].color;
}
return 'gray';
},
getAppTitle(id) {
if (APP_TITLE[id]) {
return APP_TITLE[id];
if (this.appsMixin.apps[id]?.title) {
return this.appsMixin.apps[id].title;
}
if (this.appsMixin.apps[id]) {
return this.appsMixin.apps[id].title;
if (APP_TITLE[id]) {
return APP_TITLE[id];
}
return '';
},
getAppIcon(id) {
if (APP_ICONS[id]) {
return APP_ICONS[id].icon;
if (this.appsMixin.apps[id]?.icon) {
return `mdi-${this.appsMixin.apps[id].icon}`;
}
if (this.appsMixin.apps[id]) {
return `mdi-${this.appsMixin.apps[id].icon}`;
if (APP_ICONS[id]) {
return APP_ICONS[id].icon;
}
return 'mdi-help';

View File

@ -99,6 +99,12 @@ export const APP_ICONS = {
color: 'black',
darkColor: 'white',
},
python: {
icon: 'mdi-language-python',
},
powershell: {
icon: 'mdi-powershell',
},
};
export const APP_TITLE = {
@ -107,6 +113,8 @@ export const APP_TITLE = {
tofu: 'OpenTofu Code',
bash: 'Bash Script',
pulumi: 'Pulumi Code',
python: 'Python Script',
powershell: 'PowerShell Script',
};
export const APP_INVENTORY_TITLE = {

View File

@ -85,7 +85,6 @@
</v-btn>
<v-btn
v-if="!isDefaultApp(item.id)"
icon
class="mr-1"
@click="editItem(item.id)"