Cars cz. 2

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

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":"BRAK DANYCH","naped4x4":"NIE","model":"EN57","_id":"3WYiUbXyKdNCora2"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"TAK","model":"Newag Impuls","_id":"6PK2fLdLhPZEeDPY"} {"ubezpieczony":"NIE","benzyna":"BRAK DANYCH","uszkodzony":"TAK","naped4x4":"TAK","model":"Newag Impuls","_id":"Njg77UGgaUwa7BNO"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"TAK","model":"Volvo V70","_id":"6jnh5hrirnvSKuHr"} {"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"NIE","model":"Volvo S60","_id":"Ybsk8Tp8XVEx9YCI"}
{"ubezpieczony":"TAK","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"NIE","model":"Newag Impuls","_id":"DaNohMWhUwKNZCVi"} {"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"TAK","model":"Ford Fiesta","_id":"cTR4SUI0UrZM1MzX"}
{"ubezpieczony":"TAK","benzyna":"NIE","uszkodzony":"TAK","naped4x4":"NIE","model":"Volvo V70","_id":"IaFTfZzBsgwAkVcr"} {"ubezpieczony":"TAK","benzyna":"TAK","uszkodzony":"TAK","naped4x4":"NIE","model":"Volkswagen Polo","_id":"eSeokpNe3Hr5xM92"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"TAK","naped4x4":"NIE","model":"Volvo V70","_id":"Kp8Yecf7rZBgzl19"} {"ubezpieczony":"NIE","benzyna":"TAK","uszkodzony":"TAK","naped4x4":"NIE","model":"Volvo S60","_id":"kpIYNiYxGkR0Pjeg"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"TAK","naped4x4":"NIE","model":"Newag Impuls","_id":"PydJXj7NnHLfaJDh"} {"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"NIE","model":"Volvo V70","_id":"la6azGJJdcMGsuiq"}
{"ubezpieczony":"NIE","benzyna":"NIE","uszkodzony":"TAK","naped4x4":"NIE","model":"Ford Fiesta","_id":"TyGi23AD9aqtLhyw"} {"ubezpieczony":"NIE","benzyna":"TAK","uszkodzony":"TAK","naped4x4":"TAK","model":"Newag Impuls","_id":"q1epOgXNeFQCF5wb"}
{"ubezpieczony":"NIE","benzyna":"TAK","uszkodzony":"NIE","naped4x4":"TAK","model":"Ford Fiesta","_id":"byQKYXe8ZDubEmnQ"} {"ubezpieczony":"TAK","benzyna":"NIE","uszkodzony":"TAK","naped4x4":"NIE","model":"Ford Fiesta","_id":"qfpGtQuIRrCFPkJb"}
{"ubezpieczony":"NIE","benzyna":"TAK","uszkodzony":"TAK","naped4x4":"NIE","model":"Volvo S60","_id":"dza3RMhhHMcwW7Fo"} {"ubezpieczony":"TAK","benzyna":"NIE","uszkodzony":"NIE","naped4x4":"TAK","model":"Fiat Siesta","_id":"qiboa7ygHrMvH6I6"}
{"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"}
+92 -2
View File
@@ -13,7 +13,12 @@ const DB = new DS({
const hbs = create({ const hbs = create({
defaultLayout: 'main.hbs', defaultLayout: 'main.hbs',
extname: '.hbs' extname: '.hbs',
helpers: {
equ(p, q) {
return p == q;
}
}
}); });
app.engine('.hbs', hbs.engine); app.engine('.hbs', hbs.engine);
@@ -74,9 +79,94 @@ app.get("/list", function (req, res) {
car: docs car: docs
}; };
res.render('list.hbs', ctx); 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);
});
})
/// -------- /// --------
app.use(express.static('static')) app.use(express.static('static'))
+8 -8
View File
@@ -31,7 +31,7 @@ const MATCHING_GROUP_REGEXP = /\((?:\?<(.*?)>)?(?!\?)/g
module.exports = Layer module.exports = Layer
function Layer (path, options, fn) { function Layer(path, options, fn) {
if (!(this instanceof Layer)) { if (!(this instanceof Layer)) {
return new Layer(path, options, fn) return new Layer(path, options, fn)
} }
@@ -46,7 +46,7 @@ function Layer (path, options, fn) {
this.path = undefined this.path = undefined
this.slash = path === '/' && opts.end === false this.slash = path === '/' && opts.end === false
function matcher (_path) { function matcher(_path) {
if (_path instanceof RegExp) { if (_path instanceof RegExp) {
const keys = [] const keys = []
let name = 0 let name = 0
@@ -59,7 +59,7 @@ function Layer (path, options, fn) {
}) })
} }
return function regexpMatcher (p) { return function regexpMatcher(p) {
const match = _path.exec(p) const match = _path.exec(p)
if (!match) { if (!match) {
return false return false
@@ -103,7 +103,7 @@ function Layer (path, options, fn) {
* @api private * @api private
*/ */
Layer.prototype.handleError = function handleError (error, req, res, next) { Layer.prototype.handleError = function handleError(error, req, res, next) {
const fn = this.handle const fn = this.handle
if (fn.length !== 4) { if (fn.length !== 4) {
@@ -139,7 +139,7 @@ Layer.prototype.handleError = function handleError (error, req, res, next) {
* @api private * @api private
*/ */
Layer.prototype.handleRequest = function handleRequest (req, res, next) { Layer.prototype.handleRequest = function handleRequest(req, res, next) {
const fn = this.handle const fn = this.handle
if (fn.length > 3) { if (fn.length > 3) {
@@ -175,7 +175,7 @@ Layer.prototype.handleRequest = function handleRequest (req, res, next) {
* @api private * @api private
*/ */
Layer.prototype.match = function match (path) { Layer.prototype.match = function match(path) {
let match let match
if (path != null) { if (path != null) {
@@ -216,7 +216,7 @@ Layer.prototype.match = function match (path) {
* @private * @private
*/ */
function decodeParam (val) { function decodeParam(val) {
if (typeof val !== 'string' || val.length === 0) { if (typeof val !== 'string' || val.length === 0) {
return val return val
} }
@@ -236,7 +236,7 @@ function decodeParam (val) {
/** /**
* Loosens the given path for path-to-regexp matching. * Loosens the given path for path-to-regexp matching.
*/ */
function loosen (path) { function loosen(path) {
if (path instanceof RegExp || path === '/') { if (path instanceof RegExp || path === '/') {
return path return path
} }
+17
View File
@@ -148,4 +148,21 @@ button {
button:hover { button:hover {
background-color: purple; 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="/delete">Delete</a>
<a href="/edit">Edit</a> <a href="/edit">Edit</a>
<a href="/search">Search</a> <a href="/search">Search</a>
<a href="/advanced_search">Advanced search</a>
</nav> </nav>
{{{ body }}} {{{ body }}}
</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>