Skip to content

Commit

Permalink
partie admin onglets utilisateurs et demandes terminés (reste l'ongle…
Browse files Browse the repository at this point in the history
…t accueil et offres + rediriger vers page candidat et afficher bouton administrer)
  • Loading branch information
darsane21 committed Jun 20, 2023
1 parent 1cf096c commit 1b03e95
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 88 deletions.
35 changes: 30 additions & 5 deletions app/controllers/AdminController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {OffreDePoste} from "../entity/OffreDePoste";
import {UserRepository} from "../repository/UserRepository";
import {User} from "../entity/User";
import {loggedInNoRedirection} from "../passport/passportFunctions";
import {OrganisationRepository} from "../repository/OrganisationRepository";
import {Alert} from "../utils/Alert";
import {OrganisationRepository} from "../repository/OrganisationRepository";
import {Organisation} from "../entity/Organisation";

export class AdminController {
static index(req: express.Request, res: express.Response) {
Expand All @@ -14,8 +15,10 @@ export class AdminController {

static utilisateurs(req: express.Request, res: express.Response) {
UserRepository.getAll().then((users: User[]) => {
console.log(users);
res.render("admin/utilisateurs", { title: "Utilisateurs", users, userLogged: loggedInNoRedirection(req, res)});
OrganisationRepository.getAll().then((organisations : Organisation[]) => {
console.log(users);
res.render("admin/utilisateurs", { title: "Utilisateurs", organisations: organisations, users, userLogged: loggedInNoRedirection(req, res)});
});
});
}

Expand Down Expand Up @@ -70,10 +73,32 @@ export class AdminController {
}
}

static async supprimerUtilisateur(req: express.Request, res: express.Response) {
let email = req.params.email;
const alerts: Alert[] = [];

await UserRepository.supprimerUtilisateur(email).then((user: User) => {
let alert = new Alert("success", "L'utilisateur a bien été supprimé");
alerts.push(alert);
})
.catch((err) => {
let alert = new Alert("danger", "L'utilisateur n'a pas été supprimé");
alerts.push(alert);
console.log(err);
});

UserRepository.getAll().then((users: User[]) => {
res.render("admin/utilisateurs", { title: "Utilisateurs", users, alerts: alerts, userLogged: loggedInNoRedirection(req, res)});
});
}

static demandes(req: express.Request, res: express.Response) {
UserRepository.getRecruiterDemand().then((users: User[]) => {
//console.log(users);
res.render("admin/demandes", {title: "Demandes", users: users, userLogged: loggedInNoRedirection(req, res)});
UserRepository.getOldRecruiterDemand().then((oldUsers: User[]) => {
OrganisationRepository.getAll().then((organisations : Organisation[]) => {
res.render("admin/demandes", {title: "Demandes", users: users, organisations: organisations, oldUsers: oldUsers, userLogged: loggedInNoRedirection(req, res)});
});
});
});
}

Expand Down
47 changes: 41 additions & 6 deletions app/repository/UserRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,52 @@ export class UserRepository {
);
}

delete(id: number): Promise<boolean> {
throw new Error("Method not implemented.");
static supprimerUtilisateur(email:string): Promise<User> {
const query = `DELETE FROM ${UserRepository.tableName}
WHERE email = ?`;
return new Promise<User>(
(resolve, reject) =>
pool.query(query, [email], (err, result) => {
if (err) {
return reject(err);
}
return resolve(result);
}
)
);
}


static getRecruiterDemand(): Promise<[User]> {
const query = `SELECT u.email, u.nom, u.prenom, o.siren, o.nom as organisation, o.type, o.siege
FROM ${UserRepository.tableName} u
INNER JOIN ${OrganisationRepository.tableName} o using (siren)
WHERE u.demande_organisation = 'En cours'`;
WHERE u.demande_organisation = 'En cours'
OR u.demande_organisation = 'refus'
OR u.demande_organisation = 'acceptation'`;
return new Promise<[User]>(
(resolve, reject) =>
pool.query(query, (err, result) => {
if (err) {
return reject(err);
}
if(result[0]){
console.log(result[0]);
let organisation = new Organisation(result[0].siren, result[0].organisation, result[0].type, result[0].siege);
result[0].organisation = organisation;
console.log(result);
}
return resolve(result);
}
)
);
}

static getOldRecruiterDemand(): Promise<[User]> {
const query = `SELECT u.email, u.nom, u.prenom, u.demande_organisation, o.siren, o.nom as organisation, o.type, o.siege
FROM ${UserRepository.tableName} u
INNER JOIN ${OrganisationRepository.tableName} o using (siren)
WHERE u.demande_organisation = 'refus'
OR u.demande_organisation = 'acceptation'`;
return new Promise<[User]>(
(resolve, reject) =>
pool.query(query, (err, result) => {
Expand Down Expand Up @@ -170,8 +206,7 @@ export class UserRepository {
static setDemandRefused(email: string): Promise<[User]> {
const query = `UPDATE ${UserRepository.tableName}
SET demande_organisation = 'refus',
role='Candidat',
siren=null
role='Candidat'
WHERE email = ?`;
return new Promise<[User]>(
(resolve, reject) =>
Expand Down
1 change: 1 addition & 0 deletions app/routes/AdminRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ adminRouter.get("/utilisateurs", AdminController.utilisateurs);
adminRouter.get("/utilisateur/:email", AdminController.utilisateur);
adminRouter.get("/modifierUtilisateur/:email", AdminController.modifierUtilisateur);
adminRouter.post("/modifierUtilisateur/:email", AdminController.modifierUtilisateur);
adminRouter.get("/supprimerUtilisateur/:email", AdminController.supprimerUtilisateur);

adminRouter.get("/demandes", AdminController.demandes);
adminRouter.get("/demande/:email", AdminController.demande);
Expand Down
2 changes: 1 addition & 1 deletion app/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ CREATE TABLE `Utilisateur`
((demande_organisation = 'En cours' OR demande_organisation = 'acceptation' OR role = 'Recruteur') AND
siren IS NOT NULL)
OR
((demande_organisation = 'refus' OR role = 'Administrateur' OR role = 'Candidat') AND siren IS NULL)
((demande_organisation = 'refus' OR role = 'Administrateur' OR role = 'Candidat'))
)
);

Expand Down
182 changes: 113 additions & 69 deletions app/views/admin/demandes.ejs
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demandes</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
crossorigin="anonymous"></script>
</head>
<body>

<%- include('../partials/adminHeader.ejs') %>.

<div class="container col-xxl-8 px-4 py-5">
Expand All @@ -21,66 +8,123 @@
<h5>Entreprise</h5>
<select class="form-select" id="entrepriseFilter">
<option value="">Toutes les entreprises</option>
<option value="Carrefour">Carrefour</option>
<option value="Renault">Renault</option>
<option value="Orpi">Orpi</option>
<% organisations.forEach((organisation) => { %>
<option value="<%= organisation.nom %>"><%= organisation.nom %></option>
<% }) %>
</select>

<table class="table mt-4">
<thead>
<tr>
<th scope="col">id</th>
<th scope="col">Nom</th>
<th scope="col">Prénom</th>
<th scope="col">Entreprise</th>
<th scope="col">Détails</th>
<th scope="col">Statut</th>
</tr>
</thead>
<tbody id="demandesTableBody">
<% users.forEach((user) => { %>
<tr class="demandeRow">
<td><%= user.email %></td>
<td><%= user.nom %></td>
<td><%= user.prenom %></td>
<td><%= user.organisation.nom %></td>
<td>
<a href="/admin/demande/<%= user.email %>" class="btn btn-outline-primary btn-sm">Détails</a>
</td>
<td>
<a href="/admin/refuserDemande/<%= user.email %>" type="button"
class="btn btn-danger btn-sm">Refuser</a>
<a href="/admin/accepterDemande/<%= user.email %>" type="button"
class="btn btn-success btn-sm">Accepter</a>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</div>
</div>

<script>
function filterDemandes() {
const entrepriseFilter = document.querySelector("#entrepriseFilter").value;
<div class="accordion mt-4" id="demandesAccordion">
<div class="accordion-item">
<h2 class="accordion-header" id="nouvellesDemandesHeader">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#nouvellesDemandesCollapse" aria-expanded="true"
aria-controls="nouvellesDemandesCollapse">
Nouvelles demandes
</button>
</h2>
<div id="nouvellesDemandesCollapse" class="accordion-collapse collapse show"
aria-labelledby="nouvellesDemandesHeader" data-bs-parent="#demandesAccordion">
<div class="accordion-body">
<table class="table">
<thead>
<tr>
<th scope="col">id</th>
<th scope="col">Nom</th>
<th scope="col">Prénom</th>
<th scope="col">Entreprise</th>
<th scope="col">Détails</th>
<th scope="col">Statut</th>
</tr>
</thead>
<tbody id="demandesTableBody">
<% users.forEach((user) => { %>
<tr class="demandeRow">
<td><%= user.email %></td>
<td><%= user.nom %></td>
<td><%= user.prenom %></td>
<td><%= user.organisation.nom %></td>
<td>
<a href="/admin/demande/<%= user.email %>"
class="btn btn-outline-primary btn-sm">Détails</a>
</td>
<td>
<a href="/admin/refuserDemande/<%= user.email %>" type="button"
class="btn btn-danger btn-sm">Refuser</a>
<a href="/admin/accepterDemande/<%= user.email %>" type="button"
class="btn btn-success btn-sm">Accepter</a>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="anciennesDemandesHeader">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#anciennesDemandesCollapse" aria-expanded="false"
aria-controls="anciennesDemandesCollapse">
Anciennes demandes
</button>
</h2>
<div id="anciennesDemandesCollapse" class="accordion-collapse collapse"
aria-labelledby="anciennesDemandesHeader" data-bs-parent="#demandesAccordion">
<div class="accordion-body">
<table class="table">
<thead>
<tr>
<th scope="col">id</th>
<th scope="col">Nom</th>
<th scope="col">Prénom</th>
<th scope="col">Entreprise</th>
<th scope="col">Détails</th>
<th scope="col">Statut</th>
</tr>
</thead>
<tbody id="oldDemandesTableBody">
<% oldUsers.forEach((user) => { %>
<tr class="demandeRow">
<td><%= user.email %></td>
<td><%= user.nom %></td>
<td><%= user.prenom %></td>
<td><%= user.organisation.nom %></td>
<td>
<a href="/admin/demande/<%= user.email %>"
class="btn btn-outline-primary btn-sm">Détails</a>
</td>
<td class="<%= user.demande_organisation === 'acceptation' ? 'text-success' : (user.demande_organisation === 'refus' ? 'text-danger' : '') %>">
<%= user.demande_organisation === 'acceptation' ? 'Accepté' : (user.demande_organisation === 'refus' ? 'Refusé' : '') %>
</td>
</tr>
<% }) %>
</tbody>
</table>
</div>
</div>
</div>
</div>

const demandeRows = document.querySelectorAll(".demandeRow");
demandeRows.forEach((row) => {
const entrepriseCell = row.querySelector("td:nth-child(4)");
const entrepriseValue = entrepriseCell.textContent.trim();
<script>
function filterDemandes() {
const entrepriseFilter = document.querySelector("#entrepriseFilter").value;
const shouldShowRow = (
entrepriseFilter === "" || entrepriseValue === entrepriseFilter
);
const demandeRows = document.querySelectorAll(".demandeRow");
demandeRows.forEach((row) => {
const entrepriseCell = row.querySelector("td:nth-child(4)");
const entrepriseValue = entrepriseCell.textContent.trim();
row.style.display = shouldShowRow ? "table-row" : "none";
});
}
const shouldShowRow = (
entrepriseFilter === "" || entrepriseValue === entrepriseFilter
);
const entrepriseFilter = document.querySelector("#entrepriseFilter");
entrepriseFilter.addEventListener("change", filterDemandes);
</script>
row.style.display = shouldShowRow ? "table-row" : "none";
});
}
</body>
</html>
const entrepriseFilter = document.querySelector("#entrepriseFilter");
entrepriseFilter.addEventListener("change", filterDemandes);
</script>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/admin/modifierUtilisateur.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

<div class="col-md-4">
<label for="state" class="form-label fw-bold">Demande à rejoindre une organisation</label>
<input type="text" class="form-control" name="demande_organisation" value="<%= user.demande_organisation ? user.demande_organisation : 'Aucune' %>" readonly>
<input type="text" class="form-control bg-light" name="demande_organisation" value="<%= user.demande_organisation ? user.demande_organisation : 'Aucune' %>" readonly>
</div>
</div>

Expand Down Expand Up @@ -86,7 +86,7 @@
<hr class="my-4">

<div class="d-flex gap-2 justify-content-center py-2">
<a href="/admin/utilisateurs" class="btn btn-primary">Retour</a>
<a href="/admin/utilisateur/<%= user.email %>" class="btn btn-primary">Retour</a>
<button type="submit" class="btn btn-warning">Valider la modification</button>
</div>
</form>
Expand Down
19 changes: 18 additions & 1 deletion app/views/admin/utilisateur.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,29 @@
<div class="d-flex gap-2 justify-content-center py-2">
<a href="/admin/utilisateurs" class="btn btn-primary">Retour</a>
<a href="/admin/modifierUtilisateur/<%= user.email %>" class="btn btn-warning">Modifier</a>
<a href="/admin/supprimerUtilisateur/<%= user.email %>" class="btn btn-danger">Supprimer</a>
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#confirmDeleteModal">Supprimer</button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" id="confirmDeleteModal" tabindex="-1" aria-labelledby="confirmDeleteModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="confirmDeleteModalLabel">Confirmation de suppression</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Êtes-vous sûr de vouloir supprimer cet utilisateur ?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Annuler</button>
<a href="/admin/supprimerUtilisateur/<%= user.email %>" class="btn btn-danger">Supprimer</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Loading

0 comments on commit 1b03e95

Please sign in to comment.