Skip to content

Commit

Permalink
Merge pull request #192 from ConductionNL/development
Browse files Browse the repository at this point in the history
Development to main
  • Loading branch information
remko48 authored Feb 13, 2025
2 parents bccff4c + a2a719c commit 1b50821
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 184 deletions.
22 changes: 11 additions & 11 deletions lib/Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FileService
const ROOT_FOLDER = 'Open Registers';
const APP_GROUP = 'openregister';
const APP_USER = 'OpenRegister';
const FILE_TAG_TYPE = 'file';
const FILE_TAG_TYPE = 'files';
/**
* Constructor for FileService
*
Expand Down Expand Up @@ -354,24 +354,24 @@ private function getCurrentDomain(): string
private function getUser(): IUser
{
$openCatalogiUser = $this->userManager->get(self::APP_USER);

if (!$openCatalogiUser) {
// Create OpenCatalogi user if it doesn't exist
$password = bin2hex(random_bytes(16)); // Generate random password
$openCatalogiUser = $this->userManager->createUser(self::APP_USER, $password);

if (!$openCatalogiUser) {
throw new \Exception('Failed to create OpenCatalogi user account.');
}

// Add user to OpenCatalogi group
$group = $this->groupManager->get(self::APP_GROUP);
if (!$group) {
$group = $this->groupManager->createGroup(self::APP_GROUP);
}
$group->addUser($openCatalogiUser);
}

return $openCatalogiUser;
}

Expand Down Expand Up @@ -420,7 +420,7 @@ public function formatFiles(array $files): array
'size' => $file->getSize(),
'hash' => $file->getEtag(),
'published' => (new DateTime())->setTimestamp($file->getCreationTime())->format('c'),
'modified' => (new DateTime())->setTimestamp($file->getUploadTime())->format('c'),
'modified' => (new DateTime())->setTimestamp($file->getUploadTime())->format('c'),
'labels' => $this->getFileTags(fileId: $file->getId())
];

Expand Down Expand Up @@ -517,7 +517,7 @@ public function findShare(string $path, ?int $shareType = 3): ?IShare
private function createShare(array $shareData): IShare
{
$userId = $this->getUser()->getUID();

// Create a new share
$share = $this->shareManager->newShare();
$share->setTarget(target: '/'.$shareData['path']);
Expand Down Expand Up @@ -565,7 +565,7 @@ public function createShareLink(string $path, ?int $shareType = 3, ?int $permiss
}

$userId = $this->getUser()->getUID();

try {
$userFolder = $this->rootFolder->getUserFolder(userId: $userId);
} catch (NotPermittedException) {
Expand Down Expand Up @@ -819,14 +819,14 @@ public function addFile(ObjectEntity $objectEntity, string $fileName, string $co
$this->userSession->setUser($this->getUser());

$file = $folder->newFile($fileName);

// Write content to the file
$file->putContent($content);

$this->userSession->setUser($currentUser);

return $file;

} catch (NotPermittedException $e) {
$this->logger->error("Permission denied creating file $fileName: " . $e->getMessage());
throw new NotPermittedException("Cannot create file $fileName: " . $e->getMessage());
Expand Down
6 changes: 6 additions & 0 deletions src/navigation/MainMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import { navigationStore } from '../store/store.js'
<CubeOutline :size="20" />
</template>
</NcAppNavigationItem>
<NcAppNavigationItem :active="navigationStore.selected === 'search'" name="Search" @click="navigationStore.setSelected('search')">
<template #icon>
<LayersSearchOutline :size="20" />
</template>
</NcAppNavigationItem>
</NcAppNavigationList>

<NcAppNavigationSettings>
Expand All @@ -51,6 +56,7 @@ import DatabaseOutline from 'vue-material-design-icons/DatabaseOutline.vue'
import FileTreeOutline from 'vue-material-design-icons/FileTreeOutline.vue'
import DatabaseArrowRightOutline from 'vue-material-design-icons/DatabaseArrowRightOutline.vue'
import CubeOutline from 'vue-material-design-icons/CubeOutline.vue'
import LayersSearchOutline from 'vue-material-design-icons/LayersSearchOutline.vue'
export default {
name: 'MainMenu',
Expand Down
8 changes: 7 additions & 1 deletion src/sidebars/SideBars.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<script setup>
import { navigationStore } from '../store/store.js'
</script>

<template>
<div />
<SearchSideBar v-if="navigationStore.selected === 'search'" />
</template>

<script>
import SearchSideBar from './search/SearchSideBar.vue'
export default {
name: 'SideBars',
components: {
SearchSideBar,
},
}
</script>
136 changes: 72 additions & 64 deletions src/sidebars/search/SearchSideBar.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { searchStore } from '../../store/store.js'
import { searchStore, registerStore, schemaStore } from '../../store/store.js'
</script>

<template>
Expand All @@ -11,96 +11,104 @@ import { searchStore } from '../../store/store.js'
<template #icon>
<Magnify :size="20" />
</template>
Zoek snel in het voor uw beschikbare federatieve netwerk<br>
<NcTextField class="searchField"
:value.sync="searchStore.search"
label="Zoeken" />
<NcNoteCard v-if="searchStore.searchError" type="error">
<p>{{ searchStore.searchError }}</p>
</NcNoteCard>
<NcSelect v-bind="registerOptions"
v-model="selectedRegister"
input-label="Registratie"
:loading="registerLoading" />
<NcSelect v-bind="schemaOptions"
v-model="selectedSchema"
input-label="Schema"
:loading="schemaLoading"
:disabled="!selectedRegister?.id" />
</NcAppSidebarTab>
<NcAppSidebarTab id="settings-tab" name="Catalogi" :order="2">

<NcAppSidebarTab id="upload-tab" name="Upload" :order="2">
<template #icon>
<DatabaseOutline :size="20" />
<Upload :size="20" />
</template>
<NcCheckboxRadioSwitch v-for="(catalogiItem, i) in catalogiStore.catalogiList"
:key="`${catalogiItem}${i}`"
type="switch"
:checked.sync="searchStore.catalogi[catalogiItem.id]">
{{ catalogiItem.title || 'Geen titel' }}
</NcCheckboxRadioSwitch>
<NcButton type="primary">
Upload
</NcButton>
</NcAppSidebarTab>
<NcAppSidebarTab id="share-tab" name="Publicatie typen" :order="3">

<NcAppSidebarTab id="download-tab" name="Download" :order="3">
<template #icon>
<FileTreeOutline :size="20" />
<Download :size="20" />
</template>
<NcCheckboxRadioSwitch v-for="(metaData, i) in metadataStore.metaDataList"
:key="`${metaData}${i}`"
type="switch"
:checked.sync="searchStore.metadata[metaData.id]">
{{ metaData.title || 'Geen titel' }}
</NcCheckboxRadioSwitch>
<NcButton type="primary">
Download
</NcButton>
</NcAppSidebarTab>
</NcAppSidebar>
</template>
<script>
import { NcAppSidebar, NcAppSidebarTab, NcTextField, NcNoteCard, NcCheckboxRadioSwitch } from '@nextcloud/vue'
import { NcAppSidebar, NcAppSidebarTab, NcSelect, NcButton } from '@nextcloud/vue'
import Magnify from 'vue-material-design-icons/Magnify.vue'
import DatabaseOutline from 'vue-material-design-icons/DatabaseOutline.vue'
import FileTreeOutline from 'vue-material-design-icons/FileTreeOutline.vue'
import { debounce } from 'lodash'
import Upload from 'vue-material-design-icons/Upload.vue'
import Download from 'vue-material-design-icons/Download.vue'
export default {
name: 'SearchSideBar',
components: {
NcAppSidebar,
NcAppSidebarTab,
NcTextField,
NcCheckboxRadioSwitch,
// Icons
Magnify,
DatabaseOutline,
FileTreeOutline,
},
props: {
search: {
type: String,
required: true,
},
metadata: {
type: Object,
required: true,
},
catalogi: {
type: Object,
required: true,
},
NcSelect,
NcButton,
},
data() {
return {
starred: false,
registerLoading: false,
selectedRegister: null,
schemaLoading: false,
selectedSchema: null,
}
},
computed: {
// when registerList is filled, make a options object for NcSelect
registerOptions() {
return {
options: registerStore.registerList.map(register => ({
label: register.title,
id: register.id,
})),
}
},
// when schemaList is filled, make a options object for NcSelect based on the selected register
schemaOptions() {
const fullSelectedRegister = registerStore.registerList.find(register => register.id === (this.selectedRegister?.id || Symbol('no selected register')))
if (!fullSelectedRegister) return []
return {
options: schemaStore.schemaList
.filter(schema => fullSelectedRegister.schemas.includes(schema.id))
.map(schema => ({
label: schema.title,
id: schema.id,
})),
}
},
},
watch: {
search: 'debouncedSearch',
metadata: {
handler() {
this.debouncedSearch()
},
deep: true,
// when the selected register changes clear the selected schema
selectedRegister(newValue) {
this.selectedSchema = null
},
catalogi: {
handler() {
this.debouncedSearch()
},
deep: true,
// when selectedSchema changes, search for objects with the selected register and schema as filters
selectedSchema(newValue) {
if (newValue?.id) {
searchStore.searchObjects({
register: this.selectedRegister?.id,
schema: this.selectedSchema?.id,
})
}
},
},
methods: {
debouncedSearch: debounce(function() {
searchStore.getSearchResults()
}, 500),
mounted() {
this.registerLoading = true
this.schemaLoading = true
registerStore.refreshRegisterList().finally(() => (this.registerLoading = false))
schemaStore.refreshSchemaList().finally(() => (this.schemaLoading = false))
},
}
</script>
56 changes: 0 additions & 56 deletions src/store/modules/search.js

This file was deleted.

Loading

0 comments on commit 1b50821

Please sign in to comment.