Cars cz. 2

This commit is contained in:
aplikacje committed 2026-10-29 10:50:30 +01:00
1 parent d60f8a91a7
commit 3b96ac1be8
8 files changed
+257 -15

No files matched your search

+10 -13
View File
@@ -1,13 +1,10 @@
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"TAK","naped4x4":"NIE","model":"Fiat Siesta","_id":"3RzJJX56VlHImvio"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"TAK","model":"Newag Impuls","_id":"6PK2fLdLhPZEeDPY"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"TAK","model":"Volvo V70","_id":"6jnh5hrirnvSKuHr"}
{"ubezpieczony":"TAK","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"NIE","model":"Newag Impuls","_id":"DaNohMWhUwKNZCVi"}
{"ubezpieczony":"TAK","benzyna":"NIE","uszkodzony":"TAK","naped4x4":"NIE","model":"Volvo V70","_id":"IaFTfZzBsgwAkVcr"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"TAK","naped4x4":"NIE","model":"Volvo V70","_id":"Kp8Yecf7rZBgzl19"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"TAK","naped4x4":"NIE","model":"Newag Impuls","_id":"PydJXj7NnHLfaJDh"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"TAK","naped4x4":"NIE","model":"Ford Fiesta","_id":"TyGi23AD9aqtLhyw"}
{"ubezpieczony":"NIE","benzyna":"TAK","uszkodzony":"NIE","naped4x4":"TAK","model":"Ford Fiesta","_id":"byQKYXe8ZDubEmnQ"}
{"ubezpieczony":"NIE","benzyna":"TAK","uszkodzony":"TAK","naped4x4":"NIE","model":"Volvo S60","_id":"dza3RMhhHMcwW7Fo"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"TAK","naped4x4":"NIE","model":"Volkswagen Polo","_id":"ehZZRhPjKzFH8t2u"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"NIE","model":"Volkswagen Polo","_id":"ph8rQnhL6m2xq61A"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"TAK","naped4x4":"NIE","model":"Fiat Siesta","_id":"ynPUlOeBPPntM60s"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"BRAK DANYCH","naped4x4":"NIE","model":"EN57","_id":"3WYiUbXyKdNCora2"}
{"ubezpieczony":"NIE","benzyna":"BRAK DANYCH","uszkodzony":"TAK","naped4x4":"TAK","model":"Newag Impuls","_id":"Njg77UGgaUwa7BNO"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"NIE","model":"Volvo S60","_id":"Ybsk8Tp8XVEx9YCI"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"TAK","model":"Ford Fiesta","_id":"cTR4SUI0UrZM1MzX"}
{"ubezpieczony":"TAK","benzyna":"TAK","uszkodzony":"TAK","naped4x4":"NIE","model":"Volkswagen Polo","_id":"eSeokpNe3Hr5xM92"}
{"ubezpieczony":"NIE","benzyna":"TAK","uszkodzony":"TAK","naped4x4":"NIE","model":"Volvo S60","_id":"kpIYNiYxGkR0Pjeg"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"NIE","model":"Volvo V70","_id":"la6azGJJdcMGsuiq"}
{"ubezpieczony":"NIE","benzyna":"TAK","uszkodzony":"TAK","naped4x4":"TAK","model":"Newag Impuls","_id":"q1epOgXNeFQCF5wb"}
{"ubezpieczony":"TAK","benzyna":"NIE","uszkodzony":"TAK","naped4x4":"NIE","model":"Ford Fiesta","_id":"qfpGtQuIRrCFPkJb"}
{"ubezpieczony":"TAK","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"TAK","model":"Fiat Siesta","_id":"qiboa7ygHrMvH6I6"}
+92 -2
View File
@@ -13,7 +13,12 @@ const DB = new DS({
const hbs = create({
defaultLayout: 'main.hbs',
extname: '.hbs'
extname: '.hbs',
helpers: {
equ(p, q) {
return p == q;
}
}
});
app.engine('.hbs', hbs.engine);
@@ -74,8 +79,93 @@ app.get("/list", function (req, res) {
car: docs
};
res.render('list.hbs', ctx);
})
});
});
app.post("/delete", function (req, res) {
console.log(req.body);
if (req.body.deletions) {
const deletions = [req.body.deletions].flat();
console.log(deletions);
deletions.forEach(deletion_id => {
DB.remove({ _id: deletion_id }, {}, function (err, numRemoved) {
console.log("Usunięto " + numRemoved + " dokument.");
});
});
}
res.redirect("/delete");
});
app.get("/delete", function (req, res) {
DB.find({}, function (err, docs) {
let ctx = {
car: docs
};
res.render('delete.hbs', ctx);
});
});
app.get("/deleteSpecific", function (req, res) {
if (req.query.id) {
DB.remove({ _id: req.query.id }, {}, function (err, numRemoved) {
console.log("Usunięto " + numRemoved + " dokument.");
});
}
res.redirect("/delete");
});
app.get("/deleteAll", function (req, res) {
DB.remove({}, { multi: true }, function (err, numRemoved) {
console.log("usunięto dokumentów: " + numRemoved);
});
res.redirect("/delete");
});
app.post("/edit", function (req, res) {
DB.update({ _id: req.body._id }, { $set: req.body }, {}, function (err, numUpdated) {
console.log('Zaktualizowano ' + numUpdated + ' dokumentów.');
});
res.redirect("/edit");
});
app.get("/edit", function (req, res) {
DB.find({}, function (err, docs) {
let ctx = {
car: []
};
docs.forEach(doc => {
if (doc._id == req.query.id) {
doc.edycja = true;
}
ctx.car.push(doc);
})
res.render('edit.hbs', ctx);
});
});
app.post("/search", function (req, res) {
console.log(req.body);
// do dokończenia tutaj
});
app.get("/search", function (req, res) {
DB.find({}, function (err, docs) {
let ctx = {
car: docs
};
res.render('search.hbs', ctx);
});
})
/// --------
+17
View File
@@ -149,3 +149,20 @@ button {
button:hover {
background-color: purple;
}
select {
border: none;
background-color: cornflowerblue;
color: white;
padding: .5rem;
width: 100%;
box-shadow: 1px 1px 2px gray;
}
input[type='text'] {
border: none;
background-color: lightgray;
padding: .5rem;
width: 100%;
box-shadow: 1px 1px 2px gray;
}
View File
Whitespace-only changes.
+40
View File
@@ -0,0 +1,40 @@
<h2>delete cars</h2>
<section>
<form method="post">
<input type="submit" value="Delete Selected"><button onclick=" event.preventDefault();
const res = confirm('Confirm deletion');
if(res) {
window.location='/deleteAll';
}" style="margin-left: 1rem;">Delete
All</button><br><br>
<table>
<tr>
<th>_id</th>
<th>model</th>
<th>ubezpieczony</th>
<th>benzyna</th>
<th>uszkodzony</th>
<th>naped4x4</th>
<th></th>
<th></th>
</tr>
{{#each car}}
<tr>
<td>{{_id}}</td>
<td>{{model}}</td>
<td>{{ubezpieczony}}</td>
<td>{{benzyna}}</td>
<td>{{uszkodzony}}</td>
<td>{{naped4x4}}</td>
<td style="text-align: center;">
<button
onclick="event.preventDefault(); window.location='/deleteSpecific?id={{_id}}';">DELETE</button>
</td>
<td>
<input type="checkbox" name="deletions" id="del_{{_id}}" value="{{_id}}">
</td>
</tr>
{{/each}}
</table>
</form>
</section>
+62
View File
@@ -0,0 +1,62 @@
<h2>edit cars</h2>
<section>
<table>
<tr>
<th>_id</th>
<th>model</th>
<th>ubezpieczony</th>
<th>benzyna</th>
<th>uszkodzony</th>
<th>naped4x4</th>
<th></th>
<th></th>
</tr>
{{#each car}}
{{#if edycja}}
<tr>
<form method="post">
<td>{{_id}}<input type="hidden" name="_id" value="{{_id}}"></td>
<td><input type="text" name="model" value="{{model}}"></td>
<td><select name="ubezpieczony">
<option>TAK</option>
<option {{#if (equ ubezpieczony 'NIE' )}}selected{{/if}}>NIE</option>
<option {{#if (equ ubezpieczony 'BRAK DANYCH' )}}selected{{/if}}>BRAK DANYCH</option>
</select></td>
<td><select name="benzyna">
<option>TAK</option>
<option {{#if (equ benzyna 'NIE' )}}selected{{/if}}>NIE</option>
<option {{#if (equ benzyna 'BRAK DANYCH' )}}selected{{/if}}>BRAK DANYCH</option>
</select></td>
<td><select name="uszkodzony">
<option>TAK</option>
<option {{#if (equ uszkodzony 'NIE' )}}selected{{/if}}>NIE</option>
<option {{#if (equ uszkodzony 'BRAK DANYCH' )}}selected{{/if}}>BRAK DANYCH</option>
</select></td>
<td><select name="naped4x4">
<option>TAK</option>
<option {{#if (equ naped4x4 'NIE' )}}selected{{/if}}>NIE</option>
<option {{#if (equ naped4x4 'BRAK DANYCH' )}}selected{{/if}}>BRAK DANYCH</option>
</select></td>
<td style="text-align: center;"><button
style="background-color: greenyellow; color: black;">UPDATE</button></td>
<td style="text-align: center;"><button onclick="event.preventDefault(); window.location='/edit';"
style="background-color: orange;">CANCEL</button></td>
</form>
</tr>
{{else}}
<tr>
<td>{{_id}}</td>
<td>{{model}}</td>
<td>{{ubezpieczony}}</td>
<td>{{benzyna}}</td>
<td>{{uszkodzony}}</td>
<td>{{naped4x4}}</td>
<td style="text-align: center;">
<button onclick="window.location = '/edit?id={{_id}}';">EDIT</button>
</td>
<td></td>
</tr>
{{/if}}
{{/each}}
</table>
</section>
+1
View File
@@ -16,6 +16,7 @@
<a href="/delete">Delete</a>
<a href="/edit">Edit</a>
<a href="/search">Search</a>
<a href="/advanced_search">Advanced search</a>
</nav>
{{{ body }}}
</body>
+35
View File
@@ -0,0 +1,35 @@
<h2>search cars</h2>
<section>
<form method="post">
<div style="display: flex; justify-content: space-between;">
<div style="width: 50%;">
<h3>Wybierz cechę</h3>
<input style="margin-top: .5rem;" type="radio" name="criterion" id="r_ubezpieczony"
value="ubezpieczony">
<label for="r_ubezpieczony">Ubezpieczony</label><br>
<input style="margin-top: .5rem;" type="radio" name="criterion" id="r_benzyna" value="benzyna"> <label
for="r_benzyna">Benzyna</label><br>
<input style="margin-top: .5rem;" type="radio" name="criterion" id="r_uszkodzony" value="uszkodzony">
<label for="r_uszkodzony">Uszkodzony</label><br>
<input style="margin-top: .5rem;" type="radio" name="criterion" id="r_naped4x4" value="naped4x4"> <label
for="r_naped4x4">Napęd
4x4</label><br>
</div>
<div style="width: 50%;">
<h3>Wybierz wartość</h3>
<input style="margin-top: .5rem;" type="radio" name="value" id="r_tak" value="TAK"> <label
for="r_tak">TAK</label><br>
<input style="margin-top: .5rem;" type="radio" name="value" id="r_nie" value="NIE"> <label
for="r_nie">NIE</label><br>
<input style="margin-top: .5rem;" type="radio" name="value" id="r_brakdanych" value="BRAK DANYCH">
<label for="r_brakdanych">BRAK DANYCH</label><br>
</div>
</div>
<br>
<div>
<button>WYSZUKAJ POJAZDY</button>
<a href="/search"
style="margin-left: 1rem; text-decoration: none; font-weight: bold; color: darkgray;">Reset</a>
</div>
</form>
</section>