Revert "Update project directory"
This reverts commit 7b452e41.
Showing
7 changed files
with
3 additions
and
86 deletions
... | @@ -5,7 +5,6 @@ var methodOverride = require('method-override'); | ... | @@ -5,7 +5,6 @@ var methodOverride = require('method-override'); |
5 | var flash = require('connect-flash'); | 5 | var flash = require('connect-flash'); |
6 | var session = require('express-session'); | 6 | var session = require('express-session'); |
7 | var passport = require('./config/passport'); | 7 | var passport = require('./config/passport'); |
8 | -var multer = require('multer'); | ||
9 | //require('./config/passport'); | 8 | //require('./config/passport'); |
10 | 9 | ||
11 | var app = express(); | 10 | var app = express(); | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -18,7 +18,6 @@ | ... | @@ -18,7 +18,6 @@ |
18 | "express-session": "^1.17.1", | 18 | "express-session": "^1.17.1", |
19 | "method-override": "^3.0.0", | 19 | "method-override": "^3.0.0", |
20 | "mongoose": "^5.12.8", | 20 | "mongoose": "^5.12.8", |
21 | - "multer": "^1.4.2", | ||
22 | "passport": "^0.4.1", | 21 | "passport": "^0.4.1", |
23 | "passport-local": "^1.0.0" | 22 | "passport-local": "^1.0.0" |
24 | } | 23 | } | ... | ... |
... | @@ -7,32 +7,6 @@ var util = require('../util'); | ... | @@ -7,32 +7,6 @@ var util = require('../util'); |
7 | 7 | ||
8 | // Post home | 8 | // Post home |
9 | router.get('/', function(req, res){ | 9 | router.get('/', function(req, res){ |
10 | - var page = Math.max(1, parseInt(req.query.page)); | ||
11 | - var limit = Math.max(1, parseInt(req.query.limit)); | ||
12 | - page = !isNaN(page)?page:1; | ||
13 | - limit = !isNaN(limit)?limit:10; | ||
14 | - | ||
15 | - var searchQuery = createSearchQuery(req.query); // 1 | ||
16 | - | ||
17 | - var skip = (page-1)*limit; | ||
18 | - var count = await Post.countDocuments(searchQuery); // 1-1 | ||
19 | - var maxPage = Math.ceil(count/limit); | ||
20 | - var posts = await Post.find(searchQuery) // 1-2 | ||
21 | - .populate('author') | ||
22 | - .sort('-createdAt') | ||
23 | - .skip(skip) | ||
24 | - .limit(limit) | ||
25 | - .exec(); | ||
26 | - | ||
27 | - res.render('posts/index', { | ||
28 | - posts:posts, | ||
29 | - currentPage:page, | ||
30 | - maxPage:maxPage, | ||
31 | - limit:limit, | ||
32 | - searchType:req.query.searchType, // 2 | ||
33 | - searchText:req.query.searchText // 2 | ||
34 | - }); | ||
35 | - }); | ||
36 | Post.find({}) | 10 | Post.find({}) |
37 | .populate('author') | 11 | .populate('author') |
38 | .sort('-createdAt') | 12 | .sort('-createdAt') |
... | @@ -40,6 +14,7 @@ router.get('/', function(req, res){ | ... | @@ -40,6 +14,7 @@ router.get('/', function(req, res){ |
40 | if(err){return res.json(err)}; | 14 | if(err){return res.json(err)}; |
41 | res.render('posts/index', {posts:posts}); | 15 | res.render('posts/index', {posts:posts}); |
42 | }); | 16 | }); |
17 | +}); | ||
43 | 18 | ||
44 | 19 | ||
45 | // Post new | 20 | // Post new |
... | @@ -59,26 +34,10 @@ router.post('/', util.isLoggedin, function(req, res){ | ... | @@ -59,26 +34,10 @@ router.post('/', util.isLoggedin, function(req, res){ |
59 | req.flash('errors', util.parseError(err)); | 34 | req.flash('errors', util.parseError(err)); |
60 | return res.redirect('/posts/new'); | 35 | return res.redirect('/posts/new'); |
61 | }; | 36 | }; |
62 | - res.redirect('/posts'+res.locals.getPostQueryString(false, { page:1, searchText:'' })); | 37 | + res.redirect('/posts'); |
63 | }); | 38 | }); |
64 | }); | 39 | }); |
65 | 40 | ||
66 | -function createSearchQuery(queries){ | ||
67 | - var searchQuery = {}; | ||
68 | - if(queries.searchType && queries.searchText && queries.searchText.length >= 3){ // 1 | ||
69 | - var searchTypes = queries.searchType.toLowerCase().split(','); | ||
70 | - var postQueries = []; | ||
71 | - if(searchTypes.indexOf('title')>=0){ | ||
72 | - postQueries.push({ title: { $regex: new RegExp(queries.searchText, 'i') } }); // 2 | ||
73 | - } | ||
74 | - if(searchTypes.indexOf('body')>=0){ | ||
75 | - postQueries.push({ body: { $regex: new RegExp(queries.searchText, 'i') } }); | ||
76 | - } | ||
77 | - if(postQueries.length > 0) searchQuery = {$or:postQueries}; // 3 | ||
78 | - } | ||
79 | - return searchQuery; | ||
80 | - } | ||
81 | - | ||
82 | 41 | ||
83 | // Post show | 42 | // Post show |
84 | router.get('/:id', util.isLoggedin, function(req, res){ | 43 | router.get('/:id', util.isLoggedin, function(req, res){ | ... | ... |
... | @@ -33,26 +33,6 @@ util.noPermission = function(req, res){ | ... | @@ -33,26 +33,6 @@ util.noPermission = function(req, res){ |
33 | res.redirect('/login'); | 33 | res.redirect('/login'); |
34 | } | 34 | } |
35 | 35 | ||
36 | -util.getPostQueryString = function(req, res, next){ | ||
37 | - res.locals.getPostQueryString = function(isAppended=false, overwrites={}){ | ||
38 | - var queryString = ''; | ||
39 | - var queryArray = []; | ||
40 | - var page = overwrites.page?overwrites.page:(req.query.page?req.query.page:''); | ||
41 | - var limit = overwrites.limit?overwrites.limit:(req.query.limit?req.query.limit:''); | ||
42 | - var searchType = overwrites.searchType?overwrites.searchType:(req.query.searchType?req.query.searchType:''); // 1 | ||
43 | - var searchText = overwrites.searchText?overwrites.searchText:(req.query.searchText?req.query.searchText:''); // 1 | ||
44 | 36 | ||
45 | - if(page) queryArray.push('page='+page); | ||
46 | - if(limit) queryArray.push('limit='+limit); | ||
47 | - if(searchType) queryArray.push('searchType='+searchType); // 1 | ||
48 | - if(searchText) queryArray.push('searchText='+searchText); // 1 | ||
49 | - | ||
50 | - if(queryArray.length>0) queryString = (isAppended?'&':'?') + queryArray.join('&'); | ||
51 | - | ||
52 | - return queryString; | ||
53 | - } | ||
54 | - next(); | ||
55 | -} | ||
56 | 37 | ||
57 | module.exports = util; | 38 | module.exports = util; |
... | \ No newline at end of file | ... | \ No newline at end of file |
58 | - | ... | ... |
... | @@ -10,6 +10,7 @@ | ... | @@ -10,6 +10,7 @@ |
10 | <div class="container mb-3"> | 10 | <div class="container mb-3"> |
11 | <div> | 11 | <div> |
12 | <h2 class="mb-3" style="font-weight: bold; font-style:italic; float:left;">Memory</h2> | 12 | <h2 class="mb-3" style="font-weight: bold; font-style:italic; float:left;">Memory</h2> |
13 | + | ||
13 | <div style="float:right"> | 14 | <div style="float:right"> |
14 | <% if(isAuthenticated){ %> | 15 | <% if(isAuthenticated){ %> |
15 | <a class="btn btn-outline-primary" href="/posts/new">Write Memory</a> | 16 | <a class="btn btn-outline-primary" href="/posts/new">Write Memory</a> |
... | @@ -56,26 +57,5 @@ | ... | @@ -56,26 +57,5 @@ |
56 | 57 | ||
57 | 58 | ||
58 | </div> | 59 | </div> |
59 | - <form action="/posts" method="get" class="post-index-tool"> <!-- 1 --> | ||
60 | - <div class="form-row"> | ||
61 | - | ||
62 | - <div class="form-group col-9"> <!-- 2 --> | ||
63 | - <label>Search</label> | ||
64 | - <div class="input-group"> | ||
65 | - <select name="searchType" class="custom-select"> | ||
66 | - <option value="title,body" <% searchType=='title,body'?'selected':'' %>>Title, Body</option> | ||
67 | - <option value="title" <%= searchType=='title'?'selected':'' %>>Title</option> | ||
68 | - <option value="body" <%= searchType=='body'?'selected':''' %>>Body</option> | ||
69 | - </select> | ||
70 | - <input minLength="3" type="text" name="searchText" value="<%= searchText %>"> | ||
71 | - <div class="input-group-append"> | ||
72 | - <button class="btn btn-outline-primary" type="submit">search</button> | ||
73 | - </div> | ||
74 | - </div> | ||
75 | - </div> | ||
76 | - | ||
77 | - </div> | ||
78 | - </form> | ||
79 | - | ||
80 | </body> | 60 | </body> |
81 | </html> | 61 | </html> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment