From 04d63837ba5831929728c8444483a8f704e29e66 Mon Sep 17 00:00:00 2001 From: martin Date: Sun, 6 Feb 2011 22:35:53 -0500 Subject: [PATCH] -fixed problem with list-view generating too many ajax requests --- public/js/playlist/helperfunctions.js | 46 ++++++++++++++++++------ public/js/playlist/nowplayingdatagrid.js | 9 ++++- public/js/playlist/playlist.js | 12 +------ 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/public/js/playlist/helperfunctions.js b/public/js/playlist/helperfunctions.js index 62822cedf..805a1b0bb 100644 --- a/public/js/playlist/helperfunctions.js +++ b/public/js/playlist/helperfunctions.js @@ -66,6 +66,20 @@ function convertToHHMMSSmm(timeInMS){ return hours + ":" + minutes + ":" + seconds+ "." + ms; } +function convertDateToHHMM(epochTime){ + var d = new Date(epochTime); + + var hours = d.getUTCHours().toString(); + var minutes = d.getUTCMinutes().toString(); + + if (hours.length == 1) + hours = "0" + hours; + if (minutes.length == 1) + minutes = "0" + minutes; + + return hours + ":" + minutes; +} + function convertDateToHHMMSS(epochTime){ var d = new Date(epochTime); @@ -82,17 +96,29 @@ function convertDateToHHMMSS(epochTime){ return hours + ":" + minutes + ":" + seconds; } +/* Takes in a string of format similar to 2011-02-07 02:59:57, + * and converts this to epoch/posix time. */ function convertDateToPosixTime(s){ - var year = s.substring(0, 4); - var month = s.substring(5, 7); - var day = s.substring(8, 10); - var hour = s.substring(11, 13); - var minute = s.substring(14, 16); - var sec = s.substring(17, 19); - var msec = 0; - if (s.length >= 20){ - msec = s.substring(20); - } + + var temp = s.split(" "); + + var date = temp[0].split("-"); + var time = temp[1].split(":"); + + var year = date[0]; + var month = date[1]; + var day = date[2]; + var hour = time[0]; + var minute = time[1]; + var sec = 0; + var msec = 0; + + if (time[2].indexOf(".") != -1){ + var temp1 = time[2].split("."); + sec = temp1[0]; + msec = temp1[1]; + } else + sec = time[2]; return Date.UTC(year, month, day, hour, minute, sec, msec); } diff --git a/public/js/playlist/nowplayingdatagrid.js b/public/js/playlist/nowplayingdatagrid.js index 342e6bf27..6dbe741a6 100644 --- a/public/js/playlist/nowplayingdatagrid.js +++ b/public/js/playlist/nowplayingdatagrid.js @@ -96,10 +96,12 @@ function createDataGrid(){ } } ); - setTimeout(init2, 5000); + } var viewType = "now" //"day"; +var mainLoopRegistered = false; + function setViewType(type){ if (type == 0){ viewType = "now"; @@ -119,6 +121,11 @@ function init2(){ registered = true; registerSongEndListener(notifySongEnd); } + + if (!mainLoopRegistered){ + setTimeout(init2, 5000); + mainLoopRegistered = true; + } } $(document).ready(function() { diff --git a/public/js/playlist/playlist.js b/public/js/playlist/playlist.js index 71f0618b2..96e8ce9c1 100644 --- a/public/js/playlist/playlist.js +++ b/public/js/playlist/playlist.js @@ -172,7 +172,7 @@ function updatePlaybar(){ $('#show-length').empty(); if (currentShow.length > 0){ - $('#show-length').text(convertDateToHHMMSS(currentShow[0].showStartPosixTime) + " - " + convertDateToHHMMSS(currentShow[0].showEndPosixTime)); + $('#show-length').text(convertDateToHHMM(currentShow[0].showStartPosixTime) + " - " + convertDateToHHMM(currentShow[0].showEndPosixTime)); } /* Column 2 update */ @@ -228,15 +228,6 @@ function parseItems(obj){ } -function getScheduleFromServerDebug(){ - $.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"text", success:function(data){ - alert(data); - }}); - setTimeout(getScheduleFromServer, serverUpdateInterval); -} - - - function getScheduleFromServer(){ $.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){ parseItems(data.entries); @@ -248,7 +239,6 @@ function getScheduleFromServer(){ function init() { //begin producer "thread" getScheduleFromServer(); - //getScheduleFromServerDebug(); //begin consumer "thread" secondsTimer();