Create contacts & members pages
This commit is contained in:
parent
fa0e917d34
commit
1d6ae9223e
4 changed files with 168 additions and 0 deletions
34
controllers/contacts.go
Normal file
34
controllers/contacts.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.readonly.ch/bouzoure/pop-camarades/helpers"
|
||||
"git.readonly.ch/bouzoure/pop-camarades/models"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func Contacts(c *fiber.Ctx) error {
|
||||
db, err := helpers.GetDatabase()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var people []models.Person
|
||||
result := db.Order(
|
||||
"last_name collate nocase asc, first_name collate nocase asc",
|
||||
).Preload("Section").Find(
|
||||
&people, "is_contact = ?", true,
|
||||
)
|
||||
|
||||
if result.Error != nil && !errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Render("people", fiber.Map{
|
||||
"PageTitle": "Contacts",
|
||||
"MembersPage": false,
|
||||
"People": people,
|
||||
})
|
||||
}
|
||||
34
controllers/members.go
Normal file
34
controllers/members.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.readonly.ch/bouzoure/pop-camarades/helpers"
|
||||
"git.readonly.ch/bouzoure/pop-camarades/models"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func Members(c *fiber.Ctx) error {
|
||||
db, err := helpers.GetDatabase()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var people []models.Person
|
||||
result := db.Order(
|
||||
"last_name collate nocase asc, first_name collate nocase asc",
|
||||
).Preload("Section").Find(
|
||||
&people, "is_member = ?", true,
|
||||
)
|
||||
|
||||
if result.Error != nil && !errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Render("people", fiber.Map{
|
||||
"PageTitle": "Membres",
|
||||
"MembersPage": true,
|
||||
"People": people,
|
||||
})
|
||||
}
|
||||
6
main.go
6
main.go
|
|
@ -116,6 +116,12 @@ func main() {
|
|||
app.Get("/totp/verify", controllers.TotpVerifyPage)
|
||||
app.Post("/totp/verify", controllers.TotpVerifyPage)
|
||||
|
||||
// Members
|
||||
app.Get("/members", controllers.Members)
|
||||
|
||||
// Contacts
|
||||
app.Get("/contacts", controllers.Contacts)
|
||||
|
||||
// Account manage
|
||||
app.Get("/account/manage", controllers.AccountManage)
|
||||
app.Post("/account/manage", controllers.AccountManage)
|
||||
|
|
|
|||
94
views/people.html
Normal file
94
views/people.html
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
{% extends "layouts/main.html" %}
|
||||
|
||||
{% block main %}
|
||||
<div class="container mt-4">
|
||||
<div class="mb-4">
|
||||
<nav>
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/">Accueil</a></li>
|
||||
|
||||
{% if MembersPage %}
|
||||
<li class="breadcrumb-item active">Membres</li>
|
||||
{% else %}
|
||||
<li class="breadcrumb-item active">Contacts</li>
|
||||
{% endif %}
|
||||
|
||||
</ol>
|
||||
</nav>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
{% if People %}
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nom</th>
|
||||
<th>Prénom</th>
|
||||
<th>Lieu</th>
|
||||
<th>Section</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for Person in People %}
|
||||
<tr>
|
||||
<td>
|
||||
{% if Person.IsMember %}
|
||||
<a href="/member/{{ Person.ID }}">
|
||||
{{ Person.LastName }}
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="/contact/{{ Person.ID }}">
|
||||
{{ Person.LastName }}
|
||||
</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if Person.IsMember %}
|
||||
<a href="/member/{{ Person.ID }}">
|
||||
{{ Person.FirstName }}
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="/contact/{{ Person.ID }}">
|
||||
{{ Person.FirstName }}
|
||||
</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{{ Person.PostalCode }} {{ Person.City }}
|
||||
</td>
|
||||
<td>
|
||||
{% if Person.SectionID %}
|
||||
{{ Section.Section.Name }}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="my-4">
|
||||
{% if MembersPage %}
|
||||
Pas de membre pour le moment
|
||||
{% else %}
|
||||
Pas de contact pour le moment
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="mt-3">
|
||||
{% if MembersPage %}
|
||||
<a class="btn btn-md btn-primary" href="/members/add">
|
||||
<i class="bi-plus-lg"></i>
|
||||
Ajouter
|
||||
</a>
|
||||
{% else %}
|
||||
<a class="btn btn-md btn-primary" href="/contacts/add">
|
||||
<i class="bi-plus-lg"></i>
|
||||
Ajouter
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue