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

finished the extra admin settings #134

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
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
120 changes: 119 additions & 1 deletion src/views/AdminSettings.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
<template>
<div>
<NcSettingsSection :name="'Open Catalogi'" description="Eén centrale plek voor hergebruik van informatietechnologie binnen de overheid" doc-url="https://conduction.gitbook.io/opencatalogi-nextcloud/gebruikers" />
<NcSettingsSection :name="'Publications'" description="">
<h3>Publicatie</h3>
<div class="selectionContainer">
<NcSelect v-bind="attachmentSettings.file_types"
v-model="attachmentSettings.file_types.value"
required
multiple
:close-on-select="false"
input-label="Bestandstype"
:loading="attachmentSettings.loading"
:disabled="loading || attachmentSettings.loading" />

<NcCheckboxRadioSwitch :checked.sync="attachmentSettings.automatic_publish" type="switch">
Automatisch publiceren
</NcCheckboxRadioSwitch>

<NcCheckboxRadioSwitch :checked.sync="attachmentSettings.automatic_publish_attachment" type="switch">
Bijlagen automatisch mee publiceren
</NcCheckboxRadioSwitch>

<NcButton
type="primary"
:disabled="attachmentSettings.loading"
@click="saveAttachmentConfig()">
<template #icon>
<NcLoadingIcon v-if="loading || attachmentSettings.loading" :size="20" />
<Plus v-if="!loading && !attachmentSettings.loading" :size="20" />
</template>
Opslaan
</NcButton>
</div>
</NcSettingsSection>
<NcSettingsSection :name="'Data storage'" description="Korte uitleg over dat je kan opslaan in de nextcloud database of open registers en via open registers ook in externe opslag zo al mongo db">
<div v-if="!loading">
<div v-if="!openRegisterInstalled">
Expand Down Expand Up @@ -301,7 +333,7 @@

<script>
// Components
import { NcSettingsSection, NcNoteCard, NcSelect, NcButton, NcLoadingIcon } from '@nextcloud/vue'
import { NcSettingsSection, NcNoteCard, NcSelect, NcButton, NcCheckboxRadioSwitch, NcLoadingIcon } from '@nextcloud/vue'
import Plus from 'vue-material-design-icons/Plus.vue'
import Restart from 'vue-material-design-icons/Restart.vue'

Expand All @@ -312,6 +344,7 @@ export default {
NcNoteCard,
NcSelect,
NcButton,
NcCheckboxRadioSwitch,
NcLoadingIcon,
Plus,
Restart,
Expand Down Expand Up @@ -381,10 +414,46 @@ export default {
{ label: 'OpenRegister', value: 'openregister' },
],
},
attachmentSettings: {
automatic_publish_attachment: false,
automatic_publish: false,
file_types: {
options: [
{ label: 'PNG', value: 'png' },
{ label: 'JPG', value: 'jpg' },
{ label: 'PDF', value: 'pdf' },
{ label: 'DOCX', value: 'docx' },
{ label: 'XLSX', value: 'xlsx' },
{ label: 'TXT', value: 'txt' },
{ label: 'CSV', value: 'csv' },
{ label: 'ZIP', value: 'zip' },
{ label: 'RAR', value: 'rar' },
],
value: null,
},
loading: false,
},
}
},
computed: {
filteredAvailableSchemas() {
console.log('filteredAvailableSchemas')

const usedSchemas = this.objectTypes.map((objectType) => this[objectType].selectedSchema?.value)

console.log(this.objectTypes)
console.log(usedSchemas)

return this.availableSchemas?.filter((schema) => !usedSchemas.includes(schema.id.toString())) ?? []
},
},
watch: {
filteredAvailableSchemas: {
handler(newValue) {
console.log(newValue)
},
deep: true,
},
'publication.selectedSource': {
handler(newValue) {
if (newValue?.value === 'internal') {
Expand Down Expand Up @@ -559,6 +628,12 @@ export default {
.then((response) => {
this.initialization = true
response.json().then((data) => {
// Attachment Settings
this.attachmentSettings.automatic_publish = (typeof data?.automatic_publish === 'boolean') ? data.automatic_publish : false
this.attachmentSettings.automatic_publish_attachment = (typeof data?.automatic_publish_attachment === 'boolean') ? data.automatic_publish_attachment : false
this.attachmentSettings.file_types.value = this.attachmentSettings.file_types.options.filter((type) => data?.file_types?.includes(type.id))

// Other settings
this.openRegisterInstalled = data.openRegisters
this.settingsData = data
this.availableRegisters = data.availableRegisters
Expand Down Expand Up @@ -641,6 +716,49 @@ export default {
return err
})
},
saveAttachmentConfig() {
this.attachmentSettings.loading = true
console.info('Saving attachment 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,
file_types: this.attachmentSettings.file_types.value?.map((type) => type.value) || [],
automatic_publish_attachment: this.attachmentSettings.automatic_publish_attachment,
automatic_publish: this.attachmentSettings.automatic_publish,
}),
headers: {
'Content-Type': 'application/json',
},
},
)
.then((response) => {
response.json().then((data) => {
this.settingsData = {
...this.settingsData,
file_types: this.attachmentSettings.file_types.options.filter((type) => data.file_types.includes(type.id)),
automatic_publish_attachment: data.automatic_publish_attachment,
automatic_publish: data.automatic_publish,
}

})
})
.catch((err) => {
console.error(err)
return err
})
.finally(() => {
this.attachmentSettings.loading = false
})
},

saveAll() {
this.saving = true
Expand Down