From 9b5a0fc5650592bca84a70fffba3158c0e1e6dad Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Tue, 21 Feb 2012 17:31:54 +0100 Subject: [PATCH] CC-3174 : showbuilder working on trying to save/load state serialized into the db for datatables. --- .../application/controllers/ApiController.php | 110 +++++------- .../controllers/LibraryController.php | 12 +- .../controllers/PreferenceController.php | 34 +++- airtime_mvc/public/css/showbuilder.css | 9 +- .../public/js/airtime/library/library.js | 167 ++++++++++-------- .../public/js/airtime/showbuilder/builder.js | 4 +- .../plugin/dataTables.ColReorder.js | 100 ++++------- .../js/datatables/plugin/dataTables.ColVis.js | 6 +- 8 files changed, 211 insertions(+), 231 deletions(-) mode change 100644 => 100755 airtime_mvc/public/js/datatables/plugin/dataTables.ColReorder.js mode change 100644 => 100755 airtime_mvc/public/js/datatables/plugin/dataTables.ColVis.js diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 4026d7460..f9628a78a 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -24,7 +24,6 @@ class ApiController extends Zend_Controller_Action ->addActionContext('status', 'json') ->addActionContext('register-component', 'json') ->addActionContext('update-liquidsoap-status', 'json') - ->addActionContext('library-init', 'json') ->addActionContext('live-chat', 'json') ->addActionContext('update-file-system-mount', 'json') ->addActionContext('handle-watched-dir-missing', 'json') @@ -64,7 +63,7 @@ class ApiController extends Zend_Controller_Action $jsonStr = json_encode(array("version"=>Application_Model_Preference::GetAirtimeVersion())); echo $jsonStr; } - + /** * Sets up and send init values used in the Calendar. * This is only being used by schedule.js at the moment. @@ -72,16 +71,16 @@ class ApiController extends Zend_Controller_Action public function calendarInitAction(){ $this->view->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); - + if(is_null(Zend_Auth::getInstance()->getStorage()->read())) { header('HTTP/1.0 401 Unauthorized'); print 'You are not allowed to access this resource.'; return; } - + $this->view->calendarInit = array( - "timestamp" => time(), - "timezoneOffset" => date("Z"), + "timestamp" => time(), + "timezoneOffset" => date("Z"), "timeScale" => Application_Model_Preference::GetCalendarTimeScale(), "timeInterval" => Application_Model_Preference::GetCalendarTimeInterval(), "weekStartDay" => Application_Model_Preference::GetWeekStartDay() @@ -178,9 +177,9 @@ class ApiController extends Zend_Controller_Action * Retrieve the currently playing show as well as upcoming shows. * Number of shows returned and the time interval in which to * get the next shows can be configured as GET parameters. - * + * * TODO: in the future, make interval length a parameter instead of hardcode to 48 - * + * * Possible parameters: * type - Can have values of "endofday" or "interval". If set to "endofday", * the function will retrieve shows from now to end of day. @@ -199,19 +198,19 @@ class ApiController extends Zend_Controller_Action $date = new Application_Model_DateHelper; $utcTimeNow = $date->getUtcTimestamp(); $utcTimeEnd = ""; // if empty, GetNextShows will use interval instead of end of day - + $request = $this->getRequest(); $type = $request->getParam('type'); if($type == "endofday") { // make GetNextShows use end of day $utcTimeEnd = Application_Model_DateHelper::GetDayEndTimestampInUtc(); } - + $limit = $request->getParam('limit'); if($limit == "" || !is_numeric($limit)) { $limit = "5"; } - + $result = array("env"=>APPLICATION_ENV, "schedulerTime"=>gmdate("Y-m-d H:i:s"), "currentShow"=>Application_Model_Show::GetCurrentShow($utcTimeNow), @@ -219,7 +218,7 @@ class ApiController extends Zend_Controller_Action "timezone"=> date("T"), "timezoneOffset"=> date("Z"), "AIRTIME_API_VERSION"=>AIRTIME_API_VERSION); //used by caller to determine if the airtime they are running or widgets in use is out of date. - + //Convert from UTC to localtime for user. Application_Model_Show::ConvertToLocalTimeZone($result["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp")); Application_Model_Show::ConvertToLocalTimeZone($result["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp")); @@ -233,7 +232,7 @@ class ApiController extends Zend_Controller_Action exit; } } - + public function weekInfoAction() { if (Application_Model_Preference::GetAllow3rdPartyApi()){ @@ -244,7 +243,7 @@ class ApiController extends Zend_Controller_Action $date = new Application_Model_DateHelper; $dayStart = $date->getWeekStartDate(); $utcDayStart = Application_Model_DateHelper::ConvertToUtcDateTimeString($dayStart); - + $dow = array("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"); $result = array(); @@ -252,9 +251,9 @@ class ApiController extends Zend_Controller_Action $utcDayEnd = Application_Model_DateHelper::GetDayEndTimestamp($utcDayStart); $shows = Application_Model_Show::GetNextShows($utcDayStart, "0", $utcDayEnd); $utcDayStart = $utcDayEnd; - + Application_Model_Show::ConvertToLocalTimeZone($shows, array("starts", "ends", "start_timestamp", "end_timestamp")); - + $result[$dow[$i]] = $shows; } $result['AIRTIME_API_VERSION'] = AIRTIME_API_VERSION; //used by caller to determine if the airtime they are running or widgets in use is out of date. @@ -373,8 +372,8 @@ class ApiController extends Zend_Controller_Action $now = new DateTime($today_timestamp); $end_timestamp = $now->add(new DateInterval("PT2H")); $end_timestamp = $end_timestamp->format("Y-m-d H:i:s"); - - $this->view->shows = Application_Model_Show::getShows(Application_Model_DateHelper::ConvertToUtcDateTime($today_timestamp, date_default_timezone_get()), + + $this->view->shows = Application_Model_Show::getShows(Application_Model_DateHelper::ConvertToUtcDateTime($today_timestamp, date_default_timezone_get()), Application_Model_DateHelper::ConvertToUtcDateTime($end_timestamp, date_default_timezone_get()), $excludeInstance=NULL, $onlyRecord=TRUE); @@ -405,7 +404,7 @@ class ApiController extends Zend_Controller_Action $upload_dir = ini_get("upload_tmp_dir"); $tempFilePath = Application_Model_StoredFile::uploadFile($upload_dir); $tempFileName = basename($tempFilePath); - + $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : ''; $result = Application_Model_StoredFile::copyFileToStor($upload_dir, $fileName, $tempFileName); if (isset($result)){ @@ -456,19 +455,19 @@ class ApiController extends Zend_Controller_Action } if (isset($show_name)) { - + $show_name = str_replace(" ", "-", $show_name); - + //2011-12-09-19-28-00-ofirrr-256kbps $filename = $file->getName(); - + //replace the showname in the filepath incase it has been edited since the show started recording //(some old bug) $filename_parts = explode("-", $filename); $new_name = array_slice($filename_parts, 0, 6); $new_name[] = $show_name; $new_name[] = $filename_parts[count($filename_parts)-1]; - + $tmpTitle = implode("-", $new_name); } else { @@ -533,7 +532,7 @@ class ApiController extends Zend_Controller_Action } $this->view->stor = Application_Model_MusicDir::getStorDir()->getDirectory(); - + $watchedDirs = Application_Model_MusicDir::getWatchedDirs(); $watchedDirsPath = array(); foreach($watchedDirs as $wd){ @@ -573,7 +572,7 @@ class ApiController extends Zend_Controller_Action $filepath = str_replace("//", "/", $filepath); $file = Application_Model_StoredFile::RecallByFilepath($filepath); - + if (is_null($file)) { $file = Application_Model_StoredFile::Insert($md); } @@ -737,10 +736,10 @@ class ApiController extends Zend_Controller_Action $this->view->msg = Application_Model_MusicDir::setStorDir($path); } - + public function getStreamSettingAction() { global $CC_CONFIG; - + $request = $this->getRequest(); $api_key = $request->getParam('api_key'); if (!in_array($api_key, $CC_CONFIG["apiKey"])) @@ -752,10 +751,10 @@ class ApiController extends Zend_Controller_Action $this->view->msg = Application_Model_StreamSetting::getStreamSetting(); } - + public function statusAction() { global $CC_CONFIG; - + $request = $this->getRequest(); $api_key = $request->getParam('api_key'); $getDiskInfo = $request->getParam('diskinfo') == "true"; @@ -767,7 +766,7 @@ class ApiController extends Zend_Controller_Action exit; } */ - + $status = array( "platform"=>Application_Model_Systemstatus::GetPlatformInfo(), "airtime_version"=>Application_Model_Preference::GetAirtimeVersion(), @@ -779,11 +778,11 @@ class ApiController extends Zend_Controller_Action "media_monitor"=>Application_Model_Systemstatus::GetMediaMonitorStatus() ) ); - + if ($getDiskInfo){ $status["partitions"] = Application_Model_Systemstatus::GetDiskInfo(); } - + $this->view->status = $status; } @@ -796,40 +795,21 @@ class ApiController extends Zend_Controller_Action Application_Model_ServiceRegister::Register($component, $remoteAddr); } - + public function updateLiquidsoapStatusAction(){ $request = $this->getRequest(); - + $msg = $request->getParam('msg'); $stream_id = $request->getParam('stream_id'); $boot_time = $request->getParam('boot_time'); - + Application_Model_StreamSetting::setLiquidsoapError($stream_id, $msg, $boot_time); } - - /** - * Sets up and send init values used in the Library. - * This is being used by library.js - */ - public function libraryInitAction(){ - $this->view->layout()->disableLayout(); - $this->_helper->viewRenderer->setNoRender(true); - - if(is_null(Zend_Auth::getInstance()->getStorage()->read())) { - header('HTTP/1.0 401 Unauthorized'); - print 'You are not allowed to access this resource.'; - return; - } - - $this->view->libraryInit = array( - "numEntries"=>Application_Model_Preference::GetLibraryNumEntries() - ); - } - + // handles addition/deletion of mount point which watched dirs reside public function updateFileSystemMountAction(){ global $CC_CONFIG; - + $request = $this->getRequest(); $api_key = $request->getParam('api_key'); if (!in_array($api_key, $CC_CONFIG["apiKey"])) @@ -842,16 +822,16 @@ class ApiController extends Zend_Controller_Action $params = $request->getParams(); $added_list = empty($params['added_dir'])?array():explode(',',$params['added_dir']); $removed_list = empty($params['removed_dir'])?array():explode(',',$params['removed_dir']); - + // get all watched dirs $watched_dirs = Application_Model_MusicDir::getWatchedDirs(null,null); - + foreach( $added_list as $ad){ foreach( $watched_dirs as $dir ){ $dirPath = $dir->getDirectory(); - + $ad .= '/'; - + // if mount path itself was watched if($dirPath == $ad){ Application_Model_MusicDir::addWatchedDir($dirPath, false); @@ -884,7 +864,7 @@ class ApiController extends Zend_Controller_Action // is new mount point within the watched dir? // pyinotify doesn't notify anyhing in this case, so we walk through all files within // this watched dir in DB and mark them deleted. - // In case of h) of use cases, due to pyinotify behaviour of noticing mounted dir, we need to + // In case of h) of use cases, due to pyinotify behaviour of noticing mounted dir, we need to // compare agaisnt all files in cc_files table else if(substr($rd, 0, strlen($dirPath)) === $dirPath ){ $watchDir = Application_Model_MusicDir::getDirByPath($rd); @@ -903,13 +883,13 @@ class ApiController extends Zend_Controller_Action } } } - + } - + // handles case where watched dir is missing public function handleWatchedDirMissingAction(){ global $CC_CONFIG; - + $request = $this->getRequest(); $api_key = $request->getParam('api_key'); if (!in_array($api_key, $CC_CONFIG["apiKey"])) @@ -918,7 +898,7 @@ class ApiController extends Zend_Controller_Action print 'You are not allowed to access this resource.'; exit; } - + $dir = base64_decode($request->getParam('dir')); Application_Model_MusicDir::removeWatchedDir($dir, false); } diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 1b2f9dfe4..1418b0f0f 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -47,7 +47,7 @@ class LibraryController extends Zend_Controller_Action $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.pluginAPI.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.fnSetFilteringDelay.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.ColVis.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.ColReorderResize.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.ColReorder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.FixedColumns.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.TableTools.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); @@ -282,14 +282,4 @@ class LibraryController extends Zend_Controller_Action $this->view->error_msg = $file->getSoundCloudErrorMsg(); } } - - /** - * Stores the number of entries user chose to show in the Library - * to the pref db - */ - public function setNumEntriesAction() { - $request = $this->getRequest(); - $numEntries = $request->getParam('numEntries'); - Application_Model_Preference::SetLibraryNumEntries($numEntries); - } } diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index b297700b0..ee93539cd 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -14,13 +14,15 @@ class PreferenceController extends Zend_Controller_Action ->addActionContext('is-import-in-progress', 'json') ->addActionContext('change-stream-setting', 'json') ->addActionContext('get-liquidsoap-status', 'json') + ->addActionContext('get-library-datatable', 'json') + ->addActionContext('set-library-datatable', 'json') ->initContext(); } public function indexAction() { global $CC_CONFIG; - + $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); @@ -59,7 +61,7 @@ class PreferenceController extends Zend_Controller_Action public function supportSettingAction() { global $CC_CONFIG; - + $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); @@ -119,7 +121,7 @@ class PreferenceController extends Zend_Controller_Action public function directoryConfigAction() { global $CC_CONFIG; - + if(Application_Model_Preference::GetPlanLevel() == 'disabled'){ $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); @@ -136,7 +138,7 @@ class PreferenceController extends Zend_Controller_Action public function streamSettingAction() { global $CC_CONFIG; - + $request = $this->getRequest(); $baseUrl = $request->getBaseUrl(); @@ -206,10 +208,10 @@ class PreferenceController extends Zend_Controller_Action $values['output_sound_device'] = $form->getValue('output_sound_device'); } - + $values['icecast_vorbis_metadata'] = $form->getValue('icecast_vorbis_metadata'); $values['output_sound_device_type'] = $form->getValue('output_sound_device_type'); - $values['streamFormat'] = $form->getValue('streamFormat'); + $values['streamFormat'] = $form->getValue('streamFormat'); } if(!$error){ @@ -331,6 +333,26 @@ class PreferenceController extends Zend_Controller_Action } die(json_encode($out)); } + + public function setLibraryDatatableAction() { + + $request = $this->getRequest(); + $settings = $request->getParam("settings"); + + $data = serialize($settings); + Logging::log("library datatable"); + Logging::log($data); + + Application_Model_Preference::SetValue("library_datatable", $data, true); + + } + + public function getLibraryDatatableAction() { + + $data = Application_Model_Preference::GetValue("library_datatable", true); + + $this->view->settings = unserialize($data); + } } diff --git a/airtime_mvc/public/css/showbuilder.css b/airtime_mvc/public/css/showbuilder.css index 9a443518c..9bc163de2 100644 --- a/airtime_mvc/public/css/showbuilder.css +++ b/airtime_mvc/public/css/showbuilder.css @@ -2,4 +2,11 @@ #show_builder input.input_text { width:100px; -} \ No newline at end of file +} + +#show_builder span.ui-icon-triangle-1-e { + float: left; + position: relative; + left: -20px; + top: 15px; +} diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index faee0bd35..3f1a24f17 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -211,76 +211,51 @@ function addQtipToSCIcons(){ }); } -function fnCreatedRow( nRow, aData, iDataIndex ) { - - //call the context menu so we can prevent the event from propagating. - $(nRow).find('td:not(.library_checkbox):not(.library_type)').click(function(e){ - - $(this).contextMenu(); - - return false; - }); - - //add a tool tip to appear when the user clicks on the type icon. - $(nRow.children[1]).qtip({ - content: { - text: "Loading...", - title: { - text: aData.track_title - }, - ajax: { - url: "/Library/get-file-meta-data", - type: "get", - data: ({format: "html", id : aData.id, type: aData.ftype}), - success: function(data, status) { - this.set('content.text', data); - } - } - }, - position: { - my: 'left center', - at: 'right center', // Position the tooltip above the link - viewport: $(window), // Keep the tooltip on-screen at all times - effect: false // Disable positioning animation - }, - style: { - classes: "ui-tooltip-dark" - }, - show: { - event: 'click', - solo: true // Only show one tooltip at a time - }, - hide: 'mouseout' - - }).click(function(event) { - event.preventDefault(); - event.stopPropagation(); - }); -} - -/** - * Updates pref db when user changes the # of entries to show - */ -function saveNumEntriesSetting() { - $('select[name=library_display_length]').change(function() { - var url = '/Library/set-num-entries/format/json'; - $.post(url, {numEntries: $(this).val()}); - }); -} - -/** - * Use user preference for number of entries to show - */ -function getNumEntriesPreference(data) { - return parseInt(data.libraryInit.numEntries, 10); -} - -function createDataTable(data) { - var oTable; +$(document).ready(function() { + var oTable; + + $('.tabs').tabs(); oTable = $('#library_display').dataTable( { "bProcessing": true, "bServerSide": true, + + "bStateSave": true, + "fnStateSave": function (oSettings, oData) { + + $.ajax({ + url: "/preference/set-library-datatable", + type: "POST", + data: {settings : oData, format: "json"}, + dataType: "json", + success: function(){ + var x; + }, + error: function (jqXHR, textStatus, errorThrown) { + var x; + } + }); + }, + "fnStateLoad": function (oSettings) { + var o; + + $.ajax({ + url: "/preference/get-library-datatable", + type: "GET", + data: {format: "json"}, + dataType: "json", + async: false, + success: function(json){ + o = json.settings; + }, + error: function (jqXHR, textStatus, errorThrown) { + var x; + } + }); + + return o; + }, + "sAjaxSource": "/Library/contents", "fnServerData": function ( sSource, aoData, testCallback ) { aoData.push( { name: "format", value: "json"} ); @@ -293,7 +268,52 @@ function createDataTable(data) { } ); }, "fnRowCallback": AIRTIME.library.events.fnRowCallback, - "fnCreatedRow": fnCreatedRow, + "fnCreatedRow": function( nRow, aData, iDataIndex ) { + + //call the context menu so we can prevent the event from propagating. + $(nRow).find('td:not(.library_checkbox):not(.library_type)').click(function(e){ + + $(this).contextMenu(); + + return false; + }); + + //add a tool tip to appear when the user clicks on the type icon. + $(nRow.children[1]).qtip({ + content: { + text: "Loading...", + title: { + text: aData.track_title + }, + ajax: { + url: "/Library/get-file-meta-data", + type: "get", + data: ({format: "html", id : aData.id, type: aData.ftype}), + success: function(data, status) { + this.set('content.text', data); + } + } + }, + position: { + my: 'left center', + at: 'right center', // Position the tooltip above the link + viewport: $(window), // Keep the tooltip on-screen at all times + effect: false // Disable positioning animation + }, + style: { + classes: "ui-tooltip-dark" + }, + show: { + event: 'click', + solo: true // Only show one tooltip at a time + }, + hide: 'mouseout' + + }).click(function(event) { + event.preventDefault(); + event.stopPropagation(); + }); + }, "fnDrawCallback": AIRTIME.library.events.fnDrawCallback, "fnHeaderCallback": function(nHead) { $(nHead).find("input[type=checkbox]").attr("checked", false); @@ -319,8 +339,7 @@ function createDataTable(data) { "oLanguage": { "sSearch": "" }, - "iDisplayLength": getNumEntriesPreference(data), - + // R = ColReorder, C = ColVis, T = TableTools "sDom": 'Rlfr<"H"T<"library_toolbar"C>>t<"F"ip>', @@ -353,8 +372,7 @@ function createDataTable(data) { "buttonText": "Show/Hide Columns", "sAlign": "right", "aiExclude": [0, 1], - "sSize": "css", - "bShowAll": true + "sSize": "css" }, "oColReorder": { @@ -377,13 +395,6 @@ function createDataTable(data) { oTT.fnSelectNone(); } }); -} - -$(document).ready(function() { - $('.tabs').tabs(); - - $.ajax({url: "/Api/library-init/format/json", dataType:"json", success:createDataTable, - error:function(jqXHR, textStatus, errorThrown){}}); checkImportStatus(); setInterval( checkImportStatus, 5000 ); diff --git a/airtime_mvc/public/js/airtime/showbuilder/builder.js b/airtime_mvc/public/js/airtime/showbuilder/builder.js index 10796ab01..205d8db78 100644 --- a/airtime_mvc/public/js/airtime/showbuilder/builder.js +++ b/airtime_mvc/public/js/airtime/showbuilder/builder.js @@ -205,7 +205,7 @@ $(document).ready(function() { if (aData.header === true) { cl = 'sb-header'; - sSeparatorHTML = ''+aData.title+''+aData.starts+''+aData.ends+''; + sSeparatorHTML = ''+aData.title+''+aData.starts+''+aData.ends+''; fnPrepareSeparatorRow(sSeparatorHTML, cl, 0); } else if (aData.footer === true) { @@ -230,7 +230,7 @@ $(document).ready(function() { node = nRow.children[0]; if (aData.checkbox === true) { - node.innerHTML = ''; + node.innerHTML = ''; } else { node.innerHTML = ''; diff --git a/airtime_mvc/public/js/datatables/plugin/dataTables.ColReorder.js b/airtime_mvc/public/js/datatables/plugin/dataTables.ColReorder.js old mode 100644 new mode 100755 index 95c39fcec..7c7b728a2 --- a/airtime_mvc/public/js/datatables/plugin/dataTables.ColReorder.js +++ b/airtime_mvc/public/js/datatables/plugin/dataTables.ColReorder.js @@ -1,6 +1,6 @@ /* * File: ColReorder.js - * Version: 1.0.4 + * Version: 1.0.5 * CVS: $Id$ * Description: Controls for column visiblity in DataTables * Author: Allan Jardine (www.sprymedia.co.uk) @@ -163,7 +163,11 @@ $.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo ) /* Data column sorting (the column which the sort for a given column should take place on) */ for ( i=0, iLen=iCols ; i