@isoftdata/utility-dashboard-backend 1.3.0 → 1.4.1
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 +164 -164
- package/chart-helper.js +254 -254
- package/formatter-templates.json +14 -8
- package/index.js +208 -208
- package/package.json +19 -19
- package/schema.md +120 -120
package/schema.md
CHANGED
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
## Reporting/Charting
|
|
2
|
-
The dashboard component has a set of three database tables where reports, charts, and their associations are defined: `dashboard_report`, `dashboard_chart`, and `dashboard_report_chart`. Reports are a collection of various charts. Reports have parameters and charts can use said parameters. Currently Charts are rendered using [Google Charts](https://developers.google.com/chart/).
|
|
3
|
-
|
|
4
|
-
### Defining a Report
|
|
5
|
-
Reports can be created either with the frontend dashboard component or manually in the database. The frontend component supports setting the report's name, the charts contained within it, who it is shared with, and the default value of any parameters. Currently it is not possible to add or remove parameters for reports within the frontend component, as charts' queries also have to support any additional parameters.
|
|
6
|
-
|
|
7
|
-
### Report Database Row - `dashboard_report`
|
|
8
|
-
Property | Type | Description
|
|
9
|
-
---- | ---- | -----------
|
|
10
|
-
dashboard_report_id | `Unsigned integer` | **Required** - Primary key. Auto incremented.
|
|
11
|
-
report_name | `String` | **Required** - a unique name for the report.
|
|
12
|
-
report_title | `String` | When rendered, this title will be displayed at the top of the card. If omitted, `name` will be used.
|
|
13
|
-
json | `JSON` | Should be parsed into a JS object. This field contains JSON for an array of parameter objects, the format of which is detailed below.
|
|
14
|
-
share_type | `Enum` | Controls access to reports within the dashboard. Possible values include: `everyone`, `group`, `store`, and `user`. Defaults to `everyone`.
|
|
15
|
-
share_id | `Unsigned integer` | Used in conjunction with `share_type` to control access to reports. When `share_type` is 'everyone', this field is null. Otherwise, it contains the id of the user, group, or store to share the report with. Defaults to `NULL`.
|
|
16
|
-
owner_id | `Unsigned integer` | The `user_account_id` of the user who created the report in the dashboard. This user will always have access to the given report, regardless of its sharing settings, and will be shown as the report owner on the configuration screen. Defaults to `NULL`, which designates it as a default report.
|
|
17
|
-
|
|
18
|
-
#### Parameter Object
|
|
19
|
-
Property | Type | Description
|
|
20
|
-
---- | ---- | -----------
|
|
21
|
-
name | `String` | **Required** - a unique name for the parameter. This name is also used to reference param in a query.
|
|
22
|
-
title | `String` | This is used to label the parameter for the user.
|
|
23
|
-
type | `String` | Can be one of `dateRange`, `date`, or `selection`. See the tables below for parameter-type-specific properties
|
|
24
|
-
|
|
25
|
-
##### `dateRange` Type Properties
|
|
26
|
-
> In the UI, the user will see a dropdown with the possible date range values(see `default` description below).
|
|
27
|
-
|
|
28
|
-
Property | Type | Description
|
|
29
|
-
---- | ---- | -----------
|
|
30
|
-
default | `String` | One of the following values: `'Today'`, `'Yesterday'`, `'Last 7 Days'`, `'Last 30 Days'`, `'Last 90 Days'`, `'Last 365 Days'`, `'This Week'`, `'This Month'`, `'This Quarter'`, `'This Year'`, `'Previous Week'`, `'Previous Month'`, `'Previous Quarter'`, or `'Previous Year'`. If the `default` property is omitted or [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), `'Last 30 Days'` will be used.
|
|
31
|
-
|
|
32
|
-
##### `date` Type Properties
|
|
33
|
-
> In the UI, the user will see a dropdown with a date picker.
|
|
34
|
-
|
|
35
|
-
Property | Type | Description
|
|
36
|
-
---- | ---- | -----------
|
|
37
|
-
default | `String` | Can be an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date string(eg. `'2021-01-13'`). If the `default` property is omitted or [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), the today's date will be used.
|
|
38
|
-
|
|
39
|
-
##### `selection` Type properties
|
|
40
|
-
> In the UI, the user will see a dropdown with the `optionList` values(if any) and the values returned from the `optionListQuery`(if any).
|
|
41
|
-
|
|
42
|
-
Property | Type | Description
|
|
43
|
-
---- | ---- | -----------
|
|
44
|
-
default | `String` | The `id` of the option you'd like to be selected by default
|
|
45
|
-
optionList | `Object` | Each object should have an `id`, and `name`. `id` is the value that will be given to you at query time and `name` is what will be displayed in the dropdown to the user.
|
|
46
|
-
optionListQuery | `String` | A query that selects 2 columns `id` and `name`. The results of this query will be merged with `optionList` and put in the dropdown for the user.
|
|
47
|
-
|
|
48
|
-
#### Example
|
|
49
|
-
'dashboard_report_id' | 'report_name' | 'report_title' | 'json' | 'share_type' | 'share_id' | 'owner_id'
|
|
50
|
-
-- | ---- | ---- | ------- | -- | -- | --
|
|
51
|
-
1 | report_overview | Overview | `{"parameters": [{"name": "date_range", "type": "dateRange", "title": "Date Range", "default": "This Year"}]}` | everyone | `NULL` | `NULL`
|
|
52
|
-
2 | shared_report | Shared Report | `{"parameters":[{"name":"date_range","type":"dateRange","title":"Date Range","default":"This Month"}]}` | user | 1 | 2
|
|
53
|
-
|
|
54
|
-
### Defining a Chart
|
|
55
|
-
Currently, charts cannot be defined within Pro web, and must be created in the database table `dashboard_chart`. Currently, 19 charts are defined, but some are set to not show as options in the user interface.
|
|
56
|
-
|
|
57
|
-
### Chart Database Row - `dashboard_chart`
|
|
58
|
-
Property | Type | Description
|
|
59
|
-
---- | ---- | -----------
|
|
60
|
-
chart_id | `Unsigned integer` | **Required** - primary key. Auto incremented.
|
|
61
|
-
chart_name | `String` | **Required** - a unique name for the chart
|
|
62
|
-
chart_title | `String` | When rendered, this title will be displayed at the top of the card. If omitted, `name` will be used.
|
|
63
|
-
supertype | `Enum` | **Required** - designates how the chart should be loaded. Options include `google`, `table`, and `embed`. Defaults to `google`.
|
|
64
|
-
json | `json` | Should be parsed to a JS object on the server. Contains several properties: `query` (string, **required**), [`chartWrapper`](https://developers.google.com/chart/interactive/docs/reference#chartwrapper-class) (object, **required** for Google charts), `multiSeries` (object, **required** for multi-series charts), `formatting` (object).
|
|
65
|
-
show_chart | `Bit` | **Required** - Should be cast as a boolean on the server. Whether or not to show a chart in the configuration UI. Defaults to `1`.
|
|
66
|
-
|
|
67
|
-
#### MultiSeries Object
|
|
68
|
-
Property | Type | Description
|
|
69
|
-
---- | ---- | -----------
|
|
70
|
-
groupXAxisBy | `String` | **Required** - The name of the query column that determines the X axis of the chart.
|
|
71
|
-
series | `String` | **Required** - The name of the query column that determines which series a query row corresponds to.
|
|
72
|
-
value | `String` | **Required** - The namem of the query column that contains the value for that data point.
|
|
73
|
-
tooltip | `String` | The name of the (optional) query column that contains a custom plaintext tooltip, which replaces the default Google Charts tooltip. Does not work for Tree Map type charts, which have special tooltip requirements.
|
|
74
|
-
|
|
75
|
-
#### Formatting Object
|
|
76
|
-
An object whose property names are the columns in the query to be formatted. Currently only currency formatting is supported.
|
|
77
|
-
|
|
78
|
-
Property | Type | Description
|
|
79
|
-
---- | ---- | ---------
|
|
80
|
-
type | `String` | The name of a [Google Charts Formatter](https://developers.google.com/chart/interactive/docs/reference?hl=en#formatters).
|
|
81
|
-
format | `String` | The name of a formatter template, defined in `formatter-templates.json`.
|
|
82
|
-
#### JSON Example
|
|
83
|
-
|
|
84
|
-
```json
|
|
85
|
-
{
|
|
86
|
-
"chartWrapper": {
|
|
87
|
-
"chartType": "AreaChart",
|
|
88
|
-
"options": {
|
|
89
|
-
"isStacked": true,
|
|
90
|
-
"width": 1000,
|
|
91
|
-
"height": 1000
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
"multiSeries": {
|
|
95
|
-
"groupXAxisBy": "Date",
|
|
96
|
-
"series": "Part Type",
|
|
97
|
-
"value": "Sales",
|
|
98
|
-
"tooltip": "Tooltip"
|
|
99
|
-
},
|
|
100
|
-
"formatting": {
|
|
101
|
-
"Sales": {
|
|
102
|
-
"type": "NumberFormat",
|
|
103
|
-
"format": "CURRENCY"
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
"query": "SELECT t.date AS `Date`,\r\n IFNULL (t.part_type, 'Misc. Lineitems') AS `Part Type`,\r\n ROUND(@running_total:=@running_total + t.sales, 2) AS `Sales`\r\nFROM\r\n(SELECT \r\n`wa_sale`.`document_date` AS `Date`,\r\nIF(wa_sale_line.part_type = '', 'Misc. Lineitems', wa_sale_line.part_type) AS `part_type`,\r\nFORMAT(SUM(wa_sale_line.quantity * `wa_sale_line`.`price`), 2) AS `sales`\r\nFROM \r\n`wa_sale_line`\r\nINNER JOIN `wa_sale` USING(`sale_id`)\r\nWHERE\r\n`wa_sale`.`status` = 'Invoice' AND wa_sale.document_date IS NOT NULL\r\n GROUP BY \r\n `wa_sale`.`document_date`, `wa_sale_line`.`part_type`) t\r\n JOIN (SELECT @running_total:=0) r\r\n ORDER BY t.Date;"
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### Adding charts to reports
|
|
111
|
-
Adding charts to reports can be handled entirely within the dashboard component. Each row in the database table `dashboard_report_chart` defines the association of one chart to one report, the rank of the chart within the report, and any additional object properties to apply to the chart when displayed in that report.
|
|
112
|
-
|
|
113
|
-
### Report Chart Database Row - `dashboard_report_chart`
|
|
114
|
-
Property | Type | Description
|
|
115
|
-
---- | ---- | --------
|
|
116
|
-
report_chart_id | `Unsigned integer` | **Required** - Primary key. Auto incremented.
|
|
117
|
-
dashboard_report_id | `Unsigned integer` | **Required** - Foreign key constraint with `dashboard_report.dashboard_report_id`.
|
|
118
|
-
chart_id | `Unsigned integer` | **Required** - Foreign key constraint with `dashboard_chart.dashboad_chart_id`. `chart_id` and `dashboard_report_id` must be a unique pair.
|
|
119
|
-
rank | `Unsigned integer` | The order to display the chart in on the report. Defaults to 1.
|
|
120
|
-
json_override | `Text` | Parsed as JSON on the server. Contains any JSON properties to be applied to the chart for the given report, overriding any of the same property on the base chart. Primarily used for chartWarpper options. Default `NULL`.
|
|
1
|
+
## Reporting/Charting
|
|
2
|
+
The dashboard component has a set of three database tables where reports, charts, and their associations are defined: `dashboard_report`, `dashboard_chart`, and `dashboard_report_chart`. Reports are a collection of various charts. Reports have parameters and charts can use said parameters. Currently Charts are rendered using [Google Charts](https://developers.google.com/chart/).
|
|
3
|
+
|
|
4
|
+
### Defining a Report
|
|
5
|
+
Reports can be created either with the frontend dashboard component or manually in the database. The frontend component supports setting the report's name, the charts contained within it, who it is shared with, and the default value of any parameters. Currently it is not possible to add or remove parameters for reports within the frontend component, as charts' queries also have to support any additional parameters.
|
|
6
|
+
|
|
7
|
+
### Report Database Row - `dashboard_report`
|
|
8
|
+
Property | Type | Description
|
|
9
|
+
---- | ---- | -----------
|
|
10
|
+
dashboard_report_id | `Unsigned integer` | **Required** - Primary key. Auto incremented.
|
|
11
|
+
report_name | `String` | **Required** - a unique name for the report.
|
|
12
|
+
report_title | `String` | When rendered, this title will be displayed at the top of the card. If omitted, `name` will be used.
|
|
13
|
+
json | `JSON` | Should be parsed into a JS object. This field contains JSON for an array of parameter objects, the format of which is detailed below.
|
|
14
|
+
share_type | `Enum` | Controls access to reports within the dashboard. Possible values include: `everyone`, `group`, `store`, and `user`. Defaults to `everyone`.
|
|
15
|
+
share_id | `Unsigned integer` | Used in conjunction with `share_type` to control access to reports. When `share_type` is 'everyone', this field is null. Otherwise, it contains the id of the user, group, or store to share the report with. Defaults to `NULL`.
|
|
16
|
+
owner_id | `Unsigned integer` | The `user_account_id` of the user who created the report in the dashboard. This user will always have access to the given report, regardless of its sharing settings, and will be shown as the report owner on the configuration screen. Defaults to `NULL`, which designates it as a default report.
|
|
17
|
+
|
|
18
|
+
#### Parameter Object
|
|
19
|
+
Property | Type | Description
|
|
20
|
+
---- | ---- | -----------
|
|
21
|
+
name | `String` | **Required** - a unique name for the parameter. This name is also used to reference param in a query.
|
|
22
|
+
title | `String` | This is used to label the parameter for the user.
|
|
23
|
+
type | `String` | Can be one of `dateRange`, `date`, or `selection`. See the tables below for parameter-type-specific properties
|
|
24
|
+
|
|
25
|
+
##### `dateRange` Type Properties
|
|
26
|
+
> In the UI, the user will see a dropdown with the possible date range values(see `default` description below).
|
|
27
|
+
|
|
28
|
+
Property | Type | Description
|
|
29
|
+
---- | ---- | -----------
|
|
30
|
+
default | `String` | One of the following values: `'Today'`, `'Yesterday'`, `'Last 7 Days'`, `'Last 30 Days'`, `'Last 90 Days'`, `'Last 365 Days'`, `'This Week'`, `'This Month'`, `'This Quarter'`, `'This Year'`, `'Previous Week'`, `'Previous Month'`, `'Previous Quarter'`, or `'Previous Year'`. If the `default` property is omitted or [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), `'Last 30 Days'` will be used.
|
|
31
|
+
|
|
32
|
+
##### `date` Type Properties
|
|
33
|
+
> In the UI, the user will see a dropdown with a date picker.
|
|
34
|
+
|
|
35
|
+
Property | Type | Description
|
|
36
|
+
---- | ---- | -----------
|
|
37
|
+
default | `String` | Can be an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date string(eg. `'2021-01-13'`). If the `default` property is omitted or [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), the today's date will be used.
|
|
38
|
+
|
|
39
|
+
##### `selection` Type properties
|
|
40
|
+
> In the UI, the user will see a dropdown with the `optionList` values(if any) and the values returned from the `optionListQuery`(if any).
|
|
41
|
+
|
|
42
|
+
Property | Type | Description
|
|
43
|
+
---- | ---- | -----------
|
|
44
|
+
default | `String` | The `id` of the option you'd like to be selected by default
|
|
45
|
+
optionList | `Object` | Each object should have an `id`, and `name`. `id` is the value that will be given to you at query time and `name` is what will be displayed in the dropdown to the user.
|
|
46
|
+
optionListQuery | `String` | A query that selects 2 columns `id` and `name`. The results of this query will be merged with `optionList` and put in the dropdown for the user.
|
|
47
|
+
|
|
48
|
+
#### Example
|
|
49
|
+
'dashboard_report_id' | 'report_name' | 'report_title' | 'json' | 'share_type' | 'share_id' | 'owner_id'
|
|
50
|
+
-- | ---- | ---- | ------- | -- | -- | --
|
|
51
|
+
1 | report_overview | Overview | `{"parameters": [{"name": "date_range", "type": "dateRange", "title": "Date Range", "default": "This Year"}]}` | everyone | `NULL` | `NULL`
|
|
52
|
+
2 | shared_report | Shared Report | `{"parameters":[{"name":"date_range","type":"dateRange","title":"Date Range","default":"This Month"}]}` | user | 1 | 2
|
|
53
|
+
|
|
54
|
+
### Defining a Chart
|
|
55
|
+
Currently, charts cannot be defined within Pro web, and must be created in the database table `dashboard_chart`. Currently, 19 charts are defined, but some are set to not show as options in the user interface.
|
|
56
|
+
|
|
57
|
+
### Chart Database Row - `dashboard_chart`
|
|
58
|
+
Property | Type | Description
|
|
59
|
+
---- | ---- | -----------
|
|
60
|
+
chart_id | `Unsigned integer` | **Required** - primary key. Auto incremented.
|
|
61
|
+
chart_name | `String` | **Required** - a unique name for the chart
|
|
62
|
+
chart_title | `String` | When rendered, this title will be displayed at the top of the card. If omitted, `name` will be used.
|
|
63
|
+
supertype | `Enum` | **Required** - designates how the chart should be loaded. Options include `google`, `table`, and `embed`. Defaults to `google`.
|
|
64
|
+
json | `json` | Should be parsed to a JS object on the server. Contains several properties: `query` (string, **required**), [`chartWrapper`](https://developers.google.com/chart/interactive/docs/reference#chartwrapper-class) (object, **required** for Google charts), `multiSeries` (object, **required** for multi-series charts), `formatting` (object).
|
|
65
|
+
show_chart | `Bit` | **Required** - Should be cast as a boolean on the server. Whether or not to show a chart in the configuration UI. Defaults to `1`.
|
|
66
|
+
|
|
67
|
+
#### MultiSeries Object
|
|
68
|
+
Property | Type | Description
|
|
69
|
+
---- | ---- | -----------
|
|
70
|
+
groupXAxisBy | `String` | **Required** - The name of the query column that determines the X axis of the chart.
|
|
71
|
+
series | `String` | **Required** - The name of the query column that determines which series a query row corresponds to.
|
|
72
|
+
value | `String` | **Required** - The namem of the query column that contains the value for that data point.
|
|
73
|
+
tooltip | `String` | The name of the (optional) query column that contains a custom plaintext tooltip, which replaces the default Google Charts tooltip. Does not work for Tree Map type charts, which have special tooltip requirements.
|
|
74
|
+
|
|
75
|
+
#### Formatting Object
|
|
76
|
+
An object whose property names are the columns in the query to be formatted. Currently only currency formatting is supported.
|
|
77
|
+
|
|
78
|
+
Property | Type | Description
|
|
79
|
+
---- | ---- | ---------
|
|
80
|
+
type | `String` | The name of a [Google Charts Formatter](https://developers.google.com/chart/interactive/docs/reference?hl=en#formatters).
|
|
81
|
+
format | `String` | The name of a formatter template, defined in `formatter-templates.json`.
|
|
82
|
+
#### JSON Example
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"chartWrapper": {
|
|
87
|
+
"chartType": "AreaChart",
|
|
88
|
+
"options": {
|
|
89
|
+
"isStacked": true,
|
|
90
|
+
"width": 1000,
|
|
91
|
+
"height": 1000
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"multiSeries": {
|
|
95
|
+
"groupXAxisBy": "Date",
|
|
96
|
+
"series": "Part Type",
|
|
97
|
+
"value": "Sales",
|
|
98
|
+
"tooltip": "Tooltip"
|
|
99
|
+
},
|
|
100
|
+
"formatting": {
|
|
101
|
+
"Sales": {
|
|
102
|
+
"type": "NumberFormat",
|
|
103
|
+
"format": "CURRENCY"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"query": "SELECT t.date AS `Date`,\r\n IFNULL (t.part_type, 'Misc. Lineitems') AS `Part Type`,\r\n ROUND(@running_total:=@running_total + t.sales, 2) AS `Sales`\r\nFROM\r\n(SELECT \r\n`wa_sale`.`document_date` AS `Date`,\r\nIF(wa_sale_line.part_type = '', 'Misc. Lineitems', wa_sale_line.part_type) AS `part_type`,\r\nFORMAT(SUM(wa_sale_line.quantity * `wa_sale_line`.`price`), 2) AS `sales`\r\nFROM \r\n`wa_sale_line`\r\nINNER JOIN `wa_sale` USING(`sale_id`)\r\nWHERE\r\n`wa_sale`.`status` = 'Invoice' AND wa_sale.document_date IS NOT NULL\r\n GROUP BY \r\n `wa_sale`.`document_date`, `wa_sale_line`.`part_type`) t\r\n JOIN (SELECT @running_total:=0) r\r\n ORDER BY t.Date;"
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Adding charts to reports
|
|
111
|
+
Adding charts to reports can be handled entirely within the dashboard component. Each row in the database table `dashboard_report_chart` defines the association of one chart to one report, the rank of the chart within the report, and any additional object properties to apply to the chart when displayed in that report.
|
|
112
|
+
|
|
113
|
+
### Report Chart Database Row - `dashboard_report_chart`
|
|
114
|
+
Property | Type | Description
|
|
115
|
+
---- | ---- | --------
|
|
116
|
+
report_chart_id | `Unsigned integer` | **Required** - Primary key. Auto incremented.
|
|
117
|
+
dashboard_report_id | `Unsigned integer` | **Required** - Foreign key constraint with `dashboard_report.dashboard_report_id`.
|
|
118
|
+
chart_id | `Unsigned integer` | **Required** - Foreign key constraint with `dashboard_chart.dashboad_chart_id`. `chart_id` and `dashboard_report_id` must be a unique pair.
|
|
119
|
+
rank | `Unsigned integer` | The order to display the chart in on the report. Defaults to 1.
|
|
120
|
+
json_override | `Text` | Parsed as JSON on the server. Contains any JSON properties to be applied to the chart for the given report, overriding any of the same property on the base chart. Primarily used for chartWarpper options. Default `NULL`.
|