Skip to content

Commit

Permalink
Merge pull request #13 from ConductionNL/feature/feature/CONNECTOR-39…
Browse files Browse the repository at this point in the history
…/source-configurations

feature/feature/CONNECTOR-39/source-configurations
  • Loading branch information
remko48 authored Oct 3, 2024
2 parents 94f4ee3 + a19cc60 commit 5fd3a68
Show file tree
Hide file tree
Showing 6 changed files with 368 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/modals/JobArgument/EditJobArgument.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import { jobStore, navigationStore } from '../../store/store.js'
<div class="form-group">
<NcTextField
id="key"
label="Key"
label="Key*"
required
:error="checkIfKeyIsUnique(argumentItem.key)"
:helper-text="checkIfKeyIsUnique(argumentItem.key) ? 'This key is already in use. Please choose a different key name.' : ''"
:value.sync="argumentItem.key" />
<NcTextField
id="value"
Expand All @@ -31,7 +34,7 @@ import { jobStore, navigationStore } from '../../store/store.js'

<NcButton
v-if="!success"
:disabled="loading"
:disabled="loading || !argumentItem.key || checkIfKeyIsUnique(argumentItem.key)"
type="primary"
@click="editJobArgument()">
<template #icon>
Expand Down Expand Up @@ -103,13 +106,20 @@ export default {
this.isEdit = true
}
},
checkIfKeyIsUnique(key) {
const keys = Object.keys(jobStore.jobItem.arguments)
if (this.oldKey === key) return false
if (keys.includes(key)) return true
return false
},
closeModal() {
navigationStore.setModal(false)
this.success = false
this.loading = false
this.error = false
this.hasUpdated = false
this.isEdit = false
this.oldKey = ''
this.argumentItem = {
key: '',
value: '',
Expand All @@ -129,7 +139,7 @@ export default {
},
}
if (this.oldKey !== this.argumentItem.key) {
if (this.oldKey !== '' && this.oldKey !== this.argumentItem.key) {
delete newJobItem.arguments[this.oldKey]
}
Expand All @@ -144,7 +154,7 @@ export default {
} catch (error) {
this.loading = false
this.success = false
this.error = error.message || 'An error occurred while saving the mapping'
this.error = error.message || 'An error occurred while saving the job argument'
}
},
},
Expand Down
6 changes: 6 additions & 0 deletions src/modals/Modals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<EditSynchronization />
<EditJobArgument />
<DeleteJobArgument />
<EditSourceConfiguration />
<DeleteSourceConfiguration />
</div>
</template>

Expand All @@ -33,6 +35,8 @@ import EditSynchronization from './Synchronization/EditSynchronization.vue'
import DeleteSynchronization from './Synchronization/DeleteSynchronization.vue'
import EditJobArgument from './JobArgument/EditJobArgument.vue'
import DeleteJobArgument from './JobArgument/DeleteJobArgument.vue'
import EditSourceConfiguration from './SourceConfiguration/EditSourceConfiguration.vue'
import DeleteSourceConfiguration from './SourceConfiguration/DeleteSourceConfiguration.vue'
export default {
name: 'Modals',
Expand All @@ -51,6 +55,8 @@ export default {
EditSynchronization,
EditJobArgument,
DeleteJobArgument,
EditSourceConfiguration,
DeleteSourceConfiguration,
},
setup() {
return {
Expand Down
118 changes: 118 additions & 0 deletions src/modals/SourceConfiguration/DeleteSourceConfiguration.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<script setup>
import { navigationStore, sourceStore } from '../../store/store.js'
</script>

<template>
<NcDialog
v-if="navigationStore.modal === 'deleteSourceConfiguration'"
name="Delete Source Configuration"
:can-close="false">
<div v-if="success !== null || error">
<NcNoteCard v-if="success" type="success">
<p>Successfully deleted source configuration</p>
</NcNoteCard>
<NcNoteCard v-if="!success" type="error">
<p>Something went wrong deleting the source configuration</p>
</NcNoteCard>
<NcNoteCard v-if="error" type="error">
<p>{{ error }}</p>
</NcNoteCard>
</div>
<p v-if="success === null">
Do you want to delete <b>{{ sourceStore.sourceConfigurationKey }}</b>? This action cannot be undone.
</p>
<template #actions>
<NcButton :disabled="loading" icon="" @click="navigationStore.setModal(false)">
<template #icon>
<Cancel :size="20" />
</template>
{{ success !== null ? 'Close' : 'Cancel' }}
</NcButton>
<NcButton
v-if="success === null"
:disabled="loading"
icon="Delete"
type="error"
@click="deleteSourceConfiguration()">
<template #icon>
<NcLoadingIcon v-if="loading" :size="20" />
<Delete v-if="!loading" :size="20" />
</template>
Delete
</NcButton>
</template>
</NcDialog>
</template>

<script>
import { NcButton, NcDialog, NcNoteCard, NcLoadingIcon } from '@nextcloud/vue'
import Cancel from 'vue-material-design-icons/Cancel.vue'
import Delete from 'vue-material-design-icons/Delete.vue'
export default {
name: 'DeleteSourceConfiguration',
components: {
NcDialog,
NcButton,
NcNoteCard,
NcLoadingIcon,
// Icons
Cancel,
Delete,
},
data() {
return {
loading: false,
success: null,
error: false,
}
},
methods: {
deleteSourceConfiguration() {
this.loading = true
const sourceItemClone = { ...sourceStore.sourceItem }
delete sourceItemClone?.configuration[sourceStore.sourceConfigurationKey]
const sourceItem = {
...sourceStore.sourceItem,
}
sourceStore.saveSource(sourceItem)
.then(() => {
this.loading = false
this.success = true
// Wait for the user to read the feedback then close the model
const self = this
setTimeout(function() {
self.success = null
navigationStore.setModal(false)
}, 2000)
})
.catch((err) => {
this.error = err
this.loading = false
})
},
},
}
</script>
<style>
.modal__content {
margin: var(--OC-margin-50);
text-align: center;
}
.zaakDetailsContainer {
margin-block-start: var(--OC-margin-20);
margin-inline-start: var(--OC-margin-20);
margin-inline-end: var(--OC-margin-20);
}
.success {
color: green;
}
</style>
160 changes: 160 additions & 0 deletions src/modals/SourceConfiguration/EditSourceConfiguration.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<script setup>
import { sourceStore, navigationStore } from '../../store/store.js'
</script>

<template>
<NcModal v-if="navigationStore.modal === 'editSourceConfiguration'"
ref="modalRef"
label-id="editSourceConfiguration"
@close="closeModal">
<div class="modalContent">
<h2>{{ isEdit ? 'Edit' : 'Add' }} Configuration</h2>
<NcNoteCard v-if="success" type="success">
<p>Configuration successfully added</p>
</NcNoteCard>
<NcNoteCard v-if="error" type="error">
<p>{{ error }}</p>
</NcNoteCard>

<form v-if="!success" @submit.prevent="handleSubmit">
<div class="form-group">
<NcTextField
id="key"
label="Key*"
required
:error="checkIfKeyIsUnique(configurationItem.key)"
:helper-text="checkIfKeyIsUnique(configurationItem.key) ? 'This key is already in use. Please choose a different key name.' : ''"
:value.sync="configurationItem.key" />
<NcTextField
id="value"
label="Value"
:value.sync="configurationItem.value" />
</div>
</form>

<NcButton
v-if="!success"
:disabled="loading || !configurationItem.key || checkIfKeyIsUnique(configurationItem.key)"
type="primary"
@click="editSourceConfiguration()">
<template #icon>
<NcLoadingIcon v-if="loading" :size="20" />
<ContentSaveOutline v-if="!loading" :size="20" />
</template>
Save
</NcButton>
</div>
</NcModal>
</template>

<script>
import {
NcButton,
NcModal,
NcLoadingIcon,
NcNoteCard,
NcTextField,
} from '@nextcloud/vue'
import ContentSaveOutline from 'vue-material-design-icons/ContentSaveOutline.vue'
export default {
name: 'EditSourceConfiguration',
components: {
NcModal,
NcButton,
NcLoadingIcon,
NcNoteCard,
NcTextField,
// Icons
ContentSaveOutline,
},
data() {
return {
configurationItem: {
key: '',
value: '',
},
success: false,
loading: false,
error: false,
hasUpdated: false,
oldKey: '',
isEdit: false,
}
},
mounted() {
this.initializeSourceConfiguration()
},
updated() {
if (navigationStore.modal === 'editSourceConfiguration' && !this.hasUpdated) {
this.initializeSourceConfiguration()
this.hasUpdated = true
}
},
methods: {
initializeSourceConfiguration() {
if (!sourceStore.sourceConfigurationKey) {
return
}
const configurationItem = Object.entries(sourceStore.sourceItem.configuration).find(([key]) => key === sourceStore.sourceConfigurationKey)
if (configurationItem) {
this.configurationItem = {
key: configurationItem[0] || '',
value: configurationItem[1] || '',
}
this.oldKey = configurationItem[0]
this.isEdit = true
}
},
checkIfKeyIsUnique(key) {
if (!sourceStore.sourceItem.configuration) return false
const keys = Object.keys(sourceStore.sourceItem.configuration)
if (this.oldKey === key) return false
if (keys.includes(key)) return true
return false
},
closeModal() {
navigationStore.setModal(false)
this.success = false
this.loading = false
this.error = false
this.hasUpdated = false
this.isEdit = false
this.oldKey = ''
this.configurationItem = {
key: '',
value: '',
}
},
async editSourceConfiguration() {
this.loading = true
const newSourceItem = {
...sourceStore.sourceItem,
configuration: {
...sourceStore.sourceItem.configuration,
[this.configurationItem.key]: this.configurationItem.value,
},
}
if (this.oldKey !== '' && this.oldKey !== this.configurationItem.key) {
delete newSourceItem.configuration[this.oldKey]
}
try {
await sourceStore.saveSource(newSourceItem)
// Close modal or show success message
this.success = true
this.loading = false
setTimeout(() => {
this.closeModal()
}, 2000)
} catch (error) {
this.loading = false
this.success = false
this.error = error.message || 'An error occurred while saving the source configuration'
}
},
},
}
</script>
5 changes: 5 additions & 0 deletions src/store/modules/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const useSourceStore = defineStore(
sourceList: [],
sourceLog: false,
sourceLogs: [],
sourceConfigurationKey: null,
}),
actions: {
setSourceItem(sourceItem) {
Expand All @@ -34,6 +35,10 @@ export const useSourceStore = defineStore(
this.sourceLogs = sourceLogs
console.log('Source logs set to ' + sourceLogs.length + ' items')
},
setSourceConfigurationKey(sourceConfigurationKey) {
this.sourceConfigurationKey = sourceConfigurationKey
console.log('Source configuration key set to ' + sourceConfigurationKey)
},
/* istanbul ignore next */ // ignore this for Jest until moved into a service
async refreshSourceList(search = null) {
// @todo this might belong in a service?
Expand Down
Loading

0 comments on commit 5fd3a68

Please sign in to comment.