grouped object parameters
This commit is contained in:
109
client/src/components/map/GTCBParameter.tsx
Normal file
109
client/src/components/map/GTCBParameter.tsx
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
import TableValue from './TableValue'
|
||||||
|
import { Text } from '@fluentui/react-components';
|
||||||
|
import { IObjectValue } from '../../interfaces/objects';
|
||||||
|
|
||||||
|
interface ITCBParameterProps {
|
||||||
|
values: IObjectValue[];
|
||||||
|
vtable: string;
|
||||||
|
inactive?: boolean;
|
||||||
|
name: string;
|
||||||
|
map_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const GTCBParameter = ({
|
||||||
|
values,
|
||||||
|
vtable,
|
||||||
|
name,
|
||||||
|
map_id
|
||||||
|
}: ITCBParameterProps) => {
|
||||||
|
//Get value
|
||||||
|
// const { data: tcbValue } = useSWR(
|
||||||
|
// value ? `/general/params/tcb?id=${value}&vtable=${vtable}` : null,
|
||||||
|
// (url) => fetcher(url, BASE_URL.ems).then(res => res[0]),
|
||||||
|
// {
|
||||||
|
// revalidateOnFocus: false,
|
||||||
|
// revalidateIfStale: false
|
||||||
|
// }
|
||||||
|
// )
|
||||||
|
|
||||||
|
const tables = [
|
||||||
|
'BoilersTemper',
|
||||||
|
'FuelsParametrs',
|
||||||
|
'PipesTypes',
|
||||||
|
'vAddRepairEvent',
|
||||||
|
'vApartmentTypes',
|
||||||
|
'vBoilers',
|
||||||
|
'vBoilersAppointment',
|
||||||
|
'vBoilersBalance',
|
||||||
|
'vBoilersCondition',
|
||||||
|
'vBoilersFuels',
|
||||||
|
'vBoilersHotWater',
|
||||||
|
'vBoilersPerimeter',
|
||||||
|
'vBoilersPeriods',
|
||||||
|
'vBoilersScheme',
|
||||||
|
'vBoilersState',
|
||||||
|
'vBoilersTypes',
|
||||||
|
'vBuildingManagement',
|
||||||
|
'vBuildingOwner',
|
||||||
|
'vCanalization',
|
||||||
|
'vColdWaterTypes',
|
||||||
|
'vConditionEquipment',
|
||||||
|
'vCovering',
|
||||||
|
'vDensityWater',
|
||||||
|
'vDryer',
|
||||||
|
'vElectroSupplyTypes',
|
||||||
|
'vEquipmentsTypes',
|
||||||
|
'vFoundation',
|
||||||
|
'vFuelsFeed',
|
||||||
|
'vGasSupplyTypes',
|
||||||
|
'vHeatingTypes',
|
||||||
|
'vHeatTransfer',
|
||||||
|
'vHotWaterTypes',
|
||||||
|
'vMaterialsWall',
|
||||||
|
'vNormative',
|
||||||
|
'vPeriodHW',
|
||||||
|
'vPipeDiameters',
|
||||||
|
'vPipeOutDiameters',
|
||||||
|
'vPipesBearingType',
|
||||||
|
'vPipesCovering',
|
||||||
|
'vPipesEvent',
|
||||||
|
'vPipesGround',
|
||||||
|
'vPipesIsolation',
|
||||||
|
'vPipesLayer',
|
||||||
|
'vPipesMaterial',
|
||||||
|
'vPumpType',
|
||||||
|
'vRepairEvent',
|
||||||
|
'vRoof',
|
||||||
|
'vRPSType',
|
||||||
|
'vServe',
|
||||||
|
'vStreets',
|
||||||
|
'vTechStatus',
|
||||||
|
'vTrash',
|
||||||
|
'vTrashStorage',
|
||||||
|
'vVentilation',
|
||||||
|
'vValvingType',
|
||||||
|
'vWallingEquipment',
|
||||||
|
'tTypes',
|
||||||
|
]
|
||||||
|
|
||||||
|
const TCBValue = (vtable: string) => {
|
||||||
|
if (tables.includes(vtable)) {
|
||||||
|
return (
|
||||||
|
<TableValue map_id={map_id} values={values} name={name} type='select' vtable={vtable} />
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<Text>
|
||||||
|
{JSON.stringify(name)}
|
||||||
|
{JSON.stringify(Array.isArray(values) && values.length > 0 && values[0].value)}
|
||||||
|
</Text>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
TCBValue(vtable)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default GTCBParameter
|
||||||
@ -156,7 +156,7 @@ const MapComponent = ({
|
|||||||
|
|
||||||
marker.setStyle(new Style({
|
marker.setStyle(new Style({
|
||||||
image: new Icon({
|
image: new Icon({
|
||||||
src: 'public/map_pin_icon.svg',
|
src: '/map_pin_icon.svg',
|
||||||
scale: 0.2
|
scale: 0.2
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
import useSWR from 'swr'
|
import { IObjectParam, IObjectValue } from '../../interfaces/objects'
|
||||||
import { fetcher } from '../../http/axiosInstance'
|
|
||||||
import { BASE_URL } from '../../constants'
|
|
||||||
import { IObjectParam, IParam } from '../../interfaces/objects'
|
|
||||||
import TCBParameter from './TCBParameter'
|
import TCBParameter from './TCBParameter'
|
||||||
import TableValue from './TableValue'
|
import TableValue from './TableValue'
|
||||||
import { TableCell, TableCellLayout, TableRow } from '@fluentui/react-components'
|
import { Accordion, AccordionHeader, AccordionItem, AccordionPanel, Table, TableBody, TableCell, TableCellLayout, TableRow, Text } from '@fluentui/react-components'
|
||||||
|
|
||||||
interface ObjectParameterProps {
|
interface ObjectParameterProps {
|
||||||
showLabel?: boolean;
|
showLabel?: boolean;
|
||||||
@ -16,61 +13,73 @@ const ObjectParameter = ({
|
|||||||
param,
|
param,
|
||||||
map_id
|
map_id
|
||||||
}: ObjectParameterProps) => {
|
}: ObjectParameterProps) => {
|
||||||
const { data: paramData } = useSWR(
|
|
||||||
`/general/params/?param_id=${param.id_param}`,
|
|
||||||
(url) => fetcher(url, BASE_URL.ems).then(res => res[0] as IParam),
|
|
||||||
{
|
|
||||||
revalidateOnFocus: false,
|
|
||||||
revalidateIfStale: false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const Parameter = (type: string, name: string, value: unknown, vtable: string, unit: string | null) => {
|
const Parameter = (type: string, name: string, values: IObjectValue[], vtable: string, unit: string | null) => {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'bit':
|
case 'bit':
|
||||||
return (
|
return (
|
||||||
<TableValue map_id={map_id} value={value} name={name} type='boolean' />
|
<TableValue map_id={map_id} values={values} name={name} type='boolean' />
|
||||||
)
|
)
|
||||||
case 'int':
|
case 'int':
|
||||||
return (
|
return (
|
||||||
<TableValue map_id={map_id} value={value} name={name} type='number' />
|
<TableValue map_id={map_id} values={values} name={name} type='number' />
|
||||||
|
)
|
||||||
|
case 'smallint':
|
||||||
|
return (
|
||||||
|
<TableValue map_id={map_id} values={values} name={name} type='number' />
|
||||||
)
|
)
|
||||||
case 'bigint':
|
case 'bigint':
|
||||||
return (
|
return (
|
||||||
<TableValue map_id={map_id} value={value} name={name} type='number' />
|
<TableValue map_id={map_id} values={values} name={name} type='number' />
|
||||||
)
|
)
|
||||||
case 'tinyint':
|
case 'tinyint':
|
||||||
return (
|
return (
|
||||||
<TableValue map_id={map_id} value={value} name={name} type='number' />
|
<TableValue map_id={map_id} values={values} name={name} type='number' />
|
||||||
|
)
|
||||||
|
case 'smalldatetime':
|
||||||
|
return (
|
||||||
|
<TableValue map_id={map_id} values={values} name={name} type='number' />
|
||||||
)
|
)
|
||||||
// TODO: Calculate from calc procedures
|
// TODO: Calculate from calc procedures
|
||||||
case 'calculate':
|
case 'calculate':
|
||||||
return (
|
return (
|
||||||
<TableValue map_id={map_id} value={value} name={name} type='value' />
|
<TableValue map_id={map_id} values={values} name={name} type='value' />
|
||||||
)
|
)
|
||||||
case 'GTCB':
|
case 'GTCB':
|
||||||
return (
|
return (
|
||||||
<TCBParameter map_id={map_id} value={value as string} vtable={vtable} name={name} />
|
<TCBParameter map_id={map_id} values={values} vtable={vtable} name={name} />
|
||||||
)
|
)
|
||||||
case 'TCB':
|
case 'TCB':
|
||||||
return (
|
return (
|
||||||
<TCBParameter map_id={map_id} value={value as string} vtable={vtable} name={name} />
|
<TCBParameter map_id={map_id} values={values} vtable={vtable} name={name} />
|
||||||
)
|
)
|
||||||
case type.match(/varchar\((\d+)\)/)?.input:
|
case type.match(/varchar\((\d+)\)/)?.input:
|
||||||
return (
|
return (
|
||||||
<TableValue map_id={map_id} value={value} name={name} type='string' />
|
<TableValue map_id={map_id} values={values} name={name} type='string' />
|
||||||
)
|
)
|
||||||
case type.match(/numeric\((\d+),(\d+)\)/)?.input:
|
case type.match(/numeric\((\d+),(\d+)\)/)?.input:
|
||||||
return (
|
return (
|
||||||
<TableValue map_id={map_id} value={value} name={name} type='number' unit={unit} />
|
<TableValue map_id={map_id} values={values} name={name} type='number' unit={unit} />
|
||||||
)
|
)
|
||||||
case 'year':
|
case 'year':
|
||||||
return (
|
return (
|
||||||
<TableValue map_id={map_id} value={value} name={name} type='number' />
|
<TableValue map_id={map_id} values={values} name={name} type='number' />
|
||||||
)
|
)
|
||||||
case 'uniqueidentifier':
|
case 'uniqueidentifier':
|
||||||
return (
|
return (
|
||||||
<TableValue map_id={map_id} value={value} name={name} type='value' />
|
<TableValue map_id={map_id} values={values} name={name} type='value' />
|
||||||
|
)
|
||||||
|
case 'group':
|
||||||
|
return (
|
||||||
|
<TableValue map_id={map_id} values={values} name={name} type='value' />
|
||||||
|
)
|
||||||
|
case 'groupcalculate':
|
||||||
|
return (
|
||||||
|
<TableValue map_id={map_id} values={values} name={name} type='value' />
|
||||||
|
)
|
||||||
|
case 'array':
|
||||||
|
return (
|
||||||
|
<TableValue map_id={map_id} values={values} name={name} type='value' />
|
||||||
)
|
)
|
||||||
default:
|
default:
|
||||||
return (
|
return (
|
||||||
@ -83,7 +92,7 @@ const ObjectParameter = ({
|
|||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<TableCellLayout>
|
<TableCellLayout>
|
||||||
{value as string}
|
{values[0].value as string}
|
||||||
</TableCellLayout>
|
</TableCellLayout>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
@ -93,9 +102,37 @@ const ObjectParameter = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{paramData &&
|
{param && param.parameters && Array.isArray(param.parameters) && param.parameters.length > 0 ?
|
||||||
Parameter(paramData.format, paramData.name, param.value, paramData.vtable, paramData.unit)
|
<TableRow>
|
||||||
|
<TableCell colSpan={2} style={{ padding: 0 }}>
|
||||||
|
<TableCellLayout>
|
||||||
|
<Accordion collapsible defaultOpenItems={param.id_param} style={{ width: '100%' }}>
|
||||||
|
<AccordionItem style={{ width: '100%' }} value={param.id_param}>
|
||||||
|
<AccordionHeader size='small'>
|
||||||
|
<Text weight='bold' size={200} style={{ textWrap: 'wrap' }}>{param.name}</Text>
|
||||||
|
</AccordionHeader>
|
||||||
|
|
||||||
|
<AccordionPanel style={{ width: '100%', margin: 0 }}>
|
||||||
|
<Table size='extra-small'>
|
||||||
|
<TableBody>
|
||||||
|
{param.parameters.length > 0 &&
|
||||||
|
param.parameters.map((p, index) => (
|
||||||
|
<ObjectParameter key={`child-param-${param.id_param}-${index}`} param={p} map_id={map_id} />
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</AccordionPanel>
|
||||||
|
</AccordionItem>
|
||||||
|
</Accordion>
|
||||||
|
</TableCellLayout>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
:
|
||||||
|
param && Parameter(param.format, param.name, param.values, param.vtable, param.unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import useSWR from 'swr';
|
|||||||
import { BASE_URL } from '../../../constants';
|
import { BASE_URL } from '../../../constants';
|
||||||
import { fetcher } from '../../../http/axiosInstance';
|
import { fetcher } from '../../../http/axiosInstance';
|
||||||
import { useObjectsStore } from '../../../store/objects';
|
import { useObjectsStore } from '../../../store/objects';
|
||||||
import { Spinner, Table, TableBody } from '@fluentui/react-components';
|
import { Spinner, Table, TableBody, TableHeader, TableHeaderCell, TableRow } from '@fluentui/react-components';
|
||||||
|
|
||||||
const ObjectParameters = ({
|
const ObjectParameters = ({
|
||||||
map_id
|
map_id
|
||||||
@ -41,38 +41,20 @@ const ObjectParameters = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Table size='small'>
|
<Table size='extra-small'>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow appearance='neutral'>
|
||||||
|
<TableHeaderCell>Параметр</TableHeaderCell>
|
||||||
|
|
||||||
|
<TableHeaderCell>Значение</TableHeaderCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{Array.isArray(valuesData) &&
|
{Array.isArray(valuesData) &&
|
||||||
Object.entries(
|
valuesData.map((param: IObjectParam) => (
|
||||||
valuesData.reduce((acc, param) => {
|
<ObjectParameter map_id={map_id} key={param.id_param} param={param} />
|
||||||
if (!acc[param.id_param]) {
|
))
|
||||||
acc[param.id_param] = [];
|
|
||||||
}
|
|
||||||
acc[param.id_param].push(param);
|
|
||||||
return acc;
|
|
||||||
}, {} as Record<string, IObjectParam[]>)
|
|
||||||
).map(([id_param, params]) => {
|
|
||||||
// Step 1: Sort the parameters by date_s (start date) and date_po (end date)
|
|
||||||
const sortedParams = (params as IObjectParam[]).sort((b, a) => {
|
|
||||||
const dateA = new Date(a.date_s || 0);
|
|
||||||
const dateB = new Date(b.date_s || 0);
|
|
||||||
return dateA.getTime() - dateB.getTime();
|
|
||||||
});
|
|
||||||
|
|
||||||
return sortedParams.length > 1 ? (
|
|
||||||
sortedParams.map((param: IObjectParam) => {
|
|
||||||
if (param.date_po == null) {
|
|
||||||
return (
|
|
||||||
<ObjectParameter map_id={map_id} key={id_param} param={param} showLabel={false} />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
) : (
|
|
||||||
<ObjectParameter map_id={map_id} key={id_param} param={sortedParams[0]} />
|
|
||||||
);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
import useSWR from 'swr'
|
|
||||||
import { fetcher } from '../../http/axiosInstance'
|
|
||||||
import { BASE_URL } from '../../constants'
|
|
||||||
import TableValue from './TableValue'
|
import TableValue from './TableValue'
|
||||||
import { Text } from '@fluentui/react-components';
|
import { Text } from '@fluentui/react-components';
|
||||||
|
import { IObjectValue } from '../../interfaces/objects';
|
||||||
|
|
||||||
interface ITCBParameterProps {
|
interface ITCBParameterProps {
|
||||||
value: string;
|
values: IObjectValue[];
|
||||||
vtable: string;
|
vtable: string;
|
||||||
inactive?: boolean;
|
inactive?: boolean;
|
||||||
name: string;
|
name: string;
|
||||||
@ -13,27 +11,27 @@ interface ITCBParameterProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const TCBParameter = ({
|
const TCBParameter = ({
|
||||||
value,
|
values,
|
||||||
vtable,
|
vtable,
|
||||||
name,
|
name,
|
||||||
map_id
|
map_id
|
||||||
}: ITCBParameterProps) => {
|
}: ITCBParameterProps) => {
|
||||||
|
|
||||||
//Get value
|
//Get value
|
||||||
const { data: tcbValue } = useSWR(
|
// const { data: tcbValue } = useSWR(
|
||||||
`/general/params/tcb?id=${value}&vtable=${vtable}`,
|
// value ? `/general/params/tcb?id=${value}&vtable=${vtable}` : null,
|
||||||
(url) => fetcher(url, BASE_URL.ems).then(res => res[0]),
|
// (url) => fetcher(url, BASE_URL.ems).then(res => res[0]),
|
||||||
{
|
// {
|
||||||
revalidateOnFocus: false,
|
// revalidateOnFocus: false,
|
||||||
revalidateIfStale: false
|
// revalidateIfStale: false
|
||||||
}
|
// }
|
||||||
)
|
// )
|
||||||
|
|
||||||
const tables = [
|
const tables = [
|
||||||
'BoilersTemper',
|
'BoilersTemper',
|
||||||
'FuelsParametrs',
|
'FuelsParametrs',
|
||||||
'PipesTypes',
|
'PipesTypes',
|
||||||
'vAddRepairEvent',
|
'vAddRepairEvent',
|
||||||
|
'vApartmentTypes',
|
||||||
'vBoilers',
|
'vBoilers',
|
||||||
'vBoilersAppointment',
|
'vBoilersAppointment',
|
||||||
'vBoilersBalance',
|
'vBoilersBalance',
|
||||||
@ -51,6 +49,7 @@ const TCBParameter = ({
|
|||||||
'vColdWaterTypes',
|
'vColdWaterTypes',
|
||||||
'vConditionEquipment',
|
'vConditionEquipment',
|
||||||
'vCovering',
|
'vCovering',
|
||||||
|
'vDensityWater',
|
||||||
'vDryer',
|
'vDryer',
|
||||||
'vElectroSupplyTypes',
|
'vElectroSupplyTypes',
|
||||||
'vEquipmentsTypes',
|
'vEquipmentsTypes',
|
||||||
@ -62,21 +61,27 @@ const TCBParameter = ({
|
|||||||
'vHotWaterTypes',
|
'vHotWaterTypes',
|
||||||
'vMaterialsWall',
|
'vMaterialsWall',
|
||||||
'vNormative',
|
'vNormative',
|
||||||
|
'vPeriodHW',
|
||||||
'vPipeDiameters',
|
'vPipeDiameters',
|
||||||
'vPipeOutDiameters',
|
'vPipeOutDiameters',
|
||||||
'vPipesBearingType',
|
'vPipesBearingType',
|
||||||
'vPipesCovering',
|
'vPipesCovering',
|
||||||
|
'vPipesEvent',
|
||||||
'vPipesGround',
|
'vPipesGround',
|
||||||
'vPipesIsolation',
|
'vPipesIsolation',
|
||||||
'vPipesLayer',
|
'vPipesLayer',
|
||||||
'vPipesMaterial',
|
'vPipesMaterial',
|
||||||
|
'vPumpType',
|
||||||
'vRepairEvent',
|
'vRepairEvent',
|
||||||
'vRoof',
|
'vRoof',
|
||||||
'vRPSType',
|
'vRPSType',
|
||||||
|
'vServe',
|
||||||
'vStreets',
|
'vStreets',
|
||||||
'vTechStatus',
|
'vTechStatus',
|
||||||
'vTrash',
|
'vTrash',
|
||||||
|
'vTrashStorage',
|
||||||
'vVentilation',
|
'vVentilation',
|
||||||
|
'vValvingType',
|
||||||
'vWallingEquipment',
|
'vWallingEquipment',
|
||||||
'tTypes',
|
'tTypes',
|
||||||
]
|
]
|
||||||
@ -84,13 +89,13 @@ const TCBParameter = ({
|
|||||||
const TCBValue = (vtable: string) => {
|
const TCBValue = (vtable: string) => {
|
||||||
if (tables.includes(vtable)) {
|
if (tables.includes(vtable)) {
|
||||||
return (
|
return (
|
||||||
<TableValue map_id={map_id} value={tcbValue?.id} name={name} type='select' vtable={vtable} />
|
<TableValue map_id={map_id} values={values} name={name} type='select' vtable={vtable} />
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<Text>
|
<Text>
|
||||||
{JSON.stringify(name)}
|
{JSON.stringify(name)}
|
||||||
{JSON.stringify(tcbValue)}
|
{JSON.stringify(Array.isArray(values) && values.length > 0 && values[0].value)}
|
||||||
</Text>
|
</Text>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,11 +2,13 @@ import useSWR from 'swr';
|
|||||||
import { fetcher } from '../../http/axiosInstance';
|
import { fetcher } from '../../http/axiosInstance';
|
||||||
import { BASE_URL } from '../../constants';
|
import { BASE_URL } from '../../constants';
|
||||||
import { useObjectsStore } from '../../store/objects';
|
import { useObjectsStore } from '../../store/objects';
|
||||||
import { Checkbox, Input, Select, TableCell, TableCellLayout, TableRow, Text } from '@fluentui/react-components';
|
import { Input, Select, TableCell, TableCellLayout, TableRow, Text } from '@fluentui/react-components';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { IObjectValue } from '../../interfaces/objects';
|
||||||
|
|
||||||
interface TableValueProps {
|
interface TableValueProps {
|
||||||
name: string;
|
name: string;
|
||||||
value: unknown;
|
values: IObjectValue[];
|
||||||
type: 'value' | 'boolean' | 'number' | 'select' | 'string';
|
type: 'value' | 'boolean' | 'number' | 'select' | 'string';
|
||||||
unit?: string | null | undefined;
|
unit?: string | null | undefined;
|
||||||
vtable?: string;
|
vtable?: string;
|
||||||
@ -15,14 +17,17 @@ interface TableValueProps {
|
|||||||
|
|
||||||
const TableValue = ({
|
const TableValue = ({
|
||||||
name,
|
name,
|
||||||
value,
|
values,
|
||||||
type,
|
type,
|
||||||
unit,
|
unit,
|
||||||
vtable,
|
vtable,
|
||||||
map_id
|
map_id
|
||||||
}: TableValueProps) => {
|
}: TableValueProps) => {
|
||||||
const { selectedDistrict } = useObjectsStore().id[map_id]
|
const { selectedDistrict } = useObjectsStore().id[map_id]
|
||||||
|
|
||||||
//Get available values
|
//Get available values
|
||||||
|
const [value] = useState(Array.isArray(values) && values.length > 0 ? values[0].value : null)
|
||||||
|
|
||||||
const { data: tcbAll, isValidating } = useSWR(
|
const { data: tcbAll, isValidating } = useSWR(
|
||||||
type === 'select' && selectedDistrict ? `/general/params/tcb?vtable=${vtable}&id_city=${selectedDistrict}` : null,
|
type === 'select' && selectedDistrict ? `/general/params/tcb?vtable=${vtable}&id_city=${selectedDistrict}` : null,
|
||||||
(url) => fetcher(url, BASE_URL.ems).then(res => {
|
(url) => fetcher(url, BASE_URL.ems).then(res => {
|
||||||
@ -42,22 +47,22 @@ const TableValue = ({
|
|||||||
return (
|
return (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<TableCellLayout truncate>
|
<TableCellLayout truncate title={name as string}>
|
||||||
<Text size={200} style={{ textWrap: 'wrap' }}>{name as string}</Text>
|
{name as string}
|
||||||
</TableCellLayout>
|
</TableCellLayout>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell style={{ padding: '0.25rem' }}>
|
||||||
<div style={{ display: 'flex' }}>
|
<div style={{ display: 'flex' }}>
|
||||||
{type === 'boolean' ?
|
{type === 'boolean' ?
|
||||||
// <Select style={{ display: 'flex', width: '100%' }} size='small' defaultChecked={value as boolean}>
|
<Select style={{ display: 'flex', width: '100%' }} size='small' defaultChecked={value as boolean}>
|
||||||
// {[true, false].map(tcb => (
|
{[true, false].map(tcb => (
|
||||||
// <option key={JSON.stringify(tcb)} value={JSON.stringify(tcb)}>
|
<option key={JSON.stringify(tcb)} value={JSON.stringify(tcb)}>
|
||||||
// {tcb === true ? 'Да' : 'Нет'}
|
{tcb === true ? 'Да' : 'Нет'}
|
||||||
// </option>
|
</option>
|
||||||
// ))}
|
))}
|
||||||
// </Select>
|
</Select>
|
||||||
<Checkbox defaultChecked={value as boolean} />
|
// <Checkbox defaultChecked={value as boolean} />
|
||||||
:
|
:
|
||||||
type === 'number' ?
|
type === 'number' ?
|
||||||
<Input
|
<Input
|
||||||
@ -65,7 +70,7 @@ const TableValue = ({
|
|||||||
style={{ display: 'flex', width: '100%' }}
|
style={{ display: 'flex', width: '100%' }}
|
||||||
defaultValue={value as string}
|
defaultValue={value as string}
|
||||||
onChange={() => { }}
|
onChange={() => { }}
|
||||||
contentAfter={unit ? ` ${unit}` : ''}
|
contentAfter={unit ? <Text size={200} wrap={false}>{unit}</Text> : undefined}
|
||||||
//displayValue={unit ? ` ${unit}` : ''}
|
//displayValue={unit ? ` ${unit}` : ''}
|
||||||
/>
|
/>
|
||||||
:
|
:
|
||||||
@ -81,7 +86,10 @@ const TableValue = ({
|
|||||||
type === 'string' ?
|
type === 'string' ?
|
||||||
<Input style={{ display: 'flex', width: '100%' }} size='small' value={value as string} />
|
<Input style={{ display: 'flex', width: '100%' }} size='small' value={value as string} />
|
||||||
:
|
:
|
||||||
<Text size={200}>{value as string}</Text>
|
type === 'value' ?
|
||||||
|
<Input style={{ display: 'flex', width: '100%' }} size='small' value={value as string} />
|
||||||
|
:
|
||||||
|
<Text size={200}>{value as string}</Text>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|||||||
@ -1,44 +1,45 @@
|
|||||||
export interface IObjectList {
|
export interface IObjectList {
|
||||||
id: number,
|
id: number
|
||||||
name: string,
|
name: string
|
||||||
count: number
|
count: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IObjectData {
|
export interface IObjectData {
|
||||||
object_id: string,
|
object_id: string
|
||||||
id_city: number,
|
id_city: number
|
||||||
year: number,
|
year: number
|
||||||
id_parent: number | null,
|
id_parent: number | null
|
||||||
type: number,
|
type: number
|
||||||
planning: boolean,
|
planning: boolean
|
||||||
activity: boolean,
|
activity: boolean
|
||||||
kvr: string | null,
|
kvr: string | null
|
||||||
jur: string | null,
|
jur: string | null
|
||||||
fuel: string | null,
|
fuel: string | null
|
||||||
boiler_id: string | null
|
boiler_id: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IObjectParam {
|
export interface IObjectValue {
|
||||||
id_object: string,
|
value: any
|
||||||
id_param: number,
|
date_s: string | null
|
||||||
value: string,
|
date_po: string | null
|
||||||
date_s: string | null,
|
|
||||||
date_po: string | null,
|
|
||||||
id_user: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IParam {
|
export interface IObjectParam {
|
||||||
id: number,
|
id_object: string
|
||||||
id_group: number | null,
|
id_param: number
|
||||||
name: string,
|
name: string
|
||||||
format: string,
|
date_s: string | null
|
||||||
vtable: string,
|
date_po: string | null
|
||||||
unit: string | null,
|
id_user: number
|
||||||
exact_format: string | null,
|
format: string
|
||||||
inHistory: string | null
|
vtable: string
|
||||||
|
exact_format: string | null
|
||||||
|
unit: string | null
|
||||||
|
values: IObjectValue[]
|
||||||
|
parameters?: IObjectParam[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IObjectType {
|
export interface IObjectType {
|
||||||
id: number,
|
id: number
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
@ -181,20 +181,81 @@ export class GeneralService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getValuesByObjectId(object_id: string): Promise<any[]> {
|
async getValuesByObjectId(object_id: string): Promise<any[]> {
|
||||||
const generalDatabase = 'nGeneral'
|
const generalDatabase = 'nGeneral';
|
||||||
|
|
||||||
const result = await this.dataSource.query(`
|
const parameters = await this.dataSource.query(`
|
||||||
SELECT id_object, id_param, CAST(v.value AS varchar(max)) AS value,
|
SELECT
|
||||||
date_s,
|
pt.id_param,
|
||||||
date_po,
|
p.name AS name,
|
||||||
id_user
|
p.id_group,
|
||||||
FROM ${generalDatabase}..tValues v
|
p.format,
|
||||||
JOIN ${generalDatabase}..tParameters p ON v.id_param = p.id
|
p.vtable,
|
||||||
|
p.unit,
|
||||||
|
p.exact_format
|
||||||
|
FROM ${generalDatabase}..ParametersType pt
|
||||||
|
JOIN ${generalDatabase}..tParameters p
|
||||||
|
ON pt.id_param = p.id
|
||||||
|
WHERE pt.id_type = (
|
||||||
|
SELECT TOP 1 CAST(value AS int)
|
||||||
|
FROM ${generalDatabase}..tValues
|
||||||
WHERE id_object = '${object_id}'
|
WHERE id_object = '${object_id}'
|
||||||
`)
|
AND id_param = 3
|
||||||
return result
|
ORDER BY date_s DESC
|
||||||
|
)
|
||||||
|
ORDER BY pt.id_order;
|
||||||
|
`);
|
||||||
|
|
||||||
|
const values = await this.dataSource.query(`
|
||||||
|
SELECT
|
||||||
|
v.id_param,
|
||||||
|
CAST(v.value AS varchar(max)) AS value,
|
||||||
|
v.date_s,
|
||||||
|
v.date_po,
|
||||||
|
v.id_user
|
||||||
|
FROM ${generalDatabase}..tValues v
|
||||||
|
WHERE v.id_object = '${object_id}';
|
||||||
|
`);
|
||||||
|
|
||||||
|
const valuesByParam = values.reduce((acc, v) => {
|
||||||
|
if (!acc[v.id_param]) acc[v.id_param] = [];
|
||||||
|
acc[v.id_param].push({
|
||||||
|
value: v.value,
|
||||||
|
date_s: v.date_s,
|
||||||
|
date_po: v.date_po,
|
||||||
|
id_user: v.id_user
|
||||||
|
});
|
||||||
|
return acc;
|
||||||
|
}, {} as Record<number, any[]>);
|
||||||
|
|
||||||
|
const grouped = parameters
|
||||||
|
.filter(p => p.id_group == null)
|
||||||
|
.map(parent => ({
|
||||||
|
id_param: parent.id_param,
|
||||||
|
name: parent.name,
|
||||||
|
format: parent.format,
|
||||||
|
vtable: parent.vtable,
|
||||||
|
unit: parent.unit,
|
||||||
|
exact_format: parent.exact_format,
|
||||||
|
values: valuesByParam[parent.id_param] || [],
|
||||||
|
parameters: parameters
|
||||||
|
.filter(child => child.id_group === parent.id_param)
|
||||||
|
.map(child => ({
|
||||||
|
id_param: child.id_param,
|
||||||
|
name: child.name,
|
||||||
|
id_group: child.id_group,
|
||||||
|
format: child.format,
|
||||||
|
vtable: child.vtable,
|
||||||
|
unit: child.unit,
|
||||||
|
exact_format: child.exact_format,
|
||||||
|
values: valuesByParam[child.id_param] || []
|
||||||
|
}))
|
||||||
|
}));
|
||||||
|
|
||||||
|
return grouped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async getParamsById(param_id: number): Promise<any[]> {
|
async getParamsById(param_id: number): Promise<any[]> {
|
||||||
const generalDatabase = 'nGeneral'
|
const generalDatabase = 'nGeneral'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user