Admin page: delete feed / project

This commit is contained in:
2020-04-13 22:50:37 +02:00
parent 1d1a6f63a6
commit 73713d477b
12 changed files with 138 additions and 36 deletions

View File

@@ -194,4 +194,15 @@ class Feed extends PhpObject {
return $bResult;
}
public function delete() {
$sDesc = '';
if($this->getFeedId() > 0) {
$bSuccess = $this->oDb->deleteRow(self::FEED_TABLE, $this->getFeedId());
if(!$bSuccess) $sDesc = $this->oDb->getLastError();
}
else $sDesc = 'Error while setting project: no Feed ID';
return $sDesc;
}
}

View File

@@ -176,4 +176,15 @@ class Project extends PhpObject {
return $bResult;
}
public function delete() {
$sDesc = '';
if($this->getProjectId() > 0) {
$bSuccess = $this->oDb->deleteRow(self::PROJ_TABLE, $this->getProjectId());
if(!$bSuccess) $sDesc = $this->oDb->getLastError();
}
else $sDesc = 'Error while setting project: no project ID';
return $sDesc;
}
}

View File

@@ -442,11 +442,12 @@ class Spot extends Main
public function getAdminSettings() {
$oFeed = new Feed($this->oDb);
return self::getJsonResult(true, '', array(
$asData = array(
'project' => $this->oProject->getProjects(),
'feed' => $oFeed->getFeeds(),
'spot' => $oFeed->getSpots()
));
);
return self::getJsonResult(true, '', $asData);
}
public function setAdminSettings($sType, $iId, $sField, $sValue) {
@@ -497,6 +498,25 @@ class Spot extends Main
return self::getJsonResult($bSuccess, $sDesc, array($sType=>array($asResult)));
}
public function delAdminSettings($sType, $iId) {
$bSuccess = false;
$sDesc = '';
switch($sType) {
case 'project':
$oProject = new Project($this->oDb, $iId);
$sDesc = $oProject->delete();
break;
case 'feed':
$oFeed = new Feed($this->oDb, $iId);
$sDesc = $oFeed->delete();
break;
}
$bSuccess = ($sDesc=='');
return self::getJsonResult($bSuccess, $sDesc, array($sType=>array(array('id'=>$iId, 'del'=>$bSuccess))));
}
public function createProject() {
$oProject = new Project($this->oDb);
$iNewProjectId = $oProject->createProjectId();

View File

@@ -57,14 +57,17 @@ if($sAction!='')
case 'sync_pics':
$sResult = $oSpot->syncPics();
break;
case 'admin_new':
$sResult = $oSpot->createProject();
break;
case 'admin_get':
$sResult = $oSpot->getAdminSettings();
break;
case 'admin_set':
$sResult = $oSpot->setAdminSettings($sType, $iId, $sField, $oValue);
break;
case 'admin_new':
$sResult = $oSpot->createProject();
case 'admin_del':
$sResult = $oSpot->delAdminSettings($sType, $iId);
break;
case 'build_geojson':
$sResult = $oSpot->convertGpxToGeojson($sName);

View File

@@ -59,6 +59,7 @@ status = Status
last_update = Last Update
ref_spot_id = Ref. Spot ID
model = Model
delete = Delete
date_time = $0 at $1
time_zone = Time zone

View File

@@ -59,6 +59,7 @@ status = Statut
last_update = Dernière maj
ref_spot_id = ID Spot ref.
model = Modèle
delete = Supprimer
date_time = $0 à $1
time_zone = Fuseau horaire

View File

@@ -11,6 +11,7 @@
<th>[#]lang:start[#]</th>
<th>[#]lang:end[#]</th>
<th>[#]lang:time_zone[#]</th>
<th>[#]lang:delete[#]</th>
</tr>
</thead>
<tbody></tbody>
@@ -29,6 +30,7 @@
<th>[#]lang:name[#]</th>
<th>[#]lang:status[#]</th>
<th>[#]lang:last_update[#]</th>
<th>[#]lang:delete[#]</th>
</tr>
</thead>
<tbody></tbody>
@@ -53,11 +55,12 @@
<script type="text/javascript">
oSpot.pageInit = function(asHash) {
self.get('admin_get', setProjects);
$('#new').addInput('button', 'new', 'New Project', [{on:'click', callback:createProject}]);
$('#new').addButton('new', 'New Project', 'new', createProject, 'main-btn');
};
oSpot.onFeedback = function(sType, sMsg, asContext) {
delete asContext.a;
delete asContext.t;
sMsg += ' (';
$.each(asContext, function(sKey, sElem) {
sMsg += sKey+'='+sElem+' / ' ;
@@ -79,34 +82,39 @@ function setProjects(asElemTypes) {
.data('id', oElem.id)
.append($('<td>').text(oElem.id || ''));
switch(sElemType) {
case 'project':
$Elem
.append($('<td>').addInput('text', 'name', oElem.name, aoEvents))
.append($('<td>', {'class': 'mode'}).text(oElem.mode))
.append($('<td>').addInput('text', 'codename', oElem.codename, aoEvents))
.append($('<td>').addInput('date', 'active_from', oElem.active_from.substr(0, 10), aoEvents))
.append($('<td>').addInput('date', 'active_to', oElem.active_to.substr(0, 10), aoEvents))
.append($('<td>').addInput('text', 'timezone', oElem.timezone, aoEvents));
break;
case 'feed':
$Elem
.append($('<td>').addInput('text', 'ref_feed_id', oElem.ref_feed_id, aoEvents))
.append($('<td>').addInput('number', 'spot_id', oElem.id_spot, aoEvents))
.append($('<td>').addInput('number', 'project_id', oElem.id_project, aoEvents))
.append($('<td>').text(oElem.name))
.append($('<td>').text(oElem.status))
.append($('<td>').text(oElem.last_update));
break;
case 'spot':
$Elem
.append($('<td>').text(oElem.ref_spot_id))
.append($('<td>').text(oElem.name))
.append($('<td>').text(oElem.model))
break;
}
if(oElem.del) $Elem.remove();
else {
switch(sElemType) {
case 'project':
$Elem
.append($('<td>').addInput('text', 'name', oElem.name, aoEvents))
.append($('<td>', {'class': 'mode'}).text(oElem.mode))
.append($('<td>').addInput('text', 'codename', oElem.codename, aoEvents))
.append($('<td>').addInput('date', 'active_from', oElem.active_from.substr(0, 10), aoEvents))
.append($('<td>').addInput('date', 'active_to', oElem.active_to.substr(0, 10), aoEvents))
.append($('<td>').addInput('text', 'timezone', oElem.timezone, aoEvents))
.append($('<td>').addButton('close fa-lg', '', 'del_proj', del));
break;
case 'feed':
$Elem
.append($('<td>').addInput('text', 'ref_feed_id', oElem.ref_feed_id, aoEvents))
.append($('<td>').addInput('number', 'spot_id', oElem.id_spot, aoEvents))
.append($('<td>').addInput('number', 'project_id', oElem.id_project, aoEvents))
.append($('<td>').text(oElem.name))
.append($('<td>').text(oElem.status))
.append($('<td>').text(oElem.last_update))
.append($('<td>').addButton('close fa-lg', '', 'del_feed', del));
break;
case 'spot':
$Elem
.append($('<td>').text(oElem.ref_spot_id))
.append($('<td>').text(oElem.name))
.append($('<td>').text(oElem.model))
break;
}
if(bNew) $Elem.appendTo($('#'+sElemType+'s').find('table tbody'));
if(bNew) $Elem.appendTo($('#'+sElemType+'s').find('table tbody'));
}
});
});
}
@@ -145,4 +153,20 @@ function waitAndCommit(event) {
if(typeof self.tmp('wait') != 'undefined') clearTimeout(self.tmp('wait'));
self.tmp('wait', setTimeout(()=>{commit(event,$(this));}, 2000));
}
function del() {
var $Record = $(this).closest('tr');
var asInputs = {type: $Record.data('type'), id: $Record.data('id')};
self.get(
'admin_del',
function(asData){
oSpot.onFeedback('success', self.lang('admin_save_success'), asInputs);
setProjects(asData);
},
asInputs,
function(sError){
oSpot.onFeedback('error', sError, asInputs);
}
);
}
</script>

View File

@@ -266,6 +266,18 @@ $.prototype.addInput = function(sType, sName, sValue, aoEvents)
return $(this).append($Input);
};
$.prototype.addButton = function(sIcon, sText, sName, fOnClick, sClass)
{
sText = sText || '';
sClass = sClass || '';
var $Btn = $('<button>', {name: sName, 'class':sClass})
.addIcon('fa-'+sIcon, (sText != ''))
.append(sText)
.click(fOnClick);
return $(this).append($Btn);
};
$.prototype.addIcon = function(sIcon, bMargin, sStyle)
{
bMargin = bMargin || false;

View File

@@ -81,3 +81,6 @@ $fa-css-prefix: fa;
.#{$fa-css-prefix}-prev:before { content: fa-content($fa-var-chevron-left); }
.#{$fa-css-prefix}-next:before { content: fa-content($fa-var-chevron-right); }
.#{$fa-css-prefix}-close:before { content: fa-content($fa-var-times-circle); }
/* Admin */
.#{$fa-css-prefix}-new:before { content: fa-content($fa-var-plus); }

View File

@@ -1,6 +1,15 @@
#admin {
margin: 1em;
button.main-btn {
color: #000;
background: #eee;
&:hover {
color: #eee;
background: #000;
}
}
table {
margin-bottom: 1em;
border-collapse: collapse;
@@ -23,6 +32,13 @@
width: 300px;
}
}
button {
color: #AAA;
&:hover {
color: #666;
}
}
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long