Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development to main #118

Merged
merged 6 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/Service/ObjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -403,15 +403,16 @@ public function getResultArrayForRequest(string $objectType, array $requestParam
offset: $offset,
filters: $filters,
sort: $order,
extend: $extend
extend: $extend,
search: $search
);
$facets = $this->getFacets($objectType, $filters);

// Prepare response data
return [
'results' => $objects,
'facets' => $facets,
'total' => $this->getCount(objectType: $objectType, filters: $filters),
'total' => $this->getCount(objectType: $objectType, filters: $filters, search: $search),
];
}

Expand Down
127 changes: 115 additions & 12 deletions src/views/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
:disabled="loading || publication.loading" />

<NcSelect v-if="publication.selectedSource?.value === 'openregister' "
v-bind="availableRegisters"
v-bind="availableRegistersOptions"
v-model="publication.selectedRegister"
input-label="Register"
:loading="publication.loading"
Expand Down Expand Up @@ -79,7 +79,7 @@
:disabled="loading || organization.loading" />

<NcSelect v-if="organization.selectedSource?.value === 'openregister' "
v-bind="availableRegisters"
v-bind="availableRegistersOptions"
v-model="organization.selectedRegister"
input-label="Register"
:loading="organization.loading"
Expand Down Expand Up @@ -114,7 +114,7 @@
:disabled="loading || attachment.loading" />

<NcSelect v-if="attachment.selectedSource?.value === 'openregister' "
v-bind="availableRegisters"
v-bind="availableRegistersOptions"
v-model="attachment.selectedRegister"
input-label="Register"
:loading="attachment.loading"
Expand Down Expand Up @@ -149,7 +149,7 @@
:disabled="loading || catalog.loading" />

<NcSelect v-if="catalog.selectedSource?.value === 'openregister' "
v-bind="availableRegisters"
v-bind="availableRegistersOptions"
v-model="catalog.selectedRegister"
input-label="Register"
:loading="catalog.loading"
Expand Down Expand Up @@ -184,7 +184,7 @@
:disabled="loading || listing.loading" />

<NcSelect v-if="listing.selectedSource?.value === 'openregister' "
v-bind="availableRegisters"
v-bind="availableRegistersOptions"
v-model="listing.selectedRegister"
input-label="Register"
:loading="listing.loading"
Expand Down Expand Up @@ -219,7 +219,7 @@
:disabled="loading || theme.loading" />

<NcSelect v-if="theme.selectedSource?.value === 'openregister' "
v-bind="availableRegisters"
v-bind="availableRegistersOptions"
v-model="theme.selectedRegister"
input-label="Register"
:loading="theme.loading"
Expand Down Expand Up @@ -254,7 +254,7 @@
:disabled="loading || publicationtype.loading" />

<NcSelect v-if="publicationtype.selectedSource?.value === 'openregister' "
v-bind="availableRegisters"
v-bind="availableRegistersOptions"
v-model="publicationtype.selectedRegister"
input-label="Register"
:loading="publicationtype.loading"
Expand All @@ -278,6 +278,17 @@
Opslaan
</NcButton>
</div>

<NcButton
type="primary"
:disabled="saving"
@click="saveAll()">
<template #icon>
<NcLoadingIcon v-if="saving" :size="20" />
<Plus v-if="!saving" :size="20" />
</template>
Alles opslaan
</NcButton>
</div>
<NcLoadingIcon v-if="loading"
class="loadingIcon"
Expand Down Expand Up @@ -313,6 +324,8 @@ export default {
saving: false,
settingsData: {},
availableRegisters: [],
availableRegistersOptions: [],
objectTypes: [],
publication: {
selectedSource: '',
selectedRegister: '',
Expand Down Expand Up @@ -525,7 +538,7 @@ export default {
},
methods: {
setRegisterSchemaOptions(registerId, property) {
const selectedRegister = this.settingsData.availableRegisters.find((register) => register.id.toString() === registerId)
const selectedRegister = this.availableRegisters.find((register) => register.id.toString() === registerId)

this[property].availableSchemas = {
options: selectedRegister?.schemas?.map((schema) => ({
Expand All @@ -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,
Expand All @@ -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']),
}
})
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down