Skip to content

Commit

Permalink
Merge pull request #22 from ConductionNL/feature/CONNECTOR-63/mapping…
Browse files Browse the repository at this point in the history
…-cast

added cast to mapping
  • Loading branch information
remko48 authored Oct 7, 2024
2 parents 8b004de + 01f58d1 commit 5355c23
Show file tree
Hide file tree
Showing 6 changed files with 372 additions and 26 deletions.
48 changes: 27 additions & 21 deletions src/modals/Modals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<EditMapping />
<EditMappingMapping />
<DeleteMappingMapping />
<EditMappingCast />
<DeleteMappingCast />
<DeleteSynchronization />
<EditSynchronization />
<EditJobArgument />
Expand Down Expand Up @@ -43,34 +45,38 @@ import DeleteSourceConfiguration from './SourceConfiguration/DeleteSourceConfigu
import ViewLog from './Log/ViewLog.vue'
import EditMappingMapping from './mappingMapping/EditMappingMapping.vue'
import DeleteMappingMapping from './mappingMapping/DeleteMappingMapping.vue'
import EditMappingCast from './mappingCast/EditMappingCast.vue'
import DeleteMappingCast from './mappingCast/DeleteMappingCast.vue'
export default {
name: 'Modals',
components: {
DeleteSource,
EditSource,
TestSource,
DeleteJob,
EditJob,
TestJob,
DeleteLog,
EditLog,
DeleteMapping,
EditMapping,
DeleteSynchronization,
EditSynchronization,
EditJobArgument,
DeleteJobArgument,
EditSourceConfiguration,
DeleteSourceConfiguration,
ViewLog,
EditMappingMapping,
DeleteMappingMapping,
DeleteSource,
EditSource,
TestSource,
DeleteJob,
EditJob,
TestJob,
DeleteLog,
EditLog,
DeleteMapping,
EditMapping,
DeleteSynchronization,
EditSynchronization,
EditJobArgument,
DeleteJobArgument,
EditSourceConfiguration,
DeleteSourceConfiguration,
ViewLog,
EditMappingMapping,
DeleteMappingMapping,
EditMappingCast,
DeleteMappingCast,
},
setup() {
return {
return {
navigationStore,
}
}
},
}
</script>
118 changes: 118 additions & 0 deletions src/modals/mappingCast/DeleteMappingCast.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<script setup>
import { navigationStore, mappingStore } from '../../store/store.js'
</script>

<template>
<NcDialog
v-if="navigationStore.modal === 'deleteMappingCast'"
name="Delete Cast"
:can-close="false">
<div v-if="success !== null || error">
<NcNoteCard v-if="success" type="success">
<p>Successfully deleted cast</p>
</NcNoteCard>
<NcNoteCard v-if="!success" type="error">
<p>Something went wrong deleting the cast</p>
</NcNoteCard>
<NcNoteCard v-if="error" type="error">
<p>{{ error }}</p>
</NcNoteCard>
</div>
<p v-if="success === null">
Do you want to delete <b>{{ mappingStore.mappingCastKey }}</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="deleteMappingCast()">
<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: 'DeleteMappingCast',
components: {
NcDialog,
NcButton,
NcNoteCard,
NcLoadingIcon,
// Icons
Cancel,
Delete,
},
data() {
return {
loading: false,
success: null,
error: false,
}
},
methods: {
deleteMappingCast() {
this.loading = true
const mappingClone = { ...mappingStore.mappingItem }
delete mappingClone?.cast[mappingStore.mappingCastKey]
const mappingItem = {
...mappingStore.mappingItem,
}
mappingStore.saveMapping(mappingItem)
.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/mappingCast/EditMappingCast.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<script setup>
import { mappingStore, navigationStore } from '../../store/store.js'
</script>

<template>
<NcModal v-if="navigationStore.modal === 'editMappingCast'"
ref="modalRef"
label-id="editMappingCast"
@close="closeModal">
<div class="modalContent">
<h2>{{ isEdit ? 'Edit' : 'Add' }} Cast</h2>
<NcNoteCard v-if="success" type="success">
<p>Cast 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(castItem.key)"
:helper-text="checkIfKeyIsUnique(castItem.key) ? 'This key is already in use. Please choose a different key name.' : ''"
:value.sync="castItem.key" />
<NcTextField
id="value"
label="Value"
:value.sync="castItem.value" />
</div>
</form>

<NcButton
v-if="!success"
:disabled="loading || !castItem.key || checkIfKeyIsUnique(castItem.key)"
type="primary"
@click="editMapping()">
<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: 'EditMappingCast',
components: {
NcModal,
NcButton,
NcLoadingIcon,
NcNoteCard,
NcTextField,
// Icons
ContentSaveOutline,
},
data() {
return {
castItem: {
key: '',
value: '',
},
success: false,
loading: false,
error: false,
hasUpdated: false,
oldKey: '',
isEdit: false,
}
},
mounted() {
this.initializeMappingCast()
},
updated() {
if (navigationStore.modal === 'editMappingCast' && !this.hasUpdated) {
this.initializeMappingCast()
this.hasUpdated = true
}
},
methods: {
initializeMappingCast() {
if (!mappingStore.mappingCastKey) {
return
}
const castItem = Object.entries(mappingStore.mappingItem.cast).find(([key]) => key === mappingStore.mappingCastKey)
if (castItem) {
this.castItem = {
key: castItem[0] || '',
value: castItem[1] || '',
}
this.oldKey = castItem[0]
this.isEdit = true
}
},
checkIfKeyIsUnique(key) {
if (!mappingStore.mappingItem.cast) return false
const keys = Object.keys(mappingStore.mappingItem.cast)
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.castItem = {
key: '',
value: '',
}
},
async editMapping() {
this.loading = true
const newMappingItem = {
...mappingStore.mappingItem,
cast: {
...mappingStore.mappingItem.cast,
[this.castItem.key]: this.castItem.value,
},
}
if (this.oldKey !== '' && this.oldKey !== this.castItem.key) {
delete newMappingItem.cast[this.oldKey]
}
try {
await mappingStore.saveMapping(newMappingItem)
// 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 mapping'
}
},
},
}
</script>
5 changes: 5 additions & 0 deletions src/store/modules/mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const useMappingStore = defineStore(
mappingItem: false,
mappingList: [],
mappingMappingKey: null,
mappingCastKey: null,
}),
actions: {
setMappingItem(mappingItem) {
Expand All @@ -24,6 +25,10 @@ export const useMappingStore = defineStore(
this.mappingMappingKey = mappingMappingKey
console.log('Active mapping mapping key set to ' + mappingMappingKey)
},
setMappingCastKey(mappingCastKey) {
this.mappingCastKey = mappingCastKey
console.log('Active mapping cast key set to ' + mappingCastKey)
},
/* istanbul ignore next */ // ignore this for Jest until moved into a service
async refreshMappingList(search = null) {
// @todo this might belong in a service?
Expand Down
Loading

0 comments on commit 5355c23

Please sign in to comment.