Dodal movies list
This commit is contained in:
parent
0d6c2d0aa8
commit
4303625b54
4
app.js
4
app.js
@ -18,7 +18,8 @@ db.on('error', console.error.bind(console, 'MongoDB connection error:'));
|
|||||||
var oldRouter = require('./routes/main/1_0');
|
var oldRouter = require('./routes/main/1_0');
|
||||||
var newRouter = require('./routes/main/2_0');
|
var newRouter = require('./routes/main/2_0');
|
||||||
var photosRouter = require('./routes/photoRouter');
|
var photosRouter = require('./routes/photoRouter');
|
||||||
var movieRouter = require('./routes/movieRouter');
|
var movieRouter = require('./routes/movies/movieRouter');
|
||||||
|
var movieShowRouter = require('./routes/movies/movieShow');
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ app.use('/', newRouter);
|
|||||||
app.use('/old', oldRouter);
|
app.use('/old', oldRouter);
|
||||||
app.use('/api/photos', photosRouter);
|
app.use('/api/photos', photosRouter);
|
||||||
app.use('/api/movies', movieRouter);
|
app.use('/api/movies', movieRouter);
|
||||||
|
app.use('/movies', movieShowRouter);
|
||||||
|
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
|
@ -13,10 +13,7 @@ module.exports = {
|
|||||||
list: function (req, res) {
|
list: function (req, res) {
|
||||||
MovieModel.find()
|
MovieModel.find()
|
||||||
.then(movies => {
|
.then(movies => {
|
||||||
var data = {
|
return res.json(movies);
|
||||||
movies: movies
|
|
||||||
};
|
|
||||||
return res.json(data);
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
@ -26,30 +23,6 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* movieController.show()
|
|
||||||
*/
|
|
||||||
show: function (req, res) {
|
|
||||||
var id = req.params.id;
|
|
||||||
|
|
||||||
MovieModel.findOne({_id: id}, function (err, movie) {
|
|
||||||
if (err) {
|
|
||||||
return res.status(500).json({
|
|
||||||
message: 'Error when getting movie.',
|
|
||||||
error: err
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!movie) {
|
|
||||||
return res.status(404).json({
|
|
||||||
message: 'No such movie'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.json(movie);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* movieController.create()
|
* movieController.create()
|
||||||
*/
|
*/
|
||||||
|
39
public/p_movies/script.js
Normal file
39
public/p_movies/script.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
$(document).ready(async function() {
|
||||||
|
await loadmovie();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function loadmovie() {
|
||||||
|
await $.get("/api/movies", rendermovie);
|
||||||
|
}
|
||||||
|
|
||||||
|
function rendermovie(movies) {
|
||||||
|
|
||||||
|
movies.sort(function(a, b) {
|
||||||
|
return a.title.localeCompare(b.title);
|
||||||
|
});
|
||||||
|
|
||||||
|
// movies.sort(function(a, b) {
|
||||||
|
// aJ = Date.parse(a.released);
|
||||||
|
// bJ = Date.parse(b.released);
|
||||||
|
// return bJ - aJ;
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
movies.forEach(function(movie) {
|
||||||
|
|
||||||
|
var row = document.createElement("div");
|
||||||
|
row.className = "col";
|
||||||
|
|
||||||
|
row.innerHTML = "<div class='card shadow-sm'>"+
|
||||||
|
"<img class='card-img-top' src="+ movie.webImg + " width='100%'>" +
|
||||||
|
"<div class='card-body'>" +
|
||||||
|
"<h5 class='card-title'>"+ movie.title + "</h5>" +
|
||||||
|
"<p class='card-text'>"+ movie.released + "</p>" +
|
||||||
|
// "<p class='card-text'>"+ movie.genre + "</p>" +
|
||||||
|
"</div>" +
|
||||||
|
"</div>";
|
||||||
|
|
||||||
|
|
||||||
|
$("#movie_tbody").append(row);
|
||||||
|
});
|
||||||
|
}
|
@ -3,12 +3,11 @@ var express = require('express');
|
|||||||
|
|
||||||
|
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
var movieController = require('../controllers/movieController.js');
|
var movieController = require('../../controllers/movieController.js');
|
||||||
|
|
||||||
|
|
||||||
router.get('/', movieController.list);
|
router.get('/', movieController.list);
|
||||||
//router.get('/publish', movieController.publish);
|
//router.get('/publish', movieController.publish);
|
||||||
//router.get('/:id', movieController.show);
|
|
||||||
|
|
||||||
router.post('/', movieController.create);
|
router.post('/', movieController.create);
|
||||||
|
|
9
routes/movies/movieShow.js
Normal file
9
routes/movies/movieShow.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
var express = require('express');
|
||||||
|
var router = express.Router();
|
||||||
|
|
||||||
|
/* GET home page. */
|
||||||
|
router.get('/', function(req, res, next) {
|
||||||
|
res.render('movies/show');
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
@ -1,16 +1,13 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en" data-bs-theme="dark">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
||||||
<title>Document</title>
|
<title>Document</title>
|
||||||
<style>
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
|
||||||
body{
|
<script defer src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
|
||||||
background-color: rgb(100, 100, 100);
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>{{message}}</h1>
|
<h1>{{message}}</h1>
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<section class="intro">
|
<section class="intro">
|
||||||
<h1 class="section__title">
|
<h1 class="section__title">
|
||||||
Hi, I am <strong>Nikola Petrov</strong>
|
Hi, I am <strong>Nikola Petrov</strong>
|
||||||
|
24
views/movies/show.hbs
Normal file
24
views/movies/show.hbs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en" data-bs-theme="dark">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Movies</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
|
||||||
|
<script defer src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script defer src="/p_movies/script.js"></script>
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
|
||||||
|
|
||||||
|
<div class="album py-5 bg-body-tertiary">
|
||||||
|
<div class="container">
|
||||||
|
<div id="movie_tbody" class="row row-cols-3 row-cols-sm-4 row-cols-md-5 row-cols-lg-6 g-3">
|
||||||
|
<!-- JS puts images here -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user