Improve main and admin menus
This commit is contained in:
parent
64d069ddaa
commit
ff2bb2d443
3 changed files with 182 additions and 53 deletions
|
|
@ -1,15 +1,82 @@
|
|||
package controllers
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
import (
|
||||
"git.readonly.ch/bouzoure/pop-camarades/helpers"
|
||||
"git.readonly.ch/bouzoure/pop-camarades/models"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func Homepage(c *fiber.Ctx) error {
|
||||
userid, err := helpers.GetSessionUserId(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
allowedSectionsMembers, err := helpers.PermissionsGetSections(
|
||||
userid, "show_member",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
allowedSectionsContacts, err := helpers.PermissionsGetSections(
|
||||
userid, "show_contact",
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
db, err := helpers.GetDatabase()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var membersCount int64
|
||||
var contactsCount int64
|
||||
|
||||
db.Find(
|
||||
&models.Person{},
|
||||
"is_member = ? AND section_id IN ?",
|
||||
true, allowedSectionsMembers,
|
||||
).Count(&membersCount)
|
||||
|
||||
db.Find(
|
||||
&models.Person{},
|
||||
"is_contact = ? AND section_id IN ?",
|
||||
true, allowedSectionsContacts,
|
||||
).Count(&contactsCount)
|
||||
|
||||
return c.Render("index", fiber.Map{
|
||||
"PageTitle": "Accueil",
|
||||
"PageTitle": "Accueil",
|
||||
"MembersCount": membersCount,
|
||||
"ContactsCount": contactsCount,
|
||||
})
|
||||
}
|
||||
|
||||
func Admin(c *fiber.Ctx) error {
|
||||
db, err := helpers.GetDatabase()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var sectionsCount int64
|
||||
var listsCount int64
|
||||
var fieldsCount int64
|
||||
var usersCount int64
|
||||
var rolesCount int64
|
||||
|
||||
db.Find(&models.Section{}).Count(§ionsCount)
|
||||
db.Find(&models.List{}).Count(&listsCount)
|
||||
db.Find(&models.Field{}).Count(&fieldsCount)
|
||||
db.Find(&models.User{}).Count(&usersCount)
|
||||
db.Find(&models.Role{}).Count(&rolesCount)
|
||||
|
||||
return c.Render("admin", fiber.Map{
|
||||
"PageTitle": "Administration",
|
||||
"PageTitle": "Administration",
|
||||
"SectionsCount": sectionsCount,
|
||||
"ListsCount": listsCount,
|
||||
"FieldsCount": fieldsCount,
|
||||
"UsersCount": usersCount,
|
||||
"RolesCount": rolesCount,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue