CC-1977: Allow multiple files to be selected and acted upon in the library and playlist

- Fixed issues in "Manage Users" page
- Moved some code to more appropriate place
This commit is contained in:
Yuchen Wang 2012-01-13 14:17:39 -05:00
parent 186aa9e898
commit 258521ffbf
3 changed files with 74 additions and 57 deletions

View File

@ -314,8 +314,13 @@ class Application_Model_StoredFile {
}
}
Application_Model_Playlist::DeleteFileFromAllPlaylists($this->getId());
$this->_file->delete();
// don't delete from the playslist. We might want to put a flag
//Application_Model_Playlist::DeleteFileFromAllPlaylists($this->getId());
// set file_exists falg to false
$this->_file->setDbFileExists(false);
$this->_file->save();
//$this->_file->delete();
if (isset($res)) {
return $res;
@ -430,6 +435,7 @@ class Application_Model_StoredFile {
public function setFilePath($p_filepath)
{
$path_info = Application_Model_MusicDir::splitFilePath($p_filepath);
if (is_null($path_info)) {
return -1;
}
@ -499,7 +505,9 @@ class Application_Model_StoredFile {
$storedFile->_file = $file;
if(isset($md['MDATA_KEY_FILEPATH'])) {
$res = $storedFile->setFilePath($md['MDATA_KEY_FILEPATH']);
// removed "//" in the path. Always use '/' for path separator
$filepath = str_replace("//", "/", $md['MDATA_KEY_FILEPATH']);
$res = $storedFile->setFilePath($filepath);
if ($res === -1) {
return null;
}
@ -674,12 +682,20 @@ class Application_Model_StoredFile {
$fromTable = " ((".$plSelect."PL.id
FROM ".$CC_CONFIG["playListTable"]." AS PL
LEFT JOIN ".$CC_CONFIG['playListTimeView']." AS PLT USING(id))
UNION
(".$fileSelect."id FROM ".$CC_CONFIG["filesTable"]." AS FILES)) AS RESULTS";
(".$fileSelect."id FROM ".$CC_CONFIG["filesTable"]." AS FILES WHERE file_exists = 'TRUE')) AS RESULTS";
return Application_Model_StoredFile::searchFiles($fromTable, $datatables);
$results = Application_Model_StoredFile::searchFiles($fromTable, $datatables);
foreach($results['aaData'] as &$row){
// add checkbox row
$row['checkbox'] = "<input type='checkbox' name='cb_".$row['id']."'>";
// a full timestamp is being returned for playlists' year column;
// split it and grab only the year info
$yearSplit = explode('-', $row['year']);
$row['year'] = $yearSplit[0];
}
return $results;
}
public static function searchPlaylistsForSchedule($datatables)
@ -748,9 +764,6 @@ class Application_Model_StoredFile {
$orderby = join("," , $orderby);
// End Order By clause
//ordered by integer as expected by datatables.
//$CC_DBC->setFetchMode(DB_FETCHMODE_ORDERED);
if(isset($where)) {
$where = join(" AND ", $where);
$sql = $selectorCount." FROM ".$fromTable." WHERE ".$where;
@ -760,26 +773,9 @@ class Application_Model_StoredFile {
else {
$sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"];
}
$results = $CC_DBC->getAll($sql);
foreach($results as &$row){
// add checkbox row
$row['checkbox'] = "<input type='checkbox' name='cb_".$row[id]."'>";
// a full timestamp is being returned for playlists' year column;
// split it and grab only the year info
$yearSplit = explode('-', $row['year']);
$row['year'] = $yearSplit[0];
}
//$results['checkbox']
//$results = $CC_DBC->getAssoc($sql);
Logging::log(print_r($results, true));
//echo $results;
//echo $sql;
//put back to default fetch mode.
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
if(!isset($totalDisplayRows)) {
$totalDisplayRows = $totalRows;
}
@ -923,24 +919,34 @@ class Application_Model_StoredFile {
return $CC_DBC->GetOne($sql);
}
public static function listAllFiles($dir_id){
/**
*
* Enter description here ...
* @param $dir_id - if this is not provided, it returns all files with full path constructed.
* @param $propelObj - if this is true, it returns array of proepl obj
*/
public static function listAllFiles($dir_id=null, $propelObj=false){
global $CC_DBC;
// $sql = "SELECT m.directory || '/' || f.filepath as fp"
// ." FROM CC_MUSIC_DIRS m"
// ." LEFT JOIN CC_FILES f"
// ." ON m.id = f.directory"
// ." WHERE m.id = f.directory"
// ." AND m.id = $dir_id";
$sql = "SELECT filepath as fp"
." FROM CC_FILES"
." WHERE directory = $dir_id";
if($propelObj){
$sql = "SELECT m.directory || f.filepath as fp"
." FROM CC_MUSIC_DIRS m"
." LEFT JOIN CC_FILES f"
." ON m.id = f.directory WHERE m.id = $dir_id and f.file_exists = 'TRUE'";
}else{
$sql = "SELECT filepath as fp"
." FROM CC_FILES"
." WHERE directory = $dir_id and file_exists = 'TRUE'";
}
$rows = $CC_DBC->getAll($sql);
$results = array();
foreach ($rows as $row){
$results[] = $row["fp"];
if($propelObj){
$results[] = Application_Model_StoredFile::RecallByFilepath($row["fp"]);
}else{
$results[] = $row["fp"];
}
}
return $results;
@ -983,6 +989,15 @@ class Application_Model_StoredFile {
public function getSoundCloudErrorMsg(){
return $this->_file->getDbSoundCloudErrorMsg();
}
public function setFileExistsFlag($flag){
$this->_file->setDbFileExists($flag)
->save();
}
public function getFileExistsFlag(){
return $this->_file->getDbFileExists();
}
public function uploadToSoundCloud()
{

View File

@ -236,8 +236,10 @@ class Application_Model_User {
// mark record which is for the current user
foreach($res['aaData'] as &$record){
if($record[1] == $username){
$record[5] = "self";
if($record['login'] == $username){
$record['delete'] = "self";
} else {
$record['delete'] = "";
}
}

View File

@ -35,23 +35,23 @@ function removeUserCallback(row_id, nRow){
}
function rowCallback( nRow, aData, iDisplayIndex ){
$(nRow).click(function(){rowClickCallback(aData[0])});
if( aData[5] != "self"){
$('td:eq(4)', nRow).append( '<span class="ui-icon ui-icon-closethick"></span>').children('span').click(function(e){e.stopPropagation(); removeUserCallback(aData[0], nRow)});
$(nRow).click(function(){rowClickCallback(aData['id'])});
if( aData['delete'] != "self"){
$('td:eq(4)', nRow).append( '<span class="ui-icon ui-icon-closethick"></span>').children('span').click(function(e){e.stopPropagation(); removeUserCallback(aData['id'], nRow)});
}else{
$('td:eq(4)', nRow).empty().append( '<span class="ui-icon ui-icon-closethick"></span>').children('span').click(function(e){e.stopPropagation(); alert("Can't delete yourself!")});
}
if ( aData[4] == "A" )
if ( aData['type'] == "A" )
{
$('td:eq(3)', nRow).html( 'Admin' );
} else if ( aData[4] == "H" )
} else if ( aData['type'] == "H" )
{
$('td:eq(3)', nRow).html( 'DJ' );
} else if ( aData[4] == "G" )
} else if ( aData['type'] == "G" )
{
$('td:eq(3)', nRow).html( 'Guest' );
} else if ( aData[4] == "P" )
} else if ( aData['type'] == "P" )
{
$('td:eq(3)', nRow).html( 'Program Manager' );
}
@ -75,12 +75,12 @@ $(document).ready(function() {
},
"fnRowCallback": rowCallback,
"aoColumns": [
/* Id */ { "sName": "id", "bSearchable": false, "bVisible": false },
/* user name */ { "sName": "login" },
/* first name */ { "sName": "first_name" },
/* last name */ { "sName": "last_name" },
/* user type */ { "sName": "type", "bSearchable": false },
/* del button */ { "sName": "null as delete", "bSearchable": false, "bSortable": false}
/* Id */ { "sName": "id", "bSearchable": false, "bVisible": false, "mDataProp": "id" },
/* user name */ { "sName": "login", "mDataProp": "login" },
/* first name */ { "sName": "first_name", "mDataProp": "first_name" },
/* last name */ { "sName": "last_name", "mDataProp": "last_name" },
/* user type */ { "sName": "type", "bSearchable": false, "mDataProp": "type" },
/* del button */ { "sName": "null as delete", "bSearchable": false, "bSortable": false, "mDataProp": "delete"}
],
"bJQueryUI": true,
"bAutoWidth": false,