more editable fields, created CheckboxEditable

This commit is contained in:
Bachir Soussi Chiadmi 2024-03-18 21:19:44 +01:00
parent 8c90f54b3c
commit d4797e75dc
7 changed files with 141 additions and 40 deletions

View File

@ -1,7 +1,9 @@
fragment EntiteFields on Entite { fragment EntiteFields on Entite {
id
action action
menacemaintien menacemaintien
title title
can_update
image { image {
alt alt
url url

View File

@ -1042,24 +1042,17 @@ body{
} }
} }
button.edit-btn, .editable{
button.save-btn{ background: #eee;
background-color: #444; border: #eee 2px solid;
color: #fff; border-radius: 5px;
border: none; padding: 0.3em!important;
border-radius: 6px; margin-bottom: 1em;
$size: 25px; font-size: 0.756em;
width: $size; height:$size; &>*{
display: inline-block!important;
display: inline; padding: 0!important;
cursor: pointer;
>svg{
width:100%;
height:100%;
}
transition: all 0.2s ease-in-out;
&:hover{
cursor:pointer;
opacity: 0.7;
} }
} }

View File

@ -3,6 +3,8 @@
import { mapActions, mapState } from 'pinia' import { mapActions, mapState } from 'pinia'
import { ConcernementsStore } from '@stores/concernements' import { ConcernementsStore } from '@stores/concernements'
import ContentEditable from '@components/editable/ContentEditable.vue';
import CheckboxEditable from '@components/editable/CheckboxEditable.vue';
export default { export default {
props: ['concernement', 'entite', 'eid'], props: ['concernement', 'entite', 'eid'],
data() { data() {
@ -36,25 +38,63 @@ export default {
}, },
components: { components: {
ContentEditable,
CheckboxEditable
} }
} }
</script> </script>
<template> <template>
<section class="entite"> <section class="entite">
<!-- <section v-if="entite.can_update" class="editable">
<label><input type="checkbox" name="action"> Entité action</label>
</section> -->
<CheckboxEditable
v-if="entite.can_update"
label="Entité action"
:data="{
entitytype: 'node',
bundle: 'entite',
nid: this.entite.id,
field: 'field_entite_agissante'
}" />
<section v-if="entite.image.length" class="image"> <section v-if="entite.image.length" class="image">
<figure> <figure>
<img :src="entite.image[0].url" :alt="entite.image[0].alt"/> <img :src="entite.image[0].url" :alt="entite.image[0].alt"/>
<figcaption>{{ entite.image[0].alt }}</figcaption> <figcaption>{{ entite.image[0].alt }}</figcaption>
</figure> </figure>
<!-- TODO admin add image -->
</section> </section>
<section v-if="entite.action" class="action"> <section v-if="entite.action" class="action">
<label v-if="ct_entite">{{ ct_entite.field_action.description }}</label> <label v-if="ct_entite">{{ ct_entite.field_action.description }}</label>
<p>{{ entite.action }}</p> <!-- <p>{{ entite.action }}</p> -->
<ContentEditable
tag="p"
:value="entite.action"
:contenteditable="entite.can_update"
:data="{
entitytype: 'node',
bundle: 'entite',
nid: this.entite.id,
field: 'field_action'
}" />
</section> </section>
<section v-if="entite.menacemaintien" class="menace-maintien"> <section v-if="entite.menacemaintien" class="menace-maintien">
<label v-if="ct_entite">{{ field_menace_maintien_label }}</label> <label v-if="ct_entite">{{ field_menace_maintien_label }}</label>
<p>{{ entite.menacemaintien }}</p> <!-- <p>{{ entite.menacemaintien }}</p> -->
<ContentEditable
tag="p"
:value="entite.menacemaintien"
:contenteditable="entite.can_update"
:data="{
entitytype: 'node',
bundle: 'entite',
nid: this.entite.id,
field: 'field_menace_maintien'
}" />
</section> </section>
<!-- SOURCES (experiences vecues) --> <!-- SOURCES (experiences vecues) -->
<section <section

View File

@ -21,7 +21,7 @@ import SvgIcon from '@jamescoyle/vue-icon';
import { mdiChevronRight } from '@mdi/js'; import { mdiChevronRight } from '@mdi/js';
import { mdiChevronDown } from '@mdi/js'; import { mdiChevronDown } from '@mdi/js';
import ContentEditable from '@components/misc/ContentEditable.vue'; import ContentEditable from '@components/editable/ContentEditable.vue';
export default { export default {
props: ['cid', 'eid'], props: ['cid', 'eid'],
@ -233,7 +233,20 @@ export default {
<div class="entite"> <div class="entite">
<!-- TODO update entite with revisions --> <!-- TODO update entite with revisions -->
<label v-if="entite" class="menacemaintient" :class="{ hidden: headerreduced}">{{ entity_title_label }}</label> <label v-if="entite" class="menacemaintient" :class="{ hidden: headerreduced}">{{ entity_title_label }}</label>
<h3 v-if="entite" class="entite-title">{{ entite.title }}</h3> <!-- <h3 v-if="entite" class="entite-title">{{ entite.title }}</h3> -->
<ContentEditable
v-if="entite"
tag="h3"
:value="entite.title"
class="entite-title"
:contenteditable="entite.can_update"
:data="{
entitytype: 'node',
bundle: 'entite',
nid: this.entite.id,
field: 'title'
}" />
</div> </div>
</template> </template>

View File

@ -0,0 +1,64 @@
<script>
import REST from '@api/rest-axios'
import { mapActions, mapState } from 'pinia'
import { UserStore } from '@stores/user'
export default {
props: {
label: String,
data: Object
},
// emits: ['returned'],
data(){
return {
}
},
computed: {
...mapState(UserStore,['csrf_token']),
},
created () {
console.log('ContentEditable created');
},
mounted () {
},
methods: {
onInput(e){
// console.log('onInput checkbox e', e);
let checked = e.target.checked;
// console.log('onInput checkbox checked', checked);
this.save(checked)
},
save(checked){
// console.log('save csrf_token', this.csrf_token);
const params = {
type: this.data.bundle,
nid: [{"value":this.data.nid}],
[this.data.field]: {value: checked}
};
const configs = {
headers: {'X-CSRF-Token': this.csrf_token}
};
REST.patch(`/node/${this.data.nid}?_format=json`, params, configs)
.then(({ data }) => {
console.log('user REST post node data', data)
// TODO if success update the data in pinia
})
.catch(error => {
console.warn(`Issue with patch node ${this.data.bundle}`, error)
Promise.reject(error)
})
}
},
}
</script>
<template>
<section class="editable">
<label><input type="checkbox" @input="onInput"> {{ label }}</label>
</section>
</template>

View File

@ -1,12 +1,6 @@
<script> <script>
import REST from '@api/rest-axios' import REST from '@api/rest-axios'
// import JSONAPI from '@api/json-axios'
// import qs from 'querystring-es3'
// import { print } from 'graphql/language/printer'
// import gql from 'graphql-tag'
// import GQL from '@api/graphql-axios'
import { mapActions, mapState } from 'pinia' import { mapActions, mapState } from 'pinia'
import { UserStore } from '@stores/user' import { UserStore } from '@stores/user'
@ -50,27 +44,22 @@ export default {
this.save(new_field_content) this.save(new_field_content)
}, },
save(content){ save(content){
console.log('save csrf_token', this.csrf_token); // console.log('save csrf_token', this.csrf_token);
const params = { const params = {
type: this.data.bundle, type: this.data.bundle,
nid: [{"value":this.data.nid}], nid: [{"value":this.data.nid}],
[this.data.field]: {value: content} [this.data.field]: {value: content}
}; };
const configs = { const configs = {
headers: { headers: {'X-CSRF-Token': this.csrf_token}
'X-CSRF-Token': this.csrf_token,
// Authorization: `Bearer ${this.csrf_token}`,
// 'customheader': "bobobo"
}
}; };
console.log('REST', REST);
REST.patch(`/node/${this.data.nid}?_format=json`, params, configs) REST.patch(`/node/${this.data.nid}?_format=json`, params, configs)
.then(({ data }) => { .then(({ data }) => {
console.log('user REST post node data', data) console.log('user REST post node data', data)
// TODO if success update the data in pinia // TODO if success update the data in pinia
}) })
.catch(error => { .catch(error => {
console.warn('Issue with post node', error) console.warn(`Issue with patch node ${this.data.bundle}`, error)
Promise.reject(error) Promise.reject(error)
}) })
} }

View File

@ -6,7 +6,7 @@ import { ConcernementsStore } from '@stores/concernements'
import SvgIcon from '@jamescoyle/vue-icon'; import SvgIcon from '@jamescoyle/vue-icon';
import { mdiHeadphones } from '@mdi/js'; import { mdiHeadphones } from '@mdi/js';
import ContentEditable from '@components/misc/ContentEditable.vue'; import ContentEditable from '@components/editable/ContentEditable.vue';
export default { export default {
props: ['cid'], props: ['cid'],