@nocobase/plugin-data-visualization 1.0.0-alpha.13 → 1.0.0-alpha.15

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.
@@ -8,13 +8,13 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "1.0.0-alpha.13",
11
+ "@nocobase/client": "1.0.0-alpha.15",
12
12
  "dayjs": "1.11.10",
13
13
  "@formily/react": "2.3.0",
14
14
  "@formily/shared": "2.3.0",
15
15
  "lodash": "4.17.21",
16
- "@nocobase/cache": "1.0.0-alpha.13",
17
- "@nocobase/server": "1.0.0-alpha.13",
16
+ "@nocobase/cache": "1.0.0-alpha.15",
17
+ "@nocobase/server": "1.0.0-alpha.15",
18
18
  "react": "18.2.0",
19
19
  "@ant-design/icons": "5.2.6",
20
20
  "ahooks": "3.7.8",
@@ -22,8 +22,9 @@ module.exports = {
22
22
  "antd": "5.12.8",
23
23
  "@formily/antd-v5": "1.1.9",
24
24
  "@formily/core": "2.3.0",
25
- "@nocobase/utils": "1.0.0-alpha.13",
25
+ "@nocobase/utils": "1.0.0-alpha.15",
26
26
  "react-i18next": "11.18.6",
27
- "@nocobase/actions": "1.0.0-alpha.13",
28
- "@nocobase/database": "1.0.0-alpha.13"
27
+ "sequelize": "6.35.2",
28
+ "@nocobase/actions": "1.0.0-alpha.15",
29
+ "@nocobase/database": "1.0.0-alpha.15"
29
30
  };
@@ -1 +1 @@
1
- {"name":"koa-compose","description":"compose Koa middleware","repository":"koajs/compose","version":"4.1.0","keywords":["koa","middleware","compose"],"files":["index.js"],"dependencies":{},"devDependencies":{"codecov":"^3.0.0","jest":"^21.0.0","matcha":"^0.7.0","standard":"^10.0.3"},"scripts":{"bench":"matcha bench/bench.js","lint":"standard --fix .","test":"jest --forceExit --coverage"},"jest":{"testEnvironment":"node"},"license":"MIT","_lastModified":"2024-05-14T09:28:18.166Z"}
1
+ {"name":"koa-compose","description":"compose Koa middleware","repository":"koajs/compose","version":"4.1.0","keywords":["koa","middleware","compose"],"files":["index.js"],"dependencies":{},"devDependencies":{"codecov":"^3.0.0","jest":"^21.0.0","matcha":"^0.7.0","standard":"^10.0.3"},"scripts":{"bench":"matcha bench/bench.js","lint":"standard --fix .","test":"jest --forceExit --coverage"},"jest":{"testEnvironment":"node"},"license":"MIT","_lastModified":"2024-05-21T03:00:54.874Z"}
@@ -6,6 +6,7 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- export declare const dateFormatFn: (sequelize: any, dialect: string, field: string, format: string) => any;
10
- export declare const formatFn: (sequelize: any, dialect: string, field: string, format: string) => any;
11
- export declare const formatter: (sequelize: any, type: string, field: string, format: string) => any;
9
+ import { Sequelize } from 'sequelize';
10
+ export declare const dateFormatFn: (sequelize: Sequelize, dialect: string, field: string, format: string, timezone?: string) => import("sequelize/types/utils").Col | import("sequelize/types/utils").Fn;
11
+ export declare const formatFn: (sequelize: Sequelize, dialect: string, field: string, format: string) => string | import("sequelize/types/utils").Fn;
12
+ export declare const formatter: (sequelize: Sequelize, type: string, field: string, format: string, timezone?: string) => string | import("sequelize/types/utils").Col | import("sequelize/types/utils").Fn;
@@ -31,17 +31,42 @@ __export(formatter_exports, {
31
31
  formatter: () => formatter
32
32
  });
33
33
  module.exports = __toCommonJS(formatter_exports);
34
- const dateFormatFn = (sequelize, dialect, field, format) => {
34
+ const getOffsetMinutesFromTimezone = (timezone) => {
35
+ const sign = timezone.charAt(0);
36
+ timezone = timezone.slice(1);
37
+ const [hours, minutes] = timezone.split(":");
38
+ const hoursNum = Number(hours);
39
+ const minutesNum = Number(minutes);
40
+ const offset = hoursNum * 60 + minutesNum;
41
+ return `${sign}${offset} minutes`;
42
+ };
43
+ const dateFormatFn = (sequelize, dialect, field, format, timezone) => {
35
44
  switch (dialect) {
36
45
  case "sqlite":
37
46
  format = format.replace(/YYYY/g, "%Y").replace(/MM/g, "%m").replace(/DD/g, "%d").replace(/hh/g, "%H").replace(/mm/g, "%M").replace(/ss/g, "%S");
47
+ if (timezone) {
48
+ return sequelize.fn("strftime", format, sequelize.col(field), getOffsetMinutesFromTimezone(timezone));
49
+ }
38
50
  return sequelize.fn("strftime", format, sequelize.col(field));
39
51
  case "mysql":
40
52
  case "mariadb":
41
53
  format = format.replace(/YYYY/g, "%Y").replace(/MM/g, "%m").replace(/DD/g, "%d").replace(/hh/g, "%H").replace(/mm/g, "%i").replace(/ss/g, "%S");
54
+ if (timezone) {
55
+ return sequelize.fn(
56
+ "date_format",
57
+ sequelize.fn("convert_tz", sequelize.col(field), process.env.DB_TIMEZONE || "+00:00", timezone),
58
+ format
59
+ );
60
+ }
42
61
  return sequelize.fn("date_format", sequelize.col(field), format);
43
62
  case "postgres":
44
63
  format = format.replace(/hh/g, "HH24").replace(/mm/g, "MI").replace(/ss/g, "SS");
64
+ if (timezone) {
65
+ const fieldWithTZ = sequelize.literal(
66
+ `(${sequelize.getQueryInterface().quoteIdentifiers(field)} AT TIME ZONE CURRENT_SETTING('TIMEZONE') AT TIME ZONE '${timezone}')`
67
+ );
68
+ return sequelize.fn("to_char", fieldWithTZ, format);
69
+ }
45
70
  return sequelize.fn("to_char", sequelize.col(field), format);
46
71
  default:
47
72
  return sequelize.col(field);
@@ -57,13 +82,13 @@ const formatFn = (sequelize, dialect, field, format) => {
57
82
  return field;
58
83
  }
59
84
  };
60
- const formatter = (sequelize, type, field, format) => {
85
+ const formatter = (sequelize, type, field, format, timezone) => {
61
86
  const dialect = sequelize.getDialect();
62
87
  switch (type) {
63
88
  case "date":
64
89
  case "datetime":
65
90
  case "time":
66
- return dateFormatFn(sequelize, dialect, field, format);
91
+ return dateFormatFn(sequelize, dialect, field, format, timezone);
67
92
  default:
68
93
  return formatFn(sequelize, dialect, field, format);
69
94
  }
@@ -116,7 +116,7 @@ const parseBuilder = async (ctx, next) => {
116
116
  const attribute = [];
117
117
  const col = sequelize.col(field);
118
118
  if (format) {
119
- attribute.push((0, import_formatter.formatter)(sequelize, type, field, format));
119
+ attribute.push((0, import_formatter.formatter)(sequelize, type, field, format, ctx.timezone));
120
120
  } else {
121
121
  attribute.push(col);
122
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-data-visualization",
3
- "version": "1.0.0-alpha.13",
3
+ "version": "1.0.0-alpha.15",
4
4
  "displayName": "Data visualization",
5
5
  "displayName.zh-CN": "数据可视化",
6
6
  "description": "Provides data visualization feature, including chart block and chart filter block, support line charts, area charts, bar charts and more than a dozen kinds of charts, you can also extend more chart types.",
@@ -33,7 +33,7 @@
33
33
  "@nocobase/test": "1.x",
34
34
  "@nocobase/utils": "1.x"
35
35
  },
36
- "gitHead": "bd97adef70762a6691b5b58ca6572672a8cdf838",
36
+ "gitHead": "2793d371368e094ea2bba04cfbe9b9b73c44edba",
37
37
  "keywords": [
38
38
  "Blocks"
39
39
  ]