@bygd/nc-report-ui 0.1.3 → 0.1.5

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.
@@ -15,7 +15,6 @@ var FormControl$1 = require('@material-ui/core/FormControl');
15
15
  var Select$1 = require('@material-ui/core/Select');
16
16
  var MenuItem$1 = require('@material-ui/core/MenuItem');
17
17
  var reactIntersectionObserver = require('react-intersection-observer');
18
- var cron = require('cron');
19
18
  var material = require('@mui/material');
20
19
  var CheckBoxOutlineBlankIcon = require('@mui/icons-material/CheckBoxOutlineBlank');
21
20
  var CheckBoxIcon = require('@mui/icons-material/CheckBox');
@@ -25,6 +24,8 @@ var MenuItem = require('@mui/material/MenuItem');
25
24
  var FormControl = require('@mui/material/FormControl');
26
25
  var Select = require('@mui/material/Select');
27
26
  var EventEmitter = require('eventemitter3');
27
+ var Grid = require('@material-ui/core/Grid');
28
+ var Container = require('@material-ui/core/Container');
28
29
 
29
30
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
30
31
 
@@ -64,6 +65,8 @@ var MenuItem__default = /*#__PURE__*/_interopDefault(MenuItem);
64
65
  var FormControl__default = /*#__PURE__*/_interopDefault(FormControl);
65
66
  var Select__default = /*#__PURE__*/_interopDefault(Select);
66
67
  var EventEmitter__default = /*#__PURE__*/_interopDefault(EventEmitter);
68
+ var Grid__default = /*#__PURE__*/_interopDefault(Grid);
69
+ var Container__default = /*#__PURE__*/_interopDefault(Container);
67
70
 
68
71
  function _extends() {
69
72
  return _extends = Object.assign ? Object.assign.bind() : function (n) {
@@ -824,20 +827,23 @@ var Chart = ({
824
827
  setActiveViewIndex(viewIndex);
825
828
  setActiveView(chart.doc.view[viewIndex]);
826
829
  }, [chart]);
827
- React__namespace.default.useEffect(() => {
828
- let cron$1;
829
- if (chart?.doc?.refresh?.enabled === true) {
830
- cron$1 = new cron.CronJob(chart.doc.refresh.cron, () => {
831
- if (inView) {
832
- loadSource(filterRef.current);
833
- }
834
- });
835
- cron$1.start();
836
- }
837
- return () => {
838
- cron$1 && cron$1.stop();
839
- };
840
- }, [chart, inView]);
830
+
831
+ // React.useEffect(() => {
832
+ // let cron;
833
+ // if (chart?.doc?.refresh?.enabled === true) {
834
+ // cron = new CronJob(chart.doc.refresh.cron, () => {
835
+ // if (inView) {
836
+ // loadSource(filterRef.current);
837
+ // }
838
+ // });
839
+ // cron.start();
840
+ // }
841
+
842
+ // return () => {
843
+ // cron && cron.stop();
844
+ // }
845
+ // }, [chart, inView]);
846
+
841
847
  React__namespace.default.useEffect(() => {
842
848
  if (!id) return;
843
849
  init().catch(error => {
@@ -970,8 +976,81 @@ var Chart = ({
970
976
  }), chartType));
971
977
  };
972
978
 
979
+ function Dashboard({
980
+ id,
981
+ auth,
982
+ params
983
+ }) {
984
+ const [dashboard, setDashboard] = React__namespace.default.useState();
985
+ //const [schema, setSchema] = React.useState();
986
+ const [schema] = React__namespace.default.useState();
987
+ const [rows, setRows] = React__namespace.default.useState([]);
988
+ const cache = React__namespace.default.useRef({});
989
+ const channel = useChannel();
990
+ useFilterManager(channel);
991
+ const init = async () => {
992
+ // get dashboard entity
993
+ const dashboardTemp = await Api.getDashboard({
994
+ id: id
995
+ });
996
+ cache.current[dashboardTemp?.id] = dashboardTemp;
997
+ setDashboard(dashboardTemp);
998
+
999
+ // create rows and columns
1000
+ await create_rows_and_columns(dashboardTemp);
1001
+ };
1002
+ const create_rows_and_columns = async entity => {
1003
+ const srcRows = entity?.doc?.rows || [];
1004
+ const targetRows = [];
1005
+ for (let i = 0; i < srcRows.length; i++) {
1006
+ const row = srcRows[i];
1007
+ row.columns?.forEach(column => {
1008
+ // filter
1009
+ if (column.override?.filter?.length) {
1010
+ const filter = {};
1011
+ column.override.filter.forEach(item => {
1012
+ if (item.hasOwnProperty('value')) filter[item.field] = [item.value];
1013
+ // else filter[item.field] = [sourceDataRow[item.field]];
1014
+ });
1015
+ column.filter = filter;
1016
+ }
1017
+ });
1018
+ targetRows.push(row);
1019
+ }
1020
+ setRows(targetRows);
1021
+ };
1022
+ React__namespace.default.useEffect(() => {
1023
+ if (!id) return;
1024
+ init().catch(error => console.error(error.message));
1025
+ }, [id]);
1026
+ return /*#__PURE__*/React__namespace.default.createElement(Container__default.default, null, /*#__PURE__*/React__namespace.default.createElement(Grid__default.default, {
1027
+ container: true
1028
+ }, rows?.map((row, index) =>
1029
+ /*#__PURE__*/
1030
+ // hasResourceRole(row) &&
1031
+ React__namespace.default.createElement(Grid__default.default, {
1032
+ key: index,
1033
+ container: true,
1034
+ item: true
1035
+ }, row?.columns?.map((column, index) => /*#__PURE__*/React__namespace.default.createElement(Grid__default.default, _extends({
1036
+ key: index,
1037
+ item: true
1038
+ }, column.layout), /*#__PURE__*/React__namespace.default.createElement(Chart, {
1039
+ auth: auth,
1040
+ cache: cache.current,
1041
+ id: column.id,
1042
+ dashboard: dashboard,
1043
+ schema: schema,
1044
+ channel: null,
1045
+ title: column.title,
1046
+ filter: column.filter,
1047
+ params: params
1048
+ })))))));
1049
+ }
1050
+
973
1051
  var index = {
974
- Chart
1052
+ Chart,
1053
+ Dashboard
975
1054
  };
976
1055
 
977
1056
  exports.default = index;
@@ -12,7 +12,6 @@ import FormControl$2 from '@material-ui/core/FormControl';
12
12
  import Select$1 from '@material-ui/core/Select';
13
13
  import MenuItem$1 from '@material-ui/core/MenuItem';
14
14
  import { useInView } from 'react-intersection-observer';
15
- import { CronJob } from 'cron';
16
15
  import { FormControl, Autocomplete, TextField, CircularProgress, Chip, Checkbox, FormHelperText } from '@mui/material';
17
16
  import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank';
18
17
  import CheckBoxIcon from '@mui/icons-material/CheckBox';
@@ -22,6 +21,8 @@ import MenuItem from '@mui/material/MenuItem';
22
21
  import FormControl$1 from '@mui/material/FormControl';
23
22
  import Select from '@mui/material/Select';
24
23
  import EventEmitter from 'eventemitter3';
24
+ import Grid from '@material-ui/core/Grid';
25
+ import Container from '@material-ui/core/Container';
25
26
 
26
27
  function _extends() {
27
28
  return _extends = Object.assign ? Object.assign.bind() : function (n) {
@@ -782,20 +783,23 @@ var Chart = ({
782
783
  setActiveViewIndex(viewIndex);
783
784
  setActiveView(chart.doc.view[viewIndex]);
784
785
  }, [chart]);
785
- React__default.useEffect(() => {
786
- let cron;
787
- if (chart?.doc?.refresh?.enabled === true) {
788
- cron = new CronJob(chart.doc.refresh.cron, () => {
789
- if (inView) {
790
- loadSource(filterRef.current);
791
- }
792
- });
793
- cron.start();
794
- }
795
- return () => {
796
- cron && cron.stop();
797
- };
798
- }, [chart, inView]);
786
+
787
+ // React.useEffect(() => {
788
+ // let cron;
789
+ // if (chart?.doc?.refresh?.enabled === true) {
790
+ // cron = new CronJob(chart.doc.refresh.cron, () => {
791
+ // if (inView) {
792
+ // loadSource(filterRef.current);
793
+ // }
794
+ // });
795
+ // cron.start();
796
+ // }
797
+
798
+ // return () => {
799
+ // cron && cron.stop();
800
+ // }
801
+ // }, [chart, inView]);
802
+
799
803
  React__default.useEffect(() => {
800
804
  if (!id) return;
801
805
  init().catch(error => {
@@ -928,8 +932,81 @@ var Chart = ({
928
932
  }), chartType));
929
933
  };
930
934
 
935
+ function Dashboard({
936
+ id,
937
+ auth,
938
+ params
939
+ }) {
940
+ const [dashboard, setDashboard] = React__default.useState();
941
+ //const [schema, setSchema] = React.useState();
942
+ const [schema] = React__default.useState();
943
+ const [rows, setRows] = React__default.useState([]);
944
+ const cache = React__default.useRef({});
945
+ const channel = useChannel();
946
+ useFilterManager(channel);
947
+ const init = async () => {
948
+ // get dashboard entity
949
+ const dashboardTemp = await Api.getDashboard({
950
+ id: id
951
+ });
952
+ cache.current[dashboardTemp?.id] = dashboardTemp;
953
+ setDashboard(dashboardTemp);
954
+
955
+ // create rows and columns
956
+ await create_rows_and_columns(dashboardTemp);
957
+ };
958
+ const create_rows_and_columns = async entity => {
959
+ const srcRows = entity?.doc?.rows || [];
960
+ const targetRows = [];
961
+ for (let i = 0; i < srcRows.length; i++) {
962
+ const row = srcRows[i];
963
+ row.columns?.forEach(column => {
964
+ // filter
965
+ if (column.override?.filter?.length) {
966
+ const filter = {};
967
+ column.override.filter.forEach(item => {
968
+ if (item.hasOwnProperty('value')) filter[item.field] = [item.value];
969
+ // else filter[item.field] = [sourceDataRow[item.field]];
970
+ });
971
+ column.filter = filter;
972
+ }
973
+ });
974
+ targetRows.push(row);
975
+ }
976
+ setRows(targetRows);
977
+ };
978
+ React__default.useEffect(() => {
979
+ if (!id) return;
980
+ init().catch(error => console.error(error.message));
981
+ }, [id]);
982
+ return /*#__PURE__*/React__default.createElement(Container, null, /*#__PURE__*/React__default.createElement(Grid, {
983
+ container: true
984
+ }, rows?.map((row, index) =>
985
+ /*#__PURE__*/
986
+ // hasResourceRole(row) &&
987
+ React__default.createElement(Grid, {
988
+ key: index,
989
+ container: true,
990
+ item: true
991
+ }, row?.columns?.map((column, index) => /*#__PURE__*/React__default.createElement(Grid, _extends({
992
+ key: index,
993
+ item: true
994
+ }, column.layout), /*#__PURE__*/React__default.createElement(Chart, {
995
+ auth: auth,
996
+ cache: cache.current,
997
+ id: column.id,
998
+ dashboard: dashboard,
999
+ schema: schema,
1000
+ channel: null,
1001
+ title: column.title,
1002
+ filter: column.filter,
1003
+ params: params
1004
+ })))))));
1005
+ }
1006
+
931
1007
  var index = {
932
- Chart
1008
+ Chart,
1009
+ Dashboard
933
1010
  };
934
1011
 
935
1012
  export { index as default };