use pending table for scheduling

git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@296 2a923420-c742-0410-a762-8d5b09965624
This commit is contained in:
hummypkg 2011-08-22 20:55:06 +00:00
parent 81c3ef4f73
commit 945c6d1b4b
7 changed files with 246 additions and 70 deletions

View File

@ -62,6 +62,7 @@ proc db_info {db_file} {
$db close
}
db_info /var/lib/humaxtv/rsvp.db
db_info /var/lib/humaxtv/rsv.db
db_info /var/lib/humaxtv/setup.db
db_info /var/lib/humaxtv/channel.db

View File

@ -1,9 +1,55 @@
#!/mod/bin/jimsh
package require cgi
source /mod/var/mongoose/lib/setup
require rsv.class
puts "Content-Type: text/html"
puts ""
#puts [exec /etc/init.d/S90settop restart]
#file delete /tmp/.restartpending
puts [exec killall humaxtv]
cgi_input
if {[cgi_get now] eq "yes"} {
# - Busybox reboot does sync the disk but may still not be clean enough.
puts "Restarting."
exec /etc/init.d/S90settop shut
exec /sbin/reboot
exit
}
file delete /tmp/.restartpending
header
# Commit pending reservations.
rsv commit
puts {
<link href=/css/jquery.progressbar.css rel=stylesheet type=text/css />
<script type="text/javascript" src="/js/jquery.progressbar.js"></script>
<script type=text/javascript>
var handle = 0;
var pct = 0;
function update()
{
$('#progressbar').reportprogress(++pct);
if (pct == 100)
{
clearInterval(handle);
pct = 0;
window.location = '/';
}
}
$(document).ready(function() {
$('#progressbar').reportprogress(0);
handle = setInterval("update()", 300);
$.get('/cgi-bin/restart.jim?now=yes');
});
</script>
Please wait while the Humax restarts...<br>
<div id=progressbar></div>
}
footer

View File

@ -0,0 +1,31 @@
/* progress bar container */
#progressbar{
border:1px solid black;
width:200px;
height:20px;
position:relative;
color:black;
}
/* color bar */
#progressbar div.progress{
position:absolute;
width:0;
height:100%;
overflow:hidden;
background-color:#369;
}
/* text on bar */
#progressbar div.progress .text{
position:absolute;
text-align:center;
color:white;
}
/* text off bar */
#progressbar div.text{
position:absolute;
width:100%;
height:100%;
text-align:center;
}

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2007 Josh Bush (digitalbush.com)
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Progress Bar Plugin for jQuery
* Version: Alpha 2
* Release: 2007-02-26
*/
(function($) {
//Main Method
$.fn.reportprogress = function(val,maxVal) {
var max=100;
if(maxVal)
max=maxVal;
return this.each(
function(){
var div=$(this);
var innerdiv=div.find(".progress");
if(innerdiv.length!=1){
innerdiv=$("<div class='progress'></div>");
div.append("<div class='text'>&nbsp;</div>");
$("<span class='text'>&nbsp;</span>").css("width",div.width()).appendTo(innerdiv);
div.append(innerdiv);
}
var width=Math.round(val/max*100);
innerdiv.css("width",width+"%");
div.find(".text").html(width+" %");
}
);
};
})(jQuery);

View File

@ -36,14 +36,7 @@ puts {
$('#restart_humaxtv').button();
$('#restart_humaxtv').click(function() {
if (confirm('Are you sure you wish to perform a warm restart now?'))
{
$.ajax({
url: '/cgi-bin/restart.jim',
success: function() {
window.location.reload(true);
}
});
}
window.location = '/cgi-bin/restart.jim';
});
</script>
}

View File

@ -3,8 +3,6 @@
source /mod/var/mongoose/lib/setup
require altrow rsv.class progressbar
set events [rsv list]
puts {
<script type=text/javascript>
@ -28,7 +26,7 @@ $.tablesorter.addParser({
});
$(document).ready(function() {
$('#schedtable').tablesorter({
$('table.tablesorter').tablesorter({
headers: {
1: { sorter: false },
3: { sorter: 'programme' },
@ -41,24 +39,28 @@ $(document).ready(function() {
});
});
</script>
<table id=schedtable class="borders tablesorter">
<thead>
<tr>
<th></th>
<th>&nbsp;</th><th>Channel</th>
<th>Programme</th>
<th>Start Time</th>
<th>Duration</th>
<th>Mode</th>
<th>Event/Series ID</th>
<th>Events</th>
</tr>
</thead>
<tbody>
}
foreach event $events {
proc eventheader {} {
puts {
<table class="borders tablesorter">
<thead>
<tr>
<th></th>
<th>&nbsp;</th><th>Channel</th>
<th>Programme</th>
<th>Start Time</th>
<th>Duration</th>
<th>Mode</th>
<th>Event/Series ID</th>
<th>Events</th>
</tr>
</thead>
<tbody>
}
}
proc eventrow {event} {
set name [$event name]
altrow
@ -169,8 +171,31 @@ foreach event $events {
}
puts "</tr>"
}
puts "</tbody></table>"
puts "<font class=footnote>Click on the CRID to view episodes.</font>"
proc eventfooter {} {
puts "</tbody></table>"
}
set events [rsv list pending]
if {[llength $events] > 0} {
puts "<h2>Pending Scheduled Events</h2>"
eventheader
foreach event $events {eventrow $event}
eventfooter
puts {
<small>
<button onclick="window.location='/cgi-bin/db.jim?db=rsvp.db&tab=pending';">
Raw database view
</button>
</small>
}
}
puts "<h2>Scheduled Events</h2>"
set events [rsv list]
eventheader
foreach event $events {eventrow $event}
eventfooter
puts {
<small>

View File

@ -6,7 +6,16 @@ if {![exists -proc settings ]} { require settings.class }
set rsvdb [sqlite3.open /var/lib/humaxtv/rsv.db]
$rsvdb query {attach database '/var/lib/humaxtv/channel.db' as channel}
catch { $rsvdb query {.mode tcl} }
if {![file exists /var/lib/humaxtv/rsvp.db]} {
file copy /var/lib/humaxtv/rsv.db /var/lib/humaxtv/rsvp.db
set tdb [sqlite3.open /var/lib/humaxtv/rsvp.db]
$tdb query {drop table TBL_VERSION}
$tdb query {alter table TBL_RESERVATION rename to pending}
$tdb query {delete from pending}
$tdb close
}
$rsvdb query {attach database '/var/lib/humaxtv/rsvp.db' as pending}
class rsv {
ulslot -1
@ -40,6 +49,10 @@ class rsv {
sort 0
}
rsv method clear_ulslot {} {
set ulslot -1
}
rsv method name {} {
set name [string range $szevtname 1 end]
if {[string first "i7" $name] == 0} {
@ -81,25 +94,27 @@ rsv method fix_hsvc {} {
return $hsvc
}
rsv method insert {} {
rsv method insert {{table pending}} {
global rsvdb
# Find a spare slot.
if {$ulslot < 0} {
set slots [lmap i [
$rsvdb query {
select ulslot FROM TBL_RESERVATION
order by ulslot;
}] {lindex $i 1}]
set max [lindex $i end]
for {set i 0} {$i < $max} {incr i} {
if {$i ni $slots} {
set ulslot $i
break
set slotlist [$rsvdb query "
select ulslot FROM $table
order by ulslot;
"]
if {[llength $slotlist] > 0} {
set slots [lmap i $slotlist {lindex $i 1}]
set max [lindex $i end]
for {set i 0} {$i < $max} {incr i} {
if {$i ni $slots} {
set ulslot $i
break
}
}
if {$ulslot < 0} { set ulslot $($max + 1) }
}
if {$ulslot == -1} { set ulslot $($max + 1) }
if {$ulslot < 0} { set ulslot 0 }
}
set fields [lsort [$self vars]]
@ -117,7 +132,7 @@ rsv method insert {} {
#lappend vals "'[$self get $field]'"
}
set query "insert into TBL_RESERVATION("
set query "insert into ${table}("
append query [join $fields ","]
append query ") values("
append query [join $vals ","]
@ -126,16 +141,16 @@ rsv method insert {} {
$rsvdb query $query
}
proc {rsv list} {} {
set res [$::rsvdb query {
select tbl_reservation.*,
proc {rsv list} {{table tbl_reservation}} {
set res [$::rsvdb query "
select $table.*,
channel.TBL_SVC.szSvcName, channel.TBL_SVC.usLcn,
case when ersvtype > 3 then 1 else 0 end as sort
from tbl_reservation
from $table
left join channel.TBL_SVC
on main.TBL_RESERVATION.hSvc = channel.TBL_SVC.hSvc
on $table.hSvc = channel.TBL_SVC.hSvc
order by sort, nsttime
}]
"]
set records {}
foreach rec $res {
@ -146,31 +161,32 @@ proc {rsv list} {} {
}
proc {rsv lookuptab} {} {
set res [$::rsvdb query {
select tbl_reservation.szCRID, channel.TBL_SVC.hSvc
from tbl_reservation left join channel.TBL_SVC
on main.TBL_RESERVATION.hSvc = channel.TBL_SVC.hSvc
where ersvtype <= 3
}]
set records {}
foreach rec $res {
lappend records "$rec(hSvc)/[file tail $rec(szCRID)]"
foreach tab {tbl_reservation pending} {
set res [$::rsvdb query "
select $tab.szCRID, channel.TBL_SVC.hSvc
from $tab left join channel.TBL_SVC
on $tab.hSvc = channel.TBL_SVC.hSvc
where ersvtype <= 3
"]
foreach rec $res {
lappend records "$rec(hSvc)/[file tail $rec(szCRID)]"
}
}
return $records
}
proc {rsv entry} {crid svc} {
set res [$::rsvdb query {
select tbl_reservation.*,
proc {rsv entry} {{table TBL_RESERVATION} crid svc} {
set res [$::rsvdb query "
select $table.*,
channel.TBL_SVC.szSvcName, channel.TBL_SVC.usLcn
from tbl_reservation
from $table
left join channel.TBL_SVC
on main.TBL_RESERVATION.hSvc = channel.TBL_SVC.hSvc
where szCRID like '%%%s' and tbl_reservation.hsvc = '%s'
} $crid $svc]
on $table.hSvc = channel.TBL_SVC.hSvc
where szCRID like '%%%s' and $table.hsvc = '%s'
" $crid $svc]
if {[llength $res] > 0} {
return [rsv new [lindex $res 0]]
@ -182,3 +198,13 @@ proc {rsv cleanup} {} {
catch {$::rsvdb close}
}
proc {rsv commit} {} {
$::rsvdb query {begin transaction}
foreach rec [rsv list pending] {
$rec clear_ulslot
$rec insert TBL_RESERVATION
}
$::rsvdb query {delete from pending}
$::rsvdb query {commit transaction}
}