diff --git a/appinfo/routes.php b/appinfo/routes.php index 908d244..1a2bbc8 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -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'], ] ]; diff --git a/controller/utilscontroller.php b/controller/utilscontroller.php index b0bcd9c..817b789 100644 --- a/controller/utilscontroller.php +++ b/controller/utilscontroller.php @@ -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 */ diff --git a/css/admin.css b/css/admin.css index c9eeb58..b67e255 100644 --- a/css/admin.css +++ b/css/admin.css @@ -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; } diff --git a/js/admin.js b/js/admin.js index 5c4b70f..6db1628 100644 --- a/js/admin.js +++ b/js/admin.js @@ -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('

'+ + ''+ + '

'); +} + +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)); + }); + }); diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index d6ab123..0edf7e1 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -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, ''); diff --git a/templates/admin.php b/templates/admin.php new file mode 100644 index 0000000..dfb14b0 --- /dev/null +++ b/templates/admin.php @@ -0,0 +1,39 @@ + + +
+

t('GpxEdit additional settings')); ?>

+ + +
+
+ '; + echo ''; + echo ''; + echo ''; + echo '

'; + } + ?> +
+ + +
+ + + + + +
+