Skip to content

Commit 204451e

Browse files
committed
Update v1.0.4
Add a UI : Search Form
1 parent 5841e94 commit 204451e

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsonapitestserver",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"private": true,
55
"scripts": {
66
"start": "node ./bin/www"

routes/findFile.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ var path = require('path');
33

44
module.exports = {
55
extJson : '.json',
6-
findFiles: function (startPath) {
6+
findFiles: function (startPath, search) {
7+
search = (search) ? search : "";
78
if (!fs.existsSync(startPath)){
89
console.log("No file dir ", startPath);
910
return;
@@ -15,11 +16,13 @@ module.exports = {
1516
var filename = path.join(startPath, files[i]);
1617
var stat = fs.lstatSync(filename);
1718
if (stat.isDirectory()) {
18-
fileNames = fileNames.concat(this.findFiles(filename));
19+
fileNames = fileNames.concat(this.findFiles(filename, search));
1920
} else {
2021
filename = filename.replace('jsonFile', '');
2122
if (path.extname(filename) == this.extJson) {
22-
fileNames.push(filename);
23+
if (filename.includes(search)) {
24+
fileNames.push(filename);
25+
}
2326
}
2427
}
2528
}

routes/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ router.get('/' + ff.extJson, function(req, res, next) {
1111

1212
/* GET home page. */
1313
router.get('/', function(req, res, next) {
14+
var search = req.query.search;
1415
var contentType = req.headers['content-type'];
15-
var files = ff.findFiles('./jsonFile');
16+
var files = ff.findFiles('./jsonFile', search);
1617

1718
if (contentType == 'application/json') {
1819
res.json(ff.hierarchyFiles(files));
1920
} else {
2021
res.render('index', {
21-
title : 'JSON API TEST SERVER',
22-
hierarchyFiles : ff.hierarchyFiles(files)
22+
title : 'JSON API TEST SERVER',
23+
hierarchyFiles : ff.hierarchyFiles(files),
24+
search : search
2325
});
2426
}
2527
});

views/index.ejs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,24 @@
1515
<span class="navbar-toggler-icon"></span>
1616
</button> -->
1717

18-
<!-- <div class="collapse navbar-collapse" id="navbarsExample02">
19-
<ul class="navbar-nav mr-auto">
18+
<div class="collapse navbar-collapse" id="navbarsExample02">
19+
<!-- <ul class="navbar-nav mr-auto">
2020
<li class="nav-item active">
2121
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
2222
</li>
2323
<li class="nav-item">
2424
<a class="nav-link" href="#">Link</a>
2525
</li>
26-
</ul>
27-
<form class="form-inline my-2 my-md-0">
28-
<input class="form-control" type="text" placeholder="Search">
26+
</ul> -->
27+
<form class="form-inline my-2 my-md-0" action="/">
28+
<div class="input-group">
29+
<input type="text" class="form-control" name="search" placeholder="SEARCH" aria-label="SEARCH" value="<%= search %>">
30+
<div class="input-group-append">
31+
<button class="btn btn-secondary" type="submit">SEARCH</button>
32+
</div>
33+
</div>
2934
</form>
30-
</div> -->
35+
</div>
3136
</nav>
3237
</header>
3338

0 commit comments

Comments
 (0)