namirasoft-site-react 1.4.339 → 1.4.340
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.
- package/.dockerignore +86 -86
- package/.env.template +10 -10
- package/Dockerfile +18 -18
- package/config-overrides.js +72 -72
- package/dist/App.css +34 -0
- package/dist/components/NSBanner.module.css +47 -47
- package/dist/components/NSBarAction.module.css +84 -84
- package/dist/components/NSBarAlert.module.css +79 -79
- package/dist/components/NSBarNotification.module.css +34 -34
- package/dist/components/NSBarTitle.module.css +9 -9
- package/dist/components/NSBox.module.css +50 -50
- package/dist/components/NSBoxBaseCombo.module.css +6 -6
- package/dist/components/NSBoxBoolean.module.css +67 -67
- package/dist/components/NSBoxDate.module.css +4 -4
- package/dist/components/NSBoxDateTime.module.css +4 -4
- package/dist/components/NSBoxDuration.module.css +4 -4
- package/dist/components/NSBoxFile.module.css +10 -10
- package/dist/components/NSBoxPhone.module.css +35 -35
- package/dist/components/NSBoxRadio.module.css +33 -33
- package/dist/components/NSBoxSchemaBase.module.css +17 -17
- package/dist/components/NSBoxSchemaVariable.module.css +16 -16
- package/dist/components/NSBoxTextArea.module.css +12 -12
- package/dist/components/NSBoxTime.module.css +4 -4
- package/dist/components/NSButton.module.css +57 -57
- package/dist/components/NSButtonBlue.module.css +4 -4
- package/dist/components/NSButtonGreen.module.css +4 -4
- package/dist/components/NSButtonRed.module.css +4 -4
- package/dist/components/NSCard.module.css +114 -114
- package/dist/components/NSCardScreenshot.module.css +41 -41
- package/dist/components/NSChartColumn.module.css +7 -7
- package/dist/components/NSChartTable.module.css +21 -21
- package/dist/components/NSColumn.module.css +16 -16
- package/dist/components/NSCopyBox.module.css +39 -39
- package/dist/components/NSDialog.module.css +112 -112
- package/dist/components/NSDialogPageSelection.module.css +103 -103
- package/dist/components/NSDownTimer.module.css +55 -55
- package/dist/components/NSDownload.module.css +46 -46
- package/dist/components/NSElectronicCard.module.css +60 -60
- package/dist/components/NSEntityCardBackground.module.css +27 -27
- package/dist/components/NSFilterBox.module.css +56 -56
- package/dist/components/NSFilterItem.module.css +24 -24
- package/dist/components/NSFooter.module.css +134 -134
- package/dist/components/NSHeader.module.css +291 -291
- package/dist/components/NSHeaderScreenshot.module.css +35 -35
- package/dist/components/NSID.js +2 -0
- package/dist/components/NSID.js.map +1 -1
- package/dist/components/NSLabel.module.css +25 -25
- package/dist/components/NSLabelErrorNotifier.module.css +2 -2
- package/dist/components/NSLayout.module.css +14 -14
- package/dist/components/NSLine.module.css +15 -15
- package/dist/components/NSLink.module.css +36 -36
- package/dist/components/NSListGrouped.module.css +69 -69
- package/dist/components/NSLoading.module.css +30 -30
- package/dist/components/NSMenuAction.js +2 -2
- package/dist/components/NSMenuAction.module.css +88 -88
- package/dist/components/NSMenuButton.module.css +44 -44
- package/dist/components/NSNoData.module.css +9 -9
- package/dist/components/NSPagination.module.css +85 -85
- package/dist/components/NSPanel.module.css +19 -19
- package/dist/components/NSPanelAccordion.module.css +4 -4
- package/dist/components/NSRange.module.css +66 -66
- package/dist/components/NSRow.module.css +17 -17
- package/dist/components/NSSection.module.css +4 -4
- package/dist/components/NSSectionCards.module.css +38 -38
- package/dist/components/NSSectionTiles.module.css +10 -10
- package/dist/components/NSTabPage.module.css +59 -59
- package/dist/components/NSTable.module.css +263 -263
- package/dist/components/NSTile.module.css +76 -76
- package/dist/components/NSTimelineMonthly.module.css +71 -71
- package/dist/components/NSTitle.module.css +15 -15
- package/dist/index.css +6 -0
- package/dist/pages/NSNotFoundPage.module.css +18 -18
- package/dist/pages/NSUpdating.module.css +35 -35
- package/package.json +80 -80
- package/public/index.html +38 -38
- package/src/App.css +33 -33
- package/src/App.tsx +131 -131
- package/src/Color.tsx +10 -10
- package/src/CopyToClipboard.ts +6 -6
- package/src/NSBoxBuilder.tsx +914 -914
- package/src/Validator.ts +163 -163
- package/src/components/INSBox.tsx +6 -6
- package/src/components/NSBanner.module.css +47 -47
- package/src/components/NSBanner.tsx +80 -80
- package/src/components/NSBarAction.module.css +84 -84
- package/src/components/NSBarAction.tsx +90 -90
- package/src/components/NSBarAlert.module.css +79 -79
- package/src/components/NSBarAlert.tsx +35 -35
- package/src/components/NSBarNotification.module.css +34 -34
- package/src/components/NSBarNotification.tsx +85 -85
- package/src/components/NSBarTitle.module.css +9 -9
- package/src/components/NSBarTitle.tsx +23 -23
- package/src/components/NSBox.module.css +50 -50
- package/src/components/NSBox.tsx +19 -19
- package/src/components/NSBoxBaseCombo.module.css +6 -6
- package/src/components/NSBoxBaseCombo.tsx +314 -314
- package/src/components/NSBoxBaseLayout.tsx +88 -88
- package/src/components/NSBoxBaseLayoutRecursive.tsx +54 -54
- package/src/components/NSBoxBoolean.module.css +67 -67
- package/src/components/NSBoxBoolean.tsx +119 -119
- package/src/components/NSBoxBooleans.tsx +161 -161
- package/src/components/NSBoxColor.tsx +95 -95
- package/src/components/NSBoxCombo.tsx +91 -91
- package/src/components/NSBoxDate.module.css +4 -4
- package/src/components/NSBoxDate.tsx +90 -90
- package/src/components/NSBoxDateTime.module.css +4 -4
- package/src/components/NSBoxDateTime.tsx +105 -105
- package/src/components/NSBoxDouble.tsx +94 -94
- package/src/components/NSBoxDuration.module.css +4 -4
- package/src/components/NSBoxDuration.tsx +95 -95
- package/src/components/NSBoxDynamic.tsx +67 -67
- package/src/components/NSBoxDynamics.tsx +68 -68
- package/src/components/NSBoxEmail.tsx +98 -98
- package/src/components/NSBoxEntity.tsx +101 -101
- package/src/components/NSBoxEnum.tsx +108 -108
- package/src/components/NSBoxFile.module.css +10 -10
- package/src/components/NSBoxFile.tsx +101 -101
- package/src/components/NSBoxFilePath.tsx +95 -95
- package/src/components/NSBoxFont.tsx +95 -95
- package/src/components/NSBoxIPV4.tsx +95 -95
- package/src/components/NSBoxIPV4Range.tsx +95 -95
- package/src/components/NSBoxIPV6.tsx +92 -92
- package/src/components/NSBoxIPV6Range.tsx +95 -95
- package/src/components/NSBoxInteger.tsx +91 -91
- package/src/components/NSBoxMoney.tsx +95 -95
- package/src/components/NSBoxPassword.tsx +106 -106
- package/src/components/NSBoxPhone.module.css +35 -35
- package/src/components/NSBoxPhone.tsx +107 -107
- package/src/components/NSBoxRadio.module.css +33 -33
- package/src/components/NSBoxRadio.tsx +91 -91
- package/src/components/NSBoxSchemaBase.module.css +17 -17
- package/src/components/NSBoxSchemaBase.tsx +540 -540
- package/src/components/NSBoxSchemaVariable.module.css +16 -16
- package/src/components/NSBoxSchemaVariable.tsx +250 -250
- package/src/components/NSBoxSearch.tsx +97 -97
- package/src/components/NSBoxString.tsx +91 -91
- package/src/components/NSBoxTextArea.module.css +12 -12
- package/src/components/NSBoxTextArea.tsx +98 -98
- package/src/components/NSBoxTime.module.css +4 -4
- package/src/components/NSBoxTime.tsx +93 -93
- package/src/components/NSBoxTimeZone.tsx +95 -95
- package/src/components/NSBoxURL.tsx +104 -104
- package/src/components/NSBoxVersion.tsx +95 -95
- package/src/components/NSButton.module.css +57 -57
- package/src/components/NSButton.tsx +25 -25
- package/src/components/NSButtonBlue.module.css +4 -4
- package/src/components/NSButtonBlue.tsx +19 -19
- package/src/components/NSButtonGreen.module.css +4 -4
- package/src/components/NSButtonGreen.tsx +19 -19
- package/src/components/NSButtonRed.module.css +4 -4
- package/src/components/NSButtonRed.tsx +19 -19
- package/src/components/NSCard.module.css +114 -114
- package/src/components/NSCard.tsx +63 -63
- package/src/components/NSCardScreenshot.module.css +41 -41
- package/src/components/NSCardScreenshot.tsx +31 -31
- package/src/components/NSChartColumn.module.css +7 -7
- package/src/components/NSChartColumn.tsx +106 -106
- package/src/components/NSChartDoughnut.tsx +112 -112
- package/src/components/NSChartPie.tsx +105 -105
- package/src/components/NSChartRange.tsx +14 -14
- package/src/components/NSChartTable.module.css +21 -21
- package/src/components/NSChartTable.tsx +94 -94
- package/src/components/NSColumn.module.css +16 -16
- package/src/components/NSColumn.tsx +24 -24
- package/src/components/NSCopy.tsx +58 -58
- package/src/components/NSCopyBox.module.css +39 -39
- package/src/components/NSCopyBox.tsx +53 -53
- package/src/components/NSDialog.module.css +112 -112
- package/src/components/NSDialog.tsx +61 -61
- package/src/components/NSDialogDelete.tsx +26 -26
- package/src/components/NSDialogInfo.tsx +32 -32
- package/src/components/NSDialogPageSelection.module.css +103 -103
- package/src/components/NSDialogPageSelection.tsx +227 -227
- package/src/components/NSDownTimer.module.css +55 -55
- package/src/components/NSDownTimer.tsx +91 -91
- package/src/components/NSDownload.module.css +46 -46
- package/src/components/NSDownload.tsx +66 -66
- package/src/components/NSElectronicCard.module.css +60 -60
- package/src/components/NSElectronicCard.tsx +46 -46
- package/src/components/NSEntityCardBackground.module.css +27 -27
- package/src/components/NSEntityCardBackground.tsx +36 -36
- package/src/components/NSFilterBox.module.css +56 -56
- package/src/components/NSFilterBox.tsx +506 -506
- package/src/components/NSFilterItem.module.css +24 -24
- package/src/components/NSFilterItem.tsx +27 -27
- package/src/components/NSFooter.module.css +134 -134
- package/src/components/NSFooter.tsx +321 -321
- package/src/components/NSHeader.module.css +291 -291
- package/src/components/NSHeader.tsx +261 -261
- package/src/components/NSHeaderScreenshot.module.css +35 -35
- package/src/components/NSHeaderScreenshot.tsx +39 -39
- package/src/components/NSID.tsx +133 -131
- package/src/components/NSLabel.module.css +25 -25
- package/src/components/NSLabel.tsx +46 -46
- package/src/components/NSLabelErrorNotifier.module.css +2 -2
- package/src/components/NSLabelErrorNotifier.tsx +35 -35
- package/src/components/NSLayout.module.css +14 -14
- package/src/components/NSLayout.tsx +126 -126
- package/src/components/NSLine.module.css +15 -15
- package/src/components/NSLine.tsx +13 -13
- package/src/components/NSLink.module.css +36 -36
- package/src/components/NSLink.tsx +25 -25
- package/src/components/NSLinkBlue.tsx +21 -21
- package/src/components/NSLinkGreen.tsx +12 -12
- package/src/components/NSLinkRed.tsx +12 -12
- package/src/components/NSListGrouped.module.css +69 -69
- package/src/components/NSListGrouped.tsx +106 -106
- package/src/components/NSListProduct.tsx +44 -44
- package/src/components/NSLoading.module.css +30 -30
- package/src/components/NSLoading.tsx +21 -21
- package/src/components/NSMenuAction.module.css +88 -88
- package/src/components/NSMenuAction.tsx +90 -90
- package/src/components/NSMenuButton.module.css +44 -44
- package/src/components/NSMenuButton.tsx +206 -206
- package/src/components/NSNoData.module.css +9 -9
- package/src/components/NSNoData.tsx +24 -24
- package/src/components/NSPagination.module.css +85 -85
- package/src/components/NSPagination.tsx +182 -182
- package/src/components/NSPanel.module.css +19 -19
- package/src/components/NSPanel.tsx +24 -24
- package/src/components/NSPanelAccordion.module.css +4 -4
- package/src/components/NSPanelAccordion.tsx +51 -51
- package/src/components/NSRange.module.css +66 -66
- package/src/components/NSRange.tsx +83 -83
- package/src/components/NSRepeater.tsx +256 -256
- package/src/components/NSRepeaterNSBoxSchemaVariable.tsx +90 -90
- package/src/components/NSRepeaterNSTag.tsx +81 -81
- package/src/components/NSRow.module.css +17 -17
- package/src/components/NSRow.tsx +24 -24
- package/src/components/NSSection.module.css +4 -4
- package/src/components/NSSection.tsx +26 -26
- package/src/components/NSSectionCards.module.css +38 -38
- package/src/components/NSSectionCards.tsx +51 -51
- package/src/components/NSSectionTiles.module.css +10 -10
- package/src/components/NSSectionTiles.tsx +25 -25
- package/src/components/NSSectionTitle.tsx +21 -21
- package/src/components/NSSpace.tsx +28 -28
- package/src/components/NSTabPage.module.css +59 -59
- package/src/components/NSTabPage.tsx +91 -91
- package/src/components/NSTable.module.css +263 -263
- package/src/components/NSTable.tsx +482 -482
- package/src/components/NSTag.tsx +74 -74
- package/src/components/NSTile.module.css +76 -76
- package/src/components/NSTile.tsx +27 -27
- package/src/components/NSTimelineMonthly.module.css +71 -71
- package/src/components/NSTimelineMonthly.tsx +44 -44
- package/src/components/NSTitle.module.css +15 -15
- package/src/components/NSTitle.tsx +19 -19
- package/src/formatter/BackColorFormatter.tsx +23 -23
- package/src/formatter/BaseColumnFormatter.ts +16 -16
- package/src/formatter/BaseURLImageFormatter.tsx +33 -33
- package/src/formatter/BooleanFormatter.ts +22 -22
- package/src/formatter/DateFormatter.ts +21 -21
- package/src/formatter/DateTimeFormatter.ts +21 -21
- package/src/formatter/DurationFormatter.ts +13 -13
- package/src/formatter/EmailFormatter.tsx +21 -21
- package/src/formatter/EnumFormatter.ts +13 -13
- package/src/formatter/FloatFormatter.ts +23 -23
- package/src/formatter/ForeColorFormatter.tsx +24 -24
- package/src/formatter/IDFormatter.tsx +30 -30
- package/src/formatter/IPFormatter.ts +13 -13
- package/src/formatter/IntegerFormatter.ts +23 -23
- package/src/formatter/JsonFormatter.ts +21 -21
- package/src/formatter/MoneyFormatter.ts +30 -30
- package/src/formatter/PhoneFormatter.tsx +21 -21
- package/src/formatter/StringFormatter.tsx +43 -43
- package/src/formatter/TimeFormatter.ts +21 -21
- package/src/formatter/URLFormatter.tsx +21 -21
- package/src/formatter/UnknowFormatter.ts +18 -18
- package/src/index.tsx +7 -7
- package/src/main.ts +222 -222
- package/src/pages/NSNotFoundPage.module.css +18 -18
- package/src/pages/NSNotFoundPage.tsx +11 -11
- package/src/pages/NSUpdating.module.css +35 -35
- package/src/pages/NSUpdating.tsx +32 -32
- package/src/props/IBackgroundPropps.ts +5 -5
- package/src/props/IBaseComponentProps.ts +8 -8
- package/src/props/IHeaderIconProps.ts +10 -10
- package/src/props/IHeaderProps.ts +7 -7
- package/src/props/IImageProps.ts +4 -4
- package/src/props/ILinkProps.ts +5 -5
- package/src/props/IValidationNumberProps.ts +4 -4
- package/src/props/IValidationPrecisionProps.ts +3 -3
- package/src/props/IValidationProps.ts +9 -9
- package/src/props/IValidationRegexProps.ts +4 -4
- package/src/props/IValidationStringProps.ts +4 -4
- package/src/routing/NSNotifier.ts +114 -114
- package/src/routing/NSRouterMaker.tsx +20 -20
- package/src/routing/NSRouterMakerComponent.ts +5 -5
- package/src/routing/NSRouterMakerProps.ts +5 -5
|
@@ -1,507 +1,507 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import React, { Component } from 'react';
|
|
4
|
-
import { IBaseComponentProps } from '../props/IBaseComponentProps';
|
|
5
|
-
import { NSFilterItem } from './NSFilterItem';
|
|
6
|
-
import { BaseMetaColumn, BaseMetaTable, FilterItem, FilterItemColumnType, FilterItemOperator, SetTimeouService } from 'namirasoft-core';
|
|
7
|
-
import { NSListGrouped, NSListGroupedProps_Group, NSListGroupedProps_Item } from './NSListGrouped';
|
|
8
|
-
import { NSButton } from './NSButton';
|
|
9
|
-
import Styles from './NSFilterBox.module.css';
|
|
10
|
-
import { NSBoxSearch } from './NSBoxSearch';
|
|
11
|
-
import { NSBox } from './NSBox';
|
|
12
|
-
import { NSLabel } from './NSLabel';
|
|
13
|
-
|
|
14
|
-
export interface NSFilterBoxProps extends IBaseComponentProps
|
|
15
|
-
{
|
|
16
|
-
placeholder?: string;
|
|
17
|
-
getTables: () => NSFilterBoxProps_Table[];
|
|
18
|
-
getMoreTables: () => Promise<NSFilterBoxProps_Table[]>;
|
|
19
|
-
getValues: ((table: NSFilterBoxProps_Table, column: NSFilterBoxProps_Column, value: string) => Promise<NSFilterBox_Group_Value[]>) | null;
|
|
20
|
-
onChanged?: () => void;
|
|
21
|
-
filterItems?: FilterItem[];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface NSFilterBoxProps_Table
|
|
25
|
-
{
|
|
26
|
-
name: string;
|
|
27
|
-
text: string;
|
|
28
|
-
required: boolean;
|
|
29
|
-
columns: NSFilterBoxProps_Column[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface NSFilterBoxProps_Column
|
|
33
|
-
{
|
|
34
|
-
id: string,
|
|
35
|
-
name: string,
|
|
36
|
-
text: string,
|
|
37
|
-
type: FilterItemColumnType
|
|
38
|
-
getValues?: (search: string) => Promise<NSFilterBox_Group_Value[]>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface NSFilterBox_Group_Column
|
|
42
|
-
{
|
|
43
|
-
id: string;
|
|
44
|
-
name: string;
|
|
45
|
-
not: boolean;
|
|
46
|
-
}
|
|
47
|
-
export interface NSFilterBox_Group_Operator
|
|
48
|
-
{
|
|
49
|
-
not: boolean;
|
|
50
|
-
sign: string;
|
|
51
|
-
}
|
|
52
|
-
export interface NSFilterBox_Group_Value
|
|
53
|
-
{
|
|
54
|
-
value: string;
|
|
55
|
-
title: string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
interface NSFilterBoxState_Selection
|
|
59
|
-
{
|
|
60
|
-
state: GroupListState;
|
|
61
|
-
column: { table: NSFilterBoxProps_Table, column: NSFilterBoxProps_Column } | null;
|
|
62
|
-
operator: FilterItemOperator | null;
|
|
63
|
-
not: boolean | null;
|
|
64
|
-
values: NSFilterBox_Group_Value[] | null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
interface NSFilterBoxState
|
|
68
|
-
{
|
|
69
|
-
tables: NSFilterBoxProps_Table[];
|
|
70
|
-
filterItems: FilterItem[];
|
|
71
|
-
value: string;
|
|
72
|
-
selected: NSFilterBoxState_Selection;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
enum GroupListState
|
|
76
|
-
{
|
|
77
|
-
Normal = 'Normal',
|
|
78
|
-
Column = 'Column',
|
|
79
|
-
Opertor = 'Opertor',
|
|
80
|
-
Value = 'Value'
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export class NSFilterBox extends Component<NSFilterBoxProps, NSFilterBoxState>
|
|
84
|
-
{
|
|
85
|
-
private service: SetTimeouService = new SetTimeouService();
|
|
86
|
-
private NSBoxSearch_Main?: React.RefObject<NSBoxSearch> = React.createRef<NSBoxSearch>();
|
|
87
|
-
private use_all = {
|
|
88
|
-
value: "*",
|
|
89
|
-
text: "Use",
|
|
90
|
-
}
|
|
91
|
-
constructor(props: NSFilterBoxProps)
|
|
92
|
-
{
|
|
93
|
-
super(props);
|
|
94
|
-
this.state = {
|
|
95
|
-
tables: [],
|
|
96
|
-
filterItems: props.filterItems ?? [],
|
|
97
|
-
value: "",
|
|
98
|
-
selected: {
|
|
99
|
-
state: GroupListState.Normal,
|
|
100
|
-
column: null,
|
|
101
|
-
operator: null,
|
|
102
|
-
not: null,
|
|
103
|
-
values: [],
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
this.findTable = this.findTable.bind(this);
|
|
108
|
-
this.findColumn = this.findColumn.bind(this);
|
|
109
|
-
|
|
110
|
-
this.getFilterItems = this.getFilterItems.bind(this);
|
|
111
|
-
this.setFilterItems = this.setFilterItems.bind(this);
|
|
112
|
-
this.removeFilterItem = this.removeFilterItem.bind(this);
|
|
113
|
-
|
|
114
|
-
this.reloadData = this.reloadData.bind(this);
|
|
115
|
-
this.reloadTables = this.reloadTables.bind(this);
|
|
116
|
-
this.setSelected = this.setSelected.bind(this);
|
|
117
|
-
this.setSelectedValues = this.setSelectedValues.bind(this);
|
|
118
|
-
|
|
119
|
-
this.onSelected_Column = this.onSelected_Column.bind(this);
|
|
120
|
-
this.onSelected_Operator = this.onSelected_Operator.bind(this);
|
|
121
|
-
this.onSelected_Value = this.onSelected_Value.bind(this);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private findTable(name: string): NSFilterBoxProps_Table
|
|
125
|
-
{
|
|
126
|
-
let res = this.state.tables.filter(t => t.name === name);
|
|
127
|
-
if (res.length === 1)
|
|
128
|
-
return res[0];
|
|
129
|
-
throw new Error("Table not found: " + name);
|
|
130
|
-
}
|
|
131
|
-
private findColumn(table: NSFilterBoxProps_Table, id: string)
|
|
132
|
-
{
|
|
133
|
-
let res = table.columns.filter(c => c.id === id);
|
|
134
|
-
if (res.length === 1)
|
|
135
|
-
return res[0];
|
|
136
|
-
throw new Error("Column not found: " + id);
|
|
137
|
-
}
|
|
138
|
-
public getFilterItems(): FilterItem[]
|
|
139
|
-
{
|
|
140
|
-
return this.state.filterItems;
|
|
141
|
-
}
|
|
142
|
-
public setFilterItems(filterItems: FilterItem[] | null): void
|
|
143
|
-
{
|
|
144
|
-
this.setState({ filterItems: filterItems ?? [] }, () =>
|
|
145
|
-
{
|
|
146
|
-
this.props.onChanged?.();
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
private removeFilterItem(item: FilterItem): void
|
|
150
|
-
{
|
|
151
|
-
let filterItems = [...this.state.filterItems];
|
|
152
|
-
filterItems = filterItems.filter(i => i !== item)
|
|
153
|
-
this.setFilterItems(filterItems);
|
|
154
|
-
}
|
|
155
|
-
public reloadTables()
|
|
156
|
-
{
|
|
157
|
-
this.setState({ tables: this.props.getTables() }, () =>
|
|
158
|
-
{
|
|
159
|
-
this.props.getMoreTables().then(tables =>
|
|
160
|
-
{
|
|
161
|
-
this.setState({ tables: [...this.state.tables, ...tables] });
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
public reloadData()
|
|
166
|
-
{
|
|
167
|
-
if (this.state.selected.state === GroupListState.Value)
|
|
168
|
-
if (this.state.selected.column)
|
|
169
|
-
{
|
|
170
|
-
let search = this.NSBoxSearch_Main?.current?.getValue() ?? "";
|
|
171
|
-
this.setSelectedValues(null);
|
|
172
|
-
if (this.state.selected.column.column.getValues)
|
|
173
|
-
{
|
|
174
|
-
this.state.selected.column.column.getValues(search).then(values =>
|
|
175
|
-
{
|
|
176
|
-
this.setSelectedValues(values);
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
else if (this.props.getValues)
|
|
180
|
-
{
|
|
181
|
-
this.props.getValues(this.state.selected.column.table, this.state.selected.column.column, search).then(values =>
|
|
182
|
-
{
|
|
183
|
-
this.setSelectedValues(values);
|
|
184
|
-
}).catch(() => { });
|
|
185
|
-
}
|
|
186
|
-
else
|
|
187
|
-
this.setSelectedValues([]);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private setSelectedValues(values: NSFilterBox_Group_Value[] | null)
|
|
192
|
-
{
|
|
193
|
-
this.setSelected(this.state.selected.state, this.state.selected.column, this.state.selected.operator, this.state.selected.not, values, false);
|
|
194
|
-
}
|
|
195
|
-
private setSelected(state: GroupListState, column: { table: NSFilterBoxProps_Table, column: NSFilterBoxProps_Column } | null, operator: FilterItemOperator | null, not: boolean | null, values: NSFilterBox_Group_Value[] | null, reset: boolean, callback?: () => void)
|
|
196
|
-
{
|
|
197
|
-
this.setState({ selected: { state, column, operator, not, values } }, () =>
|
|
198
|
-
{
|
|
199
|
-
if (reset)
|
|
200
|
-
this.NSBoxSearch_Main?.current?.setValue("");
|
|
201
|
-
this.NSBoxSearch_Main?.current?.input.current?.focus();
|
|
202
|
-
callback?.();
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
override componentDidMount()
|
|
207
|
-
{
|
|
208
|
-
this.reloadTables();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
private onSelected_Column(table: NSListGroupedProps_Group<NSFilterBox_Group_Column>, column: NSListGroupedProps_Item<NSFilterBox_Group_Column>)
|
|
212
|
-
{
|
|
213
|
-
if (table.value === this.use_all.value)
|
|
214
|
-
{
|
|
215
|
-
this.onSelected_Value(column.value.not, [column.value.name]);
|
|
216
|
-
}
|
|
217
|
-
else
|
|
218
|
-
{
|
|
219
|
-
let t = this.findTable(table.value);
|
|
220
|
-
let c = this.findColumn(t, column.value.id);
|
|
221
|
-
this.setSelected(GroupListState.Opertor, { table: t, column: c }, null, null, [], false);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
private onSelected_Operator(_: NSListGroupedProps_Group<NSFilterBox_Group_Operator>, operator: NSListGroupedProps_Item<NSFilterBox_Group_Operator>)
|
|
225
|
-
{
|
|
226
|
-
if (this.state.selected.column)
|
|
227
|
-
{
|
|
228
|
-
let not = operator.value.not;
|
|
229
|
-
let o = FilterItemOperator.getBySign(operator.value.sign);
|
|
230
|
-
this.setSelected(GroupListState.Value, this.state.selected.column, o, not, [], false, () =>
|
|
231
|
-
{
|
|
232
|
-
if (o.count === 0)
|
|
233
|
-
this.onSelected_Value(not, []);
|
|
234
|
-
else if (o.count === 1)
|
|
235
|
-
{
|
|
236
|
-
if (this.state.selected.column)
|
|
237
|
-
this.reloadData();
|
|
238
|
-
}
|
|
239
|
-
else
|
|
240
|
-
{
|
|
241
|
-
alert("Operator is not supported: " + JSON.stringify(o));
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
private onSelected_Value(not: boolean, values: string[])
|
|
247
|
-
{
|
|
248
|
-
let filterItems = this.state.filterItems;
|
|
249
|
-
if (this.state.selected.column && this.state.selected.operator)
|
|
250
|
-
{
|
|
251
|
-
let table = new BaseMetaTable(null, this.state.selected.column.table.name, this.state.selected.column.table.text);
|
|
252
|
-
let column = new BaseMetaColumn(table, this.state.selected.column.column.name, this.state.selected.column.column.text, this.state.selected.column.column.type, false);
|
|
253
|
-
filterItems.push(new FilterItem(table, column, not, this.state.selected.operator, ...values));
|
|
254
|
-
}
|
|
255
|
-
else
|
|
256
|
-
{
|
|
257
|
-
let t = this.state.tables[0];
|
|
258
|
-
let table = new BaseMetaTable(null, t.name, t.text);
|
|
259
|
-
let column = new BaseMetaColumn(table, "*", "", "", false);
|
|
260
|
-
filterItems.push(new FilterItem(table, column, not, FilterItemOperator.all.equals, ...values));
|
|
261
|
-
}
|
|
262
|
-
this.setState({ filterItems }, () =>
|
|
263
|
-
{
|
|
264
|
-
this.NSBoxSearch_Main?.current?.setValue("");
|
|
265
|
-
this.props.onChanged?.();
|
|
266
|
-
});
|
|
267
|
-
this.setSelected(GroupListState.Normal, null, null, null, [], true);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
override render()
|
|
271
|
-
{
|
|
272
|
-
let getComputedValue = () =>
|
|
273
|
-
{
|
|
274
|
-
let ans = "";
|
|
275
|
-
if (this.state.selected.column)
|
|
276
|
-
ans += this.state.selected.column.table.text + "." + this.state.selected.column.column.text + " ";
|
|
277
|
-
if (this.state.selected.not)
|
|
278
|
-
ans += "!";
|
|
279
|
-
if (this.state.selected.operator)
|
|
280
|
-
ans += this.state.selected.operator.sign + " ";
|
|
281
|
-
return ans;
|
|
282
|
-
}
|
|
283
|
-
let computed_value = getComputedValue();
|
|
284
|
-
let value = this.NSBoxSearch_Main?.current?.getValue() ?? "";
|
|
285
|
-
|
|
286
|
-
let groups_column: NSListGroupedProps_Group<NSFilterBox_Group_Column>[] = [];
|
|
287
|
-
if (value)
|
|
288
|
-
groups_column.push({
|
|
289
|
-
...this.use_all,
|
|
290
|
-
items: [
|
|
291
|
-
{
|
|
292
|
-
value: { id: value, name: value, not: false },
|
|
293
|
-
text: computed_value,
|
|
294
|
-
text_bold: value,
|
|
295
|
-
}, {
|
|
296
|
-
value: { id: value, name: value, not: true },
|
|
297
|
-
text: "Not " + computed_value,
|
|
298
|
-
text_bold: value,
|
|
299
|
-
}
|
|
300
|
-
]
|
|
301
|
-
});
|
|
302
|
-
groups_column.push(...this.state.tables.map((table) =>
|
|
303
|
-
{
|
|
304
|
-
return {
|
|
305
|
-
value: table.name,
|
|
306
|
-
text: table.text,
|
|
307
|
-
items: table.columns.map((column) =>
|
|
308
|
-
{
|
|
309
|
-
return {
|
|
310
|
-
value: { id: column.id, name: column.name, not: false },
|
|
311
|
-
text: column.text,
|
|
312
|
-
type: column.type,
|
|
313
|
-
}
|
|
314
|
-
})
|
|
315
|
-
}
|
|
316
|
-
}))
|
|
317
|
-
|
|
318
|
-
let groups_operator: NSListGroupedProps_Group<NSFilterBox_Group_Operator>[] = [
|
|
319
|
-
{
|
|
320
|
-
value: "operators",
|
|
321
|
-
text: "Operators",
|
|
322
|
-
items: []
|
|
323
|
-
}
|
|
324
|
-
]
|
|
325
|
-
if (this.state.selected.column)
|
|
326
|
-
FilterItemOperator.getAllByType(this.state.selected.column.column.type, this.findTable(this.state.selected.column.table.name).required).forEach((operator) =>
|
|
327
|
-
{
|
|
328
|
-
groups_operator[0].items?.push({
|
|
329
|
-
value: { sign: operator.sign, not: false },
|
|
330
|
-
text: this.state.selected.column?.column.text ?? "",
|
|
331
|
-
text_bold: operator.sign,
|
|
332
|
-
description: operator.name,
|
|
333
|
-
});
|
|
334
|
-
groups_operator[0].items?.push({
|
|
335
|
-
value: { sign: operator.sign, not: true },
|
|
336
|
-
text: this.state.selected.column?.column.text ?? "",
|
|
337
|
-
text_bold: "!" + operator.sign,
|
|
338
|
-
description: "Not " + operator.name
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
let groups_value: NSListGroupedProps_Group<NSFilterBox_Group_Value>[] = [];
|
|
343
|
-
if (value)
|
|
344
|
-
groups_value.push({
|
|
345
|
-
...this.use_all,
|
|
346
|
-
items: [
|
|
347
|
-
{
|
|
348
|
-
value: { value, title: value },
|
|
349
|
-
text: computed_value,
|
|
350
|
-
text_bold: value,
|
|
351
|
-
}
|
|
352
|
-
]
|
|
353
|
-
});
|
|
354
|
-
groups_value.push({
|
|
355
|
-
value: "value",
|
|
356
|
-
text: "Value",
|
|
357
|
-
items: this.state.selected.values?.map(value =>
|
|
358
|
-
{
|
|
359
|
-
return {
|
|
360
|
-
value: value,
|
|
361
|
-
text: computed_value,
|
|
362
|
-
text_bold: value.title,
|
|
363
|
-
};
|
|
364
|
-
}) ?? null
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
return (
|
|
368
|
-
<>
|
|
369
|
-
<div
|
|
370
|
-
id={this.props.id}
|
|
371
|
-
className={`${Styles.ns_filter_box_container} ${this.props.classList?.join(" ") ?? ""}`}
|
|
372
|
-
style={this.props.style}>
|
|
373
|
-
<div className={Styles.ns_filter_box_filter_parent}
|
|
374
|
-
>
|
|
375
|
-
<div style={{ display: "flex", width: "400px", maxWidth: "100%" }}
|
|
376
|
-
>
|
|
377
|
-
{
|
|
378
|
-
computed_value && <>
|
|
379
|
-
<NSLabel
|
|
380
|
-
title={computed_value}
|
|
381
|
-
style={{
|
|
382
|
-
borderLeft: "1px black solid",
|
|
383
|
-
borderTop: "1px black solid",
|
|
384
|
-
borderBottom: "1px black solid",
|
|
385
|
-
borderTopLeftRadius: "8px",
|
|
386
|
-
borderBottomLeftRadius: "8px",
|
|
387
|
-
display: "flex",
|
|
388
|
-
flexDirection: "row",
|
|
389
|
-
width: "max-content"
|
|
390
|
-
}}
|
|
391
|
-
/>
|
|
392
|
-
</>
|
|
393
|
-
}
|
|
394
|
-
<NSBoxSearch
|
|
395
|
-
ref={this.NSBoxSearch_Main}
|
|
396
|
-
required={false}
|
|
397
|
-
hideHeader
|
|
398
|
-
title=''
|
|
399
|
-
placeholder={this.props.placeholder}
|
|
400
|
-
onChanged={e =>
|
|
401
|
-
{
|
|
402
|
-
let value = e.getValue() ?? "";
|
|
403
|
-
if (value)
|
|
404
|
-
if (this.state.selected.state === GroupListState.Normal)
|
|
405
|
-
this.setSelected(GroupListState.Column, null, null, null, [], true);
|
|
406
|
-
else if (this.state.selected.state === GroupListState.Value)
|
|
407
|
-
{
|
|
408
|
-
this.setSelectedValues(null);
|
|
409
|
-
this.service.setTimeoutIfNotCalledAgain(this.reloadData, 1000);
|
|
410
|
-
}
|
|
411
|
-
this.setState({ value });
|
|
412
|
-
}}
|
|
413
|
-
onEnterPressed={() =>
|
|
414
|
-
{
|
|
415
|
-
let value = this.NSBoxSearch_Main?.current?.getValue() ?? "";
|
|
416
|
-
if (value)
|
|
417
|
-
{
|
|
418
|
-
if (this.state.selected.state === GroupListState.Value)
|
|
419
|
-
this.onSelected_Value(false, [value]);
|
|
420
|
-
else
|
|
421
|
-
this.onSelected_Column({ ...this.use_all, items: [] }, {
|
|
422
|
-
value: { id: value, name: value, not: false },
|
|
423
|
-
text: value
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
}}
|
|
427
|
-
onClicked={() =>
|
|
428
|
-
{
|
|
429
|
-
if (this.state.selected.state === GroupListState.Normal)
|
|
430
|
-
this.setSelected(GroupListState.Column, null, null, null, [], false);
|
|
431
|
-
}}
|
|
432
|
-
style={{
|
|
433
|
-
flexGrow: 1,
|
|
434
|
-
width: "10px"
|
|
435
|
-
}}
|
|
436
|
-
/>
|
|
437
|
-
</div>
|
|
438
|
-
{
|
|
439
|
-
this.state.filterItems.length > 0 &&
|
|
440
|
-
<>
|
|
441
|
-
<NSButton
|
|
442
|
-
title={'Clear Filter' + (this.state.filterItems.length > 1 ? "s" : "")}
|
|
443
|
-
onClick={() =>
|
|
444
|
-
{
|
|
445
|
-
this.setFilterItems([]);
|
|
446
|
-
}} style={{ width: "136px", border: "2px solid #001664" }}
|
|
447
|
-
/>
|
|
448
|
-
|
|
449
|
-
<div className={Styles.ns_filter_box_selected_list_parent}>
|
|
450
|
-
{
|
|
451
|
-
this.state.filterItems.map((item, index) =>
|
|
452
|
-
<NSFilterItem
|
|
453
|
-
item={item}
|
|
454
|
-
key={`NSFilterBox_NSFilterItem_key_${index}`}
|
|
455
|
-
removeSelected={() => this.removeFilterItem(item)}
|
|
456
|
-
/>
|
|
457
|
-
)
|
|
458
|
-
}
|
|
459
|
-
</div>
|
|
460
|
-
</>
|
|
461
|
-
}
|
|
462
|
-
</div>
|
|
463
|
-
{
|
|
464
|
-
this.state.selected.state === GroupListState.Column &&
|
|
465
|
-
<NSListGrouped<NSFilterBox_Group_Column>
|
|
466
|
-
groups={groups_column}
|
|
467
|
-
onClose={() =>
|
|
468
|
-
{
|
|
469
|
-
if (this.NSBoxSearch_Main?.current?.input.current !== document.activeElement)
|
|
470
|
-
this.setSelected(GroupListState.Normal, null, null, null, [], true)
|
|
471
|
-
}}
|
|
472
|
-
onClick={this.onSelected_Column}
|
|
473
|
-
style={{ zIndex: 10, marginTop: NSBox.height.box, position: "absolute" }}
|
|
474
|
-
/>
|
|
475
|
-
}
|
|
476
|
-
{
|
|
477
|
-
this.state.selected.state === GroupListState.Opertor && <>
|
|
478
|
-
<NSListGrouped<NSFilterBox_Group_Operator>
|
|
479
|
-
groups={groups_operator}
|
|
480
|
-
onClick={this.onSelected_Operator}
|
|
481
|
-
onClose={() =>
|
|
482
|
-
{
|
|
483
|
-
if (this.NSBoxSearch_Main?.current?.input.current !== document.activeElement)
|
|
484
|
-
this.setSelected(GroupListState.Normal, null, null, null, [], true)
|
|
485
|
-
}}
|
|
486
|
-
style={{ zIndex: 10, marginTop: NSBox.height.box, position: "absolute" }}
|
|
487
|
-
/>
|
|
488
|
-
</>
|
|
489
|
-
}
|
|
490
|
-
{
|
|
491
|
-
this.state.selected.state === GroupListState.Value &&
|
|
492
|
-
<NSListGrouped<NSFilterBox_Group_Value>
|
|
493
|
-
groups={groups_value}
|
|
494
|
-
onClick={(_, item) => this.onSelected_Value(this.state.selected.not ?? false, [item.value.value])}
|
|
495
|
-
onClose={() =>
|
|
496
|
-
{
|
|
497
|
-
if (this.NSBoxSearch_Main?.current?.input.current !== document.activeElement)
|
|
498
|
-
this.setSelected(GroupListState.Normal, null, null, null, [], true)
|
|
499
|
-
}}
|
|
500
|
-
style={{ zIndex: 10, marginTop: NSBox.height.box, position: "absolute" }}
|
|
501
|
-
/>
|
|
502
|
-
}
|
|
503
|
-
</div>
|
|
504
|
-
</>
|
|
505
|
-
);
|
|
506
|
-
}
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import React, { Component } from 'react';
|
|
4
|
+
import { IBaseComponentProps } from '../props/IBaseComponentProps';
|
|
5
|
+
import { NSFilterItem } from './NSFilterItem';
|
|
6
|
+
import { BaseMetaColumn, BaseMetaTable, FilterItem, FilterItemColumnType, FilterItemOperator, SetTimeouService } from 'namirasoft-core';
|
|
7
|
+
import { NSListGrouped, NSListGroupedProps_Group, NSListGroupedProps_Item } from './NSListGrouped';
|
|
8
|
+
import { NSButton } from './NSButton';
|
|
9
|
+
import Styles from './NSFilterBox.module.css';
|
|
10
|
+
import { NSBoxSearch } from './NSBoxSearch';
|
|
11
|
+
import { NSBox } from './NSBox';
|
|
12
|
+
import { NSLabel } from './NSLabel';
|
|
13
|
+
|
|
14
|
+
export interface NSFilterBoxProps extends IBaseComponentProps
|
|
15
|
+
{
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
getTables: () => NSFilterBoxProps_Table[];
|
|
18
|
+
getMoreTables: () => Promise<NSFilterBoxProps_Table[]>;
|
|
19
|
+
getValues: ((table: NSFilterBoxProps_Table, column: NSFilterBoxProps_Column, value: string) => Promise<NSFilterBox_Group_Value[]>) | null;
|
|
20
|
+
onChanged?: () => void;
|
|
21
|
+
filterItems?: FilterItem[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface NSFilterBoxProps_Table
|
|
25
|
+
{
|
|
26
|
+
name: string;
|
|
27
|
+
text: string;
|
|
28
|
+
required: boolean;
|
|
29
|
+
columns: NSFilterBoxProps_Column[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface NSFilterBoxProps_Column
|
|
33
|
+
{
|
|
34
|
+
id: string,
|
|
35
|
+
name: string,
|
|
36
|
+
text: string,
|
|
37
|
+
type: FilterItemColumnType
|
|
38
|
+
getValues?: (search: string) => Promise<NSFilterBox_Group_Value[]>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface NSFilterBox_Group_Column
|
|
42
|
+
{
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
not: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface NSFilterBox_Group_Operator
|
|
48
|
+
{
|
|
49
|
+
not: boolean;
|
|
50
|
+
sign: string;
|
|
51
|
+
}
|
|
52
|
+
export interface NSFilterBox_Group_Value
|
|
53
|
+
{
|
|
54
|
+
value: string;
|
|
55
|
+
title: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface NSFilterBoxState_Selection
|
|
59
|
+
{
|
|
60
|
+
state: GroupListState;
|
|
61
|
+
column: { table: NSFilterBoxProps_Table, column: NSFilterBoxProps_Column } | null;
|
|
62
|
+
operator: FilterItemOperator | null;
|
|
63
|
+
not: boolean | null;
|
|
64
|
+
values: NSFilterBox_Group_Value[] | null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface NSFilterBoxState
|
|
68
|
+
{
|
|
69
|
+
tables: NSFilterBoxProps_Table[];
|
|
70
|
+
filterItems: FilterItem[];
|
|
71
|
+
value: string;
|
|
72
|
+
selected: NSFilterBoxState_Selection;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
enum GroupListState
|
|
76
|
+
{
|
|
77
|
+
Normal = 'Normal',
|
|
78
|
+
Column = 'Column',
|
|
79
|
+
Opertor = 'Opertor',
|
|
80
|
+
Value = 'Value'
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export class NSFilterBox extends Component<NSFilterBoxProps, NSFilterBoxState>
|
|
84
|
+
{
|
|
85
|
+
private service: SetTimeouService = new SetTimeouService();
|
|
86
|
+
private NSBoxSearch_Main?: React.RefObject<NSBoxSearch> = React.createRef<NSBoxSearch>();
|
|
87
|
+
private use_all = {
|
|
88
|
+
value: "*",
|
|
89
|
+
text: "Use",
|
|
90
|
+
}
|
|
91
|
+
constructor(props: NSFilterBoxProps)
|
|
92
|
+
{
|
|
93
|
+
super(props);
|
|
94
|
+
this.state = {
|
|
95
|
+
tables: [],
|
|
96
|
+
filterItems: props.filterItems ?? [],
|
|
97
|
+
value: "",
|
|
98
|
+
selected: {
|
|
99
|
+
state: GroupListState.Normal,
|
|
100
|
+
column: null,
|
|
101
|
+
operator: null,
|
|
102
|
+
not: null,
|
|
103
|
+
values: [],
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
this.findTable = this.findTable.bind(this);
|
|
108
|
+
this.findColumn = this.findColumn.bind(this);
|
|
109
|
+
|
|
110
|
+
this.getFilterItems = this.getFilterItems.bind(this);
|
|
111
|
+
this.setFilterItems = this.setFilterItems.bind(this);
|
|
112
|
+
this.removeFilterItem = this.removeFilterItem.bind(this);
|
|
113
|
+
|
|
114
|
+
this.reloadData = this.reloadData.bind(this);
|
|
115
|
+
this.reloadTables = this.reloadTables.bind(this);
|
|
116
|
+
this.setSelected = this.setSelected.bind(this);
|
|
117
|
+
this.setSelectedValues = this.setSelectedValues.bind(this);
|
|
118
|
+
|
|
119
|
+
this.onSelected_Column = this.onSelected_Column.bind(this);
|
|
120
|
+
this.onSelected_Operator = this.onSelected_Operator.bind(this);
|
|
121
|
+
this.onSelected_Value = this.onSelected_Value.bind(this);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private findTable(name: string): NSFilterBoxProps_Table
|
|
125
|
+
{
|
|
126
|
+
let res = this.state.tables.filter(t => t.name === name);
|
|
127
|
+
if (res.length === 1)
|
|
128
|
+
return res[0];
|
|
129
|
+
throw new Error("Table not found: " + name);
|
|
130
|
+
}
|
|
131
|
+
private findColumn(table: NSFilterBoxProps_Table, id: string)
|
|
132
|
+
{
|
|
133
|
+
let res = table.columns.filter(c => c.id === id);
|
|
134
|
+
if (res.length === 1)
|
|
135
|
+
return res[0];
|
|
136
|
+
throw new Error("Column not found: " + id);
|
|
137
|
+
}
|
|
138
|
+
public getFilterItems(): FilterItem[]
|
|
139
|
+
{
|
|
140
|
+
return this.state.filterItems;
|
|
141
|
+
}
|
|
142
|
+
public setFilterItems(filterItems: FilterItem[] | null): void
|
|
143
|
+
{
|
|
144
|
+
this.setState({ filterItems: filterItems ?? [] }, () =>
|
|
145
|
+
{
|
|
146
|
+
this.props.onChanged?.();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
private removeFilterItem(item: FilterItem): void
|
|
150
|
+
{
|
|
151
|
+
let filterItems = [...this.state.filterItems];
|
|
152
|
+
filterItems = filterItems.filter(i => i !== item)
|
|
153
|
+
this.setFilterItems(filterItems);
|
|
154
|
+
}
|
|
155
|
+
public reloadTables()
|
|
156
|
+
{
|
|
157
|
+
this.setState({ tables: this.props.getTables() }, () =>
|
|
158
|
+
{
|
|
159
|
+
this.props.getMoreTables().then(tables =>
|
|
160
|
+
{
|
|
161
|
+
this.setState({ tables: [...this.state.tables, ...tables] });
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
public reloadData()
|
|
166
|
+
{
|
|
167
|
+
if (this.state.selected.state === GroupListState.Value)
|
|
168
|
+
if (this.state.selected.column)
|
|
169
|
+
{
|
|
170
|
+
let search = this.NSBoxSearch_Main?.current?.getValue() ?? "";
|
|
171
|
+
this.setSelectedValues(null);
|
|
172
|
+
if (this.state.selected.column.column.getValues)
|
|
173
|
+
{
|
|
174
|
+
this.state.selected.column.column.getValues(search).then(values =>
|
|
175
|
+
{
|
|
176
|
+
this.setSelectedValues(values);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
else if (this.props.getValues)
|
|
180
|
+
{
|
|
181
|
+
this.props.getValues(this.state.selected.column.table, this.state.selected.column.column, search).then(values =>
|
|
182
|
+
{
|
|
183
|
+
this.setSelectedValues(values);
|
|
184
|
+
}).catch(() => { });
|
|
185
|
+
}
|
|
186
|
+
else
|
|
187
|
+
this.setSelectedValues([]);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private setSelectedValues(values: NSFilterBox_Group_Value[] | null)
|
|
192
|
+
{
|
|
193
|
+
this.setSelected(this.state.selected.state, this.state.selected.column, this.state.selected.operator, this.state.selected.not, values, false);
|
|
194
|
+
}
|
|
195
|
+
private setSelected(state: GroupListState, column: { table: NSFilterBoxProps_Table, column: NSFilterBoxProps_Column } | null, operator: FilterItemOperator | null, not: boolean | null, values: NSFilterBox_Group_Value[] | null, reset: boolean, callback?: () => void)
|
|
196
|
+
{
|
|
197
|
+
this.setState({ selected: { state, column, operator, not, values } }, () =>
|
|
198
|
+
{
|
|
199
|
+
if (reset)
|
|
200
|
+
this.NSBoxSearch_Main?.current?.setValue("");
|
|
201
|
+
this.NSBoxSearch_Main?.current?.input.current?.focus();
|
|
202
|
+
callback?.();
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
override componentDidMount()
|
|
207
|
+
{
|
|
208
|
+
this.reloadTables();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private onSelected_Column(table: NSListGroupedProps_Group<NSFilterBox_Group_Column>, column: NSListGroupedProps_Item<NSFilterBox_Group_Column>)
|
|
212
|
+
{
|
|
213
|
+
if (table.value === this.use_all.value)
|
|
214
|
+
{
|
|
215
|
+
this.onSelected_Value(column.value.not, [column.value.name]);
|
|
216
|
+
}
|
|
217
|
+
else
|
|
218
|
+
{
|
|
219
|
+
let t = this.findTable(table.value);
|
|
220
|
+
let c = this.findColumn(t, column.value.id);
|
|
221
|
+
this.setSelected(GroupListState.Opertor, { table: t, column: c }, null, null, [], false);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
private onSelected_Operator(_: NSListGroupedProps_Group<NSFilterBox_Group_Operator>, operator: NSListGroupedProps_Item<NSFilterBox_Group_Operator>)
|
|
225
|
+
{
|
|
226
|
+
if (this.state.selected.column)
|
|
227
|
+
{
|
|
228
|
+
let not = operator.value.not;
|
|
229
|
+
let o = FilterItemOperator.getBySign(operator.value.sign);
|
|
230
|
+
this.setSelected(GroupListState.Value, this.state.selected.column, o, not, [], false, () =>
|
|
231
|
+
{
|
|
232
|
+
if (o.count === 0)
|
|
233
|
+
this.onSelected_Value(not, []);
|
|
234
|
+
else if (o.count === 1)
|
|
235
|
+
{
|
|
236
|
+
if (this.state.selected.column)
|
|
237
|
+
this.reloadData();
|
|
238
|
+
}
|
|
239
|
+
else
|
|
240
|
+
{
|
|
241
|
+
alert("Operator is not supported: " + JSON.stringify(o));
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
private onSelected_Value(not: boolean, values: string[])
|
|
247
|
+
{
|
|
248
|
+
let filterItems = this.state.filterItems;
|
|
249
|
+
if (this.state.selected.column && this.state.selected.operator)
|
|
250
|
+
{
|
|
251
|
+
let table = new BaseMetaTable(null, this.state.selected.column.table.name, this.state.selected.column.table.text);
|
|
252
|
+
let column = new BaseMetaColumn(table, this.state.selected.column.column.name, this.state.selected.column.column.text, this.state.selected.column.column.type, false);
|
|
253
|
+
filterItems.push(new FilterItem(table, column, not, this.state.selected.operator, ...values));
|
|
254
|
+
}
|
|
255
|
+
else
|
|
256
|
+
{
|
|
257
|
+
let t = this.state.tables[0];
|
|
258
|
+
let table = new BaseMetaTable(null, t.name, t.text);
|
|
259
|
+
let column = new BaseMetaColumn(table, "*", "", "", false);
|
|
260
|
+
filterItems.push(new FilterItem(table, column, not, FilterItemOperator.all.equals, ...values));
|
|
261
|
+
}
|
|
262
|
+
this.setState({ filterItems }, () =>
|
|
263
|
+
{
|
|
264
|
+
this.NSBoxSearch_Main?.current?.setValue("");
|
|
265
|
+
this.props.onChanged?.();
|
|
266
|
+
});
|
|
267
|
+
this.setSelected(GroupListState.Normal, null, null, null, [], true);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
override render()
|
|
271
|
+
{
|
|
272
|
+
let getComputedValue = () =>
|
|
273
|
+
{
|
|
274
|
+
let ans = "";
|
|
275
|
+
if (this.state.selected.column)
|
|
276
|
+
ans += this.state.selected.column.table.text + "." + this.state.selected.column.column.text + " ";
|
|
277
|
+
if (this.state.selected.not)
|
|
278
|
+
ans += "!";
|
|
279
|
+
if (this.state.selected.operator)
|
|
280
|
+
ans += this.state.selected.operator.sign + " ";
|
|
281
|
+
return ans;
|
|
282
|
+
}
|
|
283
|
+
let computed_value = getComputedValue();
|
|
284
|
+
let value = this.NSBoxSearch_Main?.current?.getValue() ?? "";
|
|
285
|
+
|
|
286
|
+
let groups_column: NSListGroupedProps_Group<NSFilterBox_Group_Column>[] = [];
|
|
287
|
+
if (value)
|
|
288
|
+
groups_column.push({
|
|
289
|
+
...this.use_all,
|
|
290
|
+
items: [
|
|
291
|
+
{
|
|
292
|
+
value: { id: value, name: value, not: false },
|
|
293
|
+
text: computed_value,
|
|
294
|
+
text_bold: value,
|
|
295
|
+
}, {
|
|
296
|
+
value: { id: value, name: value, not: true },
|
|
297
|
+
text: "Not " + computed_value,
|
|
298
|
+
text_bold: value,
|
|
299
|
+
}
|
|
300
|
+
]
|
|
301
|
+
});
|
|
302
|
+
groups_column.push(...this.state.tables.map((table) =>
|
|
303
|
+
{
|
|
304
|
+
return {
|
|
305
|
+
value: table.name,
|
|
306
|
+
text: table.text,
|
|
307
|
+
items: table.columns.map((column) =>
|
|
308
|
+
{
|
|
309
|
+
return {
|
|
310
|
+
value: { id: column.id, name: column.name, not: false },
|
|
311
|
+
text: column.text,
|
|
312
|
+
type: column.type,
|
|
313
|
+
}
|
|
314
|
+
})
|
|
315
|
+
}
|
|
316
|
+
}))
|
|
317
|
+
|
|
318
|
+
let groups_operator: NSListGroupedProps_Group<NSFilterBox_Group_Operator>[] = [
|
|
319
|
+
{
|
|
320
|
+
value: "operators",
|
|
321
|
+
text: "Operators",
|
|
322
|
+
items: []
|
|
323
|
+
}
|
|
324
|
+
]
|
|
325
|
+
if (this.state.selected.column)
|
|
326
|
+
FilterItemOperator.getAllByType(this.state.selected.column.column.type, this.findTable(this.state.selected.column.table.name).required).forEach((operator) =>
|
|
327
|
+
{
|
|
328
|
+
groups_operator[0].items?.push({
|
|
329
|
+
value: { sign: operator.sign, not: false },
|
|
330
|
+
text: this.state.selected.column?.column.text ?? "",
|
|
331
|
+
text_bold: operator.sign,
|
|
332
|
+
description: operator.name,
|
|
333
|
+
});
|
|
334
|
+
groups_operator[0].items?.push({
|
|
335
|
+
value: { sign: operator.sign, not: true },
|
|
336
|
+
text: this.state.selected.column?.column.text ?? "",
|
|
337
|
+
text_bold: "!" + operator.sign,
|
|
338
|
+
description: "Not " + operator.name
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
let groups_value: NSListGroupedProps_Group<NSFilterBox_Group_Value>[] = [];
|
|
343
|
+
if (value)
|
|
344
|
+
groups_value.push({
|
|
345
|
+
...this.use_all,
|
|
346
|
+
items: [
|
|
347
|
+
{
|
|
348
|
+
value: { value, title: value },
|
|
349
|
+
text: computed_value,
|
|
350
|
+
text_bold: value,
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
});
|
|
354
|
+
groups_value.push({
|
|
355
|
+
value: "value",
|
|
356
|
+
text: "Value",
|
|
357
|
+
items: this.state.selected.values?.map(value =>
|
|
358
|
+
{
|
|
359
|
+
return {
|
|
360
|
+
value: value,
|
|
361
|
+
text: computed_value,
|
|
362
|
+
text_bold: value.title,
|
|
363
|
+
};
|
|
364
|
+
}) ?? null
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
return (
|
|
368
|
+
<>
|
|
369
|
+
<div
|
|
370
|
+
id={this.props.id}
|
|
371
|
+
className={`${Styles.ns_filter_box_container} ${this.props.classList?.join(" ") ?? ""}`}
|
|
372
|
+
style={this.props.style}>
|
|
373
|
+
<div className={Styles.ns_filter_box_filter_parent}
|
|
374
|
+
>
|
|
375
|
+
<div style={{ display: "flex", width: "400px", maxWidth: "100%" }}
|
|
376
|
+
>
|
|
377
|
+
{
|
|
378
|
+
computed_value && <>
|
|
379
|
+
<NSLabel
|
|
380
|
+
title={computed_value}
|
|
381
|
+
style={{
|
|
382
|
+
borderLeft: "1px black solid",
|
|
383
|
+
borderTop: "1px black solid",
|
|
384
|
+
borderBottom: "1px black solid",
|
|
385
|
+
borderTopLeftRadius: "8px",
|
|
386
|
+
borderBottomLeftRadius: "8px",
|
|
387
|
+
display: "flex",
|
|
388
|
+
flexDirection: "row",
|
|
389
|
+
width: "max-content"
|
|
390
|
+
}}
|
|
391
|
+
/>
|
|
392
|
+
</>
|
|
393
|
+
}
|
|
394
|
+
<NSBoxSearch
|
|
395
|
+
ref={this.NSBoxSearch_Main}
|
|
396
|
+
required={false}
|
|
397
|
+
hideHeader
|
|
398
|
+
title=''
|
|
399
|
+
placeholder={this.props.placeholder}
|
|
400
|
+
onChanged={e =>
|
|
401
|
+
{
|
|
402
|
+
let value = e.getValue() ?? "";
|
|
403
|
+
if (value)
|
|
404
|
+
if (this.state.selected.state === GroupListState.Normal)
|
|
405
|
+
this.setSelected(GroupListState.Column, null, null, null, [], true);
|
|
406
|
+
else if (this.state.selected.state === GroupListState.Value)
|
|
407
|
+
{
|
|
408
|
+
this.setSelectedValues(null);
|
|
409
|
+
this.service.setTimeoutIfNotCalledAgain(this.reloadData, 1000);
|
|
410
|
+
}
|
|
411
|
+
this.setState({ value });
|
|
412
|
+
}}
|
|
413
|
+
onEnterPressed={() =>
|
|
414
|
+
{
|
|
415
|
+
let value = this.NSBoxSearch_Main?.current?.getValue() ?? "";
|
|
416
|
+
if (value)
|
|
417
|
+
{
|
|
418
|
+
if (this.state.selected.state === GroupListState.Value)
|
|
419
|
+
this.onSelected_Value(false, [value]);
|
|
420
|
+
else
|
|
421
|
+
this.onSelected_Column({ ...this.use_all, items: [] }, {
|
|
422
|
+
value: { id: value, name: value, not: false },
|
|
423
|
+
text: value
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}}
|
|
427
|
+
onClicked={() =>
|
|
428
|
+
{
|
|
429
|
+
if (this.state.selected.state === GroupListState.Normal)
|
|
430
|
+
this.setSelected(GroupListState.Column, null, null, null, [], false);
|
|
431
|
+
}}
|
|
432
|
+
style={{
|
|
433
|
+
flexGrow: 1,
|
|
434
|
+
width: "10px"
|
|
435
|
+
}}
|
|
436
|
+
/>
|
|
437
|
+
</div>
|
|
438
|
+
{
|
|
439
|
+
this.state.filterItems.length > 0 &&
|
|
440
|
+
<>
|
|
441
|
+
<NSButton
|
|
442
|
+
title={'Clear Filter' + (this.state.filterItems.length > 1 ? "s" : "")}
|
|
443
|
+
onClick={() =>
|
|
444
|
+
{
|
|
445
|
+
this.setFilterItems([]);
|
|
446
|
+
}} style={{ width: "136px", border: "2px solid #001664" }}
|
|
447
|
+
/>
|
|
448
|
+
|
|
449
|
+
<div className={Styles.ns_filter_box_selected_list_parent}>
|
|
450
|
+
{
|
|
451
|
+
this.state.filterItems.map((item, index) =>
|
|
452
|
+
<NSFilterItem
|
|
453
|
+
item={item}
|
|
454
|
+
key={`NSFilterBox_NSFilterItem_key_${index}`}
|
|
455
|
+
removeSelected={() => this.removeFilterItem(item)}
|
|
456
|
+
/>
|
|
457
|
+
)
|
|
458
|
+
}
|
|
459
|
+
</div>
|
|
460
|
+
</>
|
|
461
|
+
}
|
|
462
|
+
</div>
|
|
463
|
+
{
|
|
464
|
+
this.state.selected.state === GroupListState.Column &&
|
|
465
|
+
<NSListGrouped<NSFilterBox_Group_Column>
|
|
466
|
+
groups={groups_column}
|
|
467
|
+
onClose={() =>
|
|
468
|
+
{
|
|
469
|
+
if (this.NSBoxSearch_Main?.current?.input.current !== document.activeElement)
|
|
470
|
+
this.setSelected(GroupListState.Normal, null, null, null, [], true)
|
|
471
|
+
}}
|
|
472
|
+
onClick={this.onSelected_Column}
|
|
473
|
+
style={{ zIndex: 10, marginTop: NSBox.height.box, position: "absolute" }}
|
|
474
|
+
/>
|
|
475
|
+
}
|
|
476
|
+
{
|
|
477
|
+
this.state.selected.state === GroupListState.Opertor && <>
|
|
478
|
+
<NSListGrouped<NSFilterBox_Group_Operator>
|
|
479
|
+
groups={groups_operator}
|
|
480
|
+
onClick={this.onSelected_Operator}
|
|
481
|
+
onClose={() =>
|
|
482
|
+
{
|
|
483
|
+
if (this.NSBoxSearch_Main?.current?.input.current !== document.activeElement)
|
|
484
|
+
this.setSelected(GroupListState.Normal, null, null, null, [], true)
|
|
485
|
+
}}
|
|
486
|
+
style={{ zIndex: 10, marginTop: NSBox.height.box, position: "absolute" }}
|
|
487
|
+
/>
|
|
488
|
+
</>
|
|
489
|
+
}
|
|
490
|
+
{
|
|
491
|
+
this.state.selected.state === GroupListState.Value &&
|
|
492
|
+
<NSListGrouped<NSFilterBox_Group_Value>
|
|
493
|
+
groups={groups_value}
|
|
494
|
+
onClick={(_, item) => this.onSelected_Value(this.state.selected.not ?? false, [item.value.value])}
|
|
495
|
+
onClose={() =>
|
|
496
|
+
{
|
|
497
|
+
if (this.NSBoxSearch_Main?.current?.input.current !== document.activeElement)
|
|
498
|
+
this.setSelected(GroupListState.Normal, null, null, null, [], true)
|
|
499
|
+
}}
|
|
500
|
+
style={{ zIndex: 10, marginTop: NSBox.height.box, position: "absolute" }}
|
|
501
|
+
/>
|
|
502
|
+
}
|
|
503
|
+
</div>
|
|
504
|
+
</>
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
507
|
}
|