@isoftdata/utility-dashboard-backend 3.4.0 → 4.0.0-beta.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.
- package/README.md +185 -201
- package/dist/chart-helper.d.ts +6 -10
- package/dist/chart-helper.js +58 -136
- package/dist/index.d.ts +19 -41
- package/dist/index.js +41 -71
- package/dist/style-templates.d.ts +2 -2
- package/dist/style-templates.js +4 -16
- package/dist/types/chart.d.ts +44 -59
- package/dist/types/parameter.d.ts +5 -9
- package/dist/types/report.d.ts +2 -2
- package/dist/types/session.d.ts +0 -1
- package/package.json +56 -64
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.js +0 -2
package/README.md
CHANGED
|
@@ -1,201 +1,185 @@
|
|
|
1
|
-
# utility-dashboard-backend
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
####
|
|
45
|
-
|
|
46
|
-
A
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
#### definitionList
|
|
188
|
-
|
|
189
|
-
The `parameters` property from the `json` column of a row in the `dashboard_report` table.
|
|
190
|
-
|
|
191
|
-
#### selectionList
|
|
192
|
-
|
|
193
|
-
An array of objects representing the selected parameters sent from the client. Only needed when loading the chart data, not when loading the report "metadata". Each parameter object should match the format specified in [schema.md](schema.md).
|
|
194
|
-
|
|
195
|
-
#### forClient
|
|
196
|
-
|
|
197
|
-
If this value is truthy, parameters' `queryValues` properties will be excluded, as the client does not need them.
|
|
198
|
-
|
|
199
|
-
### Returns
|
|
200
|
-
|
|
201
|
-
An array of objects matching the format outlined in [schema.md](schema.md)
|
|
1
|
+
# utility-dashboard-backend
|
|
2
|
+
A backend utility for formatting and loading dashboard chart and report data to be usable by the [frontend dashboard component](https://github.com/ISoft-Data-Systems/ractive-component-web-dashboard).
|
|
3
|
+
|
|
4
|
+
## Installation
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm i @isoftdata/utility-dashboard-backend
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
> Breaking change in version 3: ESM style exports
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
> Version 3.Y.Z of the frontend component is required for use with version 2.Y.Z of the backend component.
|
|
14
|
+
* A MySQL database schema as outlined in [schema.md](schema.md)
|
|
15
|
+
* A backend that can fetches rows from the chart, report, and report chart tables from the database with their primary keys. Any json columns should be parsed as objects.
|
|
16
|
+
* A connection or pool of connections from the `mysql` NPM module for running the charts' queries
|
|
17
|
+
* The [dashboard Ractive component](https://github.com/ISoft-Data-Systems/ractive-component-web-dashboard) on the client
|
|
18
|
+
|
|
19
|
+
## API
|
|
20
|
+
|
|
21
|
+
### formatReportMetadata
|
|
22
|
+
|
|
23
|
+
This function returns data in the format expected for the `loadReportMetadata` function on the dashboard client component.
|
|
24
|
+
|
|
25
|
+
#### Function signature
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
async formatReportMetadata(mysqlConnection, { report, chartsInReport, session })
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
#### Example Usage (From Pro Web `server/chart-loader.js`)
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
async function loadReportMetadata({ dashboardReportId, chartId, session }) {
|
|
35
|
+
const report = await db.dashboardReport.loadById({ dashboardReportId }) // gets a report by its id
|
|
36
|
+
const chartsInReport = await db.dashboardChart.loadByReport({ dashboardReportId, chartId }) // gets all charts for a specified report, or if `chartId` is specified, only gets that chart for that report.
|
|
37
|
+
return await formatReportMetadata(db.pool, { report, chartsInReport, session })
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### mysqlConnection
|
|
42
|
+
A connection or pool of connections from the `mysql` npm module.
|
|
43
|
+
|
|
44
|
+
#### report
|
|
45
|
+
|
|
46
|
+
A report `object`, a single row from the `dashboard_report`/`wa_dashboard_report` table/view. The `parameters` Array from the `json` column should also be parsed from JSON and appended to this object.
|
|
47
|
+
|
|
48
|
+
Example:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
{
|
|
52
|
+
dashboardReportId: 1,
|
|
53
|
+
reportName: 'report_overview',
|
|
54
|
+
reportTitle: 'Overview',
|
|
55
|
+
shareType: 'everyone',
|
|
56
|
+
shareId: null,
|
|
57
|
+
ownerId: null,
|
|
58
|
+
parameters: [ // parameters deconstructed from `json` column after parsing
|
|
59
|
+
{
|
|
60
|
+
name: 'date_range',
|
|
61
|
+
type: 'dateRange',
|
|
62
|
+
title: 'Date Range',
|
|
63
|
+
default: 'This Year'
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### chartsInReport
|
|
70
|
+
|
|
71
|
+
An `Array` of chart `object`s, one for each chart in the report, multiple rows from the `dashboard_chart`/`wa_dashboard_chart` table/view joined with `dashboard_report_chart`/`wa_dashboard_report_chart` to get the chart's rank.
|
|
72
|
+
|
|
73
|
+
Example:
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
[
|
|
77
|
+
{
|
|
78
|
+
chartId: 10,
|
|
79
|
+
name: 'line_sales_over_time_and_previous_period',
|
|
80
|
+
title: 'Sales over Time',
|
|
81
|
+
supertype: 'google',
|
|
82
|
+
formatting: { Sales: [Object] },
|
|
83
|
+
multiSeries: {
|
|
84
|
+
value: 'Sales',
|
|
85
|
+
series: 'Period',
|
|
86
|
+
tooltip: 'Tooltip',
|
|
87
|
+
groupXAxisBy: 'Date'
|
|
88
|
+
},
|
|
89
|
+
chartWrapper: { options: [Object], chartType: 'LineChart' },
|
|
90
|
+
rank: 1
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
chartId: 16,
|
|
94
|
+
name: 'map_sales_by_lat_long',
|
|
95
|
+
title: 'Sales Map',
|
|
96
|
+
supertype: 'google',
|
|
97
|
+
formatting: { Sales: [Object] },
|
|
98
|
+
chartWrapper: { options: [Object], chartType: 'GeoChart' },
|
|
99
|
+
rank: 2
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### session
|
|
105
|
+
Session object from the Auth Module
|
|
106
|
+
|
|
107
|
+
#### site (optional)
|
|
108
|
+
The 'type' of site for the product this is used in. Determines the MySQL table to query for site selection parameters, and used to calculate `siteIdColumn` if that is not specified.
|
|
109
|
+
#### siteIdColumn (optional)
|
|
110
|
+
The name of the column that stores the site id in the site table. Defaults to `${site}id`.
|
|
111
|
+
#### siteNameColumn (optional)
|
|
112
|
+
The store name column.
|
|
113
|
+
|
|
114
|
+
### formatChartDataForReport
|
|
115
|
+
|
|
116
|
+
This function returns data in the format expected for the `loadChartDataForReport` function on the dashboard client component, including applying any report-specific chart options overrides and running the chart's query.
|
|
117
|
+
|
|
118
|
+
#### Function signature
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
async formatChartDataForReport(mysqlConnection, { reportParameters, chart, reportChart, parameterSelectionList, session })
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
#### Example usage: (from Pro Web `server/chart-loader.js`)
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
async function loadChartDataForReport ({ dashboardReportId, chartId, parameterSelectionList, session }) {
|
|
128
|
+
const report = await db.dashboardReport.loadById({ dashboardReportId }) // get the report object
|
|
129
|
+
const chart = await db.dashboardChart.loadById({ chartId }) // get the chart object
|
|
130
|
+
const reportChart = await db.dashboardReportChart.loadByReportAndChartId({ chartId, dashboardReportId }) // get the report chart for the rank/overrides
|
|
131
|
+
try {
|
|
132
|
+
const chartData = await formatChartDataForReport(db.pool, { reportParameters: report.parameters, chart, reportChart, parameterSelectionList, session })
|
|
133
|
+
return chartData
|
|
134
|
+
} catch (err) {
|
|
135
|
+
console.error(err)
|
|
136
|
+
return { isErrored: true }
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### mysqlConnection
|
|
142
|
+
A connection or pool of connections from the `mysql` npm module.
|
|
143
|
+
|
|
144
|
+
#### reportParameters
|
|
145
|
+
The `parameters` array from a report object.
|
|
146
|
+
|
|
147
|
+
#### chartId
|
|
148
|
+
The id of a chart row in `wa_dashboard_chart`.
|
|
149
|
+
|
|
150
|
+
#### parameterSelectionList
|
|
151
|
+
The array of selected parameters sent from the client dashboard.
|
|
152
|
+
|
|
153
|
+
#### session
|
|
154
|
+
Session object from the Auth Module
|
|
155
|
+
|
|
156
|
+
### loadOutputParameterValues
|
|
157
|
+
|
|
158
|
+
This function outputs the report's parameter values in the format expected by the dashboard client and backend. When sending to the client, including `forClient: true` will not include the properties only needed by the backend.
|
|
159
|
+
|
|
160
|
+
### Function signature
|
|
161
|
+
|
|
162
|
+
```js
|
|
163
|
+
async function loadOutputParameterValues(mysqlConnection, { definitionList, selectionList = [], forClient = false })
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### Example Usage
|
|
167
|
+
|
|
168
|
+
#### mysqlConnection
|
|
169
|
+
A connection or pool of connections from the `mysql` npm module.
|
|
170
|
+
|
|
171
|
+
#### definitionList
|
|
172
|
+
|
|
173
|
+
The `parameters` property from the `json` column of a row in the `dashboard_report` table.
|
|
174
|
+
|
|
175
|
+
#### selectionList
|
|
176
|
+
|
|
177
|
+
An array of objects representing the selected parameters sent from the client. Only needed when loading the chart data, not when loading the report "metadata". Each parameter object should match the format specified in [schema.md](schema.md).
|
|
178
|
+
|
|
179
|
+
#### forClient
|
|
180
|
+
|
|
181
|
+
If this value is truthy, parameters' `queryValues` properties will be excluded, as the client does not need them.
|
|
182
|
+
|
|
183
|
+
### Returns
|
|
184
|
+
|
|
185
|
+
An array of objects matching the format outlined in [schema.md](schema.md)
|
package/dist/chart-helper.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Formatting, GoogleDataTable, MultiSeriesOptions, ProcessedFormatting, Table } from './types/chart
|
|
3
|
-
export type FieldType = 'string' | 'number' | 'datetime' | 'timeofday' | 'date'
|
|
1
|
+
import { DatabaseConnectionInterface, QueryCommand, RowDataPacket } from '@isoftdata/utility-db';
|
|
2
|
+
import type { Formatting, GoogleDataTable, MultiSeriesOptions, ProcessedFormatting, Table } from './types/chart';
|
|
3
|
+
export type FieldType = 'string' | 'number' | 'datetime' | 'timeofday' | 'date';
|
|
4
4
|
export type QueryFieldsObject = Record<string, FieldType>;
|
|
5
|
-
export declare function queryWithFields(connection:
|
|
6
|
-
|
|
7
|
-
values: unknown[];
|
|
8
|
-
}): Promise<{
|
|
9
|
-
results: RowDataPacket[];
|
|
5
|
+
export declare function queryWithFields(connection: DatabaseConnectionInterface, query: QueryCommand): Promise<{
|
|
6
|
+
results: object[];
|
|
10
7
|
fields: QueryFieldsObject;
|
|
11
8
|
}>;
|
|
12
9
|
export type getMultiSeriesDataInput = {
|
|
@@ -25,7 +22,6 @@ export declare function coerceNullColumn(columnProp: string, data: RowDataPacket
|
|
|
25
22
|
export declare function handleFormattingTemplates(formatting?: Formatting): ProcessedFormatting;
|
|
26
23
|
export declare function getDataTableFormat(data: RowDataPacket[], fields: QueryFieldsObject, multiSeries?: MultiSeriesOptions): GoogleDataTable;
|
|
27
24
|
export declare function makeDataCumulative(dataTable: GoogleDataTable, cumulative?: boolean): GoogleDataTable;
|
|
28
|
-
export declare function
|
|
25
|
+
export declare function getRactiveTableDataFormat(rows: RowDataPacket[], fields: {
|
|
29
26
|
[key: string]: string;
|
|
30
27
|
}, formatting: ProcessedFormatting, styleTemplates?: {}): Table;
|
|
31
|
-
export { getSvelteDataTableFormat as getRactiveDataTableFormat };
|