|
42 | 42 | >
|
43 | 43 | Origin
|
44 | 44 | </th>
|
| 45 | + <th |
| 46 | + class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider cursor-pointer" |
| 47 | + data-sortby="firstVisit" |
| 48 | + v-on:click="sort" |
| 49 | + v-on:keyup.enter="sort" |
| 50 | + v-on:keyup.space="sort" |
| 51 | + tabindex="0" |
| 52 | + aria-label="sort by first visit" |
| 53 | + > |
| 54 | + First Visit |
| 55 | + </th> |
45 | 56 | <th
|
46 | 57 | class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider cursor-pointer"
|
47 | 58 | data-sortby="lastVisit"
|
|
75 | 86 | </p>
|
76 | 87 | </div>
|
77 | 88 | </td>
|
| 89 | + <td class="px-5 py-5 border-b border-gray-200 bg-white text-sm"> |
| 90 | + <p class="text-gray-900 whitespace-no-wrap"> |
| 91 | + {{ entry.firstVisit }} |
| 92 | + </p> |
| 93 | + </td> |
78 | 94 | <td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
|
79 | 95 | <p class="text-gray-900 whitespace-no-wrap">
|
80 | 96 | {{ entry.lastVisit }}
|
|
100 | 116 | </template>
|
101 | 117 |
|
102 | 118 | <script>
|
103 |
| -import { getFirstVisit, compare, humanizeEntry } from "../utils.js"; |
| 119 | +import { |
| 120 | + getFirstVisit, |
| 121 | + compare, |
| 122 | + humanizeEntry, |
| 123 | + calcTotalTimeInRange, |
| 124 | +} from "../utils.js"; |
104 | 125 |
|
105 | 126 | export default {
|
106 | 127 | name: "app",
|
@@ -133,41 +154,33 @@ export default {
|
133 | 154 | dateFrom: () => this.date.dateFrom.toLocaleDateString("en-CA"),
|
134 | 155 | dateTo: () => this.date.dateTo.toLocaleDateString("en-CA"),
|
135 | 156 | sortedHistory: function () {
|
136 |
| - const dateFrom = new Date(this.date.dateFrom); |
137 |
| - const dateTo = new Date(this.date.dateTo); |
| 157 | + // handling for cleared inputs |
| 158 | + const dateFrom = this.date.dateFrom |
| 159 | + ? new Date(this.date.dateFrom) |
| 160 | + : new Date(0); |
| 161 | + const dateTo = this.date.dateTo ? new Date(this.date.dateTo) : new Date(); |
138 | 162 |
|
139 | 163 | return Array.from(this.history)
|
140 |
| - .sort((a, b) => { |
141 |
| - const keyA = a[this.sortby]; |
142 |
| - const keyB = b[this.sortby]; |
143 |
| -
|
144 |
| - return compare(keyA, keyB, this.sortby, this.ascending); |
145 |
| - }) |
146 |
| - .map(humanizeEntry) |
147 | 164 | .filter(
|
148 | 165 | (entry) =>
|
149 |
| - new Date(entry.firstVisit) >= dateFrom && |
150 |
| - new Date(entry.lastVisit) <= dateTo, |
| 166 | + new Date(entry.lastVisit).getTime() >= dateFrom.getTime() && |
| 167 | + new Date(entry.firstVisit).getTime() <= dateTo.getTime(), |
151 | 168 | )
|
152 | 169 | .filter(
|
153 | 170 | (entry) =>
|
154 | 171 | (this.search && entry.origin.includes(this.search)) || !this.search,
|
155 |
| - ); |
156 |
| - // .filter((entry) => |
157 |
| - // Object.keys(entry) |
158 |
| - // .some((key) => Number(key) >= from.year) |
159 |
| - // .some((year) => |
160 |
| - // Object.keys(entry[year]) |
161 |
| - // .some((key) => Number(key) >= from.month) |
162 |
| - // .some((month) => |
163 |
| - // Object.keys(entry[year][month]).some( |
164 |
| - // (key) => Number(key) >= from.day, |
165 |
| - // ), |
166 |
| - // ), |
167 |
| - // ), |
168 |
| - // ); |
169 |
| - // entry?.[from.year]?.[from.month]?.[from.day] || |
170 |
| - // entry?.[to.year]?.[to.month]?.[to.day], |
| 172 | + ) |
| 173 | + .map((entry) => ({ |
| 174 | + ...entry, |
| 175 | + totalTime: calcTotalTimeInRange(entry, dateFrom, dateTo), |
| 176 | + })) |
| 177 | + .sort((a, b) => { |
| 178 | + const keyA = a[this.sortby]; |
| 179 | + const keyB = b[this.sortby]; |
| 180 | +
|
| 181 | + return compare(keyA, keyB, this.sortby, this.ascending); |
| 182 | + }) |
| 183 | + .map(humanizeEntry); |
171 | 184 | },
|
172 | 185 | },
|
173 | 186 | methods: {
|
|
0 commit comments