namirasoft-account-react 1.4.19 → 1.4.21
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/.env.template +10 -10
- package/config-overrides.js +72 -72
- package/dist/IEntityInfo.d.ts +11 -11
- package/dist/Messages.js.map +1 -1
- package/dist/NSARouterMaker.d.ts +0 -1
- package/dist/NSARouterMaker.js.map +1 -1
- package/dist/Router.d.ts +0 -1
- package/dist/components/NSAAccessListDialog.js.map +1 -1
- package/dist/components/NSAAccessListDialog.module.css +87 -0
- package/dist/components/NSABoxOTP.js.map +1 -1
- package/dist/components/NSABoxOTP.module.css +11 -0
- package/dist/components/NSAMessageListDialog.js.map +1 -1
- package/dist/components/NSAMessageListDialog.module.css +98 -0
- package/dist/components/NSAProductListDialog.js.map +1 -1
- package/dist/components/NSAProductListDialog.module.css +45 -0
- package/dist/components/NSAWorkspaceListDialog.js.map +1 -1
- package/dist/components/NSAWorkspaceListDialog.module.css +43 -0
- package/dist/index.js.map +1 -1
- package/dist/layouts/Actions.d.ts +2 -1
- package/dist/layouts/Actions.js +38 -17
- package/dist/layouts/Actions.js.map +1 -1
- package/dist/layouts/NSALayout.d.ts +2 -1
- package/dist/layouts/NSALayout.js +58 -37
- package/dist/layouts/NSALayout.js.map +1 -1
- package/dist/layouts/NSASectionEdit.d.ts +0 -1
- package/dist/layouts/NSASectionEdit.js +12 -8
- package/dist/layouts/NSASectionEdit.js.map +1 -1
- package/dist/layouts/NSASectionList.js +6 -4
- package/dist/layouts/NSASectionList.js.map +1 -1
- package/dist/layouts/NSASectionTabs.d.ts +0 -1
- package/dist/layouts/NSASectionTabs.js +4 -7
- package/dist/layouts/NSASectionTabs.js.map +1 -1
- package/dist/layouts/NSASectionView.js +4 -3
- package/dist/layouts/NSASectionView.js.map +1 -1
- package/dist/pages/NSAHomePage.module.css +23 -0
- package/dist/pages/NSALoginPage.module.css +20 -0
- package/dist/pages/NSAVerificationPage.module.css +23 -0
- package/package.json +70 -70
- package/public/index.html +21 -21
- package/src/App.css +31 -31
- package/src/App.tsx +18 -18
- package/src/IEntityInfo.ts +31 -31
- package/src/INSARouterMaker.ts +7 -7
- package/src/INSARouterProps.ts +17 -17
- package/src/INSARouterState.ts +5 -5
- package/src/Info.ts +20 -20
- package/src/Message.ts +6 -6
- package/src/Messages.ts +33 -33
- package/src/NSARouterMaker.tsx +142 -142
- package/src/Router.tsx +39 -39
- package/src/components/NSAAccessListDialog.module.css +86 -86
- package/src/components/NSAAccessListDialog.tsx +160 -160
- package/src/components/NSABoxOTP.module.css +10 -10
- package/src/components/NSABoxOTP.tsx +63 -63
- package/src/components/NSAMessageListDialog.module.css +97 -97
- package/src/components/NSAMessageListDialog.tsx +116 -116
- package/src/components/NSAProductListDialog.module.css +44 -44
- package/src/components/NSAProductListDialog.tsx +100 -100
- package/src/components/NSAWorkspaceListDialog.module.css +42 -42
- package/src/components/NSAWorkspaceListDialog.tsx +73 -73
- package/src/index.tsx +24 -24
- package/src/layouts/Actions.ts +147 -119
- package/src/layouts/Menus.ts +15 -15
- package/src/layouts/NSALayout.tsx +417 -387
- package/src/layouts/NSASectionEdit.tsx +144 -140
- package/src/layouts/NSASectionList.tsx +161 -158
- package/src/layouts/NSASectionTabs.tsx +152 -156
- package/src/layouts/NSASectionView.tsx +61 -60
- package/src/main.ts +19 -19
- package/src/pages/NSAHomePage.module.css +22 -22
- package/src/pages/NSAHomePage.tsx +27 -27
- package/src/pages/NSALoginPage.module.css +19 -19
- package/src/pages/NSALoginPage.tsx +65 -65
- package/src/pages/NSAVerificationPage.module.css +22 -22
- package/src/pages/NSAVerificationPage.tsx +59 -59
- package/tsconfig.json +43 -43
|
@@ -1,141 +1,145 @@
|
|
|
1
|
-
import { IBaseComponentProps } from "namirasoft-site-react";
|
|
2
|
-
import { NSSection, NSPanel, NSButtonBlue, NSLine, NSSpace, NSSpaceSizeType } from 'namirasoft-site-react';
|
|
3
|
-
import { INSARouterProps } from "../INSARouterProps";
|
|
4
|
-
import { forwardRef, ReactNode, useEffect, useImperativeHandle, useRef } from "react";
|
|
5
|
-
import { useParams } from "react-router-dom";
|
|
6
|
-
import { IEntityInfo } from "../IEntityInfo";
|
|
7
|
-
import { NamingConvention } from "namirasoft-core";
|
|
8
|
-
import { NSASectionTabs, NSASectionTabsRef } from "./NSASectionTabs";
|
|
9
|
-
|
|
10
|
-
export interface NSASectionEditProps<EntityType extends { id: string }, EntityTypeInput = EntityType> extends IBaseComponentProps, INSARouterProps
|
|
11
|
-
{
|
|
12
|
-
isEdit: boolean;
|
|
13
|
-
ui: {
|
|
14
|
-
getEntity: (entity: EntityType | null) => EntityTypeInput;
|
|
15
|
-
setEntity: (entity: EntityType) => void;
|
|
16
|
-
action?: {
|
|
17
|
-
menus: {
|
|
18
|
-
apply?: boolean,
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
tabs?: boolean;
|
|
22
|
-
panel?: boolean;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface NSASectionEditRef
|
|
27
|
-
{
|
|
28
|
-
NSASectionTabs: NSASectionTabsRef | null;
|
|
29
|
-
onApply: () => void;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function onApply<EntityType extends { id: string }, EntityTypeInput = EntityType>(props: NSASectionEditProps<EntityType, EntityTypeInput>, entity: IEntityInfo<EntityType, EntityTypeInput>, id: string | undefined): void
|
|
33
|
-
{
|
|
34
|
-
try
|
|
35
|
-
{
|
|
36
|
-
let Name_Pascal_Space = NamingConvention.lower_case_underscore.convert(entity.name, NamingConvention.Pascal_Case_Space);
|
|
37
|
-
|
|
38
|
-
let onSuccess = (new_entity: EntityType, message: string) =>
|
|
39
|
-
{
|
|
40
|
-
props.notifier.onSuccess(message);
|
|
41
|
-
if (entity.client.onSuccess)
|
|
42
|
-
entity.client.onSuccess(new_entity);
|
|
43
|
-
else
|
|
44
|
-
{
|
|
45
|
-
let url =
|
|
46
|
-
if (
|
|
47
|
-
url = entity.client.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
{
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
1
|
+
import { IBaseComponentProps } from "namirasoft-site-react";
|
|
2
|
+
import { NSSection, NSPanel, NSButtonBlue, NSLine, NSSpace, NSSpaceSizeType } from 'namirasoft-site-react';
|
|
3
|
+
import { INSARouterProps } from "../INSARouterProps";
|
|
4
|
+
import { forwardRef, ReactNode, useEffect, useImperativeHandle, useRef } from "react";
|
|
5
|
+
import { useParams } from "react-router-dom";
|
|
6
|
+
import { IEntityInfo } from "../IEntityInfo";
|
|
7
|
+
import { NamingConvention } from "namirasoft-core";
|
|
8
|
+
import { NSASectionTabs, NSASectionTabsRef } from "./NSASectionTabs";
|
|
9
|
+
|
|
10
|
+
export interface NSASectionEditProps<EntityType extends { id: string }, EntityTypeInput = EntityType> extends IBaseComponentProps, INSARouterProps
|
|
11
|
+
{
|
|
12
|
+
isEdit: boolean;
|
|
13
|
+
ui: {
|
|
14
|
+
getEntity: (entity: EntityType | null) => EntityTypeInput;
|
|
15
|
+
setEntity: (entity: EntityType) => void;
|
|
16
|
+
action?: {
|
|
17
|
+
menus: {
|
|
18
|
+
apply?: boolean,
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
tabs?: boolean;
|
|
22
|
+
panel?: boolean;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface NSASectionEditRef
|
|
27
|
+
{
|
|
28
|
+
NSASectionTabs: NSASectionTabsRef | null;
|
|
29
|
+
onApply: () => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function onApply<EntityType extends { id: string }, EntityTypeInput = EntityType>(props: NSASectionEditProps<EntityType, EntityTypeInput>, entity: IEntityInfo<EntityType, EntityTypeInput>, id: string | undefined): void
|
|
33
|
+
{
|
|
34
|
+
try
|
|
35
|
+
{
|
|
36
|
+
let Name_Pascal_Space = NamingConvention.lower_case_underscore.convert(entity.name, NamingConvention.Pascal_Case_Space);
|
|
37
|
+
|
|
38
|
+
let onSuccess = (new_entity: EntityType, message: string) =>
|
|
39
|
+
{
|
|
40
|
+
props.notifier.onSuccess(message);
|
|
41
|
+
if (entity.client.onSuccess)
|
|
42
|
+
entity.client.onSuccess(new_entity);
|
|
43
|
+
else
|
|
44
|
+
{
|
|
45
|
+
let url = null;
|
|
46
|
+
if (entity.client.getViewURL)
|
|
47
|
+
url = entity.client.getViewURL(new_entity.id);
|
|
48
|
+
else if (entity.client.getListURL)
|
|
49
|
+
url = entity.client.getListURL();
|
|
50
|
+
if (url)
|
|
51
|
+
props.url.redirect(url, {});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
let old_entity: EntityType | null = null;
|
|
55
|
+
let cur_entity = props.ui.getEntity(old_entity);
|
|
56
|
+
if (props.isEdit)
|
|
57
|
+
{
|
|
58
|
+
if (id)
|
|
59
|
+
{
|
|
60
|
+
if (entity.client.onUpdate)
|
|
61
|
+
entity.client.onUpdate(id, cur_entity).then(new_entity =>
|
|
62
|
+
{
|
|
63
|
+
if (new_entity)
|
|
64
|
+
onSuccess(new_entity, Name_Pascal_Space + " has been updated successfully");
|
|
65
|
+
}).catch(() => { });
|
|
66
|
+
else if (entity.server.update)
|
|
67
|
+
entity.server.update(id, cur_entity).then((new_entity) =>
|
|
68
|
+
{
|
|
69
|
+
onSuccess(new_entity, Name_Pascal_Space + " has been updated successfully");
|
|
70
|
+
}).catch(() => { });
|
|
71
|
+
}
|
|
72
|
+
else
|
|
73
|
+
throw new Error("ID was not provided.");
|
|
74
|
+
}
|
|
75
|
+
else
|
|
76
|
+
{
|
|
77
|
+
if (entity.client.onCreate)
|
|
78
|
+
entity.client.onCreate(cur_entity).then(new_entity =>
|
|
79
|
+
{
|
|
80
|
+
if (new_entity)
|
|
81
|
+
onSuccess(new_entity, Name_Pascal_Space + " has been created successfully");
|
|
82
|
+
}).catch(() => { });
|
|
83
|
+
else if (entity.server.create)
|
|
84
|
+
entity.server.create(cur_entity).then((new_entity) =>
|
|
85
|
+
{
|
|
86
|
+
onSuccess(new_entity, Name_Pascal_Space + " has been created successfully");
|
|
87
|
+
}).catch(() => { });
|
|
88
|
+
}
|
|
89
|
+
} catch (error: any)
|
|
90
|
+
{
|
|
91
|
+
props.notifier.onError(error);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const NSASectionEdit = forwardRef<any, any>(<EntityType extends { id: string }, EntityTypeInput = EntityType>(
|
|
96
|
+
props: Omit<NSASectionEditProps<EntityType, EntityTypeInput> & { entity: IEntityInfo<EntityType, EntityTypeInput>, children: ReactNode; } & INSARouterProps, "ref">,
|
|
97
|
+
ref: React.Ref<NSASectionEditRef>
|
|
98
|
+
) =>
|
|
99
|
+
{
|
|
100
|
+
let { id } = useParams();
|
|
101
|
+
let NSASectionTabs_Ref = useRef<NSASectionTabsRef>(null);
|
|
102
|
+
|
|
103
|
+
useEffect(() =>
|
|
104
|
+
{
|
|
105
|
+
if (id)
|
|
106
|
+
if (props.entity.server.get)
|
|
107
|
+
props.entity.server.get(id).then((entity) =>
|
|
108
|
+
{
|
|
109
|
+
props.ui.setEntity(entity);
|
|
110
|
+
}).catch(() => { });
|
|
111
|
+
|
|
112
|
+
}, [id]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
113
|
+
|
|
114
|
+
useImperativeHandle(ref, () => ({
|
|
115
|
+
NSASectionTabs: NSASectionTabs_Ref.current,
|
|
116
|
+
onApply: () =>
|
|
117
|
+
{
|
|
118
|
+
onApply(props, props.entity, id);
|
|
119
|
+
}
|
|
120
|
+
}));
|
|
121
|
+
|
|
122
|
+
let panel = props.ui.panel;
|
|
123
|
+
if (panel !== false)
|
|
124
|
+
panel = true;
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<NSSection
|
|
128
|
+
id={props.id}
|
|
129
|
+
classList={[`${props.classList?.join(" ")}`]}
|
|
130
|
+
center_items={true}
|
|
131
|
+
>
|
|
132
|
+
{
|
|
133
|
+
panel ? <NSPanel grid={false}>
|
|
134
|
+
{props.children}
|
|
135
|
+
</NSPanel> : props.children
|
|
136
|
+
}
|
|
137
|
+
<NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
|
|
138
|
+
<NSButtonBlue title="Apply" onClick={() => { onApply(props, props.entity, id); }} />
|
|
139
|
+
<NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
|
|
140
|
+
{props.isEdit && <NSLine />}
|
|
141
|
+
{props.isEdit && <NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>}
|
|
142
|
+
{props.isEdit && (props.ui.tabs ?? true) && <NSASectionTabs ref={NSASectionTabs_Ref} id={id ?? ""} {...props} />}
|
|
143
|
+
</NSSection>
|
|
144
|
+
);
|
|
141
145
|
});
|
|
@@ -1,159 +1,162 @@
|
|
|
1
|
-
import { Component, ReactNode, createRef } from "react";
|
|
2
|
-
import { EnvService, FilterItem, FilterItemColumnType, FilterItemOperator, ObjectService } from "namirasoft-core";
|
|
3
|
-
import { NSLine, NSSection, NSSpace, NSSpaceSizeType, NSTable, NSFilterBox, INSFilterBoxProps_Table, INSFilterBoxProps_Column, TableColumnInfo, TableRowInfo } from "namirasoft-site-react";
|
|
4
|
-
import { MetaDatabase, NamirasoftFieldServer } from "namirasoft-field";
|
|
5
|
-
import { IEntityInfo } from "../IEntityInfo";
|
|
6
|
-
import { INSARouterProps } from "../INSARouterProps";
|
|
7
|
-
import { NSASectionTabs } from "./NSASectionTabs";
|
|
8
|
-
|
|
9
|
-
export interface NSASectionListProps<EntityType extends { id: string }>
|
|
10
|
-
{
|
|
11
|
-
ui: {
|
|
12
|
-
getColumnAttributes?: () => { [key: string]: string };
|
|
13
|
-
getCellFormattedValue?: (value: any, column: TableColumnInfo, row: TableRowInfo<EntityType>) => any;
|
|
14
|
-
tabs?: boolean;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface NSASectionListState
|
|
19
|
-
{
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class NSASectionList<EntityType extends { id: string }, EntityTypeInput = EntityType> extends Component<NSASectionListProps<EntityType> & INSARouterProps & { entity: IEntityInfo<EntityType, EntityTypeInput> } & INSARouterProps, NSASectionListState>
|
|
23
|
-
{
|
|
24
|
-
public NSFilterBox_Top = createRef<NSFilterBox>();
|
|
25
|
-
public NSTable_Main = createRef<NSTable<EntityType>>();
|
|
26
|
-
constructor(props: NSASectionListProps<EntityType> & INSARouterProps & { entity: IEntityInfo<EntityType, EntityTypeInput>, children: ReactNode })
|
|
27
|
-
{
|
|
28
|
-
super(props);
|
|
29
|
-
this.state = { totalItems: 0 };
|
|
30
|
-
}
|
|
31
|
-
getSelectedIDs(): string[]
|
|
32
|
-
{
|
|
33
|
-
return this.NSTable_Main.current?.getSelectedIDs() ?? [];
|
|
34
|
-
}
|
|
35
|
-
override componentDidMount()
|
|
36
|
-
{
|
|
37
|
-
let filters;
|
|
38
|
-
try
|
|
39
|
-
{
|
|
40
|
-
let encoded = this.props.url.getQuery("filters");
|
|
41
|
-
filters = FilterItem.decode(encoded);
|
|
42
|
-
} catch (error)
|
|
43
|
-
{
|
|
44
|
-
}
|
|
45
|
-
if (filters)
|
|
46
|
-
this.NSFilterBox_Top.current?.setFilterItems(filters);
|
|
47
|
-
else
|
|
48
|
-
this.NSTable_Main.current?.reload(null, null);
|
|
49
|
-
}
|
|
50
|
-
override render()
|
|
51
|
-
{
|
|
52
|
-
const getColumns = (): TableColumnInfo[] =>
|
|
53
|
-
{
|
|
54
|
-
return this.props.entity.client.getColumns();
|
|
55
|
-
};
|
|
56
|
-
const getRowKey = (row: TableRowInfo<EntityType>): string =>
|
|
57
|
-
{
|
|
58
|
-
return row.value.id.toString();
|
|
59
|
-
};
|
|
60
|
-
let ids = this.getSelectedIDs();
|
|
61
|
-
let id = "";
|
|
62
|
-
if (ids.length === 1)
|
|
63
|
-
id = ids[0];
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<NSSection center_items={false}>
|
|
67
|
-
<NSFilterBox ref={this.NSFilterBox_Top}
|
|
68
|
-
getTables={() =>
|
|
69
|
-
{
|
|
70
|
-
return this.props.entity.tables.map(table =>
|
|
71
|
-
{
|
|
72
|
-
let columns = table.table.getColumns().map(c => { return { ...c, type: new ObjectService(c.type).getEnum(FilterItemColumnType, FilterItemColumnType.Any) }; });
|
|
73
|
-
return { table: { name: table.table.name, text: table.table.text, columns }, required: table.required };
|
|
74
|
-
})
|
|
75
|
-
}}
|
|
76
|
-
getMoreTables={async () =>
|
|
77
|
-
{
|
|
78
|
-
let REACT_APP_BASE_URL_FIELD = new EnvService("REACT_APP_BASE_URL_FIELD", true).getString();
|
|
79
|
-
let server = new NamirasoftFieldServer(REACT_APP_BASE_URL_FIELD, this.props.account.token_manager, this.props.notifier.onError);
|
|
80
|
-
let f_items = [
|
|
81
|
-
new FilterItem(MetaDatabase.main.field, MetaDatabase.main.field.columns.product_id, false, FilterItemOperator.all.equals, this.props.entity.product_id),
|
|
82
|
-
new FilterItem(MetaDatabase.main.field, MetaDatabase.main.field.columns.entity, false, FilterItemOperator.all.equals, this.props.entity.name)
|
|
83
|
-
];
|
|
84
|
-
let c_items = [
|
|
85
|
-
new FilterItem(MetaDatabase.main.category, MetaDatabase.main.category.columns.product_id, false, FilterItemOperator.all.equals, this.props.entity.product_id),
|
|
86
|
-
new FilterItem(MetaDatabase.main.category, MetaDatabase.main.category.columns.entity, false, FilterItemOperator.all.equals, this.props.entity.name)
|
|
87
|
-
];
|
|
88
|
-
let ans: { table: INSFilterBoxProps_Table, required: boolean }[] = [];
|
|
89
|
-
try
|
|
90
|
-
{
|
|
91
|
-
let f = server.field.List(f_items, null, null);
|
|
92
|
-
let c = server.category.List(c_items, null, null);
|
|
93
|
-
let r = await Promise.all([f, c]);
|
|
94
|
-
|
|
95
|
-
if (r[0].rows.length > 0)
|
|
96
|
-
ans.push({
|
|
97
|
-
table: {
|
|
98
|
-
name: "fields",
|
|
99
|
-
text: "Fields",
|
|
100
|
-
columns: r[0].rows.map(f => { return { name: f.name, text: f.name, type: new ObjectService(f.type).getEnum(FilterItemColumnType, FilterItemColumnType.Number) } })
|
|
101
|
-
},
|
|
102
|
-
required: false
|
|
103
|
-
});
|
|
104
|
-
if (r[1].rows.length > 0)
|
|
105
|
-
ans.push({
|
|
106
|
-
table: {
|
|
107
|
-
name: "categories",
|
|
108
|
-
text: "Categories",
|
|
109
|
-
columns: r[1].rows.map(c => { return { name: c.name, text: c.name, type: FilterItemColumnType.Number } })
|
|
110
|
-
},
|
|
111
|
-
required: false
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
} catch (error)
|
|
115
|
-
{
|
|
116
|
-
}
|
|
117
|
-
// todo add tags
|
|
118
|
-
return ans;
|
|
119
|
-
}}
|
|
120
|
-
getData={async (table: INSFilterBoxProps_Table, column: INSFilterBoxProps_Column) =>
|
|
121
|
-
{
|
|
122
|
-
return await this.props.entity.server.value_list(table.name, column.name);
|
|
123
|
-
}}
|
|
124
|
-
onChanged={() =>
|
|
125
|
-
{
|
|
126
|
-
this.NSTable_Main.current?.setSelectedIDs([]);
|
|
127
|
-
this.NSTable_Main.current?.reload(null, null);
|
|
128
|
-
}} />
|
|
129
|
-
<NSTable<EntityType>
|
|
130
|
-
ref={this.NSTable_Main}
|
|
131
|
-
checkbox={true}
|
|
132
|
-
columns={getColumns()}
|
|
133
|
-
getRows={async () =>
|
|
134
|
-
{
|
|
135
|
-
if (this.NSTable_Main.current)
|
|
136
|
-
{
|
|
137
|
-
let items = this.NSFilterBox_Top.current?.getFilterItems() ?? [];
|
|
138
|
-
let NSPagination = this.NSTable_Main.current.NSPagination.current;
|
|
139
|
-
if (NSPagination)
|
|
140
|
-
{
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
1
|
+
import { Component, ReactNode, createRef } from "react";
|
|
2
|
+
import { EnvService, FilterItem, FilterItemColumnType, FilterItemOperator, ObjectService } from "namirasoft-core";
|
|
3
|
+
import { NSLine, NSSection, NSSpace, NSSpaceSizeType, NSTable, NSFilterBox, INSFilterBoxProps_Table, INSFilterBoxProps_Column, TableColumnInfo, TableRowInfo } from "namirasoft-site-react";
|
|
4
|
+
import { MetaDatabase, NamirasoftFieldServer } from "namirasoft-field";
|
|
5
|
+
import { IEntityInfo } from "../IEntityInfo";
|
|
6
|
+
import { INSARouterProps } from "../INSARouterProps";
|
|
7
|
+
import { NSASectionTabs } from "./NSASectionTabs";
|
|
8
|
+
|
|
9
|
+
export interface NSASectionListProps<EntityType extends { id: string }>
|
|
10
|
+
{
|
|
11
|
+
ui: {
|
|
12
|
+
getColumnAttributes?: () => { [key: string]: string };
|
|
13
|
+
getCellFormattedValue?: (value: any, column: TableColumnInfo, row: TableRowInfo<EntityType>) => any;
|
|
14
|
+
tabs?: boolean;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface NSASectionListState
|
|
19
|
+
{
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class NSASectionList<EntityType extends { id: string }, EntityTypeInput = EntityType> extends Component<NSASectionListProps<EntityType> & INSARouterProps & { entity: IEntityInfo<EntityType, EntityTypeInput> } & INSARouterProps, NSASectionListState>
|
|
23
|
+
{
|
|
24
|
+
public NSFilterBox_Top = createRef<NSFilterBox>();
|
|
25
|
+
public NSTable_Main = createRef<NSTable<EntityType>>();
|
|
26
|
+
constructor(props: NSASectionListProps<EntityType> & INSARouterProps & { entity: IEntityInfo<EntityType, EntityTypeInput>, children: ReactNode })
|
|
27
|
+
{
|
|
28
|
+
super(props);
|
|
29
|
+
this.state = { totalItems: 0 };
|
|
30
|
+
}
|
|
31
|
+
getSelectedIDs(): string[]
|
|
32
|
+
{
|
|
33
|
+
return this.NSTable_Main.current?.getSelectedIDs() ?? [];
|
|
34
|
+
}
|
|
35
|
+
override componentDidMount()
|
|
36
|
+
{
|
|
37
|
+
let filters;
|
|
38
|
+
try
|
|
39
|
+
{
|
|
40
|
+
let encoded = this.props.url.getQuery("filters");
|
|
41
|
+
filters = FilterItem.decode(encoded);
|
|
42
|
+
} catch (error)
|
|
43
|
+
{
|
|
44
|
+
}
|
|
45
|
+
if (filters)
|
|
46
|
+
this.NSFilterBox_Top.current?.setFilterItems(filters);
|
|
47
|
+
else
|
|
48
|
+
this.NSTable_Main.current?.reload(null, null);
|
|
49
|
+
}
|
|
50
|
+
override render()
|
|
51
|
+
{
|
|
52
|
+
const getColumns = (): TableColumnInfo[] =>
|
|
53
|
+
{
|
|
54
|
+
return this.props.entity.client.getColumns();
|
|
55
|
+
};
|
|
56
|
+
const getRowKey = (row: TableRowInfo<EntityType>): string =>
|
|
57
|
+
{
|
|
58
|
+
return row.value.id.toString();
|
|
59
|
+
};
|
|
60
|
+
let ids = this.getSelectedIDs();
|
|
61
|
+
let id = "";
|
|
62
|
+
if (ids.length === 1)
|
|
63
|
+
id = ids[0];
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<NSSection center_items={false}>
|
|
67
|
+
<NSFilterBox ref={this.NSFilterBox_Top}
|
|
68
|
+
getTables={() =>
|
|
69
|
+
{
|
|
70
|
+
return this.props.entity.tables.map(table =>
|
|
71
|
+
{
|
|
72
|
+
let columns = table.table.getColumns().map(c => { return { ...c, type: new ObjectService(c.type).getEnum(FilterItemColumnType, FilterItemColumnType.Any) }; });
|
|
73
|
+
return { table: { name: table.table.name, text: table.table.text, columns }, required: table.required };
|
|
74
|
+
})
|
|
75
|
+
}}
|
|
76
|
+
getMoreTables={async () =>
|
|
77
|
+
{
|
|
78
|
+
let REACT_APP_BASE_URL_FIELD = new EnvService("REACT_APP_BASE_URL_FIELD", true).getString();
|
|
79
|
+
let server = new NamirasoftFieldServer(REACT_APP_BASE_URL_FIELD, this.props.account.token_manager, this.props.notifier.onError);
|
|
80
|
+
let f_items = [
|
|
81
|
+
new FilterItem(MetaDatabase.main.field, MetaDatabase.main.field.columns.product_id, false, FilterItemOperator.all.equals, this.props.entity.product_id),
|
|
82
|
+
new FilterItem(MetaDatabase.main.field, MetaDatabase.main.field.columns.entity, false, FilterItemOperator.all.equals, this.props.entity.name)
|
|
83
|
+
];
|
|
84
|
+
let c_items = [
|
|
85
|
+
new FilterItem(MetaDatabase.main.category, MetaDatabase.main.category.columns.product_id, false, FilterItemOperator.all.equals, this.props.entity.product_id),
|
|
86
|
+
new FilterItem(MetaDatabase.main.category, MetaDatabase.main.category.columns.entity, false, FilterItemOperator.all.equals, this.props.entity.name)
|
|
87
|
+
];
|
|
88
|
+
let ans: { table: INSFilterBoxProps_Table, required: boolean }[] = [];
|
|
89
|
+
try
|
|
90
|
+
{
|
|
91
|
+
let f = server.field.List(f_items, null, null);
|
|
92
|
+
let c = server.category.List(c_items, null, null);
|
|
93
|
+
let r = await Promise.all([f, c]);
|
|
94
|
+
|
|
95
|
+
if (r[0].rows.length > 0)
|
|
96
|
+
ans.push({
|
|
97
|
+
table: {
|
|
98
|
+
name: "fields",
|
|
99
|
+
text: "Fields",
|
|
100
|
+
columns: r[0].rows.map(f => { return { name: f.name, text: f.name, type: new ObjectService(f.type).getEnum(FilterItemColumnType, FilterItemColumnType.Number) } })
|
|
101
|
+
},
|
|
102
|
+
required: false
|
|
103
|
+
});
|
|
104
|
+
if (r[1].rows.length > 0)
|
|
105
|
+
ans.push({
|
|
106
|
+
table: {
|
|
107
|
+
name: "categories",
|
|
108
|
+
text: "Categories",
|
|
109
|
+
columns: r[1].rows.map(c => { return { name: c.name, text: c.name, type: FilterItemColumnType.Number } })
|
|
110
|
+
},
|
|
111
|
+
required: false
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
} catch (error)
|
|
115
|
+
{
|
|
116
|
+
}
|
|
117
|
+
// todo add tags
|
|
118
|
+
return ans;
|
|
119
|
+
}}
|
|
120
|
+
getData={async (table: INSFilterBoxProps_Table, column: INSFilterBoxProps_Column) =>
|
|
121
|
+
{
|
|
122
|
+
return await this.props.entity.server.value_list(table.name, column.name);
|
|
123
|
+
}}
|
|
124
|
+
onChanged={() =>
|
|
125
|
+
{
|
|
126
|
+
this.NSTable_Main.current?.setSelectedIDs([]);
|
|
127
|
+
this.NSTable_Main.current?.reload(null, null);
|
|
128
|
+
}} />
|
|
129
|
+
<NSTable<EntityType>
|
|
130
|
+
ref={this.NSTable_Main}
|
|
131
|
+
checkbox={true}
|
|
132
|
+
columns={getColumns()}
|
|
133
|
+
getRows={async () =>
|
|
134
|
+
{
|
|
135
|
+
if (this.NSTable_Main.current)
|
|
136
|
+
{
|
|
137
|
+
let items = this.NSFilterBox_Top.current?.getFilterItems() ?? [];
|
|
138
|
+
let NSPagination = this.NSTable_Main.current.NSPagination.current;
|
|
139
|
+
if (NSPagination)
|
|
140
|
+
{
|
|
141
|
+
if (this.props.entity.server.list)
|
|
142
|
+
{
|
|
143
|
+
let res = await this.props.entity.server.list(items, NSPagination.getCurrentPage(), NSPagination.getPageSize());
|
|
144
|
+
return res;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { rows: [], count: 0 };
|
|
149
|
+
}}
|
|
150
|
+
getRowKey={getRowKey}
|
|
151
|
+
getColumnAttributes={this.props.ui.getColumnAttributes}
|
|
152
|
+
getCellFormattedValue={this.props.ui.getCellFormattedValue}
|
|
153
|
+
onSelectedIDsChanged={() => this.setState({})}
|
|
154
|
+
/>
|
|
155
|
+
<NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
|
|
156
|
+
<NSLine></NSLine>
|
|
157
|
+
<NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
|
|
158
|
+
{(this.props.ui.tabs ?? true) && <NSASectionTabs id={id} {...this.props} />}
|
|
159
|
+
</NSSection>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
159
162
|
}
|