diff --git a/lib/Service/ObjectService.php b/lib/Service/ObjectService.php index eae59e1d..9cc1d9ca 100644 --- a/lib/Service/ObjectService.php +++ b/lib/Service/ObjectService.php @@ -164,17 +164,16 @@ public function getObjects( ?int $limit = null, ?int $offset = null, ?array $filters = [], - ?array $searchConditions = [], - ?array $searchParams = [], ?array $sort = [], - ?array $extend = [] + ?array $extend = [], + ?string $search = null ): array { // Get the appropriate mapper for the object type $mapper = $this->getMapper($objectType); // Use the mapper to find and return the objects based on the provided parameters - $objects = $mapper->findAll($limit, $offset, $filters, sort: $sort); + $objects = $mapper->findAll($limit, $offset, $filters, sort: $sort, search: $search); // Convert entity objects to arrays using jsonSerialize $objects = array_map(function($object) { @@ -349,11 +348,11 @@ public function getOpenRegisters(): ?\OCA\OpenRegister\Service\ObjectService return null; } - private function getCount(string $objectType, array $filters = []): int + private function getCount(string $objectType, array $filters = [], ?string $search = null): int { $mapper = $this->getMapper($objectType); if($mapper instanceof \OCA\OpenRegister\Service\ObjectService === true) { - return $mapper->count(filters: $filters); + return $mapper->count(filters: $filters, search: $search); } return 0; @@ -376,6 +375,7 @@ public function getResultArrayForRequest(string $objectType, array $requestParam $order = $requestParams['order'] ?? $requestParams['_order'] ?? []; $extend = $requestParams['extend'] ?? $requestParams['_extend'] ?? null; $page = $requestParams['page'] ?? $requestParams['_page'] ?? null; + $search = $requestParams['_search'] ?? null; if ($page !== null && isset($limit)) { $offset = $limit * ($page - 1); @@ -393,7 +393,7 @@ public function getResultArrayForRequest(string $objectType, array $requestParam // Remove unnecessary parameters from filters $filters = $requestParams; unset($filters['_route']); // TODO: Investigate why this is here and if it's needed - unset($filters['_extend'], $filters['_limit'], $filters['_offset'], $filters['_order'], $filters['_page']); + unset($filters['_extend'], $filters['_limit'], $filters['_offset'], $filters['_order'], $filters['_page'], $filters['_search']); unset($filters['extend'], $filters['limit'], $filters['offset'], $filters['order'], $filters['page']); // Fetch objects based on filters and order @@ -403,7 +403,8 @@ public function getResultArrayForRequest(string $objectType, array $requestParam offset: $offset, filters: $filters, sort: $order, - extend: $extend + extend: $extend, + search: $search ); $facets = $this->getFacets($objectType, $filters); @@ -411,7 +412,7 @@ public function getResultArrayForRequest(string $objectType, array $requestParam return [ 'results' => $objects, 'facets' => $facets, - 'total' => $this->getCount(objectType: $objectType, filters: $filters), + 'total' => $this->getCount(objectType: $objectType, filters: $filters, search: $search), ]; } diff --git a/src/views/AdminSettings.vue b/src/views/AdminSettings.vue index 889c6046..9e739032 100644 --- a/src/views/AdminSettings.vue +++ b/src/views/AdminSettings.vue @@ -44,7 +44,7 @@ :disabled="loading || publication.loading" /> + + + + Alles opslaan + register.id.toString() === registerId) + const selectedRegister = this.availableRegisters.find((register) => register.id.toString() === registerId) this[property].availableSchemas = { options: selectedRegister?.schemas?.map((schema) => ({ @@ -549,8 +562,9 @@ export default { this.openRegisterInstalled = data.openRegisters this.settingsData = data this.availableRegisters = data.availableRegisters + this.objectTypes = data.objectTypes - this.availableRegisters = { + this.availableRegistersOptions = { options: data.availableRegisters.map((register) => ({ value: register.id.toString(), label: register.title, @@ -564,7 +578,7 @@ export default { } this[objectType] = { selectedSource: this.labelOptions.options.find((option) => option.value === data[objectType + '_source'] ?? data[objectType + '_source']), - selectedRegister: this.availableRegisters.options.find((option) => option.value === data[objectType + '_register']), + selectedRegister: this.availableRegistersOptions.options.find((option) => option.value === data[objectType + '_register']), selectedSchema: this[objectType].availableSchemas?.options?.find((option) => option.value === data[objectType + '_schema']), } }) @@ -584,8 +598,7 @@ export default { saveConfig(configId) { this[configId].loading = true this.saving = true - // eslint-disable-next-line no-console - console.log(`Saving ${configId} config`) + console.info(`Saving ${configId} config`) const settingsDataCopy = this.settingsData @@ -628,6 +641,96 @@ export default { return err }) }, + + saveAll() { + this.saving = true + this.objectTypes.forEach((objectType) => { + this[objectType].loading = true + }) + + console.info('Saving all config') + + const settingsDataCopy = this.settingsData + + delete settingsDataCopy.objectTypes + delete settingsDataCopy.openRegisters + delete settingsDataCopy.availableRegisters + + fetch('/index.php/apps/opencatalogi/settings', + { + method: 'POST', + body: JSON.stringify({ + ...settingsDataCopy, + attachment_register: this.attachment.selectedRegister?.value ?? '', + attachment_schema: this.attachment.selectedSchema?.value ?? '', + attachment_source: this.attachment.selectedSource?.value ?? 'internal', + catalog_register: this.catalog.selectedRegister?.value ?? '', + catalog_schema: this.catalog.selectedSchema?.value ?? '', + catalog_source: this.catalog.selectedSource?.value ?? 'internal', + listing_register: this.listing.selectedRegister?.value ?? '', + listing_schema: this.listing.selectedSchema?.value ?? '', + listing_source: this.listing.selectedSource?.value ?? 'internal', + organization_register: this.organization.selectedRegister?.value ?? '', + organization_schema: this.organization.selectedSchema?.value ?? '', + organization_source: this.organization.selectedSource?.value ?? 'internal', + publication_register: this.publication.selectedRegister?.value ?? '', + publication_schema: this.publication.selectedSchema?.value ?? '', + publication_source: this.publication.selectedSource?.value ?? 'internal', + publicationtype_register: this.publicationtype.selectedRegister?.value ?? '', + publicationtype_schema: this.publicationtype.selectedSchema?.value ?? '', + publicationtype_source: this.publicationtype.selectedSource?.value ?? 'internal', + theme_register: this.theme.selectedRegister?.value ?? '', + theme_schema: this.theme.selectedSchema?.value ?? '', + theme_source: this.theme.selectedSource?.value ?? 'internal', + }), + headers: { + 'Content-Type': 'application/json', + }, + }, + ) + .then((response) => { + response.json().then((data) => { + this.saving = false + this.objectTypes.forEach((objectType) => { + this[objectType].loading = false + }) + this.settingsData = { + ...this.settingsData, + attachment_register: data.attachment_register, + attachment_schema: data.attachment_schema, + attachment_source: data.attachment_source, + catalog_register: data.catalog_register, + catalog_schema: data.catalog_schema, + catalog_source: data.catalog_source, + listing_register: data.listing_register, + listing_schema: data.listing_schema, + listing_source: data.listing_source, + organization_register: data.organization_register, + organization_schema: data.organization_schema, + organization_source: data.organization_source, + publication_register: data.publication_register, + publication_schema: data.publication_schema, + publication_source: data.publication_source, + publicationtype_register: data.publicationtype_register, + publicationtype_schema: data.publicationtype_schema, + publicationtype_source: data.publicationtype_source, + theme_register: data.theme_register, + theme_schema: data.theme_schema, + theme_source: data.theme_source, + } + + }) + }) + .catch((err) => { + console.error(err) + this.saving = false + this.objectTypes.forEach((objectType) => { + this[objectType].loading = false + }) + return err + }) + }, + resetConfig() { this.saving = true