From cdf738cb400e8a92f4da2ec1d3a366daedce113b Mon Sep 17 00:00:00 2001 From: Antoine WEBER Date: Tue, 15 Sep 2015 10:41:00 +0200 Subject: [PATCH] ajout page de channel --- routes/channel.js | 43 +++++++++++++++++++++++++++++++++++++++++++ views/channel.jade | 22 ++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 routes/channel.js create mode 100644 views/channel.jade diff --git a/routes/channel.js b/routes/channel.js new file mode 100644 index 0000000..8ed0a9c --- /dev/null +++ b/routes/channel.js @@ -0,0 +1,43 @@ +var express = require('express'); +var router = express.Router(); + + +/* GET home page. */ +router.get('/:id', function(req, res, next) { + var config = require('../config'); + var db = config.init_db(); + + var data = []; + //on fais toute les opération de base a la suite + db.serialize(function() { + + //db.run("CREATE TABLE if not exists user_info (info TEXT)"); + //var stmt = db.prepare("INSERT INTO user_info VALUES (?)"); + //for (var i = 0; i < 10; i++) { + // stmt.run("Ipsum " + i); + //} + //stmt.finalize(); + + db.each("SELECT i.id as id, i.title as title, p.file as file, i.duration as second, i.year as year" + + " FROM metadata_items i, media_parts p " + + " WHERE p.media_item_id=i.id AND i.library_section_id = ? " + + " ORDER BY i.title ASC",req.params.id, function(err, row) { + var tab = row.file.split('/'); + var tab2 = tab[tab.length -1].split('\\'); + var filename = tab2[tab2.length -1]; + if(row.title != ''){ + row.filename = filename; + data.push(row); + } + }, + //aprés toute les opération de la base + function() { + res.render('channel', { title: 'Liste des vidéos',videos: data }); + }); + + }); + + db.close(); +}); + +module.exports = router; diff --git a/views/channel.jade b/views/channel.jade new file mode 100644 index 0000000..8450b97 --- /dev/null +++ b/views/channel.jade @@ -0,0 +1,22 @@ +extends layout + +block content + h1= title + + table(id="example", class="table table-striped table-bordered", cellspacing="0", width="100%") + thead + tr + th Nom + th Durée + th Année + tbody + each video, i in videos + tr + td + a(href="/file/#{video.id}/#{video.filename}")= video.title + td= video.second + td= video.year + script. + $(document).ready(function() { + $('#example').DataTable(); + });