Skip to content

Commit

Permalink
feat(apps): add priority
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Jul 22, 2024
1 parent 83b8aad commit de0eda9
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 53 deletions.
22 changes: 10 additions & 12 deletions api/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/gorilla/context"
"net/http"
"reflect"
"sort"
"strings"
)

Expand Down Expand Up @@ -80,29 +81,26 @@ 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)

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

Expand Down
9 changes: 5 additions & 4 deletions db_lib/ShellApp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion util/App.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
45 changes: 28 additions & 17 deletions util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -811,16 +804,26 @@ func (conf *ConfigType) GenerateSecrets() {
conf.AccessKeyEncryption = base64.StdEncoding.EncodeToString(accessKeyEncryption)
}

var appCommands = map[string]string{
"ansible": "ansible-playbook",
"terraform": "terraform",
"tofu": "tofu",
"bash": "bash",
}

var appPriorities = map[string]int{
"ansible": 1000,
"terraform": 900,
"tofu": 800,
"bash": 700,
"powershell": 600,
"python": 500,
}

func LookupDefaultApps() {
appCommands := map[string]string{
"ansible": "ansible-playbook",
"terraform": "terraform",
"tofu": "tofu",
"bash": "bash",
}

for app, cmd := range appCommands {
if _, ok := Config.Apps[app]; ok {
for appID, cmd := range appCommands {
if _, ok := Config.Apps[appID]; ok {
continue
}

Expand All @@ -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() {
Expand Down
13 changes: 7 additions & 6 deletions web/src/components/AppForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions web/src/components/AppsMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 8 additions & 0 deletions web/src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand Down
1 change: 0 additions & 1 deletion web/src/views/Apps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
</v-btn>

<v-btn
v-if="!isDefaultApp(item.id)"
icon
class="mr-1"
@click="editItem(item.id)"
Expand Down

0 comments on commit de0eda9

Please sign in to comment.