admin setting, extra symbols, get symbols ok

merge-requests/1/head
Julien Veyssier 2016-12-12 23:23:15 +01:00
parent 8aef60ba0c
commit c73a9dd18e
6 changed files with 173 additions and 1 deletions

View File

@ -59,7 +59,7 @@ If you want to help to translate this app in your language, take the english=>fr
<licence>AGPL</licence> <licence>AGPL</licence>
<summary>Simple GPX file editor</summary> <summary>Simple GPX file editor</summary>
<author>Julien Veyssier</author> <author>Julien Veyssier</author>
<version>0.0.2</version> <version>0.0.3</version>
<namespace>GpxEdit</namespace> <namespace>GpxEdit</namespace>
<documentation> <documentation>
<user>https://gitlab.com/eneiluj/gpxedit-oc/wikis/userdoc</user> <user>https://gitlab.com/eneiluj/gpxedit-oc/wikis/userdoc</user>
@ -79,4 +79,7 @@ If you want to help to translate this app in your language, take the english=>fr
<nextcloud min-version="9.0" max-version="11"/> <nextcloud min-version="9.0" max-version="11"/>
</dependencies> </dependencies>
<ocsid>174782</ocsid> <ocsid>174782</ocsid>
<settings>
<admin>OCA\GpxEdit\Settings\Admin</admin>
</settings>
</info> </info>

View File

@ -28,5 +28,6 @@ return [
['name' => 'utils#deleteTileServer', 'url' => '/deleteTileServer', 'verb' => 'POST'], ['name' => 'utils#deleteTileServer', 'url' => '/deleteTileServer', 'verb' => 'POST'],
['name' => 'utils#getOptionsValues', 'url' => '/getOptionsValues', 'verb' => 'POST'], ['name' => 'utils#getOptionsValues', 'url' => '/getOptionsValues', 'verb' => 'POST'],
['name' => 'utils#saveOptionsValues', 'url' => '/saveOptionsValues', 'verb' => 'POST'], ['name' => 'utils#saveOptionsValues', 'url' => '/saveOptionsValues', 'verb' => 'POST'],
['name' => 'utils#getExtraSymbol', 'url' => '/getExtraSymbol', 'verb' => 'GET'],
] ]
]; ];

View File

@ -23,6 +23,7 @@ use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\IRequest; use OCP\IRequest;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
/** /**
@ -113,6 +114,27 @@ class UtilsController extends Controller {
} }
} }
/**
* Add one tile server to the DB for current user
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getExtraSymbol() {
$filename = str_replace(array('../', '..\\'), '', $_GET['name']);
$filepath = $this->config->getSystemValue('datadirectory').'/gpxedit/symbols/'.$filename;
$filecontent = file_get_contents($filepath);
echo $filecontent;
$response = new Response(
);
$response->setHeaders(Array('Content-type'=>'image/png'));
$csp = new ContentSecurityPolicy();
$csp->addAllowedImageDomain('*')
->addAllowedMediaDomain('*')
->addAllowedConnectDomain('*');
$response->setContentSecurityPolicy($csp);
return $response;
}
/** /**
* Add one tile server to the DB for current user * Add one tile server to the DB for current user
* @NoAdminRequired * @NoAdminRequired

8
css/admin.css 100644
View File

@ -0,0 +1,8 @@
button#addExtraSymbol{
width: 33px;
height: 33px;
}
.extraSymbol img{
width: 28px;
height: 28px;
}

44
js/admin.js 100644
View File

@ -0,0 +1,44 @@
(function() {
if (!OCA.GpxEdit) {
OCA.GpxEdit = {};
}
OCA.GpxEdit.Admin = {
initialize: function() {
$('#submitMaxUpload').on('click', _.bind(this._onClickSubmitMaxUpload, this));
},
_onClickSubmitMaxUpload: function () {
OC.msg.startSaving('#maxUploadSizeSettingsMsg');
var request = $.ajax({
url: OC.generateUrl('/apps/files/settings/maxUpload'),
type: 'POST',
data: {
maxUploadSize: $('#maxUploadSize').val()
}
});
request.done(function (data) {
$('#maxUploadSize').val(data.maxUploadSize);
OC.msg.finishedSuccess('#maxUploadSizeSettingsMsg', 'Saved');
});
request.fail(function () {
OC.msg.finishedError('#maxUploadSizeSettingsMsg', 'Error');
});
}
}
})();
$(document).ready(function() {
OCA.GpxEdit.Admin.initialize();
var url = OC.generateUrl('/apps/gpxedit/getExtraSymbol?');
$('p.extraSymbol img').each(function(){
var filename = $(this).attr('src');
var fullurl = url+'name='+encodeURI(filename);
$(this).attr('src', fullurl);
});
});

View File

@ -0,0 +1,94 @@
<?php
namespace OCA\GpxEdit\Settings;
use bantu\IniGetWrapper\IniGetWrapper;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IRequest;
use OCP\IConfig;
use OCP\Settings\ISettings;
use OCP\Util;
/**
* Recursive find files from name pattern
*/
function globRecursive($path, $find, $recursive=True) {
$result = Array();
$dh = opendir($path);
while (($file = readdir($dh)) !== false) {
if (substr($file, 0, 1) === '.') continue;
$rfile = "{$path}/{$file}";
if (is_dir($rfile) and $recursive) {
foreach (globRecursive($rfile, $find) as $ret) {
array_push($result, $ret);
}
} else {
if (fnmatch($find, $file)){
array_push($result, $rfile);
}
}
}
closedir($dh);
return $result;
}
class Admin implements ISettings {
/** @var IniGetWrapper */
private $iniWrapper;
/** @var IRequest */
private $request;
private $config;
private $dataDirPath;
public function __construct(IniGetWrapper $iniWrapper, IRequest $request, IConfig $config) {
$this->iniWrapper = $iniWrapper;
$this->request = $request;
$this->config = $config;
$this->dataDirPath = $this->config->getSystemValue('datadirectory').'/gpxedit';
if (! is_dir($this->dataDirPath)){
mkdir($this->dataDirPath);
}
if (! is_dir($this->dataDirPath.'/symbols')){
mkdir($this->dataDirPath.'/symbols');
}
}
/**
* @return TemplateResponse
*/
public function getForm() {
//$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));
}
$parameters = [
'extraSymbolList' => $extraSymbolList
];
return new TemplateResponse('gpxedit', 'admin', $parameters, '');
}
/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection() {
return 'additional';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/
public function getPriority() {
return 5;
}
}