Advertisement
xapu

Config parser

Oct 21st, 2020
2,692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     // TODO keep this comment until the subsystem dashboard migration is complete
  2.   createSelector(getSystemDetailDashboardState, getRawConfig)// export const getSystemDetailDashboardConfigurationParsedFromV1 =
  3. export const getSystemDetailDashboardConfigurationParsedFromV1 =    //   createSelector(getSystemDetailDashboardRawConfig, (rawConfig, hasLayout) => {
  4.   createSelector(getSystemDetailDashboardRawConfig, getSystemEntityHasSystemLayout, (rawConfig, hasLayout) => {
  5.  
  6. //     const createDashboardRow = (type: 'chart' | 'kpiRow' | 'systemLayout', configuration): IConfigurationRow =>
  7.     const createDashboardRow = (type: 'chart' | 'kpiRow' | 'systemLayout', configuration): IConfigurationRow => //       ({ type, configuration, uid: Math.random().toString() });
  8.       ({ type, configuration, uid: Math.random().toString() });
  9.  
  10. //     // Creates row that serves as placeholder for the systemLayout row
  11.     // Creates row that serves as placeholder for the systemLayout row  //     const systemLayout = hasLayout ? [createDashboardRow('systemLayout', { minimized: false })] : [];
  12.     const systemLayout = hasLayout ? [createDashboardRow('systemLayout', { minimized: false })] : [];  
  13.  
  14. //     // Parse old eCharts config to the new format and creates a row config for each one
  15.     // Parse old eCharts config to the new format and creates a row config for each one //     const parsedCharts = (rawConfig.charts || []).map(rawChart => createDashboardRow('chart', setUpConfig(rawChart)));
  16.     const parsedCharts = (rawConfig.charts || []).map(rawChart => createDashboardRow('chart', setUpConfig(rawChart)))
  17.  
  18. //     // Parse old kpi box configs to the new format and creates a single row config that contains all exiting kpi-s
  19.     // Parse old kpi box configs to the new format and creates a single row config that contains all exiting kpi-s  //     const parsedKpi = (rawConfig.kpi_boxes && rawConfig.kpi_boxes.length !== 0)
  20.     const parsedKpi = (rawConfig.kpi_boxes && rawConfig.kpi_boxes.length !== 0) //       ? [createDashboardRow('kpiRow', {
  21.       ? [createDashboardRow('kpiRow', { //         kpiConfigs: rawConfig.kpi_boxes.map(x => {
  22.         kpiConfigs: rawConfig.kpi_boxes.map(x => {  //           if (x.type === KPIBoxType.VALUE) {
  23.           if (x.type === KPIBoxType.VALUE) {    //             return ({
  24.             return ({   //               uid: Math.random().toString(),
  25.               uid: Math.random().toString(),    //               ...x,
  26.               ...x, //               title: x.abbreviation,
  27.               title: x.abbreviation,    //               tooltip: x.alias,
  28.               tooltip: x.alias, //               precision: x.decimals || 0,
  29.               precision: x.decimals || 0,   //               multiplier: 1,
  30.               multiplier: 1,    //               showLabel: !!x.value_mapping,
  31.               showLabel: !!x.value_mapping, //               value_mapping: (x.value_mapping || []).map(y => ({ ...y, uid: Math.random() }))
  32.               value_mapping: (x.value_mapping || []).map(y => ({ ...y, uid: Math.random() }))   //             });
  33.             }); //           }
  34.           } //           if (x.type === KPIBoxType.CALCULATED) {
  35.           if (x.type === KPIBoxType.CALCULATED) {   //             return ({
  36.             return ({   //               uid: Math.random().toString(),
  37.               uid: Math.random().toString(),    //               ...x,
  38.               ...x, //               title: x.abbreviation,
  39.               title: x.abbreviation,    //               tooltip: x.alias,
  40.               tooltip: x.alias, //               precision: x.decimals || 0,
  41.               precision: x.decimals || 0,   //               multiplier: 1
  42.               multiplier: 1 //             });
  43.             }); //           }
  44.           }
  45.  
  46. //           if (x.type === KPIBoxType.STATUS) {
  47.           if (x.type === KPIBoxType.STATUS) {   //             const baseStatusKPI: any = {
  48.             const baseStatusKPI: any = {    //               uid: Math.random().toString(),
  49.               uid: Math.random().toString(),    //               title: x.abbreviation,
  50.               title: x.abbreviation,    //               tooltip: x.alias,
  51.               tooltip: x.alias, //               type: x.type
  52.               type: x.type  //             };
  53.             }//             baseStatusKPI.sourceType = KPIBoxSourceType.SYSTEM;
  54.             baseStatusKPI.sourceType = KPIBoxSourceType.SYSTEM;
  55.  
  56. //             if (x.subsystemId) {
  57.             if (x.subsystemId) {    //               baseStatusKPI.subsystemId = x.subsystemId;
  58.               baseStatusKPI.subsystemId = x.subsystemId;    //               baseStatusKPI.sourceType = KPIBoxSourceType.SUBSYSTEM;
  59.               baseStatusKPI.sourceType = KPIBoxSourceType.SUBSYSTEM;    //             }
  60.             }  
  61.  
  62. //             if (x.controllerId) {
  63.             if (x.controllerId) {   //               // We are using idx of controller instead of the id so it doesn't make sense to store the id
  64.               // We are using idx of controller instead of the id so it doesn't make sense to store the id  //               baseStatusKPI.controller_idx = 0;
  65.               baseStatusKPI.controller_idx = 0; //               baseStatusKPI.sourceType = KPIBoxSourceType.CONTROLLER;
  66.               baseStatusKPI.sourceType = KPIBoxSourceType.CONTROLLER;   //             }
  67.             }  
  68.  
  69. //             if (x.abbreviation) {
  70.             if (x.abbreviation) {   //               baseStatusKPI.title = x.abbreviation;
  71.               baseStatusKPI.title = x.abbreviation; //               baseStatusKPI.tooltip = x.alias;
  72.               baseStatusKPI.tooltip = x.alias;  //             }
  73.             }   //             return baseStatusKPI;
  74.             return baseStatusKPI;   //           }
  75.           }
  76.  
  77. //           if (x.type === KPIBoxType.MAP) {
  78.           if (x.type === KPIBoxType.MAP) {  //             const baseStatusKPI: any = {
  79.             const baseStatusKPI: any = {    //               uid: Math.random().toString(),
  80.               uid: Math.random().toString(),    //               title: x.abbreviation,
  81.               title: x.abbreviation,    //               tooltip: x.alias,
  82.               tooltip: x.alias, //               type: x.type
  83.               type: x.type  //             };
  84.             }
  85.  
  86. //             if (!x.source) {
  87.             if (!x.source) {    //               baseStatusKPI.sourceType = KPIBoxSourceType.SYSTEM;
  88.               baseStatusKPI.sourceType = KPIBoxSourceType.SYSTEM;   //               return baseStatusKPI;
  89.               return baseStatusKPI; //             }
  90.             }  
  91.  
  92.  
  93.  
  94. //             baseStatusKPI.sourceType = KPIBoxSourceType.CONTROLLER;
  95.             baseStatusKPI.sourceType = KPIBoxSourceType.CONTROLLER; //             baseStatusKPI.device_id = x.source.device_id;
  96.             baseStatusKPI.device_id = x.source.device_id;   //             baseStatusKPI.controller_instance_idx = x.source.controller_instance_idx;
  97.             baseStatusKPI.controller_instance_idx = x.source.controller_instance_idx;  
  98.  
  99. //             return baseStatusKPI;
  100.             return baseStatusKPI;   //           }
  101.           } //           return {
  102.           return {  //             uid: Math.random().toString(),
  103.             uid: Math.random().toString()//             ...x,
  104.             ...x,   //             title: x.alias
  105.             title: x.alias  //           };
  106.           };    //         }),
  107.         }), //         // TODO: add generic placeholder name
  108.         // TODO: add generic placeholder name   //         title: 'General System Details',
  109.         title: 'General System Details',    //         minimized: false
  110.         minimized: false    //       })]
  111.       })]   //       : [];
  112.       : []; //     return [...systemLayout, ...parsedKpi, ...parsedCharts];
  113.     return [...systemLayout, ...parsedKpi, ...parsedCharts];    //   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement