|
5 | 5 |
|
6 | 6 | interface AugmentedActivity extends Activity { |
7 | 7 | date_locale: string, |
| 8 | + date_time_locale: string, |
8 | 9 | date_iso: string, |
9 | 10 | time: number, |
10 | 11 | field_names: string, |
|
36 | 37 | return { |
37 | 38 | ...activity, |
38 | 39 | date_locale: date.toLocaleDateString(), |
| 40 | + date_time_locale: date.toLocaleString(), |
39 | 41 | date_iso: date.toISOString().split('T')[0], |
40 | 42 | time: date.getTime(), |
41 | 43 | field_names: to_names(activity.fields), |
|
44 | 46 | } |
45 | 47 |
|
46 | 48 | function byDateThenUser(a: AugmentedActivity, b: AugmentedActivity) { |
47 | | - return a.date_iso === b.date_iso ? a.user === b.user ? des(a.time, b.time) |
48 | | - : asc(a.user.username, b.user.username) |
49 | | - : des(a.date_iso, b.date_iso) |
| 49 | + if (a.date_iso !== b.date_iso) { |
| 50 | + return des(a.date_iso, b.date_iso); |
| 51 | + } |
| 52 | +
|
| 53 | + if (a.user.username !== b.user.username) { |
| 54 | + return asc(a.user.username, b.user.username); |
| 55 | + } |
| 56 | +
|
| 57 | + return des(a.time, b.time); |
50 | 58 | } |
51 | 59 |
|
52 | 60 | const asc = (a: string | number, b: string | number) => a > b ? 1 : -1 |
53 | 61 | const des = (a: string | number, b: string | number) => a < b ? 1 : -1 |
54 | 62 |
|
55 | 63 | function to_names(fields: Field[] = []): string { |
56 | | - return fields.map(field => field.name).join(', ') |
| 64 | + // This is quite rudimentary, but far better than nothing |
| 65 | + return [...new Set(fields.map(field => field.fieldLabel?.label) |
| 66 | + .filter(label => !!label))] |
| 67 | + .join(', ') |
57 | 68 | } |
58 | 69 | </script> |
59 | 70 |
|
|
63 | 74 | <thead> |
64 | 75 | <tr> |
65 | 76 | <td>user</td> |
66 | | - <th>date</th> |
67 | 77 | <th>action</th> |
68 | 78 | <th>entry</th> |
69 | 79 | <th>fields</th> |
| 80 | + <th>date</th> |
70 | 81 | </tr> |
71 | 82 | </thead> |
72 | 83 | <tbody> |
73 | 84 | {#each sorted_activities as activity} |
74 | 85 | <tr> |
75 | 86 | <td>{ activity.user.username }</td> |
76 | | - <td>{ activity.date_locale }</td> |
77 | 87 | <td>{ action_display[activity.action] || activity.action }</td> |
78 | 88 | <td>{ activity.entry || '—' }</td> |
79 | 89 | <td>{ activity.field_names || '—' }</td> |
| 90 | + <td>{ activity.date_time_locale }</td> |
80 | 91 | </tr> |
81 | 92 | {:else} |
82 | 93 | <tr><td>No activity</td></tr> |
|
0 commit comments