misc
This commit is contained in:
@@ -7,11 +7,22 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.dynamicdiscord.de/malobeo/portal/openapi"
|
||||
"git.dynamicdiscord.de/malobeo/portal/services"
|
||||
)
|
||||
|
||||
type AccessAuthController struct{}
|
||||
|
||||
type GroupWrapper struct {
|
||||
Name string
|
||||
Id int32
|
||||
}
|
||||
|
||||
type AccessAuthWithGroup struct {
|
||||
AccessAuth openapi.AccessAuthorizationResponse
|
||||
Groups []GroupWrapper
|
||||
}
|
||||
|
||||
func (gc *AccessAuthController) AccessAuthView(c *gin.Context) {
|
||||
accessAuths, err := services.AccessAuths.GetAll(c)
|
||||
|
||||
@@ -19,8 +30,32 @@ func (gc *AccessAuthController) AccessAuthView(c *gin.Context) {
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"data": gin.H{"error": err}})
|
||||
}
|
||||
|
||||
aaWrapper := []AccessAuthWithGroup{}
|
||||
for _, accessAuth := range accessAuths {
|
||||
|
||||
groupWrapper := []GroupWrapper{}
|
||||
for _, group := range accessAuth.Groups {
|
||||
groupWrapper = append(groupWrapper, GroupWrapper{
|
||||
Name: group.Name,
|
||||
Id: *group.Id.Get(),
|
||||
})
|
||||
|
||||
}
|
||||
aaWrapper = append(aaWrapper, AccessAuthWithGroup{
|
||||
AccessAuth: accessAuth,
|
||||
Groups: groupWrapper,
|
||||
})
|
||||
}
|
||||
|
||||
groups, err := services.Groups.GetAll(c)
|
||||
|
||||
if err != nil {
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"data": gin.H{"error": err}})
|
||||
}
|
||||
|
||||
data := CreateSessionData(c, gin.H{
|
||||
"accessAuths": accessAuths,
|
||||
"accessAuths": aaWrapper,
|
||||
"groups": groups,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@@ -54,6 +89,8 @@ func (gc *AccessAuthController) AddAccessAuthHandler(c *gin.Context) {
|
||||
func (gc *AccessAuthController) AccessAuthHandler(c *gin.Context) {
|
||||
action := c.PostForm("action")
|
||||
idStr := c.Param("id")
|
||||
fmt.Println("AA ID: ")
|
||||
fmt.Println(idStr)
|
||||
id, err := strconv.Atoi(idStr)
|
||||
|
||||
if err != nil {
|
||||
@@ -63,10 +100,12 @@ func (gc *AccessAuthController) AccessAuthHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
if action == "createTimetable" {
|
||||
fmt.Println(c)
|
||||
weekdayStr := c.PostForm("weekday")
|
||||
starttime := c.PostForm("starttime")
|
||||
durationStr := c.PostForm("duration")
|
||||
duration, err := strconv.Atoi(durationStr)
|
||||
fmt.Printf("Creating timetable with %s, %s, %d", weekdayStr, starttime, duration)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
@@ -89,6 +128,70 @@ func (gc *AccessAuthController) AccessAuthHandler(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if action == "addGroups" {
|
||||
fmt.Println("ADD GROUp")
|
||||
groupIds := c.PostFormArray("groups[]")
|
||||
|
||||
for _, groupIdStr := range groupIds {
|
||||
groupId, err := strconv.Atoi(groupIdStr)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
|
||||
err = services.AccessAuths.AddGroup(c, int32(id), int32(groupId))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if action == "removeGroup" {
|
||||
fmt.Println("REMOVE GROUp")
|
||||
fmt.Println(c)
|
||||
groupIdStr := c.PostForm("groupId")
|
||||
fmt.Println(groupIdStr)
|
||||
groupId, err := strconv.Atoi(groupIdStr)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
|
||||
err = services.AccessAuths.RemoveGroup(c, int32(id), int32(groupId))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if action == "activate" {
|
||||
_, err := services.AccessAuths.SetActive(c, int32(id), true)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if action == "deactivate" {
|
||||
_, err := services.AccessAuths.SetActive(c, int32(id), false)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if action == "delete" {
|
||||
err := services.AccessAuths.Delete(c, int32(id))
|
||||
|
||||
|
||||
@@ -62,6 +62,17 @@ func (gc *GroupController) GroupHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if action == "addCard" {
|
||||
cardName := c.PostForm("Name")
|
||||
_, err := services.Cards.Create(c, cardName, int32(id))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if action == "delete" {
|
||||
err := services.Groups.Delete(c, int32(id))
|
||||
|
||||
|
||||
@@ -46,7 +46,14 @@ func (u *AccessAuthService) GetById(c *gin.Context, id int32) (*openapi.AccessAu
|
||||
}
|
||||
|
||||
func (u *AccessAuthService) Create(c *gin.Context, name string) (*openapi.AccessAuthorizationResponse, error) {
|
||||
accessAuthorizationCreate := *openapi.NewAccessAuthorizationCreate(name, false, []openapi.TimetableCreate{})
|
||||
accessAuthorizationCreate := *openapi.NewAccessAuthorizationCreate(name, "timetable", false)
|
||||
accessAuthorizationCreate.Timetables = []openapi.TimetableCreate{
|
||||
{
|
||||
Weekday: 1,
|
||||
Starttime: "11:00",
|
||||
Duration: 30,
|
||||
},
|
||||
}
|
||||
apiClient := internal.GetApiClient(c)
|
||||
|
||||
resp, r, err := apiClient.AccessAuthAPI.AddAccessauthApiV1AaPost(context.Background()).AccessAuthorizationCreate(accessAuthorizationCreate).Execute()
|
||||
@@ -202,3 +209,27 @@ func (u *AccessAuthService) RemoveTimetable(c *gin.Context, accessAuthId int32,
|
||||
fmt.Fprintf(os.Stdout, "Response from `AccessAuthAPI.ChangeAccessauthAaAaIdPatch`: %v\n", resp)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (u *AccessAuthService) AddGroup(c *gin.Context, accessAuthId int32, groupId int32) error {
|
||||
apiClient := internal.GetApiClient(c)
|
||||
_, _, err := apiClient.AccessAuthAPI.AssignAccessauthApiV1AaAssignGroupIdAaIdPut(context.Background(), groupId, accessAuthId).Execute()
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when adding group to AccessAuth: %v\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *AccessAuthService) RemoveGroup(c *gin.Context, accessAuthId int32, groupId int32) error {
|
||||
apiClient := internal.GetApiClient(c)
|
||||
_, _, err := apiClient.AccessAuthAPI.UnassignAccessauthApiV1AaUnassignGroupIdAaIdPut(context.Background(), groupId, accessAuthId).Execute()
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when removing group from AccessAuth: %v\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@ var (
|
||||
type CardService struct{}
|
||||
|
||||
// return jwt tokenstring on success
|
||||
func (u *CardService) Create(c *gin.Context, groupId int32) (*openapi.Card, error) {
|
||||
func (u *CardService) Create(c *gin.Context, name string, groupId int32) (*openapi.Card, error) {
|
||||
apiClient := internal.GetApiClient(c)
|
||||
|
||||
resp, r, err := apiClient.CardAPI.AddCardApiV1CardsGroupIdPost(context.Background(), groupId).Execute()
|
||||
cardCreate := *openapi.NewCardCreate(name, groupId) // CardCreate |
|
||||
resp, r, err := apiClient.CardAPI.AddCardApiV1CardsPost(context.Background()).CardCreate(cardCreate).Execute()
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when calling `CardAPI.CreateCardCardsPost``: %v\n", err)
|
||||
|
||||
@@ -13,13 +13,20 @@
|
||||
<div class="mx-auto grid-cols-1 p-4 m-4 bg-gray-100 flex flex-wrap border rounded shadow-md">
|
||||
<div class="gap-4">
|
||||
<div class="font-bold text-center mb-4">
|
||||
{{ .Name }}<br>
|
||||
{{ .AccessAuth.Name }}<br>
|
||||
{{ if .AccessAuth.IsActive }}
|
||||
<span class="inline-flex items-center rounded-md bg-green-50 px-2 py-1 text-xs font-medium text-green-700
|
||||
ring-1 ring-green-600/20 ring-inset">Active</span>
|
||||
{{ else }}
|
||||
<span class="inline-flex items-center rounded-md bg-red-50 px-2 py-1 text-xs font-medium text-red-700
|
||||
ring-1 ring-red-600/10 ring-inset">Inactive</span>
|
||||
{{ end }}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="grid grid-cols-1 gap-4">
|
||||
<form action="/access/{{ .Id }}" method="POST">
|
||||
<form action="/access/{{ .AccessAuth.Id }}" method="POST">
|
||||
<div class="font-bold text-center mb-4">
|
||||
Add new Timetable Entry
|
||||
</div>
|
||||
@@ -39,7 +46,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<label for="starttime">Select a time:</label>
|
||||
<input type="time" id="starttime" name="appt">
|
||||
<input type="time" id="starttime" name="starttime">
|
||||
</div>
|
||||
<div>
|
||||
<label for="duration" class="block text-sm/6 font-medium text-gray-900">Duration in Minutes</label>
|
||||
@@ -50,24 +57,58 @@
|
||||
text-white text-sm/6 font-bold py-2 px-4 rounded">Add</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{{ range .Timetables }}
|
||||
<form action="/access/{{ .Id }}" method="POST">
|
||||
{{ .Weekday }} - {{ .Starttime }} - {{ .Duration }} -
|
||||
<div>
|
||||
<button type="submit" name="action" value="createTimetable" class="bg-green-500 hover:bg-red-700
|
||||
text-white text-sm/6 font-bold py-2 px-4 rounded">Add</button>
|
||||
{{ range .AccessAuth.Timetables }}
|
||||
<div class="mx-auto p-4 m-4 bg-gray-100 flex flex-wrap border rounded shadow-md">
|
||||
{{ .Weekday }} - {{ .Starttime }} - {{ .Duration }}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<form action="/access/{{ .AccessAuth.Id }}" method="POST">
|
||||
{{ range .Groups }}
|
||||
<div class="mx-auto p-4 m-4 bg-gray-100 flex flex-wrap border rounded shadow-md">
|
||||
{{ .Name }}
|
||||
<input type="hidden" name="groupId" value="{{ .Id }}" required>
|
||||
<div class="grid grid-cols-2 mt-4 flex flex-wrap gap-2 w-full">
|
||||
<button type="submit" name="action" value="removeGroup" class="bg-red-500 hover:bg-red-700 text-white
|
||||
text-sm/6 font-bold py-2 px-4 rounded">Remove Group</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{{ end }}
|
||||
<form action="/access/{{ .Id }}" method="POST">
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="mb-4">
|
||||
<form action="/access/{{ .AccessAuth.Id }}" method="POST">
|
||||
<label class="block text-sm/6 text-gray-900">Add Group</label>
|
||||
<div class="space-y-2">
|
||||
{{ range $.data.groups }}
|
||||
<label class="flex text-sm/6 items-center">
|
||||
<input type="checkbox" class="form-checkbox h-4 w-4 text-gray-900" value="{{ .Id }}" name="groups[]">
|
||||
<span class="ml-2 text-sm/6 text-gray-900">{{ .Name }}</span>
|
||||
</label>
|
||||
{{ end }}
|
||||
</div>
|
||||
<div class="grid grid-cols-2 mt-4 flex flex-wrap gap-2 w-full">
|
||||
<button type="submit" name="delete" value="delete" class="bg-red-500 hover:bg-red-700 text-white text-sm/6 font-bold py-2 px-4 rounded">Delete</button>
|
||||
</div>
|
||||
<button type="submit" name="action" value="addGroups" class="bg-green-500 hover:bg-red-700 text-white
|
||||
text-sm/6 font-bold py-2 px-4 rounded">Add Groups</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
<form action="/access/{{ .AccessAuth.Id }}" method="POST">
|
||||
<div class="grid grid-cols-2 mt-4 flex flex-wrap gap-2 w-full">
|
||||
<button type="submit" name="action" value="activate" class="bg-green-500 hover:bg-red-700 text-white
|
||||
text-sm/6 font-bold py-2 px-4 rounded">Activate</button>
|
||||
<button type="submit" name="action" value="deactivate" class="bg-green-500 hover:bg-red-700 text-white
|
||||
text-sm/6 font-bold py-2 px-4 rounded">Deactivate</button>
|
||||
<button type="submit" name="action" value="delete" class="bg-red-500 hover:bg-red-700 text-white
|
||||
text-sm/6 font-bold py-2 px-4 rounded">Delete</button>
|
||||
<button type="submit" name="action" value="clearTimetable" class="bg-blue-500 hover:bg-red-700 text-white
|
||||
text-sm/6 font-bold py-2 px-4 rounded">Clear (MOCK)</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -86,7 +127,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-4 mt-4 flex flex-wrap gap-2 w-full">
|
||||
<button type="submit" class="bg-green-500 hover:bg-green-700 text-white text-sm/6 font-bold py-2 px-4 rounded">Add</button>
|
||||
<button type="submit" class="bg-green-500 hover:bg-green-700 text-white text-sm/6 font-bold py-2 px-4 rounded">Create</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -20,6 +20,30 @@
|
||||
<label for="variant-value1" class="block text-sm/6 font-medium text-gray-900">Name</label>
|
||||
<input type="text" id="name" name="name" value="{{ .Name }}" class="w-full border border-gray-300 rounded-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
</div>
|
||||
|
||||
<form action="/access/{{ .Id }}" method="POST">
|
||||
{{ range .Cards }}
|
||||
<div class="mx-auto p-4 m-4 bg-gray-100 flex flex-wrap border rounded shadow-md">
|
||||
{{ .Name }} - {{ .CardSerial }}
|
||||
<div class="grid grid-cols-2 mt-4 flex flex-wrap gap-2 w-full">
|
||||
<button type="submit" name="action" value="removeGroup" class="bg-red-500 hover:bg-red-700 text-white
|
||||
text-sm/6 font-bold py-2 px-4 rounded">Remove Card</button>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
</form>
|
||||
|
||||
<div class="mb-4">
|
||||
<form action="/access/{{ .Id }}" method="POST">
|
||||
<label for="variant-value1" class="block text-sm/6 font-medium text-gray-900">Card Name</label>
|
||||
<input type="text" id="name" name="name" placeholder="name" class="w-full border border-gray-300 rounded-md p-2 focus:outline-none focus:ring focus:ring-blue-500">
|
||||
<div class="grid grid-cols-2 mt-4 flex flex-wrap gap-2 w-full">
|
||||
<button type="submit" name="action" value="addCard" class="bg-green-500 hover:bg-red-700 text-white
|
||||
text-sm/6 font-bold py-2 px-4 rounded">Add Card</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="grid grid-cols-2 mt-4 flex flex-wrap gap-2 w-full">
|
||||
<button type="submit" name="action" value="delete" class="bg-red-500 hover:bg-red-700 text-white text-sm/6 font-bold py-2 px-4 rounded">Delete</button>
|
||||
|
||||
Reference in New Issue
Block a user