Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/DIMOC-215/catalogi-liste…
Browse files Browse the repository at this point in the history
…d' into feature/DIMOC-48/update-directory-service
  • Loading branch information
rjzondervan committed Aug 7, 2024
2 parents d64b082 + 9bc7184 commit 32c548c
Show file tree
Hide file tree
Showing 30 changed files with 366 additions and 368 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/CI-workflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ jobs:
run: phpcbf .
continue-on-error: ${{ github.ref != 'refs/heads/main' }}

- name: Commit code formatting changes
if: success() && github.ref != 'refs/heads/main'
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add src
git diff --cached --quiet || (git commit -m "Update src from PHP Codesniffer" && git pull origin $(git rev-parse --abbrev-ref HEAD) --rebase --autostash && git push)
#- name: Commit code formatting changes
# if: success() && github.ref != 'refs/heads/main'
# run: |
# git config user.name "GitHub Actions"
# git config user.email "[email protected]"
# git add src
# git diff --cached --quiet || (git commit -m "Update src from PHP Codesniffer" && git pull origin $(git rev-parse --abbrev-ref HEAD) --rebase --autostash && git push)

- name: Run phpcs
run: phpcs -q --report=checkstyle src | cs2pr
Expand Down
10 changes: 10 additions & 0 deletions docs/beheerders/directory.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# Directory

De directory vormt het overzicht van alle andere (externe) catalogi die bij jouw installatie bekend zijn. Een Catalogus die bij jouw installatie bekend is noemen een listing (als in is gelist op jouw directory).

## Opzetten federatief netwerk

Directories worden tussen installaties onderling uitgewisseld en geupdate. Je hoeft dus nooit handmatig catalogi van andere toe te voegen aan jouw catalogus.

## Listing

Bij een listing kan je de volgende zaken aanpassen.
12 changes: 6 additions & 6 deletions lib/Controller/CatalogiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public function index(ObjectService $objectService, SearchService $searchService
if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch);
$searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' => $this->catalogMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' => $this->catalogMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}

$filters = $searchService->createMongoDBSearchFilter($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

try {
$dbConfig = [
Expand Down
12 changes: 6 additions & 6 deletions lib/Controller/DirectoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ public function index(ObjectService $objectService, SearchService $searchService
if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch);
$searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' => $this->listingMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' => $this->listingMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}

$filters = $searchService->createMongoDBSearchFilter($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

$dbConfig['base_uri'] = $this->config->getValueString(app: $this->appName, key: 'mongodbLocation');
$dbConfig['headers']['api-key'] = $this->config->getValueString(app: $this->appName, key: 'mongodbKey');
Expand Down
12 changes: 6 additions & 6 deletions lib/Controller/MetaDataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public function index(ObjectService $objectService, SearchService $searchService
if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch);
$searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' =>$this->metaDataMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' =>$this->metaDataMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}

$filters = $searchService->createMongoDBSearchFilter($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

$dbConfig['base_uri'] = $this->config->getValueString(app: $this->appName, key: 'mongodbLocation');
$dbConfig['headers']['api-key'] = $this->config->getValueString(app: $this->appName, key: 'mongodbKey');
Expand Down
42 changes: 10 additions & 32 deletions lib/Controller/OrganisationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use OCA\OpenCatalogi\Db\OrganisationMapper;
use OCA\OpenCatalogi\Service\ObjectService;
use OCP\AppFramework\Controller;
use OCA\OpenCatalogi\Service\SearchService;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IAppConfig;
Expand Down Expand Up @@ -44,47 +45,24 @@ public function page(): TemplateResponse
*
* @return JSONResponse
*/
public function index(ObjectService $objectService): JSONResponse
public function index(ObjectService $objectService, SearchService $searchService): JSONResponse
{

$filters = $this->request->getParams();

$searchConditions = [];
$searchParams = [];
$fieldsToSearch = ['title', 'description', 'summary'];

foreach ($filters as $key => $value) {
if ($key === '_search') {
// MongoDB
$searchRegex = ['$regex' => $value, '$options' => 'i'];
$filters['$or'] = [];

// MySQL
$searchParams['search'] = '%' . strtolower($value) . '%';

foreach ($fieldsToSearch as $field) {
// MongoDB
$filters['$or'][] = [$field => $searchRegex];

// MySQL
$searchConditions[] = "LOWER($field) LIKE :search";
}
}

if (str_starts_with($key, '_')) {
unset($filters[$key]);
}
}

if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
// Unset mongodb filter
unset($filters['$or']);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' => $this->organisationMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' => $this->organisationMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}


$filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

try {
$dbConfig = [
'base_uri' => $this->config->getValueString($this->appName, 'mongodbLocation'),
Expand Down
24 changes: 6 additions & 18 deletions lib/Controller/PublicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@

class PublicationsController extends Controller
{
const TEST_ARRAY = [
"354980e5-c967-4ba5-989b-65c2b0cd2ff4" => [
"id" => "354980e5-c967-4ba5-989b-65c2b0cd2ff4",
"name" => "Input voor OpenCatalogi",
"summary" => "Dit is een selectie van high-value datasets in DCAT-AP 2.0 standaard x"
],
"2ab0011e-9b4c-4c50-a50d-a16fc0be0178" => [
"id" => "2ab0011e-9b4c-4c50-a50d-a16fc0be0178",
"title" => "Publication two",
"description" => "summary for two"
]
];

public function __construct
(
Expand Down Expand Up @@ -119,15 +107,15 @@ public function index(ObjectService $objectService, SearchService $searchService
if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch);
$searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' => $this->publicationMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' => $this->publicationMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}

$filters = $searchService->createMongoDBSearchFilter($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters, $fieldsToSearch);
$filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

$dbConfig['base_uri'] = $this->config->getValueString(app: $this->appName, key: 'mongodbLocation');
$dbConfig['headers']['api-key'] = $this->config->getValueString(app: $this->appName, key: 'mongodbKey');
Expand Down
8 changes: 4 additions & 4 deletions lib/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public function index(SearchService $searchService): JSONResponse
if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
$searchParams = $searchService->createMySQLSearchParams($filters, $fieldsToSearch);
$searchConditions = $searchService->createMySQLSearchConditions($filters, $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams($filters);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' => $this->publicationMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' => $this->publicationMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}

//@TODO: find a better way to get query params. This fixes it for now.
Expand Down
44 changes: 11 additions & 33 deletions lib/Controller/ThemesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use OCA\OpenCatalogi\Db\ThemeMapper;
use OCA\OpenCatalogi\Service\ObjectService;
use OCA\OpenCatalogi\Service\SearchService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\JSONResponse;
Expand Down Expand Up @@ -58,47 +59,24 @@ public function page(): TemplateResponse
*
* @return JSONResponse
*/
public function index(ObjectService $objectService): JSONResponse
public function index(ObjectService $objectService, SearchService $searchService): JSONResponse
{

$filters = $this->request->getParams();

$searchConditions = [];
$searchParams = [];
$fieldsToSearch = ['title', 'description', 'summary'];

foreach ($filters as $key => $value) {
if ($key === '_search') {
// MongoDB
$searchRegex = ['$regex' => $value, '$options' => 'i'];
$filters['$or'] = [];

// MySQL
$searchParams['search'] = '%' . strtolower($value) . '%';

foreach ($fieldsToSearch as $field) {
// MongoDB
$filters['$or'][] = [$field => $searchRegex];

// MySQL
$searchConditions[] = "LOWER($field) LIKE :search";
}
}

if (str_starts_with($key, '_')) {
unset($filters[$key]);
}
}

if($this->config->hasKey($this->appName, 'mongoStorage') === false
|| $this->config->getValueString($this->appName, 'mongoStorage') !== '1'
) {
// Unset mongodb filter
unset($filters['$or']);
$searchParams = $searchService->createMySQLSearchParams(filters: $filters);
$searchConditions = $searchService->createMySQLSearchConditions(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

return new JSONResponse(['results' => $this->themeMapper->findAll(filters: $filters, searchParams: $searchParams, searchConditions: $searchConditions)]);
return new JSONResponse(['results' => $this->themeMapper->findAll(limit: null, offset: null, filters: $filters, searchConditions: $searchConditions, searchParams: $searchParams)]);
}


$filters = $searchService->createMongoDBSearchFilter(filters: $filters, fieldsToSearch: $fieldsToSearch);
$filters = $searchService->unsetSpecialQueryParams(filters: $filters);

try {
$dbConfig = [
'base_uri' => $this->config->getValueString($this->appName, 'mongodbLocation'),
Expand Down Expand Up @@ -160,7 +138,7 @@ public function show(string $id, ObjectService $objectService): JSONResponse
*/
public function create(ObjectService $objectService): JSONResponse
{

$data = $this->request->getParams();

foreach ($data as $key => $value) {
Expand Down
6 changes: 3 additions & 3 deletions src/modals/Modals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<EditMetaDataPropertyModal />
<AddCatalogModal />
<EditCatalogModal />
<AddListingModal />
<AddDirectoryModal />
<EditListingModal />
<AddPublicationDataModal />
<EditPublicationDataModal />
Expand All @@ -37,7 +37,7 @@ import EditMetaDataPropertyModal from './metaData/EditMetaDataPropertyModal.vue'
import AddCatalogModal from './catalog/AddCatalogModal.vue'
import EditCatalogModal from './catalog/EditCatalogModal.vue'
import AddListingModal from './directory/AddListingModal.vue'
import AddDirectoryModal from './directory/AddDirectoryModal.vue'
import EditListingModal from './directory/EditListingModal.vue'
import AddOrganisationModal from './organisation/AddOrganisationModal.vue'
import EditOrganisatioModal from './organisation/EditOrganisationModal.vue'
Expand All @@ -59,7 +59,7 @@ export default {
EditMetaDataPropertyModal,
AddCatalogModal,
EditCatalogModal,
AddListingModal,
AddDirectoryModal,
EditListingModal,
AddPublicationDataModal,
EditPublicationDataModal,
Expand Down
16 changes: 12 additions & 4 deletions src/modals/catalog/AddCatalogModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ import { catalogiStore, navigationStore } from '../../store/store.js'
label="Beschrijving"
maxlength="255"
:value.sync="catalogi.description" />
<NcCheckboxRadioSwitch :disabled="loading"
label="Listed"
:checked.sync="catalogi.listed">
Listed
</NcCheckboxRadioSwitch>
</div>
<NcButton v-if="success === null"
:disabled="!catalogi.title || loading"
type="primary"
@click="addCatalog">
<template #icon>
<NcLoadingIcon v-if="loading" :size="20" />
<ContentSaveOutline v-if="!loading" :size="20" />
<Plus v-if="!loading" :size="20" />
</template>
Toevoegen
</NcButton>
Expand All @@ -50,8 +55,8 @@ import { catalogiStore, navigationStore } from '../../store/store.js'
</template>

<script>
import { NcButton, NcModal, NcTextField, NcLoadingIcon, NcNoteCard } from '@nextcloud/vue'
import ContentSaveOutline from 'vue-material-design-icons/ContentSaveOutline.vue'
import { NcButton, NcModal, NcTextField, NcLoadingIcon, NcNoteCard, NcCheckboxRadioSwitch } from '@nextcloud/vue'
import Plus from 'vue-material-design-icons/Plus.vue'
export default {
name: 'AddCatalogModal',
Expand All @@ -61,15 +66,17 @@ export default {
NcButton,
NcLoadingIcon,
NcNoteCard,
NcCheckboxRadioSwitch,
// Icons
ContentSaveOutline,
Plus,
},
data() {
return {
catalogi: {
title: '',
summary: '',
description: '',
listed: false,
},
loading: false,
success: null,
Expand All @@ -84,6 +91,7 @@ export default {
title: '',
summary: '',
description: '',
listed: false,
}
},
addCatalog() {
Expand Down
Loading

0 comments on commit 32c548c

Please sign in to comment.