terrier-engine 4.25.0 → 4.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,9 +4,19 @@ import TerrierPart from "../../terrier/parts/terrier-part"
4
4
  import {RegularSchedule, RegularScheduleForm} from "../../terrier/schedules"
5
5
  import {Logger} from "tuff-core/logging"
6
6
  import {EmailListForm} from "../../terrier/emails"
7
+ import {DdDiveRun} from "../gen/models"
8
+ import Db from "../dd-db"
9
+ import dayjs from "dayjs"
10
+ import Dates from "../queries/dates"
11
+ import DiveRuns from "./dive-runs";
7
12
 
8
13
  const log = new Logger("Dive Delivery")
9
14
 
15
+
16
+ ////////////////////////////////////////////////////////////////////////////////
17
+ // Delivery Form
18
+ ////////////////////////////////////////////////////////////////////////////////
19
+
10
20
  export type DiveDeliverySettings = {
11
21
  delivery_schedule: RegularSchedule
12
22
  delivery_recipients: string[]
@@ -16,11 +26,13 @@ export class DiveDeliveryForm extends TerrierPart<DiveEditorState> {
16
26
 
17
27
  scheduleForm!: RegularScheduleForm
18
28
  recipientsForm!: EmailListForm
29
+ deliveryList!: DiveDeliveryList
19
30
 
20
31
  async init() {
21
32
  const schedule = this.state.dive.delivery_schedule || {schedule_type: 'none'}
22
33
  this.scheduleForm = this.makePart(RegularScheduleForm, schedule)
23
34
  this.recipientsForm = this.makePart(EmailListForm, {emails: this.state.dive.delivery_recipients || []})
35
+ this.deliveryList = this.makePart(DiveDeliveryList, this.state)
24
36
 
25
37
  this.listen('datachanged', this.scheduleForm.dataChangedKey, m => {
26
38
  log.info(`Schedule form data changed`, m.data)
@@ -42,6 +54,11 @@ export class DiveDeliveryForm extends TerrierPart<DiveEditorState> {
42
54
  parent.part(this.scheduleForm)
43
55
  parent.h3(".glyp-users").text("Recipients")
44
56
  parent.part(this.recipientsForm)
57
+ parent.div('.deliveries', deliveriesContainer => {
58
+ // it looks better without the gap between the header and list
59
+ deliveriesContainer.h3(".glyp-inbox").text("Deliveries")
60
+ deliveriesContainer.part(this.deliveryList)
61
+ })
45
62
  }
46
63
 
47
64
  /**
@@ -55,3 +72,46 @@ export class DiveDeliveryForm extends TerrierPart<DiveEditorState> {
55
72
  }
56
73
 
57
74
  }
75
+
76
+
77
+ ////////////////////////////////////////////////////////////////////////////////
78
+ // Delivery List
79
+ ////////////////////////////////////////////////////////////////////////////////
80
+
81
+ class DiveDeliveryList extends TerrierPart<DiveEditorState> {
82
+
83
+ runs: DdDiveRun[] = []
84
+
85
+ async init() {
86
+ this.runs = await Db().query("dd_dive_run")
87
+ .where({dd_dive_id: this.state.dive.id})
88
+ .where("delivery_recipients is not null")
89
+ .orderBy("created_at desc")
90
+ .limit(100)
91
+ .exec()
92
+
93
+ this.dirty()
94
+ }
95
+
96
+ get parentClasses(): Array<string> {
97
+ return ['dive-delivery-list']
98
+ }
99
+
100
+ render(parent: PartTag) {
101
+ for (const run of this.runs) {
102
+ parent.div(".run", view => {
103
+ view.div(".recipients.glyp-users.with-icon").text(run.delivery_recipients?.join("; ") || "No Recipients")
104
+ view.div('.datetime', dateTimeView => {
105
+ const d = dayjs(run.created_at)
106
+ dateTimeView.div(".date").text(d.format(Dates.displayFormat))
107
+ dateTimeView.div(".time").text(d.format("H:mm A"))
108
+ })
109
+ run.dd_dive = this.state.dive // so that the filename is better
110
+ view.a(".download.glyp-download", {href: DiveRuns.outputUrl(run), target: '_blank'})
111
+ .data({tooltip: "Download the dive results for this delivery"})
112
+ })
113
+ }
114
+ }
115
+
116
+ }
117
+
@@ -15,12 +15,18 @@ import {TerrierFormFields} from "../../terrier/forms"
15
15
  import * as inflection from "inflection"
16
16
  import Dates, {DateLiteral, DatePeriodPickerPart, DatePeriodPickerState, LiteralDateRange} from "../queries/dates"
17
17
  import dayjs from "dayjs"
18
- import {ProgressBarPart} from "../../terrier/progress";
19
- import {LogListPart} from "../../terrier/logging";
18
+ import {ProgressBarPart} from "../../terrier/progress"
19
+ import {LogListPart} from "../../terrier/logging"
20
20
  import Messages from "tuff-core/messages"
21
+ import Format from "../../terrier/format"
21
22
 
22
23
  const log = new Logger("DiveRuns")
23
24
 
25
+
26
+ ////////////////////////////////////////////////////////////////////////////////
27
+ // Run Modal
28
+ ////////////////////////////////////////////////////////////////////////////////
29
+
24
30
  type RunQueryResult = {
25
31
  id: string
26
32
  time: string
@@ -309,4 +315,34 @@ export class DiveRunModal extends ModalPart<{dive: DdDive }> {
309
315
  })
310
316
  }
311
317
 
312
- }
318
+ }
319
+
320
+
321
+ ////////////////////////////////////////////////////////////////////////////////
322
+ // Utilities
323
+ ////////////////////////////////////////////////////////////////////////////////
324
+
325
+ /**
326
+ * Generates a relative URL to download the output of the given run with an optional custom file name.
327
+ * @param run
328
+ * @param filename
329
+ */
330
+ function outputUrl(run: DdDiveRun, filename?: string): string {
331
+ if (!filename?.length) {
332
+ const nameComps: string[] = []
333
+ const dive = run.dd_dive
334
+ if (dive) {
335
+ nameComps.push(inflection.underscore(dive.name))
336
+ }
337
+ const d = dayjs(run.created_at)
338
+ nameComps.push(d.format('YYYY-MM-DD_HHmmss'))
339
+ filename = nameComps.join('_') + '.xlsx'
340
+ }
341
+ return `/data_dive/download_run/${run.id}/${filename}?t=${dayjs().format(Format.timestamp)}`
342
+ }
343
+
344
+ const DiveRuns = {
345
+ outputUrl
346
+ }
347
+ export default DiveRuns
348
+
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "files": [
5
5
  "*"
6
6
  ],
7
- "version": "4.25.0",
7
+ "version": "4.26.0",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/Terrier-Tech/terrier-engine"
package/terrier/format.ts CHANGED
@@ -12,13 +12,20 @@ function cents(c: number | string): string {
12
12
  return '$' + (num/100).toFixed(2)
13
13
  }
14
14
 
15
+ ////////////////////////////////////////////////////////////////////////////////
16
+ // Dates and Times
17
+ ////////////////////////////////////////////////////////////////////////////////
18
+
19
+ const timestamp = 'YYYYMMDDHHMMSS'
20
+
15
21
 
16
22
  ////////////////////////////////////////////////////////////////////////////////
17
23
  // Export
18
24
  ////////////////////////////////////////////////////////////////////////////////
19
25
 
20
26
  const Format = {
21
- cents
27
+ cents,
28
+ timestamp
22
29
  }
23
30
 
24
31
  export default Format