@isoftdata/utility-dashboard-backend 2.0.2 → 2.1.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/schema.md DELETED
@@ -1,125 +0,0 @@
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
- #### Base 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 Parameters
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 Parameters
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 Parameters
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). If the user passes a value that isn't in the `optionList`, the first option in the array will be used instead.
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`. The `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. Values are [escaped by the mysql library](https://github.com/mysqljs/mysql#escaping-query-values), unless `rawSql: true` is on an option's object.
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
- ##### `session` Type Parameters
49
- > These parameters are not shown in the UI since they do not require or allow user input.
50
-
51
- The `name` property is camel cased and used to access the variable from the session object.
52
-
53
- #### Example
54
- 'dashboard_report_id' | 'report_name' | 'report_title' | 'json' | 'share_type' | 'share_id' | 'owner_id'
55
- -- | ---- | ---- | ------- | -- | -- | --
56
- 1 | report_overview | Overview | `{"parameters": [{"name": "date_range", "type": "dateRange", "title": "Date Range", "default": "This Year"}]}` | everyone | `NULL` | `NULL`
57
- 2 | shared_report | Shared Report | `{"parameters":[{"name":"date_range","type":"dateRange","title":"Date Range","default":"This Month"}]}` | user | 1 | 2
58
-
59
- ### Defining a Chart
60
- 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.
61
-
62
- ### Chart Database Row - `dashboard_chart`
63
- Property | Type | Description
64
- ---- | ---- | -----------
65
- chart_id | `Unsigned integer` | **Required** - primary key. Auto incremented.
66
- chart_name | `String` | **Required** - a unique name for the chart
67
- chart_title | `String` | When rendered, this title will be displayed at the top of the card. If omitted, `name` will be used.
68
- supertype | `Enum` | **Required** - designates how the chart should be loaded. Options include `google`, `table`, and `embed`. Defaults to `google`.
69
- 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).
70
- 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`.
71
-
72
- #### MultiSeries Object
73
- Property | Type | Description
74
- ---- | ---- | -----------
75
- groupXAxisBy | `String` | **Required** - The name of the query column that determines the X axis of the chart.
76
- series | `String` | **Required** - The name of the query column that determines which series a query row corresponds to.
77
- value | `String` | **Required** - The namem of the query column that contains the value for that data point.
78
- 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.
79
-
80
- #### Formatting Object
81
- An object whose property names are the columns in the query to be formatted. Currently only currency formatting is supported.
82
-
83
- Property | Type | Description
84
- ---- | ---- | ---------
85
- type | `String` | The name of a [Google Charts Formatter](https://developers.google.com/chart/interactive/docs/reference?hl=en#formatters).
86
- format | `String` | The name of a formatter template, defined in `formatter-templates.json`.
87
- #### JSON Example
88
-
89
- ```json
90
- {
91
- "chartWrapper": {
92
- "chartType": "AreaChart",
93
- "options": {
94
- "isStacked": true,
95
- "width": 1000,
96
- "height": 1000
97
- }
98
- },
99
- "multiSeries": {
100
- "groupXAxisBy": "Date",
101
- "series": "Part Type",
102
- "value": "Sales",
103
- "tooltip": "Tooltip"
104
- },
105
- "formatting": {
106
- "Sales": {
107
- "type": "NumberFormat",
108
- "format": "CURRENCY"
109
- }
110
- },
111
- "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;"
112
- }
113
- ```
114
-
115
- ### Adding charts to reports
116
- 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.
117
-
118
- ### Report Chart Database Row - `dashboard_report_chart`
119
- Property | Type | Description
120
- ---- | ---- | --------
121
- report_chart_id | `Unsigned integer` | **Required** - Primary key. Auto incremented.
122
- dashboard_report_id | `Unsigned integer` | **Required** - Foreign key constraint with `dashboard_report.dashboard_report_id`.
123
- 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.
124
- rank | `Unsigned integer` | The order to display the chart in on the report. Defaults to 1.
125
- 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,31 +0,0 @@
1
-
2
- const mathjs = require('mathjs')
3
- const snakecaseKeys = require('snakecase-keys')
4
-
5
- function handleMathJsCellStyleTemplate(row, columnToStyle, templates) {
6
- let outColumn = { value: row[columnToStyle] }
7
- if (columnToStyle in templates) {
8
- // MathJS mutates the object you pass it, and we need to ensure keys are single "word" strings, so snakeize a copy of the row
9
- const scope = snakecaseKeys({ ...row }, { deep: true })
10
- for (const key in templates[columnToStyle]) {
11
- try {
12
- outColumn[key] = mathjs.evaluate(templates[columnToStyle][key], scope)
13
- } catch (err) {
14
- // Obviously we don't want to break the whole table if one cell has a bad template
15
- // For now, just log it to stderr and allow it to fall through even though it's not super debuggable
16
- console.error(`Error evaluating expression: '${templates[columnToStyle][key]}'\n`, err)
17
- }
18
- }
19
- }
20
- return outColumn
21
- }
22
-
23
- function styleRow(row, templates) {
24
- const outRow = {}
25
- for (const column in row) {
26
- outRow[column] = handleMathJsCellStyleTemplate(row, column, templates)
27
- }
28
- return outRow
29
- }
30
-
31
- module.exports = styleRow
package/stylingTest.jsonc DELETED
@@ -1,37 +0,0 @@
1
- {
2
- "query": "SELECT 'False' AS 'Seller Invoice', 'True' AS 'Rec. Payment', '' AS 'Paid For'",
3
- "formatting": {},
4
- "chartWrapper": {
5
- "options": {
6
- "width": 500,
7
- "height": 500,
8
- "width_units": "%"
9
- },
10
- "chartType": "Table"
11
- },
12
- "greedyWidth": true,
13
- "greedyHeight": true,
14
- "hideTitle": true,
15
- "table": {
16
- "perPageCount": 15,
17
- "showFooter": true,
18
- "allowExport": true,
19
- "style": {
20
- "Seller Invoice": { // Column to style
21
- "columnToCheck": false, // column to check condition against, falsy = this column
22
- "in": [ // value is in the set
23
- "False",
24
- ""
25
- ],
26
- "class": "table-danger" // class to apply
27
- },
28
- "Rec. Payment": { // Column to style
29
- "columnToCheck": "Paid For", // column to check condition against
30
- "notIn": [ // value is not in the set
31
- ""
32
- ],
33
- "class": "table-danger" // class to apply
34
- }
35
- },
36
- }
37
- }