Compare commits

..

12 Commits

Author SHA1 Message Date
Alessandre Laguierce
53275f6c11 fix: typo in README 2024-12-04 22:12:00 +01:00
damien DELPY
db885f8277
merge : adding more sets for a member. 2024-12-04 21:49:51 +01:00
Martin Eyben
a9faaa351f feat: rename box register 2024-12-04 21:39:43 +00:00
Martin Eyben
1546149b1b fix: creator name for box 2024-12-04 21:30:19 +00:00
Martin Eyben
e7d2a62b4a fix: member template 2024-12-04 21:22:32 +00:00
damien DELPY
48c2a35f93
fix: adding a bit more sets to members. 2024-12-04 21:49:34 +01:00
damien DELPY
3ba2416855
fix: now models fit with sets. 2024-12-04 20:47:31 +01:00
Martin Eyben
30e28ecd11 fix: error when no creator 2024-12-04 18:41:40 +00:00
damien DELPY
f047aff693
fix: data gen almost done. 2024-12-04 18:26:52 +01:00
damien DELPY
052a69633d
merge : new database method. 2024-12-04 18:17:41 +01:00
Nemo D'ACREMONT
8c666ee979
enhanced: use redirect after post on /box/register 2024-12-04 18:03:05 +01:00
Nemo D'ACREMONT
4a6056dc01
feat: can delete boxes from member 2024-12-04 17:57:03 +01:00
11 changed files with 279 additions and 282 deletions

View File

@ -479,10 +479,10 @@ if __name__ == '__main__':
nbMotifs : int = 10
store_table(nbMotifs, "motifs", tablesDict["motifs"])
nbPieces : int = 100
nbPieces : int = 50
store_table(nbPieces, "pieces", tablesDict["pieces"])
nbPiecesComp : int = 10
nbPiecesComp : int = 5
store_table(nbPiecesComp, "pieces_complexes",
tablesDict["pieces_complexes"])
@ -492,7 +492,7 @@ if __name__ == '__main__':
#
###########################################################################
nbModeles : int = 5
nbModeles : int = 10
funcGen = lambda : tablesDict["modeles"](
give_used_key(idMembreDict),
give_used_key(idModeleDict)
@ -638,25 +638,7 @@ if __name__ == '__main__':
)
generate_table(nbVarier, "varier", funcGen)
###########################################################################
#
# To write `insert.sql`.
#
###########################################################################
# Remove duplicatas.
for nameTable in tablesDict:
remove_duplicata(give_path_file(nameTable))
# Writing in `insert.sql`.
fileSql = open("src/insert.sql", 'w+')
fileSql.write("TRUNCATE " + ', '.join(tablesDict) + ";\n")
fileSql.write("\n")
fileSql.close()
with open("src/insert.sql", 'a') as fileSql:
for nameTable in tablesDict:
convert_table_to_sql(give_path_file(nameTable), nameTable)
### The following code is in `convert_data.py`.
###############################################################################

View File

@ -510,25 +510,26 @@ INSERT INTO contenir VALUES
(134, 900, 40),
(134, 130, 78),
(134, 133, 37),
(235, 13, 27),
(235, 183, 18),
(235, 20, 26),
(235, 253, 26),
(235, 606, 13),
(235, 777, 10),
(235, 985, 12),
(235, 219, 24),
(235, 444, 34),
(235, 498, 14),
(235, 627, 43),
(235, 797, 27),
(235, 803, 42),
(235, 886, 34),
(235, 133, 59),
(235, 210, 34),
(235, 288, 72),
(235, 945, 92),
(240, 183, 18),
(240, 20, 26),
(240, 253, 26),
(240, 606, 13),
(240, 777, 10),
(240, 985, 12),
(240, 13, 79),
(240, 183, 13),
(240, 210, 83),
(240, 233, 70),
(240, 334, 92),
(240, 423, 58),
(240, 466, 37),
(240, 571, 35),
(284, 210, 12),
(284, 335, 47),
(284, 498, 40),
@ -598,36 +599,30 @@ INSERT INTO contenir VALUES
(520, 335, 47),
(520, 498, 40),
(520, 650, 30),
(530, 233, 33),
(530, 288, 46),
(530, 304, 10),
(530, 355, 50),
(530, 488, 37),
(530, 797, 19),
(530, 130, 39),
(530, 184, 37),
(530, 232, 31),
(530, 304, 61),
(530, 334, 72),
(530, 355, 38),
(530, 36, 12),
(530, 498, 98),
(530, 580, 14),
(530, 650, 48),
(530, 776, 23),
(530, 797, 31),
(530, 921, 10),
(530, 935, 79),
(538, 130, 19),
(538, 133, 15),
(538, 210, 47),
(538, 375, 15),
(538, 501, 23),
(538, 734, 13),
(538, 921, 41),
(538, 935, 34),
(538, 13, 40),
(538, 210, 18),
(538, 219, 83),
(538, 304, 66),
(538, 334, 77),
(538, 335, 24),
(538, 36, 43),
(538, 466, 53),
(538, 501, 18),
(538, 650, 93),
(538, 686, 95),
(538, 726, 48),
(538, 859, 64),
(538, 935, 85),
(538, 945, 90),
(538, 963, 55),
(566, 13, 17),
(566, 130, 67),
(566, 183, 40),
@ -645,58 +640,41 @@ INSERT INTO contenir VALUES
(566, 734, 13),
(566, 776, 56),
(566, 945, 87),
(579, 133, 22),
(579, 130, 19),
(579, 133, 15),
(579, 210, 47),
(579, 375, 15),
(579, 501, 23),
(579, 734, 13),
(579, 921, 41),
(579, 935, 34),
(579, 184, 82),
(579, 20, 25),
(579, 355, 68),
(579, 375, 76),
(579, 423, 82),
(579, 501, 82),
(579, 571, 98),
(579, 627, 24),
(579, 650, 82),
(579, 859, 74),
(579, 886, 77),
(579, 900, 62),
(579, 945, 58),
(579, 963, 87),
(579, 985, 93),
(624, 13, 30),
(624, 130, 36),
(624, 184, 75),
(624, 210, 94),
(624, 334, 83),
(624, 335, 95),
(624, 375, 53),
(624, 423, 26),
(624, 501, 25),
(624, 529, 21),
(624, 580, 49),
(624, 606, 42),
(624, 734, 29),
(624, 797, 75),
(624, 803, 30),
(624, 886, 83),
(624, 900, 25),
(624, 985, 13),
(624, 130, 19),
(624, 133, 15),
(624, 210, 47),
(624, 375, 15),
(624, 501, 23),
(624, 734, 13),
(624, 921, 41),
(624, 935, 34),
(624, 233, 33),
(624, 288, 46),
(624, 304, 10),
(624, 355, 50),
(624, 488, 37),
(624, 797, 19),
(63, 210, 47),
(63, 375, 15),
(63, 501, 23),
(63, 734, 13),
(63, 921, 41),
(63, 935, 34),
(63, 13, 28),
(63, 130, 95),
(63, 133, 22),
(63, 183, 56),
(63, 20, 14),
(63, 219, 47),
(63, 375, 97),
(63, 423, 31),
(63, 488, 68),
(63, 498, 95),
(63, 580, 96),
(63, 627, 55),
(63, 650, 13),
(63, 726, 61),
(63, 777, 80),
(63, 803, 59),
(63, 886, 13),
(63, 945, 45),
(653, 130, 21),
(653, 20, 93),
(653, 232, 77),
@ -714,15 +692,16 @@ INSERT INTO contenir VALUES
(653, 935, 17),
(653, 945, 41),
(653, 985, 16),
(658, 130, 19),
(658, 133, 15),
(658, 210, 47),
(658, 375, 15),
(658, 501, 23),
(658, 734, 13),
(658, 921, 41),
(658, 935, 34),
(658, 13, 99),
(658, 133, 76),
(658, 210, 83),
(658, 219, 12),
(658, 334, 54),
(658, 355, 83),
(658, 36, 98),
(658, 488, 33),
(658, 559, 76),
(658, 650, 46),
(658, 677, 72),
(658, 726, 51),
@ -730,65 +709,48 @@ INSERT INTO contenir VALUES
(658, 859, 96),
(658, 900, 72),
(658, 985, 56),
(663, 233, 33),
(663, 288, 46),
(663, 304, 10),
(663, 488, 37),
(663, 797, 19),
(663, 133, 15),
(663, 210, 47),
(663, 501, 23),
(663, 734, 13),
(663, 921, 41),
(663, 935, 34),
(663, 219, 67),
(663, 335, 66),
(663, 355, 99),
(663, 375, 90),
(663, 444, 63),
(663, 498, 96),
(663, 501, 31),
(663, 580, 34),
(663, 606, 51),
(663, 686, 41),
(663, 726, 63),
(663, 734, 12),
(663, 859, 60),
(663, 900, 15),
(663, 921, 47),
(681, 13, 27),
(681, 20, 26),
(681, 253, 26),
(681, 606, 13),
(681, 777, 10),
(681, 985, 12),
(681, 133, 74),
(681, 183, 42),
(681, 219, 29),
(681, 288, 87),
(681, 334, 100),
(681, 335, 49),
(681, 355, 35),
(681, 529, 79),
(681, 709, 35),
(681, 859, 32),
(681, 900, 61),
(681, 985, 24),
(700, 233, 33),
(700, 288, 46),
(700, 304, 10),
(700, 355, 50),
(700, 488, 37),
(700, 797, 19),
(700, 130, 94),
(700, 133, 33),
(700, 183, 77),
(700, 304, 37),
(700, 345, 79),
(700, 466, 62),
(700, 498, 70),
(700, 501, 20),
(700, 559, 53),
(700, 571, 37),
(700, 606, 73),
(700, 627, 13),
(700, 776, 34),
(700, 859, 81),
(700, 900, 74),
(700, 945, 42),
(753, 233, 33),
(753, 288, 46),
(753, 304, 10),
(753, 355, 50),
(753, 488, 37),
(753, 797, 19),
(753, 13, 32),
(753, 20, 95),
(753, 219, 22),
(753, 233, 80),
(753, 253, 64),
(753, 355, 83),
(753, 36, 78),
(753, 423, 40),
(753, 466, 20),
(753, 488, 100),
(753, 529, 91),
(753, 606, 32),
(753, 686, 23),
(753, 734, 65),
(753, 797, 72),
(753, 803, 46),
(91, 233, 38),
(91, 253, 38),
(91, 288, 25),
@ -801,24 +763,21 @@ INSERT INTO contenir VALUES
(91, 498, 40),
(91, 650, 30),
(91, 133, 53),
(911, 133, 80),
(911, 219, 30),
(911, 375, 83),
(911, 423, 23),
(911, 444, 62),
(911, 466, 51),
(911, 498, 40),
(911, 529, 68),
(911, 571, 36),
(911, 580, 23),
(911, 677, 28),
(911, 726, 23),
(911, 734, 58),
(911, 777, 84),
(911, 797, 57),
(911, 803, 82),
(911, 935, 39),
(911, 945, 50),
(911, 130, 19),
(911, 133, 15),
(911, 210, 47),
(911, 375, 15),
(911, 501, 23),
(911, 734, 13),
(911, 921, 41),
(911, 935, 34),
(911, 13, 27),
(911, 183, 18),
(911, 20, 26),
(911, 253, 26),
(911, 606, 13),
(911, 777, 10),
(911, 985, 12),
(984, 233, 38),
(984, 253, 38),
(984, 288, 25),
@ -855,6 +814,16 @@ INSERT INTO enregistrer VALUES
(340, 93, 8),
(63, 733, 4),
(700, 751, 5),
(538, 443, 1),
(753, 883, 1),
(911, 93, 1),
(63, 797, 1),
(134, 162, 1),
(240, 925, 1),
(309, 929, 1),
(538, 24, 1),
(566, 312, 1),
(700, 127, 1),
(993, 162, 7);
INSERT INTO etre VALUES

View File

@ -2,7 +2,7 @@
On aime les briques
## Sujet
## Sujet
* [Projet: Travail et modalités de rendu Fichier](https://moodle.bordeaux-inp.fr/mod/resource/view.php?id=48191)
* [Sujet : Briques Fichier](https://moodle.bordeaux-inp.fr/mod/resource/view.php?id=132493)
@ -29,7 +29,7 @@ docker compose -f docker-compose.dev.yml up
Use the file `docker-compose.prod.yml` to start the app in production mode, it can be done using the following command :
```
docker compose -f docker-compose.dev.yml up
docker compose -f docker-compose.prod.yml up
```
@ -42,4 +42,3 @@ docker compose -f docker-compose.dev.yml up
2) `export $(grep -v '^#' back-end/.env.production | xargs)` and then `make`.
### EOF

View File

@ -156,28 +156,24 @@ const boxById: RequestHandler<{ id: string; }> = async (req, res) => {
res.render('box.ejs', { box });
};
const removeBoxFromMember : RequestHandler<{ id_box: string, id_member: string }> = async (req, res) => {
const id_box = parseInt(req.params.id_box);
const id_member = parseInt(req.params.id_member);
await boxService.removeBoxFromMember(id_box, id_member)
res.sendStatus(200);
}
const registerBox: RequestHandler = async (req, res, next) => {
const id_box = parseInt(req.body.id_box);
const id_member = parseInt(req.body.id_member);
const quantity = parseInt(req.body.quantity);
if (isNaN(id_box) || isNaN(id_member) || isNaN(quantity))
next();
await boxService.registerBox(id_box, id_member, quantity);
const memberEither = await memberService.getMember(id_member);
if (memberEither.hasRight) {
console.error(memberEither.right);
next();
return;
}
const member = memberEither.left;
const models = await modelService.getAllBuildableModels(member.id_member);
const boxes = await boxService.getBoxesFromMember(member.id_member);
const pieces = await getBuyedPiecesFromMember(member.id_member);
const allboxes = await boxService.getAllBoxes();
res.render('member.ejs', { member, models, boxes, pieces, allboxes });
res.redirect('/membres/byid/' + id_member);
};
const boxController = {
@ -189,7 +185,8 @@ const boxController = {
allBoxesFromDate,
boxById,
registerBox,
boxRemovePieceById
boxRemovePieceById,
removeBoxFromMember,
};
export default boxController;

View File

@ -12,6 +12,8 @@ boxRouter.post("/register", boxController.registerBox);
boxRouter.get("/:title", boxController.boxByTitle);
boxRouter.post("/:title", boxController.boxAddPieces);
boxRouter.delete("/:id_box/:id_member", boxController.removeBoxFromMember);
boxRouter.delete("/byid/:id_box", boxController.boxRemovePieceById);
boxRouter.post("/byid/:id_box", boxController.boxAddPiecesById);

View File

@ -126,6 +126,12 @@ const registerBox = async (id_box: number, id_member: number, quantity: number)
await client.query("INSERT INTO enregistrer VALUES($1, $2, $3);", [id_box, id_member, quantity]);
}
const removeBoxFromMember = async (id_box: number, id_member: number) => {
const client = new_client();
await client.query("DELETE FROM enregistrer WHERE id_boite=$1 AND id_membre=$2;", [id_box, id_member]);
}
const boxService = {
addPiecesToBox,
getBox,
@ -134,6 +140,7 @@ const boxService = {
removePieceFromBox,
registerBox,
getBoxesFromMember,
removeBoxFromMember,
};
export default boxService;

View File

@ -6,6 +6,11 @@
font-family: sans-serif;
}
button {
background-color: transparent;
cursor: pointer;
}
pre, code {
font-family: monospace;
}

View File

@ -9,19 +9,30 @@
</title>
<%- include('partials/links.ejs') %>
<style>
#box-register-form {
display: flex;
flex-direction: column;
max-width: max(30vw, 60ch);
margin: auto;
}
<style>
#box-register-form {
display: flex;
flex-direction: column;
max-width: max(30vw, 60ch);
margin: auto;
}
#box-register-form select, #box-register-form input {
padding: .5rem 1rem;
}
#box-register-form select,
#box-register-form input {
padding: .5rem 1rem;
}
</style>
i {
color: var(--bg);
}
</style>
<script>
function removeBox(id) {
fetch(window.location.origin + '/boxes/' + id + '/' + <%= member.id_member %>, {method: 'DELETE'}).then(r => window.location.reload());
}
</script>
</head>
<body>
@ -38,63 +49,68 @@
<pre>
id: <%= member.id_member%>
name: <%= member.name%>
name: <%= member.name%>
</pre>
<h2>Liste des boites enregistrées</h2>
<form name="title" action="/boxes/register" id="box-register-form" method="POST">
<input type="hidden" name="id_member" id="id_member" value="<%= member.id_member %>">
<h2>Enregistrer une boite</h2>
<form name="title" action="/boxes/register" id="box-register-form" method="POST">
<input type="hidden" name="id_member" id="id_member" value="<%= member.id_member %>">
<label for="id_box">id de la boite</label>
<select name="id_box" id="id_box">
<label for="id_box">Nom de la boite</label>
<select name="id_box" id="id_box">
<% allboxes.forEach(function(box) { %>
<option value="<%=box.id%>"><%=box.id%></option>
<% }); %>
</select>
<label for="quantity">Quantité</label>
<input type="number" name="quantity" min="0" step="1" id="quantity">
<input type="submit" value="Ajouter">
</form>
<div class="table">
<table>
<thead>
<tr>
<th>Id</th>
<th>Nom</th>
<th>Nombre de pièces</th>
<th>Quantité</th>
<th></th>
</tr>
</thead>
<tbody>
<% boxes.forEach(function(box) { %>
<tr>
<td>
<%=box.first.id%>
</td>
<td>
<%=box.first.title%>
</td>
<td><%- box.first.pieces.reduce( (p,q)=> p + q.second, 0
)
-%></td>
<td>
<%=box.second%>
</td>
<td><a href="/boxes/byid/<%=box.first.id%>"><i class="fa-solid fa-eye"></i></a></td>
</tr>
<option value="<%=box.id%>">
<%=box.title%>
</option>
<% }); %>
</select>
</tbody>
</table>
<label for="quantity">Quantité</label>
<input type="number" name="quantity" min="1" step="1" id="quantity" value="1">
<div class="box"></div>
<input type="submit" value="Ajouter">
</form>
<h2>Liste des boites enregistrées</h2>
<div class="table">
<table>
<thead>
<tr>
<th>Id</th>
<th>Nom</th>
<th>Nombre de pièces</th>
<th>Quantité</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% boxes.forEach(function(box) { %>
<tr>
<td>
<%=box.first.id%>
</td>
<td>
<%=box.first.title%>
</td>
<td><%- box.first.pieces.reduce( (p,q)=> p + q.second, 0
)
-%></td>
<td>
<%=box.second%>
</td>
<td><a href="/boxes/byid/<%=box.first.id%>"><i class="fa-solid fa-eye"></i></a></td>
<td><button onclick="removeBox(<%=box.first.id%>)"><i class="fa-solid fa-trash"></i></button></td>
</tr>
<% }); %>
</tbody>
</table>
<div class="box"></div>
</div>
<h2>
@ -158,19 +174,26 @@
<td>
<%=model.name%>
</td>
<td><a href="/membres/byid/<%=model.creator%>"><i class="fa-solid fa-user"></i>
<%=model.creator%>
</a></td>
<td><a href="/models/byname/<%=model.name%>"><i class="fa-solid fa-eye"></i></a></td>
<% if (model.creator===undefined) {%>
<td></td>
<% } else {%>
<td><a href="/membres/byid/<%=model.creator.id_member%>"><i class="fa-solid fa-user"></i>
<%=model.creator.name%>
</a></td>
<% } %>
<td><a href="/models/byname/<%=model.name%>"><i class="fa-solid fa-eye"></i></a></td>
</tr>
<% }); %>
</tbody>
</table>
<div class="box"></div>
</div>
</main>
</main>
</body>
</html>

View File

@ -23,7 +23,7 @@
id : <%= model.id %>
url : <%= model.url %>
creator : <%= model.creator.name %>
creator : <%- model.creator !== undefined ? model.creator.name : 'system' %>
inheritFrom : <%= model.inheritFrom %>
<h2>Liste des pièces nécessaires</h2>
<div class="table">

View File

@ -13,40 +13,53 @@
<body>
<%- include('partials/header.ejs') %>
<main>
<h1>
Liste des modeles
</h1>
<main>
<h1>
Liste des modeles
</h1>
<div class="table">
<table>
<thead>
<table>
<thead>
<tr>
<th>Id modèle</th>
<th>Nom modèle</th>
<th>Proposé par</th>
<th>Avis</th>
<th></th>
</tr>
</thead>
<tbody>
<% models.forEach(function(model) { %>
<tr>
<th>Id modèle</th>
<th>Nom modèle</th>
<th>Proposé par</th>
<th>Avis</th>
<th></th>
</tr>
</thead>
<tbody>
<% models.forEach(function(model) { %>
<tr>
<td><%=model.id%></td>
<td><%=model.name%></td>
<td><a href="/membres/byid/<%=model.creator.id_member%>"><i class="fa-solid fa-user"></i> <%=model.creator.name%></a></td>
<td><%=model.review.first%>/5 (<%=model.review.second%> avis)</td>
<td><a href="/models/byname/<%=model.name%>"><i class="fa-solid fa-eye"></i></a></td>
<td>
<%=model.id%>
</td>
<td>
<%=model.name%>
</td>
<% if (model.creator===undefined) {%>
<td></td>
<% } else {%>
<td><a href="/membres/byid/<%=model.creator.id_member%>"><i class="fa-solid fa-user"></i>
<%=model.creator.name%>
</a></td>
<% } %>
<td>
<%=model.review.first%>/5 (<%=model.review.second%> avis)
</td>
<td><a href="/models/byname/<%=model.name%>"><i class="fa-solid fa-eye"></i></a></td>
</tr>
<% }); %>
<% }); %>
</tbody>
</table>
<div class="box"></div>
</div>
</tbody>
</table>
<div class="box"></div>
</div>
</main>
</main>
</body>

View File

@ -6,7 +6,7 @@ type Model = {
id: number;
name: string;
url: string;
creator: Member;
creator: Member | undefined;
inheritFrom: number;
pieces: Array<Pair<Piece, number>>
review: Pair<number, number>