|
4 | 4 | <div v-if="loading">Loading...</div> |
5 | 5 | <div v-else-if="error" class="error-message">{{ error }}</div> |
6 | 6 | <div v-else> |
7 | | - <v-data-table |
8 | | - :headers="headers" |
9 | | - :items="history" |
10 | | - class="elevation-1" |
11 | | - > |
| 7 | + <v-data-table :headers="headers" :items="history" class="elevation-1"> |
12 | 8 | <template v-slot:item.hasNegativeInterval="{ item }"> |
13 | | - <v-chip |
14 | | - :color="item.hasNegativeInterval ? 'error' : 'success'" |
15 | | - :text-color="'white'" |
16 | | - small |
17 | | - > |
| 9 | + <v-chip :color="item.hasNegativeInterval ? 'error' : 'success'" :text-color="'white'" small> |
18 | 10 | {{ item.hasNegativeInterval ? 'INVALID' : 'Valid' }} |
19 | 11 | </v-chip> |
20 | 12 | </template> |
21 | | - |
| 13 | + |
22 | 14 | <template v-slot:item.intervalFromPrevious="{ item }"> |
23 | | - <span |
24 | | - :class="{ 'negative-interval': item.hasNegativeInterval }" |
25 | | - > |
| 15 | + <span :class="{ 'negative-interval': item.hasNegativeInterval }"> |
26 | 16 | {{ item.intervalFromPrevious !== undefined ? item.intervalFromPrevious : '-' }} |
27 | 17 | </span> |
28 | 18 | </template> |
29 | 19 |
|
30 | 20 | <template v-slot:item.formattedTimeStamp="{ item }"> |
31 | | - <span |
32 | | - :class="{ 'invalid-timestamp': item.hasNegativeInterval }" |
33 | | - > |
| 21 | + <span :class="{ 'invalid-timestamp': item.hasNegativeInterval }"> |
34 | 22 | {{ item.formattedTimeStamp }} |
35 | 23 | </span> |
36 | 24 | </template> |
@@ -108,28 +96,28 @@ export default defineComponent({ |
108 | 96 | try { |
109 | 97 | const cardHistoryID = getCardHistoryID(this.courseId, this.cardId); |
110 | 98 | const historyDoc: CardHistory<CardRecord> = await this.userDB.get(cardHistoryID); |
111 | | - |
| 99 | +
|
112 | 100 | // Sort records by timestamp and format them |
113 | | - const sortedRecords = [...historyDoc.records].sort((a, b) => |
114 | | - moment(a.timeStamp).valueOf() - moment(b.timeStamp).valueOf() |
| 101 | + const sortedRecords = [...historyDoc.records].sort( |
| 102 | + (a, b) => moment(a.timeStamp).valueOf() - moment(b.timeStamp).valueOf() |
115 | 103 | ); |
116 | | - |
| 104 | +
|
117 | 105 | this.history = sortedRecords.map((record, index) => { |
118 | 106 | const currentTime = moment(record.timeStamp); |
119 | 107 | const formatted: FormattedRecord = { |
120 | 108 | ...record, |
121 | 109 | formattedTimeStamp: currentTime.format('YYYY-MM-DD HH:mm:ss'), |
122 | 110 | timeSpentSeconds: Math.round(record.timeSpent / 1000), |
123 | 111 | }; |
124 | | - |
| 112 | +
|
125 | 113 | // Calculate interval from previous record |
126 | 114 | if (index > 0) { |
127 | 115 | const previousTime = moment(sortedRecords[index - 1].timeStamp); |
128 | 116 | const intervalMinutes = currentTime.diff(previousTime, 'minutes', true); |
129 | 117 | formatted.intervalFromPrevious = Math.round(intervalMinutes * 100) / 100; |
130 | 118 | formatted.hasNegativeInterval = intervalMinutes < 0; |
131 | 119 | } |
132 | | - |
| 120 | +
|
133 | 121 | return formatted; |
134 | 122 | }); |
135 | 123 | } catch (e) { |
|
0 commit comments