diff --git a/css/style.css b/css/style.css index 6a0a2a82..8dab25f7 100644 --- a/css/style.css +++ b/css/style.css @@ -6,6 +6,10 @@ width: 20%; } +.site-redirect-box { + padding: 8px 0; +} + #external .icon-more { width: 16px; height: 16px; @@ -24,7 +28,8 @@ } #external ul.external_sites li { - padding: 5px 0 10px; + margin-left: -5px; + padding: 5px 0 10px 5px; } #external ul.external_sites li.saving { diff --git a/js/admin.js b/js/admin.js index 513e84dc..48f478d0 100644 --- a/js/admin.js +++ b/js/admin.js @@ -116,7 +116,7 @@ e.preventDefault(); var $el = $(self._compiledTemplate({ - id: 'undefined', + id: 'new-' + Date.now(), name: t('external', 'New site'), icon: 'external.svg', type: 'link', @@ -183,6 +183,7 @@ lang: $site.find('.site-lang').val(), type: $site.find('.site-type').val(), device: $site.find('.site-device').val(), + redirect: $site.find('.site-redirect').prop("checked") ? 1 : 0, icon: $site.find('.site-icon').val() }; diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index fdf4a8da..783288b7 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -64,10 +64,16 @@ public function registerNavigationEntries(IServerContainer $server, array $sites } catch (\RuntimeException $e) { $image = $url->imagePath('external', 'external.svg'); } + + $href = $site['url']; + if (!$site['redirect']) { + $href = $url->linkToRoute('external.site.showPage', ['id'=> $site['id']]); + } + return [ 'id' => 'external_index' . $site['id'], 'order' => 80 + $site['id'], - 'href' => $url->linkToRoute('external.site.showPage', ['id'=> $site['id']]), + 'href' => $href, 'icon' => $image, 'type' => $site['type'], 'name' => $site['name'], @@ -88,7 +94,11 @@ public function registerPersonalPage(IServerContainer $server, array $sites) { $url = $server->getURLGenerator(); $hiddenFields = $event->getArgument('hiddenFields'); - $hiddenFields['external_quota_link'] = $url->linkToRoute('external.site.showPage', ['id'=> $site['id']]); + + $hiddenFields['external_quota_link'] = $site['url']; + if (!$site['redirect']) { + $hiddenFields['external_quota_link'] = $url->linkToRoute('external.site.showPage', ['id'=> $site['id']]); + } $hiddenFields['external_quota_name'] = $site['name']; $event->setArgument('hiddenFields', $hiddenFields); diff --git a/lib/Controller/APIController.php b/lib/Controller/APIController.php index eb86c9a0..a98bb0d1 100644 --- a/lib/Controller/APIController.php +++ b/lib/Controller/APIController.php @@ -129,11 +129,12 @@ public function getAdmin() { * @param string $type * @param string $device * @param string $icon + * @param int $redirect * @return DataResponse */ - public function add($name, $url, $lang, $type, $device, $icon) { + public function add($name, $url, $lang, $type, $device, $icon, $redirect) { try { - return new DataResponse($this->sitesManager->addSite($name, $url, $lang, $type, $device, $icon)); + return new DataResponse($this->sitesManager->addSite($name, $url, $lang, $type, $device, $icon, (bool) $redirect)); } catch (InvalidNameException $e) { return new DataResponse(['error' => $this->l->t('The given label is invalid'), 'field' => 'name'], Http::STATUS_BAD_REQUEST); } catch (InvalidURLException $e) { @@ -157,11 +158,12 @@ public function add($name, $url, $lang, $type, $device, $icon) { * @param string $type * @param string $device * @param string $icon + * @param int $redirect * @return DataResponse */ - public function update($id, $name, $url, $lang, $type, $device, $icon) { + public function update($id, $name, $url, $lang, $type, $device, $icon, $redirect) { try { - return new DataResponse($this->sitesManager->updateSite($id, $name, $url, $lang, $type, $device, $icon)); + return new DataResponse($this->sitesManager->updateSite($id, $name, $url, $lang, $type, $device, $icon, (bool) $redirect)); } catch (SiteNotFoundException $e) { return new DataResponse(['error' => $this->l->t('The site does not exist'), 'field' => 'site'], Http::STATUS_NOT_FOUND); } catch (InvalidNameException $e) { diff --git a/lib/Controller/SiteController.php b/lib/Controller/SiteController.php index 5539fbfc..e031e71e 100644 --- a/lib/Controller/SiteController.php +++ b/lib/Controller/SiteController.php @@ -110,8 +110,13 @@ public function renderQuotaLink() { } } + $url = $quotaLink['url']; + if (!$quotaLink['redirect']) { + $url = $this->url->linkToRoute('external.site.showPage', ['id'=> $quotaLink['id']]); + } + return new TemplateResponse('external', 'quota', [ - 'quotaLink' => $this->url->linkToRoute('external.site.showPage', ['id'=> $quotaLink['id']]), + 'quotaLink' => $url, 'quotaName' => $quotaLink['name'], ], ''); } diff --git a/lib/SitesManager.php b/lib/SitesManager.php index 6b30b8df..9d98d69f 100644 --- a/lib/SitesManager.php +++ b/lib/SitesManager.php @@ -135,6 +135,7 @@ protected function fillSiteArray(array $site) { 'lang' => '', 'type' => self::TYPE_LINK, 'device' => self::DEVICE_ALL, + 'redirect' => false, ], $site ); @@ -147,6 +148,7 @@ protected function fillSiteArray(array $site) { * @param string $type * @param string $device * @param string $icon + * @param bool $redirect * @return array * @throws InvalidNameException * @throws InvalidURLException @@ -155,7 +157,7 @@ protected function fillSiteArray(array $site) { * @throws InvalidDeviceException * @throws IconNotFoundException */ - public function addSite($name, $url, $lang, $type, $device, $icon) { + public function addSite($name, $url, $lang, $type, $device, $icon, $redirect) { $id = 1 + (int) $this->config->getAppValue('external', 'max_site', 0); if ($name === '') { @@ -206,6 +208,7 @@ public function addSite($name, $url, $lang, $type, $device, $icon) { 'type' => $type, 'device' => $device, 'icon' => $icon, + 'redirect' => $redirect, ]; $this->config->setAppValue('external', 'sites', json_encode($sites)); $this->config->setAppValue('external', 'max_site', $id); @@ -221,6 +224,7 @@ public function addSite($name, $url, $lang, $type, $device, $icon) { * @param string $type * @param string $device * @param string $icon + * @param bool $redirect * @return array * @throws SiteNotFoundException * @throws InvalidNameException @@ -230,7 +234,7 @@ public function addSite($name, $url, $lang, $type, $device, $icon) { * @throws InvalidDeviceException * @throws IconNotFoundException */ - public function updateSite($id, $name, $url, $lang, $type, $device, $icon) { + public function updateSite($id, $name, $url, $lang, $type, $device, $icon, $redirect) { $sites = $this->getSites(); if (!isset($sites[$id])) { throw new SiteNotFoundException(); @@ -283,6 +287,7 @@ public function updateSite($id, $name, $url, $lang, $type, $device, $icon) { 'type' => $type, 'device' => $device, 'icon' => $icon, + 'redirect' => $redirect, ]; $this->config->setAppValue('external', 'sites', json_encode($sites)); diff --git a/templates/settings.php b/templates/settings.php index 81fb843f..fcff3609 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -108,6 +108,15 @@ +
+ +
+
t('Remove site')); ?>