2 <div class="bg-gray-50">
3 <div class="max-w-xl mx-auto py-1 divide-y md:max-w-4xl">
4 <div class="py-10 px-5 rounded-md shadow-lg">
9 @input="onHeaderChange"
10 class="w-10/12 px-1 py-2 mb-1 border-b border-gray-500 focus:outline-none focus:border-indigo-500 transition-colors text-gray-900" />
11 <button class="bg-gray-200 w-12 h-12 px-3 py-2 mb-1 ml-0 text-sm font-bold tracking-wider text-gray hover:bg-gray-400 inline-flex items-center justify-center"
12 @click="searchHeader">
13 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-list-check" viewBox="0 0 16 16">
14 <path fill-rule="evenodd" d="M5 11.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zM3.854 2.146a.5.5 0 0 1 0 .708l-1.5 1.5a.5.5 0 0 1-.708 0l-.5-.5a.5.5 0 1 1 .708-.708L2 3.293l1.146-1.147a.5.5 0 0 1 .708 0zm0 4a.5.5 0 0 1 0 .708l-1.5 1.5a.5.5 0 0 1-.708 0l-.5-.5a.5.5 0 1 1 .708-.708L2 7.293l1.146-1.147a.5.5 0 0 1 .708 0zm0 4a.5.5 0 0 1 0 .708l-1.5 1.5a.5.5 0 0 1-.708 0l-.5-.5a.5.5 0 0 1 .708-.708l.146.147 1.146-1.147a.5.5 0 0 1 .708 0z"/>
17 <button class="bg-blue-500 w-10 h-10 p-3 ml-3 text-sm font-bold tracking-wider text-white rounded-full hover:bg-red-600 inline-flex items-center justify-center"
18 v-if="selectedOption == null"
20 <svg xmlns="http://www.w3.org/2000/svg" class="fill-current" viewBox="0 0 24 24">
21 <path d="M24 10h-10v-10h-4v10h-10v4h10v10h4v-10h10z"/>
24 <button class="bg-blue-500 w-10 h-10 p-3 ml-3 text-sm font-bold tracking-wider text-white rounded-full hover:bg-red-600 inline-flex items-center justify-center"
26 @click="deleteHeader">
27 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
28 <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
29 <path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4L4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
34 <div class="py-10 px-5 rounded-md shadow-lg">
36 <div v-if="loading()">Loading...</div>
37 <div v-else class="py-1" v-for="list in todo_list" :key="list.id">
39 @onCheckChange="onCheckChange"
40 @onTextChange="onTextChange"
41 @onDelete="onDelete"/>
45 class="p-0 w-10 h-10 bg-blue-600 rounded-full hover:bg-blue-700 active:shadow-lg mouse shadow transition ease-in duration-200 focus:outline-none"
47 v-if="selectedHeadrId != 0">
48 <svg viewBox="0 0 20 20" enable-background="new 0 0 20 20" class="w-6 h-6 inline-block">
49 <path fill="#FFFFFF" d="M16,10c0,0.553-0.048,1-0.601,1H11v4.399C11,15.951,10.553,16,10,16c-0.553,0-1-0.049-1-0.601V11H4.601
50 C4.049,11,4,10.553,4,10c0-0.553,0.049-1,0.601-1H9V4.601C9,4.048,9.447,4,10,4c0.553,0,1,0.048,1,0.601V9h4.399
51 C15.952,9,16,9.447,16,10z" />
59 <snack-bar :msg="snackText" ref="snackBar"/>
61 :dataList="todo_header"
64 @onSelected="onSelected"/>
66 <spinner ref="spinner"/>
74 import moment from 'moment'
75 import _ from 'lodash' // eslint-disable-line no-unused-vars
76 //import { useQuery, useResult } from '@vue/apollo-composable' // eslint-disable-line no-unused-vars
77 import gql from 'graphql-tag'
78 import selectBox from '@/components/selectBox.vue'
79 import todo from '@/components/todo.vue'
80 import snackBar from '@/components/snackBar.vue'
81 import selectPanel from '@/components/selectPanel.vue'
82 import spinner from '@/components/spinner.vue'
94 this.$apollo.queries.todo_list.refetch({
99 // 選択中のオプションオブジェクト。任意入力値の場合は null を返す
101 if(!this.todo_header){
104 const selected = this.todo_header.find(item => item.name === this.titleName)
105 return selected || null
110 // // const { result, loading, error, refetch } = useQuery(gql`
111 // // query todo_header {
119 // // const users = useResult(result)
127 // onBeforeMount(() => {
128 // console.log('Component is onBeforeMount!')
129 // // this.$apollo.queries.todo_list.refetch({
130 // // selectedHeadrId: 0
139 this.titleName = head.name
140 this.selectedTitle(head.id)
143 if(this.selectedOption){
144 this.selectedTitle(this.selectedOption.id)
146 this.$apollo.queries.todo_list.refetch({
149 this.selectedHeadrId = 0
153 if(_.isEmpty(this.titleName)){
154 this.$refs.snackBar.setMessageAndshow('タイトルが入ってないよ!')
163 this.$refs.spinner.show()
164 this.$apollo.queries.todo_header.refetch()
166 this.$refs.selectPanel.show()
167 }).catch((error) => {
168 this.$refs.snackBar.setMessageAndshow('db error?')
171 this.$refs.spinner.close()
175 onCheckChange(data) {
176 this.updateMutate(data);
179 this.updateMutate(data);
182 const UPDATE_DONE = gql`mutation updateTodoMutation($header_id: Int!, $id: Int!, $done: Boolean = false, $name: String = "", $updated: timestamp = "") {
183 update_todo_list_by_pk(pk_columns: {header_id: $header_id, id: $id}, _set: {updated: $updated, name: $name, done: $done}) {
188 this.$refs.spinner.show()
189 this.$apollo.mutate({
190 mutation: UPDATE_DONE,
192 header_id: data.header_id
196 , updated: this.getNowFormatted()
200 this.$refs.snackBar.setMessageAndshow('update error!')
203 this.$refs.spinner.close()
207 const DELETE_TODO = gql`mutation deleteTodoMutation($header_id: Int!, $id: Int!) {
208 delete_todo_list_by_pk(id: $id, header_id: $header_id) {
213 this.$refs.spinner.show()
214 this.mutateApollo(DELETE_TODO, {
215 header_id: data.header_id
217 }).catch((error) => {
218 this.$refs.snackBar.setMessageAndshow('delete error!')
221 this.$refs.spinner.close()
225 const now = this.getNowFormatted()
227 if(this.selectedHeadrId === 0){
232 const CREATE_TODO = gql`mutation createTodoMutation($header_id: Int!,
234 $done: Boolean = false,
236 $created: timestamp = "",
237 $updated: timestamp = "") {
238 insert_todo_list_one(object: {header_id: $header_id, id: $id, done: $done, name: $name, created: $created, updated: $updated}) {
248 this.$refs.spinner.show()
249 this.$apollo.queries.todo_list_aggregate.refetch({
250 selectedHeadrId: this.selectedHeadrId
252 return this.mutateApollo(CREATE_TODO, {
253 header_id:this.selectedHeadrId
254 , id:this.todo_list_aggregate.aggregate.max.id + 1
260 }).catch((error) => {
261 this.$refs.snackBar.setMessageAndshow('add error!')
264 this.$refs.spinner.close()
268 return this.$apollo.queries.todo_list.loading
271 return this.formattedData()
273 formattedData(param){
274 return moment(param).format("YYYY-MM-DDTHH:mm:ss.SSS")
277 this.$refs.spinner.show()
278 this.$apollo.queries.todo_list.refetch({
279 selectedHeadrId: titleId
281 this.selectedHeadrId = titleId
283 this.$refs.spinner.close()
286 mutateApollo(gqlMutation, variables){
287 const promise = this.$apollo.mutate({
288 mutation: gqlMutation,
292 this.reFetch(this.selectedHeadrId)
293 return new Promise(resolve => {resolve()})
296 return new Promise((resolve, reject) => {reject(error)})
309 // Simple query that will update the 'hello' vue property
310 todo_header: gql`query {
316 todo_list: gql`query ($selectedHeadrId: Int){
317 todo_list (where: {header_id: {_eq: $selectedHeadrId}}, order_by: {id: asc}) {
326 todo_list_aggregate: gql`query ($selectedHeadrId: Int){
327 todo_list_aggregate(where: {header_id: {_eq: $selectedHeadrId}}) {
340 <!-- Add "scoped" attribute to limit CSS to this component only -->