{ "version": 3, "sources": ["src/app/store/metering-points/combined-selectors.ts"], "sourcesContent": ["import { MeteringPointsState } from '@appStore/metering-points';\r\nimport { createFeatureSelector, createSelector } from '@ngrx/store';\r\nimport { MeteringPointGroup, Customer, MeteringPoint } from '@model';\r\nimport { CustomersState } from '@appStore/customers';\r\nimport { MeteringType } from '@enums';\r\nimport { sortByProperty } from '@utils/sx-utilities';\r\n\r\nconst getMeteringPointFeatureState = createFeatureSelector('meteringpoints');\r\nconst getMeteringPointsState = createSelector(\r\n getMeteringPointFeatureState,\r\n state => state.meteringPoints\r\n);\r\nconst getMeteringPointGroupsState = createSelector(\r\n getMeteringPointFeatureState,\r\n state => state.meteringPointGroups\r\n);\r\n\r\nconst getCustomerFeatureState = createFeatureSelector('customers');\r\nconst getCustomerState = createSelector(\r\n getCustomerFeatureState,\r\n (state: CustomersState) => state.customers\r\n);\r\n\r\nexport const getFilledMeteringPointGroups = createSelector(\r\n getMeteringPointsState,\r\n getMeteringPointGroupsState,\r\n (mpState, mpgState) => {\r\n const meteringPoints = mpState.data;\r\n const meteringPointGroups = mpgState.data;\r\n\r\n if (meteringPoints.length === 0) {\r\n return meteringPointGroups;\r\n }\r\n\r\n let mappedGroups = [] as MeteringPointGroup[];\r\n meteringPointGroups.forEach(mpg => {\r\n mappedGroups = meteringPointGroups.map(meteringPointGroup => {\r\n return {\r\n ...meteringPointGroup,\r\n meteringPoints: meteringPointGroup.meteringPoints.map(meteringPoint => {\r\n const lookup = meteringPoints.find(mp => mp.id === meteringPoint.id);\r\n if (lookup) {\r\n return { ...lookup };\r\n }\r\n return { ...meteringPoint };\r\n })\r\n };\r\n });\r\n });\r\n\r\n return sortByProperty(mappedGroups, 'name');\r\n }\r\n);\r\n\r\nexport const getMeteringPointsWithGroups = createSelector(\r\n getMeteringPointsState,\r\n getMeteringPointGroupsState,\r\n (mpState, mpgState) => {\r\n const meteringPointGroups = mpgState.data;\r\n let meteringPoints = mpState.data;\r\n if (meteringPoints.length > 0 && meteringPointGroups.length > 0) {\r\n meteringPoints = meteringPoints.map(mp => {\r\n const mpgs = meteringPointGroups.filter(mpg => mpg.meteringPoints.map(x => x.id).indexOf(mp.id) >= 0);\r\n return { ...mp, parentGroups: mpgs.map(d => ({ name: d.name, id: d.id })) };\r\n });\r\n }\r\n return meteringPoints;\r\n }\r\n);\r\n\r\nexport const getSelectedMeteringPointWithGroups = createSelector(\r\n getMeteringPointsState,\r\n getMeteringPointGroupsState,\r\n (mpState, mpgState) => {\r\n const meteringPointGroups = mpgState.data;\r\n let selectedMeteringPoint = mpState.selected;\r\n if (selectedMeteringPoint && meteringPointGroups.length > 0) {\r\n const mpgs = meteringPointGroups.filter(\r\n mpg => mpg.meteringPoints.map(x => x.id).indexOf(selectedMeteringPoint.id) >= 0\r\n );\r\n return { ...selectedMeteringPoint, parentGroups: mpgs.map(d => ({ name: d.name, id: d.id })) };\r\n }\r\n return { ...selectedMeteringPoint, parentGroups: [] };\r\n }\r\n);\r\n\r\nexport const getFilledCustomers = createSelector(\r\n getCustomerState,\r\n getMeteringPointsState,\r\n getMeteringPointGroupsState,\r\n (cState, mpState, mpgState) => {\r\n const customers = cState.data;\r\n const meteringPointGroups = mpgState.data;\r\n let meteringPoints = mpState.data;\r\n\r\n if (meteringPoints.length > 0 && meteringPointGroups.length > 0) {\r\n meteringPoints = meteringPoints.map(mp => {\r\n const mpgs = meteringPointGroups.filter(mpg => mpg.meteringPoints.map(x => x.id).indexOf(mp.id) >= 0);\r\n return { ...mp, parentGroups: mpgs.map(d => ({ name: d.name, id: d.id })) };\r\n });\r\n }\r\n\r\n if (customers.length > 0 && meteringPoints.length > 0) {\r\n const filledCustomers = [] as Customer[];\r\n\r\n customers.forEach(currentCustomer => {\r\n if (currentCustomer.meteringPointsCold || currentCustomer.meteringPointsHeat) {\r\n return;\r\n }\r\n\r\n const custData: Customer = {\r\n ...currentCustomer,\r\n meteringPointsHeat: [\r\n ...meteringPoints.filter(x => x.customerId === currentCustomer.id && x.meteringType === MeteringType.Hot)\r\n ],\r\n meteringPointsCold: [\r\n ...meteringPoints.filter(x => x.customerId === currentCustomer.id && x.meteringType === MeteringType.Cold)\r\n ]\r\n };\r\n\r\n filledCustomers.push(custData);\r\n });\r\n return sortByProperty(filledCustomers, 'name');\r\n } else {\r\n return [];\r\n }\r\n }\r\n);\r\n\r\n\r\nexport const getFilledCustomersWithContainedMeteringPoints = createSelector(\r\n getCustomerState,\r\n getMeteringPointsState,\r\n getMeteringPointGroupsState,\r\n (cState, mpState, mpgState) => {\r\n const customers = cState.data;\r\n const meteringPointGroups = mpgState.data;\r\n let meteringPoints = mpState.data;\r\n\r\n if (meteringPoints.length > 0 && meteringPointGroups.length > 0) {\r\n meteringPoints = meteringPoints.map(mp => {\r\n const mpgs = meteringPointGroups.filter(mpg => mpg.meteringPoints.map(x => x.id).indexOf(mp.id) >= 0);\r\n return { ...mp, parentGroups: mpgs.map(d => ({ name: d.name, id: d.id })) };\r\n });\r\n }\r\n\r\n if (customers.length > 0 && meteringPoints.length > 0) {\r\n const filledCustomers = [] as Customer[];\r\n\r\n customers.forEach(currentCustomer => {\r\n if (currentCustomer.meteringPointsCold || currentCustomer.meteringPointsHeat) {\r\n return;\r\n }\r\n\r\n // With Contained MeteringPoints\r\n let containedMeteringPoints: MeteringPoint[] = [];\r\n let logicalMeteringPoints: MeteringPoint[] = [];\r\n meteringPoints.forEach(mp => {\r\n if (mp.containedMeteringPoints && mp.containedMeteringPoints.length > 0) {\r\n\r\n logicalMeteringPoints.push(mp);\r\n mp.containedMeteringPoints.forEach(cmp => {\r\n containedMeteringPoints.push({...cmp, type: 'CONTAINED'});\r\n });\r\n }\r\n });\r\n\r\n let allHotMeteringPoints = meteringPoints.concat(containedMeteringPoints.map(c => c));\r\n allHotMeteringPoints = allHotMeteringPoints.filter((item) => !logicalMeteringPoints.includes(item));\r\n\r\n const custData: Customer = {\r\n ...currentCustomer,\r\n meteringPointsHeat: [\r\n ...allHotMeteringPoints.filter(x => x.customerId === currentCustomer.id && x.meteringType === MeteringType.Hot)\r\n ],\r\n meteringPointsCold: [\r\n ...meteringPoints.filter(x => x.customerId === currentCustomer.id && x.meteringType === MeteringType.Cold)\r\n ]\r\n };\r\n\r\n filledCustomers.push(custData);\r\n });\r\n return sortByProperty(filledCustomers, 'name');\r\n } else {\r\n return [];\r\n }\r\n }\r\n);\r\n\r\n\r\nexport const getFilledCustomersWithDisruptions = createSelector(\r\n getCustomerState,\r\n getMeteringPointsState,\r\n getMeteringPointGroupsState,\r\n (cState, mpState, mpgState) => {\r\n const customers = cState.data;\r\n const meteringPointGroups = mpgState.data;\r\n let meteringPoints = mpState.data.filter(mp => mp.disruptionInfos);\r\n\r\n if (meteringPoints.length > 0 && meteringPointGroups.length > 0) {\r\n meteringPoints = meteringPoints.map(mp => {\r\n const mpgs = meteringPointGroups.filter(mpg => mpg.meteringPoints.map(x => x.id).indexOf(mp.id) >= 0);\r\n return { ...mp, parentGroups: mpgs.map(d => ({ name: d.name, id: d.id })) };\r\n });\r\n }\r\n\r\n if (customers.length > 0 && meteringPoints.length > 0) {\r\n const filledCustomers = [] as Customer[];\r\n\r\n customers.forEach(currentCustomer => {\r\n if (currentCustomer.meteringPointsCold || currentCustomer.meteringPointsHeat) {\r\n return;\r\n }\r\n\r\n const custData: Customer = {\r\n ...currentCustomer,\r\n meteringPointsHeat: [\r\n ...meteringPoints.filter(x => x.customerId === currentCustomer.id && x.meteringType === MeteringType.Hot)\r\n ],\r\n meteringPointsCold: [\r\n ...meteringPoints.filter(x => x.customerId === currentCustomer.id && x.meteringType === MeteringType.Cold)\r\n ]\r\n };\r\n if (custData.meteringPointsCold.length > 0 || custData.meteringPointsHeat.length > 0) {\r\n filledCustomers.push(custData);\r\n }\r\n });\r\n return sortByProperty(filledCustomers, 'name');\r\n } else {\r\n return [];\r\n }\r\n }\r\n);\r\n"], "mappings": "gHAOA,IAAMA,EAA+BC,EAA2C,gBAAgB,EAC1FC,EAAyBC,EAC7BH,EACAI,GAASA,EAAMC,cA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C,oBAAsBD,EAAgBE,mBACxD,OAGF,IAAMC,EAAqBzB,EAAAC,EAAA,GACtBqB,GADsB,CAEzBE,mBAAoB,CAClB,GAAGxC,EAAe0B,OAAOC,GAAKA,EAAEe,aAAeJ,EAAgBhB,IAAMK,EAAEgB,eAAiBC,EAAaC,GAAG,CAAC,EAE3GN,mBAAoB,CAClB,GAAGvC,EAAe0B,OAAOC,GAAKA,EAAEe,aAAeJ,EAAgBhB,IAAMK,EAAEgB,eAAiBC,EAAaE,IAAI,CAAC,KAG1GL,EAASF,mBAAmB7B,OAAS,GAAK+B,EAASD,mBAAmB9B,OAAS,IACjF2B,EAAgBU,KAAKN,CAAQ,CAEjC,CAAC,EACMlB,EAAec,EAAiB,MAAM,CAC/C,KACE,OAAO,CAAA,CAEX,CAAC", "names": ["getMeteringPointFeatureState", "createFeatureSelector", "getMeteringPointsState", "createSelector", "state", "meteringPoints", "getMeteringPointGroupsState", "meteringPointGroups", "getCustomerFeatureState", "getCustomerState", "customers", "getFilledMeteringPointGroups", "mpState", "mpgState", "data", "length", "mappedGroups", "forEach", "mpg", "map", "meteringPointGroup", "__spreadProps", "__spreadValues", "meteringPoint", "lookup", "find", "mp", "id", "sortByProperty", "getMeteringPointsWithGroups", "mpgs", "filter", "x", "indexOf", "parentGroups", "d", "name", "getSelectedMeteringPointWithGroups", "selectedMeteringPoint", "selected", "getFilledCustomers", "cState", "filledCustomers", "currentCustomer", "meteringPointsCold", "meteringPointsHeat", "custData", "customerId", "meteringType", "MeteringType", "Hot", "Cold", "push", "getFilledCustomersWithContainedMeteringPoints", "containedMeteringPoints", "logicalMeteringPoints", "cmp", "type", "allHotMeteringPoints", "concat", "c", "item", "includes", "getFilledCustomersWithDisruptions", "disruptionInfos"] }