From 3bc5a24b27f08202f25df931f1a8ae5b78e58b49 Mon Sep 17 00:00:00 2001 From: Jan Grewe <jan@faked.org> Date: Sat, 22 Feb 2014 03:10:05 +0100 Subject: [PATCH] add latest movies carousel --- api.php | 17 +++++++++++++++++ css/mediarack.css | 6 +++++- index.php | 33 +++++++++++++++++++++++++++------ js/mediarack.js | 21 +++++++++++++-------- 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/api.php b/api.php index a542715..7963532 100644 --- a/api.php +++ b/api.php @@ -196,6 +196,23 @@ if ($_GET['get'] == 'latest' && $_GET['type'] == 'shows') { die; } +if ($_GET['get'] == 'latest' && $_GET['type'] == 'movies') { + $cpdb = new PDO('sqlite:'.$cpPath.'/couchpotato.db'); + $cpdb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $movies = $cpdb->query("SELECT lt.title, l.year FROM library AS l + JOIN librarytitle AS lt ON l.id=lt.libraries_id + JOIN movie AS m on l.id=m.library_id + JOIN status AS s ON m.status_id=s.id + WHERE m.status_id = 3 AND `default` = 1 + ORDER BY m.last_edit DESC LIMIT 10;"); + $output = array(); + foreach ($movies as $movie) { + array_push($output, array("movie" => $movie['title'].' ('.$movie['year'].')')); + } + echo json_encode($output); + die; +} + function cleanName($name, $strict = true) { if($strict == true) diff --git a/css/mediarack.css b/css/mediarack.css index 76de927..b32c490 100644 --- a/css/mediarack.css +++ b/css/mediarack.css @@ -73,15 +73,19 @@ div#shows, div#movies { display: none; } -ul#latestShows li { +ul#latestShows li, +ul#latestMovies li { text-align: center; } div.epLabel { + max-width: 200px; margin-top: 5px; font-size: 8pt; font-weight: bold; line-height: 15px; + text-align: center; + } .jcarousel-wrapper { diff --git a/index.php b/index.php index 733facc..6221455 100644 --- a/index.php +++ b/index.php @@ -56,13 +56,34 @@ <div class="container"> - <div class="content jumbotron" id="home"> - <div class="jcarousel-wrapper"> - <div class="jcarousel"> - <ul id="latestShows"></ul> + <div class="content" id="home"> + <div class="panel panel-default"> + <div class="panel-heading"> + <h3 class="panel-title">Newest TV Show Episodes</h3> + </div> + <div class="panel-body"> + <div class="jcarousel-wrapper"> + <div class="jcarousel jcShows"> + <ul id="latestShows"></ul> + </div> + <a href="#" class="jcarousel-control-prev jcShows">‹</a> + <a href="#" class="jcarousel-control-next jcShows">›</a> + </div> + </div> + </div> + <div class="panel panel-default"> + <div class="panel-heading"> + <h3 class="panel-title">Newest Movies</h3> + </div> + <div class="panel-body"> + <div class="jcarousel-wrapper"> + <div class="jcarousel jcMovies"> + <ul id="latestMovies"></ul> + </div> + <a href="#" class="jcarousel-control-prev jcMovies">‹</a> + <a href="#" class="jcarousel-control-next jcMovies">›</a> + </div> </div> - <a href="#" class="jcarousel-control-prev">‹</a> - <a href="#" class="jcarousel-control-next">›</a> </div> </div> diff --git a/js/mediarack.js b/js/mediarack.js index 58cd0ac..4c4e992 100644 --- a/js/mediarack.js +++ b/js/mediarack.js @@ -8,7 +8,8 @@ var loadMovies = true; $(document).ready(function() { - getLatest(); + getLatest('Shows'); + getLatest('Movies'); getShows(); getMovies(); @@ -36,17 +37,21 @@ $(document).ready(function() { }); -function getLatest() { +function getLatest(type) { $.getJSON('api.php', { - 'type': 'shows', + 'type': type.toLowerCase(), 'get': 'latest' }, function(data) { $.each(data, function (key, ep) { - var ulLatestContainer = $("#latestShows"); - var liLatestItem = $('<li><img src="api.php?get=poster&show='+escape(ep.show)+'" /><div class="epLabel">'+ep.show+'<br />'+ep.episode+'<br />'+ep.name+'<br />'+ep.airdate+'</div></li>'); + var ulLatestContainer = $("#latest"+type); + if(type == 'Shows') { + var liLatestItem = $('<li><img src="api.php?get=poster&show='+escape(ep.show)+'" /><div class="epLabel">'+ep.show+'<br />'+ep.episode+'<br />'+ep.name+'<br />'+ep.airdate+'</div></li>'); + }else{ + var liLatestItem = $('<li><img src="api.php?get=poster&movie='+escape(ep.movie)+'" /><div class="epLabel">'+ep.movie+'</div></li>'); + } ulLatestContainer.append(liLatestItem); }); - $('.jcarousel') + $('.jcarousel.jc'+type) .on('jcarousel:create jcarousel:reload', function() { var element = $(this), width = element.innerWidth(); @@ -65,7 +70,7 @@ function getLatest() { .jcarousel({ wrap: 'both' }); - $('.jcarousel-control-prev') + $('.jcarousel-control-prev.jc'+type) .on('jcarouselcontrol:active', function() { $(this).removeClass('inactive'); }) @@ -76,7 +81,7 @@ function getLatest() { target: '-=1' }); - $('.jcarousel-control-next') + $('.jcarousel-control-next.jc'+type) .on('jcarouselcontrol:active', function() { $(this).removeClass('inactive'); }) -- GitLab