return
}
+ const CREATE_TODO_HEAD = gql`mutation createHeader($id: Int!, $name: String = "") {
+ insert_todo_header_one(object: {id: $id, name: $name}) {
+ id
+ name
+ }
+ }`
+
+ this.$refs.spinner.show()
+ this.$apollo.queries.todo_header_aggregate.refetch()
+ .then(() => {
+ this.selectedHeadrId = this.todo_header_aggregate.aggregate.max.id + 1
+ return this.mutateHead(CREATE_TODO_HEAD, {
+ id: this.selectedHeadrId
+ , name: this.titleName
+ });
+ }).then(() => {
+ this.onHeaderChange()
+ }).catch((error) => {
+ this.$refs.snackBar.setMessageAndshow('add error!')
+ console.error(error)
+ }).finally(() => {
+ this.$refs.spinner.close()
+ })
+
},
deleteHeader(){
+ if(!_.isNumber(this.selectedHeadrId)){
+ this.$refs.snackBar.setMessageAndshow('タイトルが選ばれていないよ!')
+ return
+ }
+ const DELETE_TODO_HEAD = gql`mutation delete_todo_header($id: Int!) {
+ delete_todo_header_by_pk(id: $id) {
+ id
+ }
+ }`
+
+ this.$refs.spinner.show()
+ this.deleteTodoList(this.selectedHeadrId)
+ .then(() => {
+ return this.mutateHead(DELETE_TODO_HEAD, {id: this.selectedHeadrId})
+ }).then(() => {
+ this.selectedHeadrId = 0
+ this.titleName = ""
+ }).catch((error) => {
+ this.$refs.snackBar.setMessageAndshow('add error!')
+ console.error(error)
+ }).finally(() => {
+ this.$refs.spinner.close()
+ })
+ },
+ deleteTodoList(headerId){
+ const DELETE_TODO = gql`mutation deleteTitleMutate($header_id: Int!) {
+ delete_todo_list(where: {header_id: {_eq:$header_id}}) {
+ affected_rows
+ }
+ }`
+ const promise = this.mutateApollo(DELETE_TODO, {header_id: headerId})
+ .then(() => {
+ return new Promise(resolve => {resolve()})
+ }).catch((error) => {
+ return new Promise((resolve, reject) => {reject(error)})
+ })
+ return promise
+ },
+ mutateHead(gqlMutation, variables){
+ const promise = this.$apollo.mutate({
+ mutation: gqlMutation,
+ variables: variables
+ })
+ .then(() => {
+ return this.$apollo.queries.todo_header.refetch()
+ })
+ .catch((error) => {
+ return new Promise((resolve, reject) => {reject(error)})
+ })
+ return promise
},
searchHeader(){
this.$refs.spinner.show()
}
}
}`,
-
+ todo_header_aggregate: gql`query {
+ todo_header_aggregate {
+ aggregate {
+ max {
+ id
+ }
+ }
+ }
+ }`,
},
}
</script>