admin settings : get, add, delete extra symbols OK

merge-requests/1/head
Julien Veyssier 2016-12-13 02:01:47 +01:00
parent c73a9dd18e
commit 6d4ae1b23b
6 changed files with 171 additions and 4 deletions

View File

@ -29,5 +29,7 @@ return [
['name' => 'utils#getOptionsValues', 'url' => '/getOptionsValues', 'verb' => 'POST'],
['name' => 'utils#saveOptionsValues', 'url' => '/saveOptionsValues', 'verb' => 'POST'],
['name' => 'utils#getExtraSymbol', 'url' => '/getExtraSymbol', 'verb' => 'GET'],
['name' => 'utils#uploadExtraSymbol', 'url' => '/uploadExtraSymbol', 'verb' => 'POST'],
['name' => 'utils#deleteExtraSymbol', 'url' => '/deleteExtraSymbol', 'verb' => 'POST'],
]
];

View File

@ -82,9 +82,11 @@ class UtilsController extends Controller {
private $dbconnection;
private $dbtype;
private $appPath;
//private $request;
public function __construct($AppName, IRequest $request, $UserId, $userfolder, $config){
parent::__construct($AppName, $request);
//$this->request = $request;
$this->appPath = \OC_App::getAppPath('gpxedit');
$this->userId = $UserId;
$this->dbtype = $config->getSystemValue('dbtype');
@ -115,7 +117,61 @@ class UtilsController extends Controller {
}
/**
* Add one tile server to the DB for current user
* @NoCSRFRequired
*/
public function deleteExtraSymbol($name) {
$filename = str_replace(array('../', '..\\', '/'), '', $name);
$filepath = $this->config->getSystemValue('datadirectory').'/gpxedit/symbols/'.$filename;
if (file_exists($filepath)){
unlink($filepath);
}
return new DataResponse(
[
'data' =>
[
'name' => $filename,
'message' => 'Deleted'
],
'status' => 'success'
]
);
}
/**
* @NoCSRFRequired
*/
public function uploadExtraSymbol($addExtraSymbolName) {
$newSymbol = $this->request->getUploadedFile('uploadsymbol');
$filename = str_replace(array('../', '..\\', '/'), '', $addExtraSymbolName);
if (empty($newSymbol)) {
return new DataResponse(
[
'data' => [
'message' => 'No file uploaded'
]
],
Http::STATUS_UNPROCESSABLE_ENTITY
);
}
$name = '';
if(!empty($newSymbol)) {
$filepath = $this->config->getSystemValue('datadirectory').'/gpxedit/symbols/'.$filename.'.png';
$content = file_get_contents($newSymbol['tmp_name']);
file_put_contents($filepath, $content);
}
return new DataResponse(
[
'data' =>
[
'name' => $filename.'.png',
'message' => 'Saved'
],
'status' => 'success'
]
);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/

View File

@ -3,6 +3,19 @@ button#addExtraSymbol{
height: 33px;
}
.extraSymbol img{
width: 25px;
height: 25px;
}
#gpxedit .upload-symbol-field{
display: none;
}
#gpxedit .icon-upload{
display: inline-flex;
padding: 8px;
margin: 2px 0px;
}
#gpxedit .icon-delete{
padding-top: 12px;
width: 28px;
height: 28px;
}

View File

@ -31,6 +31,30 @@
}
})();
function addLogoLine(name){
var url = OC.generateUrl('/apps/gpxedit/getExtraSymbol?');
var fullurl = url+'name='+encodeURI(name);
var nameWe = name.replace(/\.png$/, '');
$('div#extraSymbols').append('<p class="extraSymbol" id="'+nameWe+'">'+
'<img src="'+fullurl+'"><label> '+nameWe+' </label>'+
'<button class="delExtraSymbol icon-delete icon" name="'+name+'" title="Remove"></button></p>');
}
function deleteLogo(button){
button.removeClass('icon-delete').addClass('icon-loading-small');
var name = button.attr('name');
var req = {
name : name,
}
var url = OC.generateUrl('/apps/gpxedit/deleteExtraSymbol');
$.post(url, req).done(function (response) {
button.parent().remove();
OC.msg.finishedSuccess('#extraSymbolsSettingsMsg', response.data.message);
}).fail(function(){
OC.msg.finishedError('#extraSymbolsSettingsMsg', 'Failed');
button.addClass('icon-delete').removeClass('icon-loading-small');
});
}
$(document).ready(function() {
OCA.GpxEdit.Admin.initialize();
@ -41,4 +65,28 @@ $(document).ready(function() {
$(this).attr('src', fullurl);
});
var uploadParamsSymbol = {
pasteZone: null,
dropZone: null,
done: function (e, response) {
//preview('logoMime', response.result.data.name);
addLogoLine(response.result.data.name);
OC.msg.finishedSaving('#extraSymbolsSettingsMsg', response.result);
$('label#uploadsymbol').addClass('icon-upload').removeClass('icon-loading-small');
},
submit: function(e, response) {
OC.msg.startSaving('#extraSymbolsSettingsMsg');
$('label#uploadsymbol').removeClass('icon-upload').addClass('icon-loading-small');
},
fail: function (e, response){
OC.msg.finishedError('#extraSymbolsSettingsMsg', response.data.message);
$('label#uploadsymbol').addClass('icon-upload').removeClass('icon-loading-small');
}
};
$('#uploadsymbol').fileupload(uploadParamsSymbol);
$('body').on('click', 'button.delExtraSymbol', function(e) {
deleteLogo($(this));
});
});

View File

@ -7,6 +7,7 @@ use OCP\IRequest;
use OCP\IConfig;
use OCP\Settings\ISettings;
use OCP\Util;
use OCP\IURLGenerator;
/**
* Recursive find files from name pattern
@ -40,8 +41,14 @@ class Admin implements ISettings {
private $request;
private $config;
private $dataDirPath;
private $urlGenerator;
public function __construct(IniGetWrapper $iniWrapper, IRequest $request, IConfig $config) {
public function __construct(
IniGetWrapper $iniWrapper,
IRequest $request,
IConfig $config,
IURLGenerator $urlGenerator) {
$this->urlGenerator = $urlGenerator;
$this->iniWrapper = $iniWrapper;
$this->request = $request;
$this->config = $config;
@ -59,15 +66,17 @@ class Admin implements ISettings {
* @return TemplateResponse
*/
public function getForm() {
$uploadPath = $this->urlGenerator->linkToRoute('gpxedit.utils.uploadExtraSymbol');
//$extraSymbolList = Array(Array('name'=>'plop', 'url'=>'huhu'), Array('name'=>'lll', 'url'=>'uuu'));
$extraSymbolList = Array();
foreach(globRecursive($this->dataDirPath.'/symbols', '*.png', False) as $symbolfile){
$filename = basename($symbolfile);
array_push($extraSymbolList, Array('name'=>str_replace('.png', '', $filename), 'url'=>$filename));
array_push($extraSymbolList, Array('smallname'=>str_replace('.png', '', $filename), 'name'=>$filename));
}
$parameters = [
'extraSymbolList' => $extraSymbolList
'extraSymbolList' => $extraSymbolList,
'uploadPath' => $uploadPath
];
return new TemplateResponse('gpxedit', 'admin', $parameters, '');

View File

@ -0,0 +1,39 @@
<?php
OCP\Util::addscript('gpxedit', 'admin');
OCP\Util::addstyle('gpxedit', 'admin');
?>
<div class="section" id="gpxedit">
<h2><?php p($l->t('GpxEdit additional settings')); ?></h2>
<label><?php p($l->t( 'Extra symbols' )); ?> </label>
<span id="extraSymbolsSettingsMsg" class="msg"></span>
<br />
<div id="extraSymbols">
<?php
foreach($_['extraSymbolList'] as $symbol){
echo '<p class="extraSymbol" id="';
p($symbol['smallname']);
echo '">';
echo '<img src="';
p($symbol['name']);
echo '"/>';
echo '<label> ';
p($symbol['smallname']);
echo ' </label>';
echo '<button class="delExtraSymbol icon-delete icon" name="';
p($symbol['name']);
echo '" title="Remove"></button>';
echo '</p>';
}
?>
</div>
<!--button id="addExtraSymbol" class="inlineblock button icon-upload" title="Upload new symbol image"></button-->
<form class="uploadButton" method="post" action="<?php p($_['uploadPath']) ?>">
<label for="addExtraSymbolName">New symbol name :</label>
<input type="text" name="addExtraSymbolName" id="addExtraSymbolName"></input>
<input id="uploadsymbol" class="upload-symbol-field" name="uploadsymbol" type="file">
<label for="uploadsymbol" class="button icon-upload svg" id="uploadsymbol" title="<?php p($l->t('Upload new symbol image')) ?>"></label>
</form>
</div>