From c73a9dd18e3c55f2a473476d6700516197ea9e77 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Mon, 12 Dec 2016 23:23:15 +0100 Subject: [PATCH] admin setting, extra symbols, get symbols ok --- appinfo/info.xml | 5 +- appinfo/routes.php | 1 + controller/utilscontroller.php | 22 ++++++++ css/admin.css | 8 +++ js/admin.js | 44 ++++++++++++++++ lib/Settings/Admin.php | 94 ++++++++++++++++++++++++++++++++++ 6 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 css/admin.css create mode 100644 js/admin.js create mode 100644 lib/Settings/Admin.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 00a244d..e18298d 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -59,7 +59,7 @@ If you want to help to translate this app in your language, take the english=>fr AGPL Simple GPX file editor Julien Veyssier - 0.0.2 + 0.0.3 GpxEdit https://gitlab.com/eneiluj/gpxedit-oc/wikis/userdoc @@ -79,4 +79,7 @@ If you want to help to translate this app in your language, take the english=>fr 174782 + + OCA\GpxEdit\Settings\Admin + diff --git a/appinfo/routes.php b/appinfo/routes.php index 28e85f1..908d244 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -28,5 +28,6 @@ return [ ['name' => 'utils#deleteTileServer', 'url' => '/deleteTileServer', 'verb' => 'POST'], ['name' => 'utils#getOptionsValues', 'url' => '/getOptionsValues', 'verb' => 'POST'], ['name' => 'utils#saveOptionsValues', 'url' => '/saveOptionsValues', 'verb' => 'POST'], + ['name' => 'utils#getExtraSymbol', 'url' => '/getExtraSymbol', 'verb' => 'GET'], ] ]; diff --git a/controller/utilscontroller.php b/controller/utilscontroller.php index 86c1f14..b0bcd9c 100644 --- a/controller/utilscontroller.php +++ b/controller/utilscontroller.php @@ -23,6 +23,7 @@ use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\IRequest; use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Http\Response; 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 * @NoAdminRequired diff --git a/css/admin.css b/css/admin.css new file mode 100644 index 0000000..c9eeb58 --- /dev/null +++ b/css/admin.css @@ -0,0 +1,8 @@ +button#addExtraSymbol{ + width: 33px; + height: 33px; +} +.extraSymbol img{ + width: 28px; + height: 28px; +} diff --git a/js/admin.js b/js/admin.js new file mode 100644 index 0000000..5c4b70f --- /dev/null +++ b/js/admin.js @@ -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); + }); + +}); diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php new file mode 100644 index 0000000..d6ab123 --- /dev/null +++ b/lib/Settings/Admin.php @@ -0,0 +1,94 @@ +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; + } + +}