Skip to content

Commit

Permalink
WIP: copy listing metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrands02 committed Aug 15, 2024
1 parent 142ae0d commit b9cf59a
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 28 deletions.
8 changes: 6 additions & 2 deletions lib/Db/Listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Listing extends Entity implements JsonSerializable
protected ?string $description = null;
protected ?string $search = null;
protected ?string $directory = null;
protected ?string $metadata = null;
protected ?array $metadata = null;
protected ?string $catalogId = null;
protected ?string $status = null;
protected ?DateTime $lastSync = null;
Expand All @@ -29,7 +29,7 @@ public function __construct() {
$this->addType(fieldName: 'description', type: 'string');
$this->addType(fieldName: 'search', type: 'string');
$this->addType(fieldName: 'directory', type: 'string');
$this->addType(fieldName: 'metadata', type: 'string');
$this->addType(fieldName: 'metadata', type: 'json');
$this->addType(fieldName: 'catalogId', type: 'string');
$this->addType(fieldName: 'status', type: 'string');
$this->addType(fieldName: 'lastSync', type: 'datetime');
Expand All @@ -51,6 +51,10 @@ public function hydrate(array $object): self
{
$jsonFields = $this->getJsonFields();

if(isset($object['metadata']) === false) {
$object['metadata'] = [];
}

foreach($object as $key => $value) {
if (in_array($key, $jsonFields) === true && $value === []) {
$value = null;
Expand Down
34 changes: 17 additions & 17 deletions lib/Db/ListingMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function mapRowToEntityCustom(array $row): Entity {
}
}

$row['organisation'] = $organisationIsEmpty === true ? null : Organisation::fromRow($organisationData);
// $row['organisation'] = $organisationIsEmpty === true ? null : Organisation::fromRow($organisationData);

return \call_user_func($this->entityClass .'::fromRow', $row);
}
Expand Down Expand Up @@ -86,25 +86,25 @@ protected function findEntitiesCustom(IQueryBuilder $query): array {
public function findAll(?int $limit = null, ?int $offset = null, ?array $filters = [], ?array $searchConditions = [], ?array $searchParams = []): array
{
$qb = $this->db->getQueryBuilder();
$qb->select(
'l.*',
'o.id AS organisation_id',
'o.title AS organisation_title',
'o.summary AS organisation_summary',
'o.description AS organisation_description',
'o.image AS organisation_image',
'o.oin AS organisation_oin',
'o.tooi AS organisation_tooi',
'o.rsin AS organisation_rsin',
'o.pki AS organisation_pki'

$qb->select('*'
// 'l.*',
// 'o.id AS organisation_id',
// 'o.title AS organisation_title',
// 'o.summary AS organisation_summary',
// 'o.description AS organisation_description',
// 'o.image AS organisation_image',
// 'o.oin AS organisation_oin',
// 'o.tooi AS organisation_tooi',
// 'o.rsin AS organisation_rsin',
// 'o.pki AS organisation_pki'
)
->from('listings', 'l')
->leftJoin('l', 'organizations', 'o', 'l.organisation = o.id')
// ->leftJoin('l', 'organizations', 'o', 'l.organisation = o.id')
->setMaxResults($limit)
->setFirstResult($offset);


// Apply filters
foreach ($filters as $filter => $value) {
if ($value === 'IS NOT NULL') {
Expand All @@ -115,15 +115,15 @@ public function findAll(?int $limit = null, ?int $offset = null, ?array $filters
$qb->andWhere($qb->expr()->eq($filter, $qb->createNamedParameter($value)));
}
}

// Apply search conditions
if (!empty($searchConditions)) {
$qb->andWhere('(' . implode(' OR ', $searchConditions) . ')');
foreach ($searchParams as $param => $value) {
$qb->setParameter($param, $value);
}
}

// Use the existing findEntities method to fetch and map the results
return $this->findEntitiesCustom($qb);
}
Expand Down
82 changes: 82 additions & 0 deletions lib/Migration/Version6Date20240815105059.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2024 FIXME Your name <[email protected]>
*
* FIXME @author Your name <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\OpenCatalogi\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use OCP\DB\Types;

/**
* FIXME Auto-generated migration step: Please modify to your needs!
*/
class Version6Date20240815105059 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$schema = $schemaClosure();
$table = $schema->getTable('listings');

if ($table->hasColumn('metadata')) {
$table->dropColumn('metadata');
}

$table->addColumn(
name: 'metadata',
typeName: Types::JSON,
options: [
'notNull' => false,
'default' => 'a:0:{}'
]);

$output->info("Added 'metadata' column as JSON type with a default value of an empty array.");

return $schema;
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
}
2 changes: 1 addition & 1 deletion lib/Service/DirectoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function listCatalog (array $catalog): array

$listing['title'] = $catalog['title'];
$listing['organisation'] = $catalog['organisation'];
$listing['metaData'] = $catalog['metaData'];
$listing['metadata'] = $catalog['metadata'];

if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
Expand Down
12 changes: 9 additions & 3 deletions src/modals/catalogiMetadata/AddCatalogiMetadata.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { catalogiStore, navigationStore } from '../../store/store.js'
required />
</div>
<NcButton v-if="success === null"
:disabled="!metaData?.value?.id || loading"
:disabled="!metaData?.value?.source || loading"
type="primary"
@click="addCatalogMetadata">
<template #icon>
Expand Down Expand Up @@ -130,7 +130,7 @@ export default {
this.metaData = {
options: filteredData.map((metaData) => ({
id: metaData.id,
source: metaData.source,
label: metaData.title,
})),
}
Expand All @@ -146,7 +146,13 @@ export default {
this.loading = true
this.error = false
this.catalogiItem.metadata.push(this.metaData.value.id)
this.catalogiItem.metadata.push(this.metaData.value.source)
if (!this.metaData?.value?.source) {
this.error = 'Publicatie type heeft geen bron, kan niet gekoppeld worden'
this.metaDataLoading = false
return
}
fetch(
`/index.php/apps/opencatalogi/api/catalogi/${this.catalogiItem.id}`,
Expand Down
6 changes: 6 additions & 0 deletions src/modals/metaData/AddMetaDataModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ export default {
},
addMetaData() {
this.loading = true
// Prevent setting source on any way.
if (this.metadata?.source !== undefined) {
delete this.metadata.source
}
fetch(
'/index.php/apps/opencatalogi/api/metadata',
{
Expand Down
1 change: 1 addition & 0 deletions src/modals/metaData/EditMetaDataModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default {
},
editMetaData() {
this.loading = true
fetch(
`/index.php/apps/opencatalogi/api/metadata/${metadataStore.metaDataItem?.id}`,
{
Expand Down
1 change: 1 addition & 0 deletions src/modals/publication/AddPublicationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export default {
},
fetchMetaData() {
this.metaDataLoading = true
fetch('/index.php/apps/opencatalogi/api/metadata', {
method: 'GET',
})
Expand Down
4 changes: 2 additions & 2 deletions src/sidebars/SideBars.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script setup>
import { navigationStore } from '../store/store.js'
import { navigationStore, directoryStore } from '../store/store.js'
</script>

<template>
<div>
<!-- Placeholder div for all of the sidebars-->
<SearchSideBar v-if="navigationStore.selected === 'search'" />
<DashboardSideBar v-if="navigationStore.selected === 'dashboard'" />
<DirectorySideBar v-if="navigationStore.selected === 'directory'" />
<DirectorySideBar v-if="navigationStore.selected === 'directory'" :listing-item="directoryStore.listingItem" />
</div>
</template>

Expand Down
102 changes: 100 additions & 2 deletions src/sidebars/directory/DirectorySideBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import { navigationStore, directoryStore } from '../../store/store.js'
<FileTreeOutline :size="20" />
</template>
Welke meta data typen zou u uit deze catalogus willen overnemen?
<NcCheckboxRadioSwitch type="switch">
Metedata type 1
<NcCheckboxRadioSwitch v-for="(metadataSingular, i) in metadata" :key="`${metadataSingular}${i}`" type="switch">
{{ metadataSingular.title }}
</NcCheckboxRadioSwitch>
</NcAppSidebarTab>
</NcAppSidebar>
Expand Down Expand Up @@ -80,14 +80,112 @@ export default {
CogOutline,
FileTreeOutline,
},
props: {
listingItem: {
type: Object,
required: true,
},
},
data() {
return {
metadata: [],
listing: '',
}
},
watch: {
publicationItem: {
handler(newVal) {
console.log('test watch')
console.log(newVal)
if (newVal && newVal.id) {
this.fetchMetaData()
}
},
immediate: true, // Ensures the watcher runs when the component is created
},
},
mounted() {
this.fetchMetaData()
},
methods: {
openLink(url, type = '') {
window.open(url, type)
},
CopyMetadata() {
this.loading = true
// metadataStore.metaDataItem.title = 'KOPIE: ' + metadataStore.metaDataItem.title
if (Object.keys(metadataStore.metaDataItem.properties).length === 0) {
delete metadataStore.metaDataItem.properties
}
delete metadataStore.metaDataItem.id
delete metadataStore.metaDataItem._id
fetch(
'/index.php/apps/opencatalogi/api/metadata',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(metadataStore.metaDataItem),
},
)
.then((response) => {
this.loading = false
this.succes = true
// Lets refresh the catalogiList
metadataStore.refreshMetaDataList()
response.json().then((data) => {
metadataStore.setMetaDataItem(data)
})
navigationStore.setSelected('metaData')
// Wait for the user to read the feedback then close the model
const self = this
setTimeout(function() {
self.succes = false
navigationStore.setDialog(false)
}, 2000)
})
.catch((err) => {
this.error = err
this.loading = false
})
},
fetchMetaData() {
this.loading = true
console.log('test1')
console.log(directoryStore.listingItem)
if (directoryStore.listingItem && Array.isArray(directoryStore.listingItem.metadata)) {
directoryStore.listingItem?.metadata.forEach(metadataSingular => {
console.log('test2')
fetch(
'/index.php/apps/opencatalogi/api/metadata?source=' + metadataSingular,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
},
)
.then((response) => {
this.loading = false
this.succes = true
response.json().then(
(data) => {
if (data?.results[0] !== undefined) {
this.metaData.push(data.results[0])
}
return data
},
)
})
.catch((err) => {
this.error = err
this.loading = false
})
})
}
},
},
}
</script>
2 changes: 1 addition & 1 deletion src/store/modules/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useDirectoryStore = defineStore(
}),
actions: {
setListingItem(listingItem) {
this.listingItem = listingItem && new Listing(listingItem)
this.listingItem = listingItem ? new Listing(listingItem) : false
console.log('Active directory item set to ' + listingItem && listingItem.id)
},
setListingList(listingList) {
Expand Down
Loading

0 comments on commit b9cf59a

Please sign in to comment.