feat(subject): finish the subject synchronize between wheel and table

This commit is contained in:
2020-01-13 23:55:10 +01:00
parent b2771a0caf
commit fdca7dd6b9
3 changed files with 33 additions and 20 deletions

View File

@@ -5,8 +5,8 @@
</v-app-bar> </v-app-bar>
<v-content> <v-content>
<SpeechlessSubject @inputData="updateSubjects"/> <SpeechlessSubject @subjects="updateSubjects" @replace-subject="replaceSubject" :subjects="subjects"/>
<SpinningWheel :subjects="subjects"/> <SpinningWheel ref="spinningWheel" :subjects="subjects"/>
</v-content> </v-content>
</v-app> </v-app>
</template> </template>
@@ -21,11 +21,19 @@ export default {
source: String, source: String,
}, },
data: () => ({ data: () => ({
subjects: [], subjects: [
{Nom:"Un film", Lien:""},
{Nom:"Une serie", Lien:""},
{Nom:"Un logiciel", Lien:""}
],
}), }),
methods: { methods: {
updateSubjects(subjects) { updateSubjects(subjects) {
this.subjects=subjects; this.subjects=subjects;
},
replaceSubject(replace){
Object.assign(this.subjects[replace.index], replace.subject)
this.$refs.spinningWheel.replaceSubject(replace)
} }
}, },
components: { components: {

View File

@@ -81,11 +81,6 @@ export default {
{ text: 'Actions', value: 'action', sortable: false }, { text: 'Actions', value: 'action', sortable: false },
], ],
container: null, container: null,
subjects : [
{Nom:"Un film", Lien:""},
{Nom:"Une serie", Lien:""},
{Nom:"Un logiciel", Lien:""}
],
dialog: false, dialog: false,
editedIndex: -1, editedIndex: -1,
editedItem: { editedItem: {
@@ -98,10 +93,12 @@ export default {
}, },
} }
}, },
props: {
subjects : {
type : Array
}
},
methods : { methods : {
getDataSpin(){
return this.subjects;
},
editItem (item) { editItem (item) {
this.editedIndex = this.subjects.indexOf(item) this.editedIndex = this.subjects.indexOf(item)
this.editedItem = Object.assign({}, item) this.editedItem = Object.assign({}, item)
@@ -123,11 +120,12 @@ export default {
save () { save () {
if (this.editedIndex > -1) { if (this.editedIndex > -1) {
Object.assign(this.subjects[this.editedIndex], this.editedItem) Object.assign(this.subjects[this.editedIndex], this.editedItem)
this.$emit("replace-subject",{index: this.editedIndex, subject: this.editedItem})
} else { } else {
this.subjects.push(this.editedItem) this.subjects.push(this.editedItem)
this.$emit("subjects",this.subjects)
} }
this.close() this.close()
this.$emit("subjects",this.subjects)
}, },
}, },
watch: { watch: {

View File

@@ -12,14 +12,20 @@
data: function () { data: function () {
return { return {
container: null, container: null,
subjects : [ spinData: [],
{Nom:"Un film", Lien:""}, }
{Nom:"Une serie", Lien:""}, },
{Nom:"Un logiciel", Lien:""} props: {
], subjects: {
type: Array
} }
}, },
methods : { methods : {
replaceSubject(replace){
Object.assign(this.subjects[replace.index], replace.subject)
this.removeGraph()
this.buildGraph()
},
getSubjects(){ getSubjects(){
return this.subjects; return this.subjects;
}, },
@@ -106,9 +112,6 @@
.style({"fill":"black"}); .style({"fill":"black"});
} }
}, },
created() {
},
computed: { computed: {
formTitle () { formTitle () {
return this.editedIndex === -1 ? 'New Item' : 'Edit Item' return this.editedIndex === -1 ? 'New Item' : 'Edit Item'
@@ -118,6 +121,10 @@
dialog (val) { dialog (val) {
val || this.close() val || this.close()
}, },
subjects: function() {
this.removeGraph();
this.buildGraph();
},
}, },
mounted() { mounted() {
this.buildGraph() this.buildGraph()