init the start of a record

This commit is contained in:
Julien Calixte
2023-04-10 16:16:08 +02:00
parent 531a05be26
commit a934c51a2e
7 changed files with 100 additions and 1 deletions

View File

@@ -1,14 +1,32 @@
<script setup lang="ts"> <script setup lang="ts">
import { useTaskStore } from '@/modules/task/stores/useTask.store'
import { useTaskRecordStore } from '../stores/useTaskRecordStore'
const props = defineProps<{ const props = defineProps<{
taskId: string taskId: string
recordId: string
}>() }>()
const taskStore = useTaskStore()
const recordStore = useTaskRecordStore()
const task = taskStore.getTask(props.taskId)
const record = recordStore.createAndRetriveTaskRecord(
props.taskId,
props.recordId
)
</script> </script>
<template> <template>
<div class="task-record"></div> <div class="task-record">
<pre>{{ task }}</pre>
<pre>{{ record }}</pre>
</div>
</template> </template>
<style scoped lang="scss"> <style scoped lang="scss">
.task-record { .task-record {
display: flex;
} }
</style> </style>

View File

@@ -0,0 +1,34 @@
<script setup lang="ts">
import { createUuid } from '@/shared/create-uuid'
import { useTaskRecordStore } from '../stores/useTaskRecordStore'
const props = defineProps<{
taskId: string
}>()
const recordStore = useTaskRecordStore()
const records = recordStore.getTaskRecords(props.taskId)
const newRecordId = createUuid()
</script>
<template>
<ul v-if="records.length" class="task-record-list">
<li v-for="record in records" :key="record.id">
{{ record }}
</li>
</ul>
<div v-else>No record yet</div>
<router-link
:to="{
name: 'record-view',
params: { taskId, recordId: newRecordId }
}"
>start a new record</router-link
>
</template>
<style scoped lang="scss">
.task-record-list {
}
</style>

View File

@@ -4,7 +4,15 @@ import type { StepRecordable } from './step-recordable'
export interface Recordable { export interface Recordable {
id: string id: string
taskId: string taskId: string
/**
* @deprecated
* TODO: Compute this data from step records
*/
start: ISODate start: ISODate
/**
* @deprecated
* TODO: Compute this data from step records
*/
end?: ISODate end?: ISODate
stepRecords: Record<string, StepRecordable> stepRecords: Record<string, StepRecordable>
} }

View File

@@ -7,6 +7,7 @@ import { TaskRecord } from '../models/task-record'
type RecordId = string type RecordId = string
export interface TaskRecordStoreState { export interface TaskRecordStoreState {
currentStepId: string | null
records: { [recordId: string]: Recordable } records: { [recordId: string]: Recordable }
taskRecordMaps: { [taskId: string]: RecordId[] } taskRecordMaps: { [taskId: string]: RecordId[] }
} }
@@ -14,6 +15,7 @@ export interface TaskRecordStoreState {
export const useTaskRecordStore = defineStore('task-record-store', { export const useTaskRecordStore = defineStore('task-record-store', {
persist: true, persist: true,
state: (): TaskRecordStoreState => ({ state: (): TaskRecordStoreState => ({
currentStepId: null,
records: {}, records: {},
taskRecordMaps: {} taskRecordMaps: {}
}), }),
@@ -41,10 +43,17 @@ export const useTaskRecordStore = defineStore('task-record-store', {
stepId: string stepId: string
start: ISODate start: ISODate
}) { }) {
const record = this.records[params.recordId]
if (Object.values(record.stepRecords).length === 0) {
record.start = params.start
}
this.records[params.recordId].stepRecords[params.stepId] = { this.records[params.recordId].stepRecords[params.stepId] = {
problems: [], problems: [],
start: params.start start: params.start
} }
this.currentStepId = params.stepId
}, },
endStepRecord(params: { recordId: string; stepId: string; end: ISODate }) { endStepRecord(params: { recordId: string; stepId: string; end: ISODate }) {
const stepRecord = const stepRecord =
@@ -73,6 +82,9 @@ export const useTaskRecordStore = defineStore('task-record-store', {
start: params.tick start: params.tick
}) })
}, },
endRecord() {
this.currentStepId = null
},
addProblemToStepRecord(recordId: string, stepId: string, problem: string) { addProblemToStepRecord(recordId: string, stepId: string, problem: string) {
const stepRecord = this.getStepRecord(recordId, stepId) const stepRecord = this.getStepRecord(recordId, stepId)

View File

@@ -24,6 +24,12 @@ export const router = createRouter({
name: 'task-view', name: 'task-view',
props: true, props: true,
component: () => import('../views/task/TaskView.vue') component: () => import('../views/task/TaskView.vue')
},
{
path: '/task/:taskId/records/:recordId',
name: 'record-view',
props: true,
component: () => import('../views/record/RecordView.vue')
} }
] ]
}) })

View File

@@ -0,0 +1,19 @@
<script setup lang="ts">
import TaskRecord from '@/modules/record/components/TaskRecord.vue'
const props = defineProps<{
taskId: string
recordId: string
}>()
</script>
<template>
<div class="record-view">
<TaskRecord :task-id="taskId" :record-id="recordId" />
</div>
</template>
<style scoped lang="scss">
.record-view {
}
</style>

View File

@@ -1,4 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import TaskRecordList from '@/modules/record/components/TaskRecordList.vue'
import { useTaskStore } from '@/modules/task/stores/useTask.store' import { useTaskStore } from '@/modules/task/stores/useTask.store'
import { computed } from 'vue' import { computed } from 'vue'
@@ -27,6 +28,7 @@ const task = computed(() => taskStore.getTask(props.id))
<div>{{ step.title }} | {{ step.estimation }}</div> <div>{{ step.title }} | {{ step.estimation }}</div>
</li> </li>
</ul> </ul>
<task-record-list :task-id="id" />
</div> </div>
<div v-else>Task not found</div> <div v-else>Task not found</div>
</template> </template>