namirasoft-site-react 1.3.348 → 1.3.349
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/Dockerfile +18 -18
- package/config-overrides.js +70 -70
- package/dist/assets/images/404 image.svg +9 -9
- package/dist/assets/images/404 image_mobile.svg +9 -9
- package/dist/assets/images/arrow.svg +3 -3
- package/dist/assets/images/danger.svg +3 -3
- package/dist/assets/images/exit.svg +3 -3
- package/dist/assets/images/icon-input-copy.svg +3 -3
- package/dist/assets/images/icon-input-date.svg +9 -9
- package/dist/assets/images/icon-input-duration.svg +9 -9
- package/dist/assets/images/icon-input-email.svg +9 -9
- package/dist/assets/images/icon-input-float.svg +9 -9
- package/dist/assets/images/icon-input-integer.svg +9 -9
- package/dist/assets/images/icon-input-ip.svg +9 -9
- package/dist/assets/images/icon-input-phone.svg +9 -9
- package/dist/assets/images/icon-input-price.svg +9 -9
- package/dist/assets/images/icon-input-search.svg +3 -3
- package/dist/assets/images/icon-input-string.svg +9 -9
- package/dist/assets/images/icon-input-text.svg +9 -9
- package/dist/assets/images/icon-input-time.svg +9 -9
- package/dist/assets/images/icon-select-box.svg +3 -3
- package/dist/assets/images/logo.svg +9 -9
- package/dist/assets/images/menu.svg +3 -3
- package/dist/assets/images/namira.svg +9 -9
- package/dist/assets/images/rectangle.svg +3 -3
- package/dist/components/NSActionMenu.js +2 -2
- package/dist/components/NSActionMenu.module.css +75 -75
- package/dist/components/NSAssistantButton.module.css +133 -133
- package/dist/components/NSBarAction.module.css +87 -87
- package/dist/components/NSBarHeroBanner.module.css +42 -42
- package/dist/components/NSBarNotification.module.css +34 -34
- package/dist/components/NSBarTitle.module.css +9 -9
- package/dist/components/NSBox.module.css +123 -123
- package/dist/components/NSBoxBoolean.module.css +53 -53
- package/dist/components/NSBoxCombo.module.css +16 -16
- package/dist/components/NSBoxDate.module.css +39 -39
- package/dist/components/NSBoxEntity.module.css +25 -25
- package/dist/components/NSBoxErrorNotifier.module.css +2 -2
- package/dist/components/NSBoxLabel.module.css +12 -12
- package/dist/components/NSBoxOTP.module.css +10 -10
- package/dist/components/NSBoxTextArea.module.css +76 -76
- package/dist/components/NSButton.module.css +27 -27
- 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 +108 -108
- package/dist/components/NSCopyToClipboard.module.css +39 -39
- package/dist/components/NSElectronicCard.module.css +60 -60
- package/dist/components/NSEntityBar.module.css +77 -77
- package/dist/components/NSEntityCardBackground.module.css +27 -27
- package/dist/components/NSFilterBox.d.ts +1 -0
- package/dist/components/NSFilterBox.js +7 -7
- package/dist/components/NSFilterBox.js.map +1 -1
- package/dist/components/NSFilterBox.module.css +47 -47
- package/dist/components/NSFilterBoxDialog.module.css +36 -36
- package/dist/components/NSFilterItem.module.css +23 -23
- package/dist/components/NSFooter.js +1 -1
- package/dist/components/NSFooter.js.map +1 -1
- package/dist/components/NSFooter.module.css +123 -123
- package/dist/components/NSGroupedList.module.css +72 -72
- package/dist/components/NSHeader.js +1 -1
- package/dist/components/NSHeader.js.map +1 -1
- package/dist/components/NSHeader.module.css +271 -271
- package/dist/components/NSLayout.module.css +13 -13
- package/dist/components/NSLink.module.css +36 -36
- package/dist/components/NSLoading.module.css +29 -29
- package/dist/components/NSModal.js +2 -2
- package/dist/components/NSModal.module.css +70 -70
- package/dist/components/NSNoData.module.css +8 -8
- package/dist/components/NSPageSelectionModal.module.css +102 -102
- package/dist/components/NSPagination.module.css +101 -101
- package/dist/components/NSPanel.module.css +46 -46
- package/dist/components/NSRadioButton.module.css +61 -61
- package/dist/components/NSSection.module.css +10 -10
- package/dist/components/NSSectionBars.module.css +10 -10
- package/dist/components/NSSectionCards.module.css +38 -38
- package/dist/components/NSTabPage.module.css +57 -57
- package/dist/components/NSTable.module.css +253 -253
- package/dist/components/NSTag.module.css +44 -44
- package/dist/components/NSTitle.module.css +15 -15
- package/dist/components/NSVerification.module.css +22 -22
- package/dist/pages/NSNotFoundPage.module.css +18 -18
- package/package.json +67 -67
- package/public/index.html +38 -38
- package/src/App.css +16 -16
- package/src/App.tsx +166 -166
- package/src/CopyToClipboard.ts +6 -6
- package/src/Validator.ts +110 -110
- package/src/assets/images/404 image.svg +9 -9
- package/src/assets/images/404 image_mobile.svg +9 -9
- package/src/assets/images/arrow.svg +3 -3
- package/src/assets/images/danger.svg +3 -3
- package/src/assets/images/exit.svg +3 -3
- package/src/assets/images/icon-input-copy.svg +3 -3
- package/src/assets/images/icon-input-date.svg +9 -9
- package/src/assets/images/icon-input-duration.svg +9 -9
- package/src/assets/images/icon-input-email.svg +9 -9
- package/src/assets/images/icon-input-float.svg +9 -9
- package/src/assets/images/icon-input-integer.svg +9 -9
- package/src/assets/images/icon-input-ip.svg +9 -9
- package/src/assets/images/icon-input-phone.svg +9 -9
- package/src/assets/images/icon-input-price.svg +9 -9
- package/src/assets/images/icon-input-search.svg +3 -3
- package/src/assets/images/icon-input-string.svg +9 -9
- package/src/assets/images/icon-input-text.svg +9 -9
- package/src/assets/images/icon-input-time.svg +9 -9
- package/src/assets/images/icon-select-box.svg +3 -3
- package/src/assets/images/logo.svg +9 -9
- package/src/assets/images/menu.svg +3 -3
- package/src/assets/images/namira.svg +9 -9
- package/src/assets/images/rectangle.svg +3 -3
- package/src/components/NSActionMenu.module.css +75 -75
- package/src/components/NSActionMenu.tsx +88 -88
- package/src/components/NSAssistantButton.module.css +133 -133
- package/src/components/NSAssistantButton.tsx +74 -74
- package/src/components/NSBarAction.module.css +87 -87
- package/src/components/NSBarAction.tsx +86 -86
- package/src/components/NSBarHeroBanner.module.css +42 -42
- package/src/components/NSBarHeroBanner.tsx +61 -61
- package/src/components/NSBarNotification.module.css +34 -34
- package/src/components/NSBarNotification.tsx +63 -63
- package/src/components/NSBarTitle.module.css +9 -9
- package/src/components/NSBarTitle.tsx +28 -28
- package/src/components/NSBox.module.css +123 -123
- package/src/components/NSBoxBoolean.module.css +53 -53
- package/src/components/NSBoxBoolean.tsx +84 -84
- package/src/components/NSBoxCombo.module.css +16 -16
- package/src/components/NSBoxCombo.tsx +132 -132
- package/src/components/NSBoxDate.module.css +39 -39
- package/src/components/NSBoxDate.tsx +83 -83
- package/src/components/NSBoxDateTime.tsx +83 -83
- package/src/components/NSBoxDouble.tsx +88 -88
- package/src/components/NSBoxDuration.tsx +88 -88
- package/src/components/NSBoxEmail.tsx +104 -104
- package/src/components/NSBoxEntity.module.css +25 -25
- package/src/components/NSBoxEntity.tsx +178 -178
- package/src/components/NSBoxEnum.tsx +56 -56
- package/src/components/NSBoxErrorNotifier.module.css +2 -2
- package/src/components/NSBoxErrorNotifier.tsx +33 -33
- package/src/components/NSBoxIPV4.tsx +93 -93
- package/src/components/NSBoxIPV6.tsx +90 -90
- package/src/components/NSBoxInteger.tsx +86 -86
- package/src/components/NSBoxLabel.module.css +12 -12
- package/src/components/NSBoxLabel.tsx +29 -29
- package/src/components/NSBoxOTP.module.css +10 -10
- package/src/components/NSBoxOTP.tsx +65 -65
- package/src/components/NSBoxPassword.tsx +86 -86
- package/src/components/NSBoxPhone.tsx +88 -88
- package/src/components/NSBoxPrice.tsx +88 -88
- package/src/components/NSBoxSearch.tsx +103 -103
- package/src/components/NSBoxString.tsx +103 -103
- package/src/components/NSBoxTextArea.module.css +76 -76
- package/src/components/NSBoxTextArea.tsx +106 -106
- package/src/components/NSBoxTime.tsx +88 -88
- package/src/components/NSButton.module.css +27 -27
- package/src/components/NSButton.tsx +23 -23
- package/src/components/NSButtonBlue.module.css +4 -4
- package/src/components/NSButtonBlue.tsx +12 -12
- package/src/components/NSButtonGreen.module.css +4 -4
- package/src/components/NSButtonGreen.tsx +11 -11
- package/src/components/NSButtonRed.module.css +4 -4
- package/src/components/NSButtonRed.tsx +11 -11
- package/src/components/NSCard.module.css +108 -108
- package/src/components/NSCard.tsx +70 -70
- package/src/components/NSCopyToClipboard.module.css +39 -39
- package/src/components/NSCopyToClipboard.tsx +35 -35
- package/src/components/NSElectronicCard.module.css +60 -60
- package/src/components/NSElectronicCard.tsx +47 -47
- package/src/components/NSEntityBar.module.css +77 -77
- package/src/components/NSEntityBar.tsx +27 -27
- package/src/components/NSEntityCardBackground.module.css +27 -27
- package/src/components/NSEntityCardBackground.tsx +34 -34
- package/src/components/NSFilterBox.module.css +47 -47
- package/src/components/NSFilterBox.tsx +373 -374
- package/src/components/NSFilterBoxDialog.module.css +36 -36
- package/src/components/NSFilterBoxDialog.tsx +74 -74
- package/src/components/NSFilterItem.module.css +23 -23
- package/src/components/NSFilterItem.tsx +72 -72
- package/src/components/NSFooter.module.css +123 -123
- package/src/components/NSFooter.tsx +196 -196
- package/src/components/NSGroupedList.module.css +72 -72
- package/src/components/NSGroupedList.tsx +107 -107
- package/src/components/NSHeader.module.css +271 -271
- package/src/components/NSHeader.tsx +235 -235
- package/src/components/NSLayout.module.css +13 -13
- package/src/components/NSLayout.tsx +82 -82
- package/src/components/NSLine.tsx +18 -18
- package/src/components/NSLink.module.css +36 -36
- package/src/components/NSLink.tsx +25 -25
- package/src/components/NSLinkBlue.tsx +20 -20
- package/src/components/NSLinkGreen.tsx +5 -5
- package/src/components/NSLinkRed.tsx +5 -5
- package/src/components/NSLoading.module.css +29 -29
- package/src/components/NSLoading.tsx +19 -19
- package/src/components/NSModal.module.css +70 -70
- package/src/components/NSModal.tsx +49 -49
- package/src/components/NSNoData.module.css +8 -8
- package/src/components/NSNoData.tsx +24 -24
- package/src/components/NSPageSelectionModal.module.css +102 -102
- package/src/components/NSPageSelectionModal.tsx +228 -228
- package/src/components/NSPagination.module.css +101 -101
- package/src/components/NSPagination.tsx +190 -190
- package/src/components/NSPanel.module.css +46 -46
- package/src/components/NSPanel.tsx +19 -19
- package/src/components/NSRadioButton.module.css +61 -61
- package/src/components/NSRadioButton.tsx +100 -100
- package/src/components/NSSection.module.css +10 -10
- package/src/components/NSSection.tsx +23 -23
- package/src/components/NSSectionBars.module.css +10 -10
- package/src/components/NSSectionBars.tsx +25 -25
- package/src/components/NSSectionCards.module.css +38 -38
- package/src/components/NSSectionCards.tsx +51 -51
- package/src/components/NSSectionTitle.tsx +21 -21
- package/src/components/NSSpace.tsx +28 -28
- package/src/components/NSTabPage.module.css +57 -57
- package/src/components/NSTabPage.tsx +53 -53
- package/src/components/NSTable.module.css +253 -253
- package/src/components/NSTable.tsx +361 -361
- package/src/components/NSTag.module.css +44 -44
- package/src/components/NSTag.tsx +49 -49
- package/src/components/NSTitle.module.css +15 -15
- package/src/components/NSTitle.tsx +19 -19
- package/src/components/NSVerification.module.css +22 -22
- package/src/components/NSVerification.tsx +41 -41
- package/src/index.tsx +7 -7
- package/src/main.ts +78 -78
- package/src/pages/NSNotFoundPage.module.css +18 -18
- package/src/pages/NSNotFoundPage.tsx +11 -11
- package/src/props/IBaseComponentProps.ts +8 -8
- package/src/props/IHeaderIconProps.ts +9 -9
- package/src/props/IHeaderProps.ts +6 -6
- package/src/props/IImageProps.ts +4 -4
- package/src/props/ILinkProps.ts +5 -5
- package/src/props/IValidationNumberProps.ts +4 -4
- package/src/props/IValidationProps.ts +7 -7
- package/src/props/IValidationRegexProps.ts +4 -4
- package/src/props/IValidationStringProps.ts +4 -4
- package/src/routing/INSRouterMaker.ts +6 -6
- package/src/routing/INSRouterProps.ts +5 -5
- package/src/routing/INSRouterState.ts +5 -5
- package/src/routing/NSRouterMaker.tsx +33 -33
- package/src/routing/Notifier.ts +79 -79
- package/tsconfig.json +43 -43
- package/dist/App.css +0 -17
- package/dist/assets/images/1.png +0 -0
- package/dist/assets/images/2.png +0 -0
- package/dist/assets/images/3.png +0 -0
- package/dist/assets/images/4.png +0 -0
- package/dist/assets/images/5.jpg +0 -0
- package/dist/assets/images/icon-export.svg +0 -3
- package/dist/assets/images/icon-input-id.svg +0 -9
- package/dist/assets/images/icon-refresh.svg +0 -3
- package/dist/components/NSAccess.d.ts +0 -2
- package/dist/components/NSAccess.js +0 -8
- package/dist/components/NSAccess.js.map +0 -1
- package/dist/components/NSAccess.module.css +0 -39
- package/dist/components/NSBoxText.d.ts +0 -25
- package/dist/components/NSBoxText.js +0 -56
- package/dist/components/NSBoxText.js.map +0 -1
- package/dist/components/NSInput.module.css +0 -74
- package/dist/components/NSInputDate.d.ts +0 -21
- package/dist/components/NSInputDate.js +0 -41
- package/dist/components/NSInputDate.js.map +0 -1
- package/dist/components/NSInputDate.module.css +0 -42
- package/dist/components/NSInputDuration.d.ts +0 -23
- package/dist/components/NSInputDuration.js +0 -42
- package/dist/components/NSInputDuration.js.map +0 -1
- package/dist/components/NSInputEmail.d.ts +0 -22
- package/dist/components/NSInputEmail.js +0 -43
- package/dist/components/NSInputEmail.js.map +0 -1
- package/dist/components/NSInputErrorNotifier.d.ts +0 -5
- package/dist/components/NSInputErrorNotifier.js +0 -7
- package/dist/components/NSInputErrorNotifier.js.map +0 -1
- package/dist/components/NSInputErrorNotifier.module.css +0 -3
- package/dist/components/NSInputFloat.d.ts +0 -22
- package/dist/components/NSInputFloat.js +0 -41
- package/dist/components/NSInputFloat.js.map +0 -1
- package/dist/components/NSInputIP.d.ts +0 -22
- package/dist/components/NSInputIP.js +0 -43
- package/dist/components/NSInputIP.js.map +0 -1
- package/dist/components/NSInputInteger.d.ts +0 -22
- package/dist/components/NSInputInteger.js +0 -41
- package/dist/components/NSInputInteger.js.map +0 -1
- package/dist/components/NSInputPassword.d.ts +0 -22
- package/dist/components/NSInputPassword.js +0 -42
- package/dist/components/NSInputPassword.js.map +0 -1
- package/dist/components/NSInputPhone.d.ts +0 -22
- package/dist/components/NSInputPhone.js +0 -38
- package/dist/components/NSInputPhone.js.map +0 -1
- package/dist/components/NSInputPrice.d.ts +0 -22
- package/dist/components/NSInputPrice.js +0 -41
- package/dist/components/NSInputPrice.js.map +0 -1
- package/dist/components/NSInputSearch.d.ts +0 -22
- package/dist/components/NSInputSearch.js +0 -41
- package/dist/components/NSInputSearch.js.map +0 -1
- package/dist/components/NSInputString.d.ts +0 -22
- package/dist/components/NSInputString.js +0 -42
- package/dist/components/NSInputString.js.map +0 -1
- package/dist/components/NSInputText.d.ts +0 -22
- package/dist/components/NSInputText.js +0 -42
- package/dist/components/NSInputText.js.map +0 -1
- package/dist/components/NSInputTime.d.ts +0 -22
- package/dist/components/NSInputTime.js +0 -43
- package/dist/components/NSInputTime.js.map +0 -1
- package/dist/components/NSLayoutAction.d.ts +0 -5
- package/dist/components/NSLayoutAction.js +0 -20
- package/dist/components/NSLayoutAction.js.map +0 -1
- package/dist/components/NSLayoutAction.module.css +0 -88
- package/dist/components/NSLayoutHeroBanner.d.ts +0 -2
- package/dist/components/NSLayoutHeroBanner.js +0 -8
- package/dist/components/NSLayoutHeroBanner.js.map +0 -1
- package/dist/components/NSLayoutHeroBanner.module.css +0 -43
- package/dist/components/NSLayoutTitle.d.ts +0 -2
- package/dist/components/NSLayoutTitle.js +0 -11
- package/dist/components/NSLayoutTitle.js.map +0 -1
- package/dist/components/NSLayoutTitle.module.css +0 -10
- package/dist/components/NSNotification.d.ts +0 -21
- package/dist/components/NSNotification.js +0 -37
- package/dist/components/NSNotification.js.map +0 -1
- package/dist/components/NSNotification.module.css +0 -32
- package/dist/components/NSPrintModal.d.ts +0 -15
- package/dist/components/NSPrintModal.js +0 -35
- package/dist/components/NSPrintModal.js.map +0 -1
- package/dist/components/NSPrintModal.module.css +0 -82
- package/dist/components/NSSelectBox.d.ts +0 -24
- package/dist/components/NSSelectBox.js +0 -61
- package/dist/components/NSSelectBox.js.map +0 -1
- package/dist/components/NSSelectBox.module.css +0 -42
- package/dist/index.css +0 -6
- package/dist/pages/NSLoginPage.d.ts +0 -6
- package/dist/pages/NSLoginPage.js +0 -8
- package/dist/pages/NSLoginPage.js.map +0 -1
- package/dist/pages/NSLoginPage.module.css +0 -20
- package/dist/props/BaseComponentProps.d.ts +0 -6
- package/dist/props/BaseComponentProps.js +0 -2
- package/dist/props/BaseComponentProps.js.map +0 -10
- package/dist/props/INamirasoftProps.d.ts +0 -4
- package/dist/props/INamirasoftProps.js +0 -2
- package/dist/props/INamirasoftProps.js.map +0 -1
- package/dist/props/ImageProps.d.ts +0 -4
- package/dist/props/ImageProps.js +0 -2
- package/dist/props/ImageProps.js.map +0 -10
- package/dist/props/LinkProps.d.ts +0 -5
- package/dist/props/LinkProps.js +0 -2
- package/dist/props/LinkProps.js.map +0 -10
- package/dist/props/ValidationNumberProps.d.ts +0 -4
- package/dist/props/ValidationNumberProps.js +0 -2
- package/dist/props/ValidationNumberProps.js.map +0 -10
- package/dist/props/ValidationProps.d.ts +0 -6
- package/dist/props/ValidationProps.js +0 -2
- package/dist/props/ValidationProps.js.map +0 -10
- package/dist/props/ValidationRegexProps.d.ts +0 -4
- package/dist/props/ValidationRegexProps.js +0 -2
- package/dist/props/ValidationRegexProps.js.map +0 -1
- package/dist/props/ValidationStringProps.d.ts +0 -4
- package/dist/props/ValidationStringProps.js +0 -2
- package/dist/props/ValidationStringProps.js.map +0 -10
|
@@ -1,362 +1,362 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import NSButton from './NSButton';
|
|
4
|
-
import { NSPagination } from './NSPagination';
|
|
5
|
-
import { NSSpace, NSSpaceSizeType } from './NSSpace';
|
|
6
|
-
import Styles from './NSTable.module.css';
|
|
7
|
-
import { Component } from 'react';
|
|
8
|
-
import { IBaseComponentProps } from "../props/IBaseComponentProps";
|
|
9
|
-
import React from "react";
|
|
10
|
-
import { NSModal } from './NSModal';
|
|
11
|
-
import { NSPageSelectionModal } from './NSPageSelectionModal';
|
|
12
|
-
import { NSLoading } from './NSLoading';
|
|
13
|
-
import { NSNoData } from './NSNoData';
|
|
14
|
-
import { writeFile, utils } from 'xlsx';
|
|
15
|
-
|
|
16
|
-
export interface INSTableProps<RowType> extends IBaseComponentProps
|
|
17
|
-
{
|
|
18
|
-
columns: { [key: string]: string };
|
|
19
|
-
checkbox: boolean;
|
|
20
|
-
getRows: (page: number, size: number) => Promise<{ rows: RowType[], count: number }>;
|
|
21
|
-
getRowKey: (row: RowType, rowIndex: number) => string;
|
|
22
|
-
getColumnAttributes?: (column: string, columnIndex: number) => { [key: string]: string };
|
|
23
|
-
getCell?: (row: RowType, column: string, rowIndex: number, columnIndex: number, value: any) => any;
|
|
24
|
-
onRowClick?: (e: React.MouseEvent<HTMLTableRowElement, MouseEvent>, row: RowType, rowIndex: number) => void;
|
|
25
|
-
onCellClick?: (e: React.MouseEvent<HTMLTableDataCellElement, MouseEvent>, row: RowType, column: string, rowIndex: number, columnIndex: number) => boolean | undefined;
|
|
26
|
-
onSelectedIDsChanged?: () => void;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface NSTableState<RowType>
|
|
30
|
-
{
|
|
31
|
-
columns: { [key: string]: string };
|
|
32
|
-
totalItems: number;
|
|
33
|
-
rows: RowType[] | null;
|
|
34
|
-
title?: string;
|
|
35
|
-
model: {
|
|
36
|
-
show: boolean;
|
|
37
|
-
description?: string;
|
|
38
|
-
};
|
|
39
|
-
selectedIDs: string[];
|
|
40
|
-
indeterminate: boolean;
|
|
41
|
-
pageSelectionMode: PageSelectionMode;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
enum PageSelectionMode
|
|
45
|
-
{
|
|
46
|
-
Hidden = "Hidden",
|
|
47
|
-
Print = "Print",
|
|
48
|
-
CSV = "CSV"
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export class NSTable<RowType> extends Component<INSTableProps<RowType>, NSTableState<RowType>>
|
|
52
|
-
{
|
|
53
|
-
NSPagination = React.createRef<NSPagination>();
|
|
54
|
-
constructor(props: INSTableProps<RowType>)
|
|
55
|
-
{
|
|
56
|
-
super(props);
|
|
57
|
-
this.state = {
|
|
58
|
-
columns: props.columns,
|
|
59
|
-
rows: null,
|
|
60
|
-
totalItems: 0,
|
|
61
|
-
model: { show: false },
|
|
62
|
-
selectedIDs: [],
|
|
63
|
-
indeterminate: false,
|
|
64
|
-
pageSelectionMode: PageSelectionMode.Hidden
|
|
65
|
-
};
|
|
66
|
-
this.setColumns = this.setColumns.bind(this);
|
|
67
|
-
this.setRows = this.setRows.bind(this);
|
|
68
|
-
this.showModal = this.showModal.bind(this);
|
|
69
|
-
this.hideModal = this.hideModal.bind(this);
|
|
70
|
-
this.onPageChange = this.onPageChange.bind(this);
|
|
71
|
-
this.isSomeChecked = this.isSomeChecked.bind(this);
|
|
72
|
-
this.toggleAllCheckboxes = this.toggleAllCheckboxes.bind(this);
|
|
73
|
-
this.print = this.print.bind(this);
|
|
74
|
-
this.exportCSV = this.exportCSV.bind(this);
|
|
75
|
-
this.isAllChecked = this.isAllChecked.bind(this);
|
|
76
|
-
this.reload = this.reload.bind(this);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
setColumns(columns: { [key: string]: string })
|
|
80
|
-
{
|
|
81
|
-
this.setState({ columns });
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
setRows(rows: RowType[] | null, totalItems: number)
|
|
85
|
-
{
|
|
86
|
-
this.setState({ rows, totalItems });
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private showModal(description: string, title?: string)
|
|
90
|
-
{
|
|
91
|
-
this.setState({ model: { show: true, description }, title });
|
|
92
|
-
}
|
|
93
|
-
private hideModal()
|
|
94
|
-
{
|
|
95
|
-
this.setState({ model: { show: false } });
|
|
96
|
-
}
|
|
97
|
-
private onPageChange(page: number, size: number)
|
|
98
|
-
{
|
|
99
|
-
this.reload(page, size);
|
|
100
|
-
}
|
|
101
|
-
override componentDidMount(): void
|
|
102
|
-
{
|
|
103
|
-
this.reload(null, null);
|
|
104
|
-
}
|
|
105
|
-
public reload(page: number | null, size: number | null)
|
|
106
|
-
{
|
|
107
|
-
this.setRows(null, 0);
|
|
108
|
-
if (page == null)
|
|
109
|
-
page = this.NSPagination.current?.getCurrentPage() ?? 0;
|
|
110
|
-
if (size == null)
|
|
111
|
-
size = this.NSPagination.current?.getPageSize() ?? 0;
|
|
112
|
-
this.props.getRows(page, size).then(res =>
|
|
113
|
-
{
|
|
114
|
-
this.setRows(res.rows, res.count);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
private toggleAllCheckboxes()
|
|
118
|
-
{
|
|
119
|
-
let selectedIDs: string[] = [];
|
|
120
|
-
if (this.getSelectedIDs().length == 0)
|
|
121
|
-
this.state.rows?.map((row, rowIndex) =>
|
|
122
|
-
{
|
|
123
|
-
let id = this.props.getRowKey(row, rowIndex);
|
|
124
|
-
selectedIDs.push(id);
|
|
125
|
-
})
|
|
126
|
-
this.setSelectedIDs(selectedIDs);
|
|
127
|
-
this.setState({ indeterminate: false });
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
print(rows: RowType[])
|
|
131
|
-
{
|
|
132
|
-
const printWindow = window.open('', '', 'height=500,width=800');
|
|
133
|
-
printWindow!.document.write('<html><head><title>Print Table</title>');
|
|
134
|
-
printWindow!.document.write('<style>table { width: 100%; border-collapse: collapse; } th, td { border: 1px solid black; padding: 8px; text-align: left; }</style>');
|
|
135
|
-
printWindow!.document.write('</head><body>');
|
|
136
|
-
printWindow!.document.write('<table>');
|
|
137
|
-
printWindow!.document.write('<thead><tr>');
|
|
138
|
-
|
|
139
|
-
Object.keys(this.state.columns).forEach(column =>
|
|
140
|
-
{
|
|
141
|
-
printWindow!.document.write('<th>' + this.state.columns[column] + '</th>');
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
printWindow!.document.write('</tr></thead><tbody>');
|
|
145
|
-
|
|
146
|
-
// Add table rows
|
|
147
|
-
rows.forEach(row =>
|
|
148
|
-
{
|
|
149
|
-
printWindow!.document.write('<tr>');
|
|
150
|
-
Object.keys(this.state.columns).forEach(column =>
|
|
151
|
-
{
|
|
152
|
-
printWindow!.document.write('<td>' + (row as any)[column] + '</td>');
|
|
153
|
-
});
|
|
154
|
-
printWindow!.document.write('</tr>');
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
printWindow!.document.write('</tbody></table>');
|
|
158
|
-
printWindow!.document.write('</body></html>');
|
|
159
|
-
printWindow!.document.close();
|
|
160
|
-
printWindow!.print();
|
|
161
|
-
}
|
|
162
|
-
exportCSV(rows: RowType[])
|
|
163
|
-
{
|
|
164
|
-
const worksheet = utils.json_to_sheet(rows || []);
|
|
165
|
-
const workbook = utils.book_new();
|
|
166
|
-
utils.book_append_sheet(workbook, worksheet, "Table Data");
|
|
167
|
-
console.log(rows.length); // todo
|
|
168
|
-
writeFile(workbook, "TableData.xlsx");
|
|
169
|
-
}
|
|
170
|
-
getSelectedIDs(): string[]
|
|
171
|
-
{
|
|
172
|
-
return this.state.selectedIDs;
|
|
173
|
-
}
|
|
174
|
-
setSelectedIDs(ids: string[])
|
|
175
|
-
{
|
|
176
|
-
this.setState({ selectedIDs: ids }, () =>
|
|
177
|
-
{
|
|
178
|
-
if (this.props.onSelectedIDsChanged)
|
|
179
|
-
this.props.onSelectedIDsChanged();
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
private isAllChecked(): boolean
|
|
183
|
-
{
|
|
184
|
-
return this.state.rows !== null && this.state.rows.length > 0 && this.state.selectedIDs.length === this.state.rows.length;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
private isSomeChecked(): boolean
|
|
188
|
-
{
|
|
189
|
-
return this.state.selectedIDs.length > 0 && !this.isAllChecked();
|
|
190
|
-
}
|
|
191
|
-
override render()
|
|
192
|
-
{
|
|
193
|
-
let column_keys = Object.keys(this.state.columns);
|
|
194
|
-
let getColumnAttributes = (column: string, columnIndex: number) =>
|
|
195
|
-
{
|
|
196
|
-
if (this.props.getColumnAttributes)
|
|
197
|
-
return this.props.getColumnAttributes(column, columnIndex);
|
|
198
|
-
return {};
|
|
199
|
-
}
|
|
200
|
-
let getCell = (row: RowType, column: string, rowIndex: number, columnIndex: number) =>
|
|
201
|
-
{
|
|
202
|
-
let value = (row as any)[column];
|
|
203
|
-
if (this.props.getCell)
|
|
204
|
-
return this.props.getCell(row, column, rowIndex, columnIndex, value);
|
|
205
|
-
return value + "";
|
|
206
|
-
}
|
|
207
|
-
let onRowClick = (e: React.MouseEvent<HTMLTableRowElement, MouseEvent>, row: RowType, rowIndex: number) =>
|
|
208
|
-
{
|
|
209
|
-
if (this.props.onRowClick)
|
|
210
|
-
this.props.onRowClick(e, row, rowIndex);
|
|
211
|
-
};
|
|
212
|
-
let onCellClick = (e: React.MouseEvent<HTMLTableDataCellElement, MouseEvent>, row: RowType, column: string, rowIndex: number, columnIndex: number) =>
|
|
213
|
-
{
|
|
214
|
-
let overided = false;
|
|
215
|
-
if (this.props.onCellClick)
|
|
216
|
-
{
|
|
217
|
-
let res = this.props.onCellClick(e, row, column, rowIndex, columnIndex);
|
|
218
|
-
if (res === undefined)
|
|
219
|
-
{
|
|
220
|
-
overided = true;
|
|
221
|
-
} else
|
|
222
|
-
{
|
|
223
|
-
overided = res;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if (!overided)
|
|
227
|
-
{
|
|
228
|
-
this.showModal(getCell(row, column, rowIndex, columnIndex), this.state.columns[column]);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
let content;
|
|
232
|
-
if (this.state.rows === null)
|
|
233
|
-
{
|
|
234
|
-
content = (
|
|
235
|
-
<NSLoading />
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
else if (this.state.rows.length === 0)
|
|
239
|
-
{
|
|
240
|
-
content = (
|
|
241
|
-
<NSNoData lable='No Data' />
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
else
|
|
245
|
-
{
|
|
246
|
-
content = this.state.rows.map((row, rowIndex) =>
|
|
247
|
-
<tr key={this.props.getRowKey(row, rowIndex)} onClick={(e) => { onRowClick(e, row, rowIndex); }}>
|
|
248
|
-
{
|
|
249
|
-
this.props.checkbox && <td >
|
|
250
|
-
<label htmlFor={`checkbox_device_${this.props.getRowKey(row, rowIndex)}`} className={Styles.ns_checkbox_label}>
|
|
251
|
-
<input className={Styles.ns_td_input} id={`checkbox_device_${this.props.getRowKey(row, rowIndex)}`} type="checkbox" checked={this.state.selectedIDs.includes(this.props.getRowKey(row, rowIndex))} onChange={(e) =>
|
|
252
|
-
{
|
|
253
|
-
let selectedIDs = this.state.selectedIDs;
|
|
254
|
-
let id = this.props.getRowKey(row, rowIndex);
|
|
255
|
-
if (e.currentTarget.checked)
|
|
256
|
-
selectedIDs.push(id);
|
|
257
|
-
else
|
|
258
|
-
selectedIDs = selectedIDs.filter(x => x !== id);
|
|
259
|
-
this.setSelectedIDs(selectedIDs)
|
|
260
|
-
this.setState({ selectedIDs }, () =>
|
|
261
|
-
{
|
|
262
|
-
this.setState({ indeterminate: this.isSomeChecked() });
|
|
263
|
-
});
|
|
264
|
-
}} />
|
|
265
|
-
</label>
|
|
266
|
-
</td>
|
|
267
|
-
}
|
|
268
|
-
{
|
|
269
|
-
column_keys.map((column, columnIndex) => (
|
|
270
|
-
<td className='py-3' {...getColumnAttributes(column, columnIndex + 1)} key={columnIndex + 1} data-label={`${this.state.columns[column]} : `} onClick={(e) => { onCellClick(e, row, column, rowIndex, columnIndex + 1); }}>
|
|
271
|
-
{getCell(row, column, rowIndex, columnIndex + 1)}
|
|
272
|
-
</td>
|
|
273
|
-
))
|
|
274
|
-
}
|
|
275
|
-
</tr>);
|
|
276
|
-
}
|
|
277
|
-
return (
|
|
278
|
-
<div id={this.props.id}
|
|
279
|
-
className={`${Styles.ns_project_list_container} ${this.props.classList?.join(" ")}`}
|
|
280
|
-
style={this.props.style}>
|
|
281
|
-
<NSSpace size={NSSpaceSizeType.SMALL} />
|
|
282
|
-
<table className={Styles.ns_table} >
|
|
283
|
-
<thead className={Styles.ns_thead}>
|
|
284
|
-
<tr>
|
|
285
|
-
{
|
|
286
|
-
this.props.checkbox && <th className={Styles.ns_check_box}>
|
|
287
|
-
<label htmlFor='checkbox' className={Styles.ns_checkbox_label}>
|
|
288
|
-
<input className={`${Styles.ns_check_box_input} ${this.state.indeterminate ? Styles.ns_indeterminate : ""}`} id='checkbox' type='checkbox' onChange={this.toggleAllCheckboxes} checked={this.getSelectedIDs().length > 0}></input>
|
|
289
|
-
</label>
|
|
290
|
-
</th>
|
|
291
|
-
}
|
|
292
|
-
{
|
|
293
|
-
column_keys.map(column_key => <th className="py-3" key={column_key} scope="col">
|
|
294
|
-
{this.state.columns[column_key]}
|
|
295
|
-
</th>)
|
|
296
|
-
}
|
|
297
|
-
</tr>
|
|
298
|
-
</thead>
|
|
299
|
-
<tbody className={Styles.ns_tbody}>
|
|
300
|
-
{content}
|
|
301
|
-
</tbody >
|
|
302
|
-
</table>
|
|
303
|
-
<NSSpace size={NSSpaceSizeType.MICRO} />
|
|
304
|
-
<section className={Styles.ns_pagination_button}>
|
|
305
|
-
<NSPagination ref={this.NSPagination} totalItems={this.state.totalItems} onPageChange={this.onPageChange} />
|
|
306
|
-
<NSSpace size={NSSpaceSizeType.SMALL} />
|
|
307
|
-
<div className={Styles.ns_button}>
|
|
308
|
-
{
|
|
309
|
-
this.state.pageSelectionMode != PageSelectionMode.Hidden &&
|
|
310
|
-
<NSPageSelectionModal<RowType>
|
|
311
|
-
current_page={1}
|
|
312
|
-
max_page={1}
|
|
313
|
-
getItems={async (page, selected) =>
|
|
314
|
-
{
|
|
315
|
-
if (selected)
|
|
316
|
-
{
|
|
317
|
-
let rows: RowType[] = [];
|
|
318
|
-
if (this.state.rows)
|
|
319
|
-
for (let i = 0; i < this.state.rows.length; i++)
|
|
320
|
-
{
|
|
321
|
-
const row = this.state.rows[i];
|
|
322
|
-
let id = this.props.getRowKey(row, i);
|
|
323
|
-
if (this.state.selectedIDs.includes(id))
|
|
324
|
-
rows.push(row);
|
|
325
|
-
}
|
|
326
|
-
return rows;
|
|
327
|
-
}
|
|
328
|
-
let res = await this.props.getRows(page, this.NSPagination.current?.getCurrentPage() ?? 0);
|
|
329
|
-
return res.rows;
|
|
330
|
-
}}
|
|
331
|
-
onFinish={(items: RowType[]) =>
|
|
332
|
-
{
|
|
333
|
-
if (this.state.pageSelectionMode == PageSelectionMode.Print)
|
|
334
|
-
this.print(items);
|
|
335
|
-
else if (this.state.pageSelectionMode == PageSelectionMode.CSV)
|
|
336
|
-
this.exportCSV(items);
|
|
337
|
-
}}
|
|
338
|
-
onClose={() => { this.setState({ pageSelectionMode: PageSelectionMode.Hidden }); }
|
|
339
|
-
}
|
|
340
|
-
/>
|
|
341
|
-
}
|
|
342
|
-
<NSButton title='Chart' icon={{ src: "https://static.namirasoft.com/image/concept/chart/blue.svg" }} onClick={() => { }} style={{ border: '1px solid rgba(255, 148, 50, 1)', width: "128px" }} />
|
|
343
|
-
<NSButton title='Print' icon={{ src: "https://static.namirasoft.com/image/concept/print/blue.svg" }} onClick={() => { this.setState({ pageSelectionMode: PageSelectionMode.Print }); }} style={{ border: '1px solid rgba(255, 148, 50, 1)', width: "128px" }} />
|
|
344
|
-
<NSButton title='Export' icon={{ src: "https://static.namirasoft.com/image/concept/export/blue.svg" }} onClick={() => { this.setState({ pageSelectionMode: PageSelectionMode.CSV }); }} style={{ border: '1px solid rgba(255, 148, 50, 1)', width: "128px" }} />
|
|
345
|
-
<NSButton title='Refresh' icon={{ src: "https://static.namirasoft.com/image/concept/refresh/blue.svg" }} onClick={() =>
|
|
346
|
-
{
|
|
347
|
-
this.reload(null, null);
|
|
348
|
-
}} style={{ border: '1px solid rgba(3, 119, 255, 1)', width: "128px" }} />
|
|
349
|
-
|
|
350
|
-
</div>
|
|
351
|
-
</section>
|
|
352
|
-
<NSSpace size={NSSpaceSizeType.SMALL} />
|
|
353
|
-
<NSModal
|
|
354
|
-
show={this.state.model.show}
|
|
355
|
-
description={this.state.model.description}
|
|
356
|
-
onClose={() => { this.hideModal(); }}
|
|
357
|
-
title={this.state.title}
|
|
358
|
-
/>
|
|
359
|
-
</div >
|
|
360
|
-
);
|
|
361
|
-
}
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import NSButton from './NSButton';
|
|
4
|
+
import { NSPagination } from './NSPagination';
|
|
5
|
+
import { NSSpace, NSSpaceSizeType } from './NSSpace';
|
|
6
|
+
import Styles from './NSTable.module.css';
|
|
7
|
+
import { Component } from 'react';
|
|
8
|
+
import { IBaseComponentProps } from "../props/IBaseComponentProps";
|
|
9
|
+
import React from "react";
|
|
10
|
+
import { NSModal } from './NSModal';
|
|
11
|
+
import { NSPageSelectionModal } from './NSPageSelectionModal';
|
|
12
|
+
import { NSLoading } from './NSLoading';
|
|
13
|
+
import { NSNoData } from './NSNoData';
|
|
14
|
+
import { writeFile, utils } from 'xlsx';
|
|
15
|
+
|
|
16
|
+
export interface INSTableProps<RowType> extends IBaseComponentProps
|
|
17
|
+
{
|
|
18
|
+
columns: { [key: string]: string };
|
|
19
|
+
checkbox: boolean;
|
|
20
|
+
getRows: (page: number, size: number) => Promise<{ rows: RowType[], count: number }>;
|
|
21
|
+
getRowKey: (row: RowType, rowIndex: number) => string;
|
|
22
|
+
getColumnAttributes?: (column: string, columnIndex: number) => { [key: string]: string };
|
|
23
|
+
getCell?: (row: RowType, column: string, rowIndex: number, columnIndex: number, value: any) => any;
|
|
24
|
+
onRowClick?: (e: React.MouseEvent<HTMLTableRowElement, MouseEvent>, row: RowType, rowIndex: number) => void;
|
|
25
|
+
onCellClick?: (e: React.MouseEvent<HTMLTableDataCellElement, MouseEvent>, row: RowType, column: string, rowIndex: number, columnIndex: number) => boolean | undefined;
|
|
26
|
+
onSelectedIDsChanged?: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface NSTableState<RowType>
|
|
30
|
+
{
|
|
31
|
+
columns: { [key: string]: string };
|
|
32
|
+
totalItems: number;
|
|
33
|
+
rows: RowType[] | null;
|
|
34
|
+
title?: string;
|
|
35
|
+
model: {
|
|
36
|
+
show: boolean;
|
|
37
|
+
description?: string;
|
|
38
|
+
};
|
|
39
|
+
selectedIDs: string[];
|
|
40
|
+
indeterminate: boolean;
|
|
41
|
+
pageSelectionMode: PageSelectionMode;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
enum PageSelectionMode
|
|
45
|
+
{
|
|
46
|
+
Hidden = "Hidden",
|
|
47
|
+
Print = "Print",
|
|
48
|
+
CSV = "CSV"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class NSTable<RowType> extends Component<INSTableProps<RowType>, NSTableState<RowType>>
|
|
52
|
+
{
|
|
53
|
+
NSPagination = React.createRef<NSPagination>();
|
|
54
|
+
constructor(props: INSTableProps<RowType>)
|
|
55
|
+
{
|
|
56
|
+
super(props);
|
|
57
|
+
this.state = {
|
|
58
|
+
columns: props.columns,
|
|
59
|
+
rows: null,
|
|
60
|
+
totalItems: 0,
|
|
61
|
+
model: { show: false },
|
|
62
|
+
selectedIDs: [],
|
|
63
|
+
indeterminate: false,
|
|
64
|
+
pageSelectionMode: PageSelectionMode.Hidden
|
|
65
|
+
};
|
|
66
|
+
this.setColumns = this.setColumns.bind(this);
|
|
67
|
+
this.setRows = this.setRows.bind(this);
|
|
68
|
+
this.showModal = this.showModal.bind(this);
|
|
69
|
+
this.hideModal = this.hideModal.bind(this);
|
|
70
|
+
this.onPageChange = this.onPageChange.bind(this);
|
|
71
|
+
this.isSomeChecked = this.isSomeChecked.bind(this);
|
|
72
|
+
this.toggleAllCheckboxes = this.toggleAllCheckboxes.bind(this);
|
|
73
|
+
this.print = this.print.bind(this);
|
|
74
|
+
this.exportCSV = this.exportCSV.bind(this);
|
|
75
|
+
this.isAllChecked = this.isAllChecked.bind(this);
|
|
76
|
+
this.reload = this.reload.bind(this);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setColumns(columns: { [key: string]: string })
|
|
80
|
+
{
|
|
81
|
+
this.setState({ columns });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
setRows(rows: RowType[] | null, totalItems: number)
|
|
85
|
+
{
|
|
86
|
+
this.setState({ rows, totalItems });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private showModal(description: string, title?: string)
|
|
90
|
+
{
|
|
91
|
+
this.setState({ model: { show: true, description }, title });
|
|
92
|
+
}
|
|
93
|
+
private hideModal()
|
|
94
|
+
{
|
|
95
|
+
this.setState({ model: { show: false } });
|
|
96
|
+
}
|
|
97
|
+
private onPageChange(page: number, size: number)
|
|
98
|
+
{
|
|
99
|
+
this.reload(page, size);
|
|
100
|
+
}
|
|
101
|
+
override componentDidMount(): void
|
|
102
|
+
{
|
|
103
|
+
this.reload(null, null);
|
|
104
|
+
}
|
|
105
|
+
public reload(page: number | null, size: number | null)
|
|
106
|
+
{
|
|
107
|
+
this.setRows(null, 0);
|
|
108
|
+
if (page == null)
|
|
109
|
+
page = this.NSPagination.current?.getCurrentPage() ?? 0;
|
|
110
|
+
if (size == null)
|
|
111
|
+
size = this.NSPagination.current?.getPageSize() ?? 0;
|
|
112
|
+
this.props.getRows(page, size).then(res =>
|
|
113
|
+
{
|
|
114
|
+
this.setRows(res.rows, res.count);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
private toggleAllCheckboxes()
|
|
118
|
+
{
|
|
119
|
+
let selectedIDs: string[] = [];
|
|
120
|
+
if (this.getSelectedIDs().length == 0)
|
|
121
|
+
this.state.rows?.map((row, rowIndex) =>
|
|
122
|
+
{
|
|
123
|
+
let id = this.props.getRowKey(row, rowIndex);
|
|
124
|
+
selectedIDs.push(id);
|
|
125
|
+
})
|
|
126
|
+
this.setSelectedIDs(selectedIDs);
|
|
127
|
+
this.setState({ indeterminate: false });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
print(rows: RowType[])
|
|
131
|
+
{
|
|
132
|
+
const printWindow = window.open('', '', 'height=500,width=800');
|
|
133
|
+
printWindow!.document.write('<html><head><title>Print Table</title>');
|
|
134
|
+
printWindow!.document.write('<style>table { width: 100%; border-collapse: collapse; } th, td { border: 1px solid black; padding: 8px; text-align: left; }</style>');
|
|
135
|
+
printWindow!.document.write('</head><body>');
|
|
136
|
+
printWindow!.document.write('<table>');
|
|
137
|
+
printWindow!.document.write('<thead><tr>');
|
|
138
|
+
|
|
139
|
+
Object.keys(this.state.columns).forEach(column =>
|
|
140
|
+
{
|
|
141
|
+
printWindow!.document.write('<th>' + this.state.columns[column] + '</th>');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
printWindow!.document.write('</tr></thead><tbody>');
|
|
145
|
+
|
|
146
|
+
// Add table rows
|
|
147
|
+
rows.forEach(row =>
|
|
148
|
+
{
|
|
149
|
+
printWindow!.document.write('<tr>');
|
|
150
|
+
Object.keys(this.state.columns).forEach(column =>
|
|
151
|
+
{
|
|
152
|
+
printWindow!.document.write('<td>' + (row as any)[column] + '</td>');
|
|
153
|
+
});
|
|
154
|
+
printWindow!.document.write('</tr>');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
printWindow!.document.write('</tbody></table>');
|
|
158
|
+
printWindow!.document.write('</body></html>');
|
|
159
|
+
printWindow!.document.close();
|
|
160
|
+
printWindow!.print();
|
|
161
|
+
}
|
|
162
|
+
exportCSV(rows: RowType[])
|
|
163
|
+
{
|
|
164
|
+
const worksheet = utils.json_to_sheet(rows || []);
|
|
165
|
+
const workbook = utils.book_new();
|
|
166
|
+
utils.book_append_sheet(workbook, worksheet, "Table Data");
|
|
167
|
+
console.log(rows.length); // todo
|
|
168
|
+
writeFile(workbook, "TableData.xlsx");
|
|
169
|
+
}
|
|
170
|
+
getSelectedIDs(): string[]
|
|
171
|
+
{
|
|
172
|
+
return this.state.selectedIDs;
|
|
173
|
+
}
|
|
174
|
+
setSelectedIDs(ids: string[])
|
|
175
|
+
{
|
|
176
|
+
this.setState({ selectedIDs: ids }, () =>
|
|
177
|
+
{
|
|
178
|
+
if (this.props.onSelectedIDsChanged)
|
|
179
|
+
this.props.onSelectedIDsChanged();
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
private isAllChecked(): boolean
|
|
183
|
+
{
|
|
184
|
+
return this.state.rows !== null && this.state.rows.length > 0 && this.state.selectedIDs.length === this.state.rows.length;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private isSomeChecked(): boolean
|
|
188
|
+
{
|
|
189
|
+
return this.state.selectedIDs.length > 0 && !this.isAllChecked();
|
|
190
|
+
}
|
|
191
|
+
override render()
|
|
192
|
+
{
|
|
193
|
+
let column_keys = Object.keys(this.state.columns);
|
|
194
|
+
let getColumnAttributes = (column: string, columnIndex: number) =>
|
|
195
|
+
{
|
|
196
|
+
if (this.props.getColumnAttributes)
|
|
197
|
+
return this.props.getColumnAttributes(column, columnIndex);
|
|
198
|
+
return {};
|
|
199
|
+
}
|
|
200
|
+
let getCell = (row: RowType, column: string, rowIndex: number, columnIndex: number) =>
|
|
201
|
+
{
|
|
202
|
+
let value = (row as any)[column];
|
|
203
|
+
if (this.props.getCell)
|
|
204
|
+
return this.props.getCell(row, column, rowIndex, columnIndex, value);
|
|
205
|
+
return value + "";
|
|
206
|
+
}
|
|
207
|
+
let onRowClick = (e: React.MouseEvent<HTMLTableRowElement, MouseEvent>, row: RowType, rowIndex: number) =>
|
|
208
|
+
{
|
|
209
|
+
if (this.props.onRowClick)
|
|
210
|
+
this.props.onRowClick(e, row, rowIndex);
|
|
211
|
+
};
|
|
212
|
+
let onCellClick = (e: React.MouseEvent<HTMLTableDataCellElement, MouseEvent>, row: RowType, column: string, rowIndex: number, columnIndex: number) =>
|
|
213
|
+
{
|
|
214
|
+
let overided = false;
|
|
215
|
+
if (this.props.onCellClick)
|
|
216
|
+
{
|
|
217
|
+
let res = this.props.onCellClick(e, row, column, rowIndex, columnIndex);
|
|
218
|
+
if (res === undefined)
|
|
219
|
+
{
|
|
220
|
+
overided = true;
|
|
221
|
+
} else
|
|
222
|
+
{
|
|
223
|
+
overided = res;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (!overided)
|
|
227
|
+
{
|
|
228
|
+
this.showModal(getCell(row, column, rowIndex, columnIndex), this.state.columns[column]);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
let content;
|
|
232
|
+
if (this.state.rows === null)
|
|
233
|
+
{
|
|
234
|
+
content = (
|
|
235
|
+
<NSLoading />
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
else if (this.state.rows.length === 0)
|
|
239
|
+
{
|
|
240
|
+
content = (
|
|
241
|
+
<NSNoData lable='No Data' />
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
else
|
|
245
|
+
{
|
|
246
|
+
content = this.state.rows.map((row, rowIndex) =>
|
|
247
|
+
<tr key={this.props.getRowKey(row, rowIndex)} onClick={(e) => { onRowClick(e, row, rowIndex); }}>
|
|
248
|
+
{
|
|
249
|
+
this.props.checkbox && <td >
|
|
250
|
+
<label htmlFor={`checkbox_device_${this.props.getRowKey(row, rowIndex)}`} className={Styles.ns_checkbox_label}>
|
|
251
|
+
<input className={Styles.ns_td_input} id={`checkbox_device_${this.props.getRowKey(row, rowIndex)}`} type="checkbox" checked={this.state.selectedIDs.includes(this.props.getRowKey(row, rowIndex))} onChange={(e) =>
|
|
252
|
+
{
|
|
253
|
+
let selectedIDs = this.state.selectedIDs;
|
|
254
|
+
let id = this.props.getRowKey(row, rowIndex);
|
|
255
|
+
if (e.currentTarget.checked)
|
|
256
|
+
selectedIDs.push(id);
|
|
257
|
+
else
|
|
258
|
+
selectedIDs = selectedIDs.filter(x => x !== id);
|
|
259
|
+
this.setSelectedIDs(selectedIDs)
|
|
260
|
+
this.setState({ selectedIDs }, () =>
|
|
261
|
+
{
|
|
262
|
+
this.setState({ indeterminate: this.isSomeChecked() });
|
|
263
|
+
});
|
|
264
|
+
}} />
|
|
265
|
+
</label>
|
|
266
|
+
</td>
|
|
267
|
+
}
|
|
268
|
+
{
|
|
269
|
+
column_keys.map((column, columnIndex) => (
|
|
270
|
+
<td className='py-3' {...getColumnAttributes(column, columnIndex + 1)} key={columnIndex + 1} data-label={`${this.state.columns[column]} : `} onClick={(e) => { onCellClick(e, row, column, rowIndex, columnIndex + 1); }}>
|
|
271
|
+
{getCell(row, column, rowIndex, columnIndex + 1)}
|
|
272
|
+
</td>
|
|
273
|
+
))
|
|
274
|
+
}
|
|
275
|
+
</tr>);
|
|
276
|
+
}
|
|
277
|
+
return (
|
|
278
|
+
<div id={this.props.id}
|
|
279
|
+
className={`${Styles.ns_project_list_container} ${this.props.classList?.join(" ")}`}
|
|
280
|
+
style={this.props.style}>
|
|
281
|
+
<NSSpace size={NSSpaceSizeType.SMALL} />
|
|
282
|
+
<table className={Styles.ns_table} >
|
|
283
|
+
<thead className={Styles.ns_thead}>
|
|
284
|
+
<tr>
|
|
285
|
+
{
|
|
286
|
+
this.props.checkbox && <th className={Styles.ns_check_box}>
|
|
287
|
+
<label htmlFor='checkbox' className={Styles.ns_checkbox_label}>
|
|
288
|
+
<input className={`${Styles.ns_check_box_input} ${this.state.indeterminate ? Styles.ns_indeterminate : ""}`} id='checkbox' type='checkbox' onChange={this.toggleAllCheckboxes} checked={this.getSelectedIDs().length > 0}></input>
|
|
289
|
+
</label>
|
|
290
|
+
</th>
|
|
291
|
+
}
|
|
292
|
+
{
|
|
293
|
+
column_keys.map(column_key => <th className="py-3" key={column_key} scope="col">
|
|
294
|
+
{this.state.columns[column_key]}
|
|
295
|
+
</th>)
|
|
296
|
+
}
|
|
297
|
+
</tr>
|
|
298
|
+
</thead>
|
|
299
|
+
<tbody className={Styles.ns_tbody}>
|
|
300
|
+
{content}
|
|
301
|
+
</tbody >
|
|
302
|
+
</table>
|
|
303
|
+
<NSSpace size={NSSpaceSizeType.MICRO} />
|
|
304
|
+
<section className={Styles.ns_pagination_button}>
|
|
305
|
+
<NSPagination ref={this.NSPagination} totalItems={this.state.totalItems} onPageChange={this.onPageChange} />
|
|
306
|
+
<NSSpace size={NSSpaceSizeType.SMALL} />
|
|
307
|
+
<div className={Styles.ns_button}>
|
|
308
|
+
{
|
|
309
|
+
this.state.pageSelectionMode != PageSelectionMode.Hidden &&
|
|
310
|
+
<NSPageSelectionModal<RowType>
|
|
311
|
+
current_page={1}
|
|
312
|
+
max_page={1}
|
|
313
|
+
getItems={async (page, selected) =>
|
|
314
|
+
{
|
|
315
|
+
if (selected)
|
|
316
|
+
{
|
|
317
|
+
let rows: RowType[] = [];
|
|
318
|
+
if (this.state.rows)
|
|
319
|
+
for (let i = 0; i < this.state.rows.length; i++)
|
|
320
|
+
{
|
|
321
|
+
const row = this.state.rows[i];
|
|
322
|
+
let id = this.props.getRowKey(row, i);
|
|
323
|
+
if (this.state.selectedIDs.includes(id))
|
|
324
|
+
rows.push(row);
|
|
325
|
+
}
|
|
326
|
+
return rows;
|
|
327
|
+
}
|
|
328
|
+
let res = await this.props.getRows(page, this.NSPagination.current?.getCurrentPage() ?? 0);
|
|
329
|
+
return res.rows;
|
|
330
|
+
}}
|
|
331
|
+
onFinish={(items: RowType[]) =>
|
|
332
|
+
{
|
|
333
|
+
if (this.state.pageSelectionMode == PageSelectionMode.Print)
|
|
334
|
+
this.print(items);
|
|
335
|
+
else if (this.state.pageSelectionMode == PageSelectionMode.CSV)
|
|
336
|
+
this.exportCSV(items);
|
|
337
|
+
}}
|
|
338
|
+
onClose={() => { this.setState({ pageSelectionMode: PageSelectionMode.Hidden }); }
|
|
339
|
+
}
|
|
340
|
+
/>
|
|
341
|
+
}
|
|
342
|
+
<NSButton title='Chart' icon={{ src: "https://static.namirasoft.com/image/concept/chart/blue.svg" }} onClick={() => { }} style={{ border: '1px solid rgba(255, 148, 50, 1)', width: "128px" }} />
|
|
343
|
+
<NSButton title='Print' icon={{ src: "https://static.namirasoft.com/image/concept/print/blue.svg" }} onClick={() => { this.setState({ pageSelectionMode: PageSelectionMode.Print }); }} style={{ border: '1px solid rgba(255, 148, 50, 1)', width: "128px" }} />
|
|
344
|
+
<NSButton title='Export' icon={{ src: "https://static.namirasoft.com/image/concept/export/blue.svg" }} onClick={() => { this.setState({ pageSelectionMode: PageSelectionMode.CSV }); }} style={{ border: '1px solid rgba(255, 148, 50, 1)', width: "128px" }} />
|
|
345
|
+
<NSButton title='Refresh' icon={{ src: "https://static.namirasoft.com/image/concept/refresh/blue.svg" }} onClick={() =>
|
|
346
|
+
{
|
|
347
|
+
this.reload(null, null);
|
|
348
|
+
}} style={{ border: '1px solid rgba(3, 119, 255, 1)', width: "128px" }} />
|
|
349
|
+
|
|
350
|
+
</div>
|
|
351
|
+
</section>
|
|
352
|
+
<NSSpace size={NSSpaceSizeType.SMALL} />
|
|
353
|
+
<NSModal
|
|
354
|
+
show={this.state.model.show}
|
|
355
|
+
description={this.state.model.description}
|
|
356
|
+
onClose={() => { this.hideModal(); }}
|
|
357
|
+
title={this.state.title}
|
|
358
|
+
/>
|
|
359
|
+
</div >
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
362
|
}
|