feat(apps): delete apps

This commit is contained in:
Denis Gukov 2024-07-09 15:37:47 +05:00
parent 3fe1e91651
commit 15991dc411
7 changed files with 61 additions and 15 deletions

View File

@ -129,6 +129,8 @@ func deleteApp(w http.ResponseWriter, r *http.Request) {
return return
} }
delete(util.Config.Apps, appID)
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
} }

View File

@ -131,7 +131,7 @@ func Route() *mux.Router {
appsAPI := adminAPI.PathPrefix("/apps").Subrouter() appsAPI := adminAPI.PathPrefix("/apps").Subrouter()
appsAPI.Use(appMiddleware) appsAPI.Use(appMiddleware)
appsAPI.Path("/{app_id}").HandlerFunc(getApp).Methods("GET", "HEAD") appsAPI.Path("/{app_id}").HandlerFunc(getApp).Methods("GET", "HEAD")
appsAPI.Path("/{app_id}").HandlerFunc(setApp).Methods("PUT") appsAPI.Path("/{app_id}").HandlerFunc(setApp).Methods("PUT", "POST")
appsAPI.Path("/{app_id}/active").HandlerFunc(setAppActive).Methods("POST") appsAPI.Path("/{app_id}/active").HandlerFunc(setAppActive).Methods("POST")
appsAPI.Path("/{app_id}").HandlerFunc(deleteApp).Methods("DELETE") appsAPI.Path("/{app_id}").HandlerFunc(deleteApp).Methods("DELETE")

View File

@ -11,7 +11,7 @@ type Option struct {
} }
func ValidateOptionKey(key string) error { func ValidateOptionKey(key string) error {
m, err := regexp.Match(`^(?:\w.)+$`, []byte(key)) m, err := regexp.Match(`^[\w.]+$`, []byte(key))
if err != nil { if err != nil {
return err return err
} }

View File

@ -81,5 +81,19 @@ func (d *BoltDb) DeleteOptions(filter string) (err error) {
return return
} }
var options []db.Option
err = d.getObjects(0, db.OptionProps, db.RetrieveQueryParams{}, func(i interface{}) bool {
opt := i.(db.Option)
return opt.Key == filter || strings.HasPrefix(opt.Key, filter+".")
}, &options)
for _, opt := range options {
err = d.DeleteOption(opt.Key)
if err != nil {
return
}
}
return return
} }

View File

@ -398,6 +398,18 @@ func CastValueToKind(value interface{}, kind reflect.Kind) (res interface{}, ok
res = value res = value
switch kind { switch kind {
case reflect.Slice:
if reflect.ValueOf(value).Kind() == reflect.String {
var arr []string
err := json.Unmarshal([]byte(value.(string)), &arr)
if err != nil {
panic(err)
}
res = arr
ok = true
}
case reflect.String:
ok = true
case reflect.Int: case reflect.Int:
if reflect.ValueOf(value).Kind() != reflect.Int { if reflect.ValueOf(value).Kind() != reflect.Int {
res = castStringToInt(fmt.Sprintf("%v", reflect.ValueOf(value))) res = castStringToInt(fmt.Sprintf("%v", reflect.ValueOf(value)))
@ -418,6 +430,7 @@ func CastValueToKind(value interface{}, kind reflect.Kind) (res interface{}, ok
res = mapValue res = mapValue
ok = true ok = true
} }
default:
} }
return return

View File

@ -48,31 +48,37 @@ import ItemFormBase from '@/components/ItemFormBase';
export default { export default {
mixins: [ItemFormBase], mixins: [ItemFormBase],
watch: {
itemId(val) {
this.id = val;
},
},
created() {
this.id = this.itemId;
},
computed: { computed: {
isNew() { isNew() {
return false; return this.itemId === '';
}, },
}, },
data() { data() {
return { return {
id: '', id: null,
}; };
}, },
watch: {
itemId() {
this.id = this.itemId;
},
},
methods: { methods: {
beforeLoadData() {
if (!this.isNew) {
this.id = this.itemId;
}
},
afterReset() {
this.id = null;
},
getItemsUrl() { getItemsUrl() {
return '/api/apps'; return `/api/apps/${this.id}`;
}, },
getSingleItemUrl() { getSingleItemUrl() {

View File

@ -69,6 +69,7 @@ export default {
if (this.$refs.form) { if (this.$refs.form) {
this.$refs.form.resetValidation(); this.$refs.form.resetValidation();
} }
await this.afterReset();
await this.loadData(); await this.loadData();
}, },
@ -84,10 +85,18 @@ export default {
}, },
afterReset() {
},
afterSave() { afterSave() {
}, },
beforeLoadData() {
},
afterLoadData() { afterLoadData() {
}, },
@ -97,6 +106,8 @@ export default {
}, },
async loadData() { async loadData() {
await this.beforeLoadData();
if (this.isNew) { if (this.isNew) {
this.item = this.getNewItem(); this.item = this.getNewItem();
} else { } else {