mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
visgraph: build modal form to create/edit relationship
This commit is contained in:
parent
bd2ee9ddc1
commit
024531fbe1
@ -79,7 +79,7 @@ class Relation
|
||||
public function setIsActive(?bool $isActive): self
|
||||
{
|
||||
$this->isActive = $isActive;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
<teleport to="#visgraph-legend">
|
||||
<div class="my-4 post-menu legend">
|
||||
<h3>{{ $t('visgraph.Legend')}}</h3>
|
||||
<h3>{{ $t('visgraph.Legend') }}</h3>
|
||||
<div class="list-group">
|
||||
<label class="list-group-item" v-for="layer in legendLayers">
|
||||
<input
|
||||
@ -24,39 +24,79 @@
|
||||
<modal v-if="modal.showModal" :modalDialogClass="modal.modalDialogClass" @close="modal.showModal = false">
|
||||
<template v-slot:header>
|
||||
<h2 class="modal-title">{{ $t(modal.title) }}</h2>
|
||||
<!-- {{ modal.data.id }} -->
|
||||
</template>
|
||||
<template v-slot:body>
|
||||
<div v-if="modal.action === 'delete'">
|
||||
<p>
|
||||
{{ $t('visgraph.delete_confirmation_text') }}
|
||||
</p>
|
||||
<p>{{ $t('visgraph.delete_confirmation_text') }}</p>
|
||||
</div>
|
||||
<div v-else>
|
||||
<form>
|
||||
{{ modal.data.id }}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
{{ modal.data.from }}
|
||||
<h4>
|
||||
{{ getPerson(modal.data.from).text }}
|
||||
</h4>
|
||||
</div>
|
||||
<div class="col text-end">
|
||||
{{ modal.data.to }}
|
||||
<h4>
|
||||
{{ getPerson(modal.data.to).text }}
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div><!--
|
||||
<div class="my-3"><!--
|
||||
:value="relation"
|
||||
-->
|
||||
<VueMultiselect
|
||||
id="relationshipLink"
|
||||
id="relation"
|
||||
label="title"
|
||||
track-by="id"
|
||||
:custom-label="customLabel"
|
||||
:placeholder="$t('Choisissez le lien de parenté')"
|
||||
:options="relationLinks"
|
||||
v-model="relationshipLink"
|
||||
:close-on-select="true"
|
||||
:multiple="false"
|
||||
:searchable="true"
|
||||
:options="relations"
|
||||
v-model="relation"
|
||||
>
|
||||
</VueMultiselect>
|
||||
-->
|
||||
</div>
|
||||
<p>
|
||||
phrase
|
||||
</p>
|
||||
<div>
|
||||
toggle reverse
|
||||
<div v-if="relation && relation.title && relation.reverseTitle">
|
||||
<p class="text-center" v-if="reverse">
|
||||
{{ $t('visgraph.relation_from_to_like', [
|
||||
getPerson(modal.data.to).text,
|
||||
getPerson(modal.data.from).text,
|
||||
relation.title.fr.toLowerCase(),
|
||||
])}}
|
||||
<br>
|
||||
{{ $t('visgraph.relation_from_to_like', [
|
||||
getPerson(modal.data.from).text,
|
||||
getPerson(modal.data.to).text,
|
||||
relation.reverseTitle.fr.toLowerCase(),
|
||||
])}}
|
||||
</p>
|
||||
<p class="text-center" v-else>
|
||||
{{ $t('visgraph.relation_from_to_like', [
|
||||
getPerson(modal.data.from).text,
|
||||
getPerson(modal.data.to).text,
|
||||
relation.title.fr.toLowerCase(),
|
||||
])}}
|
||||
<br>
|
||||
{{ $t('visgraph.relation_from_to_like', [
|
||||
getPerson(modal.data.to).text,
|
||||
getPerson(modal.data.from).text,
|
||||
relation.reverseTitle.fr.toLowerCase(),
|
||||
])}}
|
||||
</p>
|
||||
</div>
|
||||
<div class="form-check form-switch">
|
||||
<input
|
||||
class="form-check-input"
|
||||
type="checkbox"
|
||||
id="reverse"
|
||||
v-model="reverse"
|
||||
>
|
||||
<label class="form-check-label" for="reverse">{{ $t('visgraph.reverse_relation') }}</label>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@ -75,6 +115,7 @@ import vis from 'vis-network/dist/vis-network'
|
||||
import { mapState, mapGetters } from "vuex"
|
||||
import Modal from 'ChillMainAssets/vuejs/_components/Modal'
|
||||
import VueMultiselect from 'vue-multiselect'
|
||||
import { getRelationsList } from "./api";
|
||||
|
||||
export default {
|
||||
name: "App",
|
||||
@ -86,9 +127,12 @@ export default {
|
||||
return {
|
||||
container: '',
|
||||
checkedLayers: [],
|
||||
relations: [],
|
||||
relation: null,
|
||||
reverse: false,
|
||||
modal: {
|
||||
showModal: false,
|
||||
modalDialogClass: "modal-dialog-scrollable modal-md",
|
||||
modalDialogClass: "modal-md",
|
||||
title: null,
|
||||
action: null,
|
||||
data: {},
|
||||
@ -101,9 +145,9 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['nodes', 'edges']),
|
||||
...mapState(['households', 'courses', 'excludedNodesIds',
|
||||
...mapState(['households', 'courses', 'excludedNodesIds', 'persons',
|
||||
// not used
|
||||
'persons', 'links', 'relationships', 'personLoadedIds', 'householdLoadingIds', 'courseLoadedIds', 'relationshipLoadedIds',
|
||||
'links', 'relationships', 'personLoadedIds', 'householdLoadingIds', 'courseLoadedIds', 'relationshipLoadedIds',
|
||||
]),
|
||||
|
||||
visgraph_data() {
|
||||
@ -141,7 +185,28 @@ export default {
|
||||
|
||||
checkedLayers() { // required to refresh data checkedLayers
|
||||
return this.checkedLayers
|
||||
}
|
||||
},
|
||||
|
||||
relation: {
|
||||
get() {
|
||||
return this.relation
|
||||
},
|
||||
set(value) {
|
||||
console.log('setter relation', value) // <=== InternalError: too much recursion
|
||||
this.relation = value
|
||||
}
|
||||
},
|
||||
|
||||
reverse: {
|
||||
get() {
|
||||
return this.reverse
|
||||
},
|
||||
set(value) {
|
||||
console.log('setter reverse', value) // <=== InternalError: too much recursion
|
||||
this.reverse = value
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
},
|
||||
created() {
|
||||
@ -157,6 +222,7 @@ export default {
|
||||
mounted() {
|
||||
console.log('=== mounted: init graph')
|
||||
this.initGraph()
|
||||
this.getRelationsList()
|
||||
},
|
||||
methods: {
|
||||
initGraph() {
|
||||
@ -191,8 +257,8 @@ export default {
|
||||
},
|
||||
|
||||
addRelationshipModal(edgeData) {
|
||||
console.log('==> addRelationshipModal <=======================', edgeData)
|
||||
this.modal.data = edgeData
|
||||
console.log('==- addRelationshipModal', edgeData)
|
||||
this.modal.action = 'create'
|
||||
this.modal.title = 'visgraph.add_relationship_link'
|
||||
this.modal.button.class = 'btn-create'
|
||||
@ -200,8 +266,8 @@ export default {
|
||||
this.modal.showModal = true
|
||||
},
|
||||
editRelationshipModal(edgeData) {
|
||||
console.log('==> editRelationshipModal <=======================', edgeData)
|
||||
this.modal.data = edgeData
|
||||
console.log('==- editRelationshipModal', edgeData)
|
||||
this.modal.action = 'edit'
|
||||
this.modal.title = 'visgraph.edit_relationship_link'
|
||||
this.modal.button.class = 'btn-edit'
|
||||
@ -209,8 +275,8 @@ export default {
|
||||
this.modal.showModal = true
|
||||
},
|
||||
deleteRelationshipModal(edgeData) {
|
||||
console.log('==> deleteRelationshipModal <=======================', edgeData)
|
||||
this.modal.data = edgeData
|
||||
console.log('==- deleteRelationshipModal', edgeData)
|
||||
this.modal.action = 'delete'
|
||||
this.modal.title = 'visgraph.delete_relationship_link'
|
||||
this.modal.button.class = 'btn-delete'
|
||||
@ -218,31 +284,29 @@ export default {
|
||||
this.modal.showModal = true
|
||||
},
|
||||
|
||||
relationLinks() {
|
||||
console.log('fetch relationLinks')
|
||||
return getRelations().then(relationsList => new Promise(resolve => {
|
||||
console.log('relationsList', relationsList)
|
||||
getRelationsList() {
|
||||
console.log('fetch relationsList')
|
||||
return getRelationsList().then(relations => new Promise(resolve => {
|
||||
console.log('+ relations list', relations.results.filter(r => r.isActive === true))
|
||||
this.relations = relations.results
|
||||
resolve()
|
||||
})).catch()
|
||||
},
|
||||
customLabel(value) {
|
||||
console.log('customLabel', value)
|
||||
return (value.title && value.reverseTitle) ? `${value.title.fr} ↔ ${value.reverseTitle.fr}` : ''
|
||||
},
|
||||
getPerson(idtext) {
|
||||
let person = this.persons.filter(p => p.id === idtext)
|
||||
return person[0]
|
||||
}
|
||||
}
|
||||
/*
|
||||
TODO / TO CHECK / TO UNDERSTAND
|
||||
|
||||
///// A
|
||||
new vis.Network(), param 2: why we don't need to instanciate node and edges with new vis.DataSet like in example ?
|
||||
{
|
||||
nodes: new vis.DataSet(this.nodes),
|
||||
edges: new vis.DataSet(this.relationships)
|
||||
}
|
||||
///// B
|
||||
refreshNetwork() computed: need to watch/listen event to force refreshing ?
|
||||
|
||||
*/
|
||||
}
|
||||
</script>
|
||||
|
||||
<style src="vis-network/dist/dist/vis-network.min.css"></style>
|
||||
<style src="vue-multiselect/dist/vue-multiselect.css"></style>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
div#visgraph {
|
||||
margin: 2em auto;
|
||||
|
@ -15,6 +15,8 @@ const visMessages = {
|
||||
edit_relationship_link: "Modifier le lien de filiation",
|
||||
delete_relationship_link: "Êtes-vous sûr ?",
|
||||
delete_confirmation_text: "Vous allez supprimer le lien entre ces 2 usagers.",
|
||||
reverse_relation: "Inverser la relation",
|
||||
relation_from_to_like: "{0} est {2} de {1}",
|
||||
},
|
||||
edit: 'Éditer',
|
||||
del: 'Supprimer',
|
||||
|
@ -152,7 +152,7 @@ const store = createStore({
|
||||
.then(household => new Promise(resolve => {
|
||||
//console.log('getHouseholdByPerson', household)
|
||||
commit('addHousehold', adapt2vis(household))
|
||||
commit('addExcludedNode', household.id)
|
||||
//commit('addExcludedNode', household.id)
|
||||
dispatch('addLinkFromPersonsToHousehold', household)
|
||||
resolve()
|
||||
})
|
||||
@ -290,7 +290,7 @@ const store = createStore({
|
||||
commit('addLink', {
|
||||
from: `person_${r.fromPerson.id}`,
|
||||
to: `person_${r.toPerson.id}`,
|
||||
id: 'r' + r.id + '_p' + r.fromPerson.id + '_p' + r.toPerson.id,
|
||||
id: 'r' + splitId(r.id,'id') + '_p' + r.fromPerson.id + '_p' + r.toPerson.id,
|
||||
arrows: 'to',
|
||||
color: 'lightblue',
|
||||
font: { color: '#33839d' },
|
||||
@ -315,7 +315,7 @@ const store = createStore({
|
||||
commit('markPersonLoaded', person.id)
|
||||
commit('addPerson', adapt2vis(person, { folded: true }))
|
||||
|
||||
console.log('********* fetch infos for missing', person.id, '******')
|
||||
console.log(' fetch infos for missing', person.id)
|
||||
//dispatch('fetchInfoForPerson', person)
|
||||
},
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user