|
@@ -29,6 +29,9 @@ import ContentEditable from '@components/editable/ContentEditable.vue';
|
|
|
import CheckboxEditable from '@components/editable/CheckboxEditable.vue';
|
|
|
import SelectEditable from '@components/editable/SelectEditable.vue';
|
|
|
|
|
|
+// import vueAutocomplete from "@venegrad/vue3-autocomplete"
|
|
|
+import VueSimpleSuggest from '@vojtechlanka/vue-simple-suggest';
|
|
|
+
|
|
|
export default {
|
|
|
props: ['cid', 'eid'],
|
|
|
data(){
|
|
@@ -44,7 +47,10 @@ export default {
|
|
|
chevrondown_path: mdiChevronDown,
|
|
|
headerreduced: false,
|
|
|
mdiStickerPlusOutline_path: mdiStickerPlusOutline,
|
|
|
- reloading_concernements: false
|
|
|
+ reloading_concernements: false,
|
|
|
+ prox_default_values: [],
|
|
|
+ prox_new_value: {},
|
|
|
+ prox_suggestions: []
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
@@ -54,9 +60,13 @@ export default {
|
|
|
'ct_concernement',
|
|
|
'ct_entite',
|
|
|
'detailsZoomValue',
|
|
|
+ 'allEntitesById'
|
|
|
// 'concernements_are_loading'
|
|
|
]),
|
|
|
- ...mapState(UserStore,['name','csrf_token']),
|
|
|
+ ...mapState(UserStore,['name',
|
|
|
+ 'csrf_token',
|
|
|
+ 'isloggedin',
|
|
|
+ 'user_entites']),
|
|
|
created(){
|
|
|
let d = new Date(this.concernement.created);
|
|
|
console.log('d', d);
|
|
@@ -184,6 +194,15 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
deep: true
|
|
|
+ },
|
|
|
+ user_entites: {
|
|
|
+ handler (n, o) {
|
|
|
+ console.log('TerrainDeVie watch user_entites');
|
|
|
+ if (n) {
|
|
|
+ this.checkForUserProxmite();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deep: true
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
@@ -191,8 +210,9 @@ export default {
|
|
|
'setDetailsZoomValue',
|
|
|
'loadConcernements',
|
|
|
'reloadConcernements',
|
|
|
- 'reloadConcernementEntites']),
|
|
|
- // 'loadConcernementsRevisions'
|
|
|
+ 'reloadConcernementEntites',
|
|
|
+ 'reloadProximites'
|
|
|
+ ]),
|
|
|
onClickInfos(){
|
|
|
this.infos_opened = !this.infos_opened;
|
|
|
},
|
|
@@ -208,7 +228,9 @@ export default {
|
|
|
GQL.post('', { query: print(ast) })
|
|
|
.then(({data: { data: { entite }}}) => {
|
|
|
console.log('load entite loaded', entite)
|
|
|
- this.entite = entite
|
|
|
+ this.entite = entite;
|
|
|
+ // this.setProxSuggestions()
|
|
|
+ this.checkForUserProxmite();
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.warn('Issue with load entite', error)
|
|
@@ -341,16 +363,124 @@ export default {
|
|
|
|
|
|
REST.patch(`/node/${this.cid}?_format=json`, params_node, configs)
|
|
|
.then(({ data }) => {
|
|
|
- console.log('REST patch entite new field_sources', data)
|
|
|
+ console.log('REST patch entite new field_entite', data)
|
|
|
resolve(data)
|
|
|
})
|
|
|
.catch(error => {
|
|
|
- console.warn(`Issue with patch node entite field_sources`, error)
|
|
|
+ console.warn(`Issue with patch node entite field_entite`, error)
|
|
|
reject(error)
|
|
|
})
|
|
|
// resolve('test')
|
|
|
})
|
|
|
- }
|
|
|
+ },
|
|
|
+ // setProxSuggestions(){
|
|
|
+ // this.prox_suggestions = [];
|
|
|
+ // // check that entite is well referenced in a loaded concernement
|
|
|
+ // this.user_entites.forEach((entite) => {
|
|
|
+ // if (this.allEntitesById[entite.id]) {
|
|
|
+ // // check if not already proximited
|
|
|
+ // let tobesuggested = true;
|
|
|
+ // this.prox_default_values.forEach((default_entite) => {
|
|
|
+ // if (default_entite.id === entite.id) {
|
|
|
+ // tobesuggested = false;
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // if (tobesuggested) {
|
|
|
+ // this.prox_suggestions.push(entite)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // console.log('this.prox_suggestions', this.prox_suggestions);
|
|
|
+ // // this.checkForUserProxmite();
|
|
|
+ // },
|
|
|
+ checkForUserProxmite(){
|
|
|
+ if (this.entite && this.isloggedin && !this.entite.can_update ) {
|
|
|
+ console.log('checkForUserProxmite', this.entite);
|
|
|
+ // this.prox_suggestions.forEach((user_entite) => {
|
|
|
+ this.prox_default_values = [];
|
|
|
+ this.prox_suggestions = [];
|
|
|
+ this.user_entites.forEach((user_entite) => {
|
|
|
+ console.log('user_entite', user_entite);
|
|
|
+ console.log('entite', this.allEntitesById[user_entite.id]);
|
|
|
+ if (this.allEntitesById[user_entite.id]) {
|
|
|
+ let tobesuggested = true
|
|
|
+ this.allEntitesById[user_entite.id].entite.proximite.forEach((prox_field_entite) => {
|
|
|
+ if(prox_field_entite.id === this.entite.id) {
|
|
|
+ this.prox_default_values.push(user_entite);
|
|
|
+ tobesuggested = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (tobesuggested) {
|
|
|
+ this.prox_suggestions.push(user_entite)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ console.log('this.prox_default_values', this.prox_default_values);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onProximiteSelected(src_entite){
|
|
|
+ console.log('onProximiteSelected', src_entite);
|
|
|
+ if (src_entite) {
|
|
|
+ this.proxvaluetitle = src_entite.title;
|
|
|
+ // get all the field_proximite values, we don't want to ersae everything
|
|
|
+ let proximites = [];
|
|
|
+ this.allEntitesById[src_entite.id].entite.proximite.forEach((target_entite) =>{
|
|
|
+ proximites.push({
|
|
|
+ target_id: target_entite.id,
|
|
|
+ })
|
|
|
+ })
|
|
|
+ // add the new field value
|
|
|
+ proximites.push({
|
|
|
+ target_id: this.entite.id,
|
|
|
+ })
|
|
|
+ console.log('proximites', proximites);
|
|
|
+
|
|
|
+ this.recordProximites(src_entite.id, proximites);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deleteProximite(src_entite){
|
|
|
+ console.log('deleteProximite', src_entite);
|
|
|
+ if (src_entite) {
|
|
|
+ // get all the field_proximite values, excpet the one we want to delete
|
|
|
+ let proximites = [];
|
|
|
+ this.allEntitesById[src_entite.id].entite.proximite.forEach((target_entite) =>{
|
|
|
+ if(target_entite.id !== this.entite.id){
|
|
|
+ proximites.push({
|
|
|
+ target_id: target_entite.id,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.recordProximites(src_entite.id, proximites);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ recordProximites(src_id, proximites){
|
|
|
+ console.log(`recordProximites proximites`, proximites);
|
|
|
+
|
|
|
+ const params_node = {
|
|
|
+ type: 'entite',
|
|
|
+ nid: [{value: src_id}],
|
|
|
+ 'field_proximite': proximites
|
|
|
+ };
|
|
|
+
|
|
|
+ const configs = {
|
|
|
+ headers: {'X-CSRF-Token': this.csrf_token}
|
|
|
+ };
|
|
|
+
|
|
|
+ REST.patch(`/node/${src_id}?_format=json`, params_node, configs)
|
|
|
+ .then(({ data }) => {
|
|
|
+ console.log('REST patch entite new field_proximite', data)
|
|
|
+ this.reloadProximites(src_id)
|
|
|
+ .then(() => {
|
|
|
+ // TODO clear the autocomplete field
|
|
|
+ this.prox_new_value = null;
|
|
|
+ })
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ console.warn(`Issue with patch node entite field_proximite`, error)
|
|
|
+ // reject(error)
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
|
|
|
},
|
|
|
components: {
|
|
@@ -360,7 +490,8 @@ export default {
|
|
|
SvgIcon,
|
|
|
ContentEditable,
|
|
|
CheckboxEditable,
|
|
|
- SelectEditable
|
|
|
+ SelectEditable,
|
|
|
+ VueSimpleSuggest
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -386,6 +517,41 @@ export default {
|
|
|
field: {field_name: 'title', value:'value'}
|
|
|
}" />
|
|
|
|
|
|
+ <!-- proximité -->
|
|
|
+ <section
|
|
|
+ v-if="entite && isloggedin && !entite.can_update"
|
|
|
+ id="new-proxomite"
|
|
|
+ class="editable-proximites"
|
|
|
+ >
|
|
|
+ <label>Mes proximités</label>
|
|
|
+ <div class="wrapper editable">
|
|
|
+ <ul v-if="prox_default_values.length">
|
|
|
+ <li v-for="(prox_entite, i) in prox_default_values" v-key="i">
|
|
|
+ <em>{{ prox_entite.title }}</em>
|
|
|
+ <span
|
|
|
+ class="delete"
|
|
|
+ @click="deleteProximite(prox_entite)"
|
|
|
+ >x</span>
|
|
|
+ </li>
|
|
|
+ </ul>
|
|
|
+ <template v-if="prox_suggestions.length" >
|
|
|
+ <span>Lier <em>{{ entite.title }}</em> a une de mes entitées</span>
|
|
|
+ <VueSimpleSuggest
|
|
|
+ mode="select"
|
|
|
+ :list="prox_suggestions"
|
|
|
+ v-model="prox_new_value"
|
|
|
+ display-attribute="title"
|
|
|
+ value-attribute="id"
|
|
|
+ filter-by-query="true"
|
|
|
+ min-length="0"
|
|
|
+ placeholder="Tappez le nom de votre entite..."
|
|
|
+ @update:model-select="onProximiteSelected"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </div>
|
|
|
+ </section>
|
|
|
+
|
|
|
+ <!-- agissante -->
|
|
|
<CheckboxEditable
|
|
|
v-if="entite && entite.can_update"
|
|
|
:checked="entite.agissante"
|
|
@@ -413,6 +579,8 @@ export default {
|
|
|
field: 'field_confidentialite'
|
|
|
}" />
|
|
|
|
|
|
+
|
|
|
+
|
|
|
</div>
|
|
|
</template>
|
|
|
|