-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Contexts): add Contexts to navigation when applicable
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
- Loading branch information
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace OCA\Tables\Listener; | ||
|
||
use OCA\Tables\AppInfo\Application; | ||
use OCA\Tables\Service\ContextService; | ||
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\INavigationManager; | ||
use OCP\IURLGenerator; | ||
use OCP\IUserSession; | ||
|
||
/** | ||
* @template-implements IEventListener<Event|BeforeTemplateRenderedEvent> | ||
*/ | ||
class BeforeTemplateRenderedListener implements IEventListener { | ||
public function __construct( | ||
protected INavigationManager $navigationManager, | ||
protected IURLGenerator $urlGenerator, | ||
protected IUserSession $userSession, | ||
protected ContextService $contextService, | ||
) { | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function handle(Event $event): void { | ||
if (!$event instanceof BeforeTemplateRenderedEvent) { | ||
return; | ||
} | ||
|
||
$user = $this->userSession->getUser(); | ||
if ($user === null) { | ||
return; | ||
} | ||
|
||
// temporarily show all | ||
//$contexts = $this->contextService->findForNavigation($user->getUID()); | ||
$contexts = $this->contextService->findAll($user->getUID()); | ||
foreach ($contexts as $context) { | ||
/* temporarily, show all | ||
if ($context->getOwnerType() === Application::OWNER_TYPE_USER | ||
&& $context->getOwnerId() === $user->getUID()) { | ||
// filter out entries for owners unless it is set to be visible | ||
$skipEntry = true; | ||
foreach ($context->getSharing() as $shareInfo) { | ||
// TODO: integrate into DB query in Mapper | ||
if (isset($shareInfo['display_mode']) && $shareInfo['display_mode'] === Application::NAV_ENTRY_MODE_ALL) { | ||
// a custom override makes it visible | ||
$skipEntry = false; | ||
break; | ||
} elseif (!isset($shareInfo['display_mode']) && $shareInfo['display_mode_default'] === Application::NAV_ENTRY_MODE_ALL) { | ||
// no custom override, and visible also for owner by default | ||
$skipEntry = false; | ||
break; | ||
} | ||
} | ||
if ($skipEntry) { | ||
continue; | ||
} | ||
} | ||
*/ | ||
|
||
$iconRelPath = 'material/' . $context->getIcon() . '.svg'; | ||
$icon = file_exists(__DIR__ . '/../../img/' . $iconRelPath) ? $iconRelPath : 'app.svg'; | ||
|
||
$this->navigationManager->add([ | ||
'id' => Application::APP_ID . '::' . $context->getId(), | ||
'name' => $context->getName(), | ||
'href' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', | ||
'icon' => $this->urlGenerator->imagePath(Application::APP_ID, $icon), | ||
'order' => 8, | ||
'type' => 'link', | ||
]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters