Skip to content

Commit

Permalink
Merge pull request #547 from nextcloud/fix/quota-links-stable26
Browse files Browse the repository at this point in the history
[stable26] Fix quota links in files
  • Loading branch information
provokateurin authored Aug 30, 2023
2 parents 529af45 + 804033a commit 2e0d18b
Show file tree
Hide file tree
Showing 6 changed files with 6,559 additions and 7,405 deletions.
12 changes: 0 additions & 12 deletions js/quota-files-sidebar.js

This file was deleted.

58 changes: 37 additions & 21 deletions lib/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Services\IInitialState;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\INavigationManager;
Expand All @@ -42,12 +43,19 @@ class BeforeTemplateRenderedListener implements IEventListener {
/** @var IURLGenerator */
protected $urlGenerator;

public function __construct(SitesManager $sitesManager,
/** @var IInitialState */
private $initialState;

public function __construct(
SitesManager $sitesManager,
INavigationManager $navigationManager,
IURLGenerator $urlGenerator) {
IURLGenerator $urlGenerator,
IInitialState $initialState,
) {
$this->sitesManager = $sitesManager;
$this->navigationManager = $navigationManager;
$this->urlGenerator = $urlGenerator;
$this->initialState = $initialState;
}

public function handle(Event $event): void {
Expand All @@ -63,20 +71,36 @@ public function handle(Event $event): void {
protected function loadQuotaInformationOnFilesApp(LoadAdditionalScriptsEvent $event): void {
$sites = $this->sitesManager->getSitesToDisplay();

$data = [];
foreach ($sites as $site) {
if ($site['type'] === SitesManager::TYPE_QUOTA) {
$link = $site['url'];
if (!$site['redirect']) {
$link = $this->urlGenerator->linkToRoute('external.site.showPage', ['id' => $site['id']]);
}

$event->addHiddenField('external_quota_link', $link);
$event->addHiddenField('external_quota_name', $site['name']);
$image = $this->generateImageLink($site);
$href = $this->getHref($site);

Util::addScript('external', 'quota-files-sidebar');
return;
$data[] = ['name' => $site['name'], 'href' => $href, 'image' => $image];
}
}

if (count($data) > 0) {
$this->initialState->provideInitialState('external-quota-sites', $data);
Util::addScript('external', 'dist/quota-files-sidebar');
}
}

protected function generateImageLink(array $site): string {
if ($site['icon'] !== '') {
return $this->urlGenerator->linkToRoute('external.icon.showIcon', ['icon' => $site['icon']]);
}

return $this->urlGenerator->linkToRoute('external.icon.showIcon', ['icon' => 'external.svg']);
}

protected function getHref(array $site): string {
if (!$site['redirect']) {
return $this->urlGenerator->linkToRoute('external.site.showPage', ['id' => $site['id']]);
}

return $site['url'];
}

protected function generateNavigationLinks(): void {
Expand All @@ -88,16 +112,8 @@ protected function generateNavigationLinks(): void {
}

$this->navigationManager->add(function () use ($site) {
if ($site['icon'] !== '') {
$image = $this->urlGenerator->linkToRoute('external.icon.showIcon', ['icon' => $site['icon']]);
} else {
$image = $this->urlGenerator->linkToRoute('external.icon.showIcon', ['icon' => 'external.svg']);
}

$href = $site['url'];
if (!$site['redirect']) {
$href = $this->urlGenerator->linkToRoute('external.site.showPage', ['id' => $site['id']]);
}
$image = $this->generateImageLink($site);
$href = $this->getHref($site);

return [
'id' => 'external_index' . $site['id'],
Expand Down
Loading

0 comments on commit 2e0d18b

Please sign in to comment.