From 3906597c9f1f54bcddfa5dedceb5e213020a032c Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi Date: Tue, 1 Aug 2023 09:33:06 +0545 Subject: [PATCH] reuse component Signed-off-by: Swikriti Tripathi reuse Signed-off-by: Swikriti Tripathi emit event Signed-off-by: Swikriti Tripathi add op icon vue Signed-off-by: Swikriti Tripathi --- lib/Listener/OpenProjectReferenceListener.php | 27 ++++++ .../WorkPackageReferenceProvider.php | 9 +- lib/Search/OpenProjectSearchProvider.php | 20 +--- src/components/icons/OpenProjectIcon.vue | 31 ++++++ src/components/tab/EmptyContent.vue | 20 ++-- src/components/tab/SearchInput.vue | 58 ++++++++--- src/reference.js | 19 +++- src/views/WorkPackagePickerElement.vue | 97 +++++++++++++++++++ 8 files changed, 239 insertions(+), 42 deletions(-) create mode 100644 src/components/icons/OpenProjectIcon.vue create mode 100644 src/views/WorkPackagePickerElement.vue diff --git a/lib/Listener/OpenProjectReferenceListener.php b/lib/Listener/OpenProjectReferenceListener.php index b6d84eae6..e802197b4 100644 --- a/lib/Listener/OpenProjectReferenceListener.php +++ b/lib/Listener/OpenProjectReferenceListener.php @@ -23,15 +23,36 @@ namespace OCA\OpenProject\Listener; use OCA\OpenProject\AppInfo\Application; +use OCA\OpenProject\Service\OpenProjectAPIService; +use OCP\AppFramework\Services\IInitialState; use OCP\Collaboration\Reference\RenderReferenceEvent; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\IConfig; use OCP\Util; /** * @template-implements IEventListener */ class OpenProjectReferenceListener implements IEventListener { + + /** + * @var IInitialState + */ + private $initialStateService; + + /** + * @var IConfig + */ + private $config; + + public function __construct( + IInitialState $initialStateService, + IConfig $config + ) { + $this->initialStateService = $initialStateService; + $this->config = $config; + } public function handle(Event $event): void { // @phpstan-ignore-next-line - make phpstan not complain in nextcloud version other than 26 if (!$event instanceof RenderReferenceEvent) { @@ -39,5 +60,11 @@ public function handle(Event $event): void { } Util::addScript(Application::APP_ID, Application::APP_ID . '-reference'); + $this->initialStateService->provideInitialState('admin-config-status', OpenProjectAPIService::isAdminConfigOk($this->config)); + + $this->initialStateService->provideInitialState( + 'openproject-url', + $this->config->getAppValue(Application::APP_ID, 'openproject_instance_url') + ); } } diff --git a/lib/Reference/WorkPackageReferenceProvider.php b/lib/Reference/WorkPackageReferenceProvider.php index b3e26e56d..37c87d320 100644 --- a/lib/Reference/WorkPackageReferenceProvider.php +++ b/lib/Reference/WorkPackageReferenceProvider.php @@ -34,7 +34,7 @@ use OCP\IL10N; use OCP\IURLGenerator; -class WorkPackageReferenceProvider extends ADiscoverableReferenceProvider implements ISearchableReferenceProvider { +class WorkPackageReferenceProvider extends ADiscoverableReferenceProvider { private const RICH_OBJECT_TYPE = Application::APP_ID . '_work_package'; // as we know we are on NC >= 26, we can use Php 8 syntax for class attributes @@ -76,13 +76,6 @@ public function getIconUrl(): string { ); } - /** - * @inheritDoc - */ - public function getSupportedSearchProviderIds(): array { - return ['openproject-search']; - } - /** * Parse a link to find a work package ID * diff --git a/lib/Search/OpenProjectSearchProvider.php b/lib/Search/OpenProjectSearchProvider.php index e6a85957b..c8e16175f 100644 --- a/lib/Search/OpenProjectSearchProvider.php +++ b/lib/Search/OpenProjectSearchProvider.php @@ -110,24 +110,14 @@ public function search(IUser $user, ISearchQuery $query): SearchResult { $offset = $offset ? intval($offset) : 0; $openprojectUrl = OpenProjectAPIService::sanitizeUrl($this->config->getAppValue(Application::APP_ID, 'openproject_instance_url')); $accessToken = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'token'); - - if ($accessToken === '') { + $searchEnabled = $this->config->getUserValue( + $user->getUID(), + Application::APP_ID, 'search_enabled', + $this->config->getAppValue(Application::APP_ID, 'default_enable_unified_search', '0')) === '1'; + if ($accessToken === '' || !$searchEnabled) { return SearchResult::paginated($this->getName(), [], 0); } - $routeFrom = $query->getRoute(); - $requestedFromSmartPicker = $routeFrom === '' || $routeFrom === 'smart-picker'; - - if (!$requestedFromSmartPicker) { - $searchEnabled = $this->config->getUserValue( - $user->getUID(), - Application::APP_ID, 'search_enabled', - $this->config->getAppValue(Application::APP_ID, 'default_enable_unified_search', '0')) === '1'; - if (!$searchEnabled) { - return SearchResult::paginated($this->getName(), [], 0); - } - } - $searchResults = $this->service->searchWorkPackage($user->getUID(), $term, null, false); $searchResults = array_slice($searchResults, $offset, $limit); diff --git a/src/components/icons/OpenProjectIcon.vue b/src/components/icons/OpenProjectIcon.vue new file mode 100644 index 000000000..2be36a9a3 --- /dev/null +++ b/src/components/icons/OpenProjectIcon.vue @@ -0,0 +1,31 @@ + + + diff --git a/src/components/tab/EmptyContent.vue b/src/components/tab/EmptyContent.vue index 0ad99eb51..621ab5361 100644 --- a/src/components/tab/EmptyContent.vue +++ b/src/components/tab/EmptyContent.vue @@ -3,10 +3,11 @@
- + +
-
+
{{ emptyContentTitleMessage }}
@@ -25,6 +26,7 @@ import LinkPlusIcon from 'vue-material-design-icons/LinkPlus.vue' import LinkOffIcon from 'vue-material-design-icons/LinkOff.vue' import CheckIcon from 'vue-material-design-icons/Check.vue' +import OpenProjectIcon from '../icons/OpenProjectIcon.vue' import { generateUrl } from '@nextcloud/router' import { translate as t } from '@nextcloud/l10n' import OAuthConnectButton from '../OAuthConnectButton.vue' @@ -32,7 +34,7 @@ import { STATE } from '../../utils.js' export default { name: 'EmptyContent', - components: { OAuthConnectButton, LinkPlusIcon, LinkOffIcon, CheckIcon }, + components: { OAuthConnectButton, LinkPlusIcon, LinkOffIcon, CheckIcon, OpenProjectIcon }, props: { state: { type: String, @@ -57,6 +59,10 @@ export default { type: Boolean, default: false, }, + isSmartPicker: { + type: Boolean, + default: false, + }, }, data() { return { @@ -109,9 +115,11 @@ export default { display: flex; align-items: center; justify-content: center; - img { - height: 50px; - width: 50px; + &--openproject { + margin: 90px; + display: block; + align-items: center; + justify-content: center; } } &--message { diff --git a/src/components/tab/SearchInput.vue b/src/components/tab/SearchInput.vue index c486dc2fd..5cd68a350 100644 --- a/src/components/tab/SearchInput.vue +++ b/src/components/tab/SearchInput.vue @@ -28,6 +28,7 @@ + +