add types of group

This commit is contained in:
soukainna 2022-11-08 16:49:42 +01:00
parent 556f8a24c0
commit 6364056ae1
4 changed files with 38 additions and 4 deletions

View File

@ -69,11 +69,18 @@ func (h *ApplicationHandler) CreateGroupModule(w http.ResponseWriter, r *http.Re
w.WriteHeader(http.StatusBadRequest)
return
}
if r.FormValue("type") == "" {
fmt.Println("invalid type")
w.WriteHeader(http.StatusBadRequest)
return
}
groupid := uuid.NewString()
dataMap := map[string]any{
"name": r.FormValue("name"),
"type": r.FormValue("type"),
}
data, err := structpb.NewValue(dataMap)
@ -101,7 +108,8 @@ func (h *ApplicationHandler) CreateGroupModule(w http.ResponseWriter, r *http.Re
http.Redirect(w, r, fmt.Sprintf("/app/group_module/groups/%s", groupid), http.StatusFound)
return
}
h.Renderer.CreateGroupModule(w, r)
group_types := h.config.GetStringSlice("modules.groups.group_types")
h.Renderer.CreateGroupModule(w, r, group_types)
}
func filterAcccount(r *http.Request, a *mobilityaccounts.Account) bool {

View File

@ -38,10 +38,12 @@ func (renderer *Renderer) Groups(w http.ResponseWriter, r *http.Request, groups
renderer.Render("group_module", w, r, files, state)
}
func (renderer *Renderer) CreateGroupModule(w http.ResponseWriter, r *http.Request) {
func (renderer *Renderer) CreateGroupModule(w http.ResponseWriter, r *http.Request, group_types []string) {
files := renderer.ThemeConfig.GetStringSlice("views.group_module.create_group.files")
state := NewState(r, renderer.ThemeConfig, groupMenu)
state.ViewState = map[string]any{
"group_types": group_types,
}
renderer.Render("group_module", w, r, files, state)
}

View File

@ -8,14 +8,17 @@
<div class="max-w-7xl mx-auto px-4 sm:px-6 md:px-8 mt-8" x-data="{
fields: {
name: null,
type: null,
},
rules: {
name: ['required'],
type: ['required'],
},
formValidation: {
valid: false,
fields: {
name: {valid: null},
type: {valid: null},
}
},
isFormValid: true,
@ -33,6 +36,7 @@
}
return this.formValidation.valid
}
}">
<form class="space-y-6" method="POST" @submit="submit">
<div class="bg-white shadow px-4 py-5 sm:rounded-lg sm:p-6">
@ -43,16 +47,30 @@
</div>
<div class="mt-5 md:mt-0 md:col-span-2">
<div class="grid grid-cols-6 gap-6">
<div class="col-span-6">
<div class="col-span-5">
<label for="name" class="block text-sm font-medium text-gray-700">Nom de groupe</label>
<input type="text" name="name" id="name"
class="mt-1 focus:ring-co-blue focus:border-co-blue block w-full shadow-sm sm:text-sm rounded-2xl"
x-model="fields.name" @blur="validateField('name')"
:class="formValidation.fields.name.valid == false ? 'border-co-red border-2' : 'border-gray-300'">
</div>
<div class="col-span-3">
<label for="type" class="block text-sm font-medium text-gray-700">Type de groupe</label>
<select id="type" name="type"
x-model="fields.type" @blur="validateField('type')"
class="max-w-lg mt-1 block focus:ring-co-blue focus:border-co-blue w-full shadow-sm sm:max-w-xs sm:text-sm rounded-2xl"
:class="formValidation.fields.type.valid == false ? 'border-co-red border-2' : 'border-gray-300'">
<option value="" selected></option>
{{range .ViewState.group_types}}
<option value="{{.}}">{{.}}</option>
{{end}}
</select>
</div>
</div>
</div>
</div>
</div>
<div class="flex justify-end">
<a href="/app/group_module/">
@ -63,5 +81,6 @@
class="ml-3 inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-2xl text-white bg-co-blue hover:bg-co-blue focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-co-blue">Créer le groupe</button>
</div>
</form>
</div>
{{end}}

View File

@ -21,6 +21,11 @@
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
{{.ViewState.group.Data.name}}</dd>
</div>
<div class="py-4 sm:py-5 sm:grid sm:grid-cols-3 sm:gap-4">
<dt class="text-sm font-medium text-gray-500">Type</dt>
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
{{.ViewState.group.Data.type}}</dd>
</div>
</dl>
</div>
</div>