@sarafapp/iron_core 1.0.63 → 1.0.64
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/dist/IronCore.js +15 -5
- package/dist/core/index.d.ts +31 -0
- package/dist/{src → core/src}/BaseModel.d.ts +4 -4
- package/dist/core/src/baseForm/UseForm.d.ts +18 -0
- package/dist/{src → core/src}/baseTable/BaseTable.d.ts +3 -2
- package/dist/{src → core/src}/baseTable/Constants.d.ts +4 -3
- package/dist/{src → core/src}/baseTable/SelectableTable.d.ts +2 -2
- package/dist/{src → core/src}/baseTable/generator/SelectableTableGenerator.d.ts +3 -3
- package/dist/{src → core/src}/baseTable/moduleConnection/Table.d.ts +1 -1
- package/dist/{src → core/src}/baseTable/moduleConnection/generator/GColumn.d.ts +1 -1
- package/dist/{src → core/src}/composables/UseCrud.d.ts +4 -4
- package/dist/{src → core/src}/composables/UseData.d.ts +4 -3
- package/dist/core/src/composables/UseLoadingStatus.d.ts +15 -0
- package/dist/{src → core/src}/composables/UseParams.d.ts +3 -1
- package/dist/core/src/composables/UseRepository.d.ts +67 -0
- package/dist/core/src/composables/UseStaticTableService.d.ts +5 -0
- package/dist/{src → core/src}/crudService/CrudService.d.ts +8 -8
- package/dist/{src → core/src}/dateHandling/Converter.d.ts +1 -1
- package/dist/{src → core/src}/httpClient/ErrorHandlerRegistry.d.ts +1 -1
- package/dist/{src → core/src}/json/JsonMapper.d.ts +1 -1
- package/dist/core/src/layout/DialogService.d.ts +406 -0
- package/dist/core/src/layout/DrawerService.d.ts +14 -0
- package/dist/{src → core/src}/lib/Formatter.d.ts +1 -1
- package/dist/{src → core/src}/lib/Util.d.ts +2 -1
- package/dist/core/vite.config.d.ts +2 -0
- package/dist/example-vue/src/AntTableConfig.d.ts +6 -0
- package/dist/example-vue/src/TableService.d.ts +12 -0
- package/dist/example-vue/src/TextCell.vue.d.ts +5 -0
- package/dist/example-vue/src/app/App.vue.d.ts +2 -0
- package/dist/example-vue/src/app/router/index.d.ts +1 -0
- package/dist/example-vue/src/app/screens/Index.vue.d.ts +2 -0
- package/dist/example-vue/src/main.d.ts +0 -0
- package/dist/example-vue/vite.config.d.ts +2 -0
- package/dist/index.d.ts +2 -31
- package/index.ts +37 -0
- package/package.json +2 -5
- package/src/BaseModel.ts +127 -0
- package/src/Utils.ts +16 -0
- package/src/accessHandling/AccessControl.ts +33 -0
- package/src/accessHandling/AccessLevel.ts +52 -0
- package/src/accessHandling/Accessible.ts +3 -0
- package/src/accessHandling/EveryDirectiveAccess.ts +7 -0
- package/src/accessHandling/SSO/AuthorizationDirective.ts +65 -0
- package/src/accessHandling/SSO/AuthorizationService.ts +74 -0
- package/src/accessHandling/SSO/EveryLevelAuthorizationDirective.ts +7 -0
- package/src/accessHandling/SSO/SomeLevelsAuthorizationDirective.ts +7 -0
- package/src/accessHandling/SomeDirectiveAccess.ts +7 -0
- package/src/accessHandling/index.ts +9 -0
- package/src/baseDirective/BeforeMountDirective.ts +3 -0
- package/src/baseDirective/BeforeUnMountDirective.ts +3 -0
- package/src/baseDirective/BeforeUpdateDirective.ts +3 -0
- package/src/baseDirective/CreatedDirective.ts +3 -0
- package/src/baseDirective/MountedDirective.ts +3 -0
- package/src/baseDirective/UnMountedDirective.ts +3 -0
- package/src/baseDirective/UpdateDirective.ts +3 -0
- package/src/baseDirective/index.ts +7 -0
- package/src/baseForm/BaseRequestBodyFilter.ts +7 -0
- package/src/baseForm/FormManager.ts +95 -0
- package/src/baseForm/InputControl.ts +182 -0
- package/src/baseForm/InputControlBuilder.ts +59 -0
- package/src/baseForm/InputControlData.ts +16 -0
- package/src/baseForm/RequestBodyFilter.ts +3 -0
- package/src/baseForm/TouchSensitiveForm.ts +47 -0
- package/src/baseForm/UseForm.ts +32 -0
- package/src/baseForm/index.ts +8 -0
- package/src/baseSchedule/Schedule.ts +3 -0
- package/src/baseSchedule/Scheduler.ts +29 -0
- package/src/baseSchedule/index.ts +2 -0
- package/src/baseTable/BaseTable.ts +162 -0
- package/src/baseTable/Constants.ts +26 -0
- package/src/baseTable/OnDestory.ts +3 -0
- package/src/baseTable/RowActionSource.ts +5 -0
- package/src/baseTable/RowClick.ts +3 -0
- package/src/baseTable/RowDoubleClick.ts +3 -0
- package/src/baseTable/RowMetaClick.ts +3 -0
- package/src/baseTable/SelectableTable.ts +86 -0
- package/src/baseTable/TableAction.ts +10 -0
- package/src/baseTable/TableHeaderSchema.ts +44 -0
- package/src/baseTable/TableLoader.ts +3 -0
- package/src/baseTable/TablePaginate.ts +3 -0
- package/src/baseTable/TableService.ts +10 -0
- package/src/baseTable/TableSort.ts +5 -0
- package/src/baseTable/TableSummarySchema.ts +11 -0
- package/src/baseTable/generator/SelectableTableGenerator.ts +65 -0
- package/src/baseTable/generator/TableCellComponentRegistry.ts +15 -0
- package/src/baseTable/generator/TableConfig.ts +18 -0
- package/src/baseTable/generator/TableGenerator.ts +147 -0
- package/src/baseTable/generator/TableSource.ts +34 -0
- package/src/baseTable/index.ts +43 -0
- package/src/baseTable/moduleConnection/Action.ts +12 -0
- package/src/baseTable/moduleConnection/Column.ts +11 -0
- package/src/baseTable/moduleConnection/Table.ts +49 -0
- package/src/baseTable/moduleConnection/TableDestroy.ts +7 -0
- package/src/baseTable/moduleConnection/TableRowClick.ts +7 -0
- package/src/baseTable/moduleConnection/generator/GColumn.ts +10 -0
- package/src/baseTable/moduleConnection/generator/GTable.ts +11 -0
- package/src/composables/UseCrud.ts +53 -0
- package/src/composables/UseData.ts +70 -0
- package/src/composables/UseLoadingStatus.ts +65 -0
- package/src/composables/UseParams.ts +93 -0
- package/src/composables/UseRepository.ts +207 -0
- package/src/composables/UseState.ts +30 -0
- package/src/composables/UseStaticTableService.ts +45 -0
- package/src/composables/index.ts +7 -0
- package/src/constants/Constants.ts +126 -0
- package/src/constants/index.ts +19 -0
- package/src/crudService/CrudService.ts +121 -0
- package/src/crudService/index.ts +1 -0
- package/src/dateHandling/Constants.ts +5 -0
- package/src/dateHandling/Converter.ts +15 -0
- package/src/dateHandling/JalaliDateSetup.ts +42 -0
- package/src/dateHandling/Model.ts +27 -0
- package/src/dateHandling/Utils.ts +49 -0
- package/src/dateHandling/index.ts +5 -0
- package/src/debounce/DebounceAction.ts +4 -0
- package/src/debounce/DebounceService.ts +27 -0
- package/src/debounce/index.ts +2 -0
- package/src/deviceManagement/Constants.ts +4 -0
- package/src/deviceManagement/Visibility.ts +4 -0
- package/src/deviceManagement/VisibilityManager.ts +18 -0
- package/src/deviceManagement/index.ts +3 -0
- package/src/errorHandling/ErrorHandler.ts +3 -0
- package/src/errorHandling/HandleError.ts +20 -0
- package/src/errorHandling/index.ts +2 -0
- package/src/eventSystem/CustomEventDispatcher.ts +13 -0
- package/src/eventSystem/Model.ts +29 -0
- package/src/eventSystem/OnEvent.ts +25 -0
- package/src/eventSystem/index.ts +3 -0
- package/src/feedbackHandling/FailureFeedback.ts +3 -0
- package/src/feedbackHandling/Feedback.ts +34 -0
- package/src/feedbackHandling/HandleFeedback.ts +28 -0
- package/src/feedbackHandling/InfoFeedback.ts +3 -0
- package/src/feedbackHandling/SuccessFeedback.ts +3 -0
- package/src/feedbackHandling/WarningFeedback.ts +3 -0
- package/src/feedbackHandling/index.ts +6 -0
- package/src/httpClient/ApiBuilder.ts +57 -0
- package/src/httpClient/ErrorHandlerRegistry.ts +29 -0
- package/src/httpClient/HttpClient.ts +77 -0
- package/src/httpClient/Interceptor.ts +5 -0
- package/src/httpClient/index.ts +4 -0
- package/src/initializer/ApplicationInitializer.ts +15 -0
- package/src/initializer/Initializer.ts +3 -0
- package/src/initializer/index.ts +2 -0
- package/src/json/JsonMapper.ts +48 -0
- package/src/json/index.ts +1 -0
- package/src/layout/Constants.ts +11 -0
- package/src/layout/DialogService.ts +75 -0
- package/src/layout/DrawerService.ts +25 -0
- package/src/layout/Toast.ts +14 -0
- package/src/layout/index.ts +4 -0
- package/src/lib/Constants.ts +433 -0
- package/src/lib/Formatter.ts +68 -0
- package/src/lib/Util.ts +113 -0
- package/src/lib/index.ts +3 -0
- package/src/observables/AbstractSubject.ts +21 -0
- package/src/observables/BehaviorSubject.ts +58 -0
- package/src/observables/Observer.ts +3 -0
- package/src/observables/Subject.ts +9 -0
- package/src/observables/index.ts +4 -0
- package/src/process/Proccess.ts +21 -0
- package/src/process/ProcessManager.ts +31 -0
- package/src/process/index.ts +2 -0
- package/src/repository/Params.ts +10 -0
- package/src/repository/Repository.ts +44 -0
- package/src/repository/SyncDetail.ts +8 -0
- package/src/repository/index.ts +4 -0
- package/src/repository/model.ts +9 -0
- package/src/routeGuard/RouteGuard.ts +38 -0
- package/src/routeGuard/index.ts +1 -0
- package/src/search/client/ClientArraySearch.ts +25 -0
- package/src/search/client/ClientSearch.ts +3 -0
- package/src/search/index.ts +2 -0
- package/src/sort/SortDetail.ts +11 -0
- package/src/sort/client/Sorter.ts +28 -0
- package/src/sort/index.ts +4 -0
- package/src/sort/strategies/SimpleSort.ts +35 -0
- package/src/sort/strategies/SortStrategy.ts +4 -0
- package/src/types/Global.ts +1 -0
- package/src/types/index.ts +1 -0
- package/src/validators/Validator.ts +5 -0
- package/src/validators/index.ts +1 -0
- package/src/webSocket/Constants.ts +6 -0
- package/src/webSocket/Model.ts +16 -0
- package/src/webSocket/WebSocketService.ts +153 -0
- package/src/webSocket/index.ts +3 -0
- package/vite.config.ts +55 -0
- package/dist/src/baseForm/UseForm.d.ts +0 -5
- package/dist/src/composables/UseLoadingStatus.d.ts +0 -15
- package/dist/src/composables/UseRepository.d.ts +0 -63
- package/dist/src/composables/UseStaticTableService.d.ts +0 -4
- package/dist/src/layout/DialogService.d.ts +0 -1
- package/dist/src/layout/DrawerService.d.ts +0 -1
- package/dist/vite.config.d.ts +0 -2
- /package/dist/{src → core/src}/Utils.d.ts +0 -0
- /package/dist/{src → core/src}/accessHandling/AccessControl.d.ts +0 -0
- /package/dist/{src → core/src}/accessHandling/AccessLevel.d.ts +0 -0
- /package/dist/{src → core/src}/accessHandling/Accessible.d.ts +0 -0
- /package/dist/{src → core/src}/accessHandling/EveryDirectiveAccess.d.ts +0 -0
- /package/dist/{src → core/src}/accessHandling/SSO/AuthorizationDirective.d.ts +0 -0
- /package/dist/{src → core/src}/accessHandling/SSO/AuthorizationService.d.ts +0 -0
- /package/dist/{src → core/src}/accessHandling/SSO/EveryLevelAuthorizationDirective.d.ts +0 -0
- /package/dist/{src → core/src}/accessHandling/SSO/SomeLevelsAuthorizationDirective.d.ts +0 -0
- /package/dist/{src → core/src}/accessHandling/SomeDirectiveAccess.d.ts +0 -0
- /package/dist/{src → core/src}/accessHandling/index.d.ts +0 -0
- /package/dist/{src → core/src}/baseDirective/BeforeMountDirective.d.ts +0 -0
- /package/dist/{src → core/src}/baseDirective/BeforeUnMountDirective.d.ts +0 -0
- /package/dist/{src → core/src}/baseDirective/BeforeUpdateDirective.d.ts +0 -0
- /package/dist/{src → core/src}/baseDirective/CreatedDirective.d.ts +0 -0
- /package/dist/{src → core/src}/baseDirective/MountedDirective.d.ts +0 -0
- /package/dist/{src → core/src}/baseDirective/UnMountedDirective.d.ts +0 -0
- /package/dist/{src → core/src}/baseDirective/UpdateDirective.d.ts +0 -0
- /package/dist/{src → core/src}/baseDirective/index.d.ts +0 -0
- /package/dist/{src → core/src}/baseForm/BaseRequestBodyFilter.d.ts +0 -0
- /package/dist/{src → core/src}/baseForm/FormManager.d.ts +0 -0
- /package/dist/{src → core/src}/baseForm/InputControl.d.ts +0 -0
- /package/dist/{src → core/src}/baseForm/InputControlBuilder.d.ts +0 -0
- /package/dist/{src → core/src}/baseForm/InputControlData.d.ts +0 -0
- /package/dist/{src → core/src}/baseForm/RequestBodyFilter.d.ts +0 -0
- /package/dist/{src → core/src}/baseForm/TouchSensitiveForm.d.ts +0 -0
- /package/dist/{src → core/src}/baseForm/index.d.ts +0 -0
- /package/dist/{src → core/src}/baseSchedule/Schedule.d.ts +0 -0
- /package/dist/{src → core/src}/baseSchedule/Scheduler.d.ts +0 -0
- /package/dist/{src → core/src}/baseSchedule/index.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/OnDestory.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/RowActionSource.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/RowClick.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/RowDoubleClick.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/RowMetaClick.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/TableAction.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/TableHeaderSchema.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/TableLoader.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/TablePaginate.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/TableService.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/TableSort.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/TableSummarySchema.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/generator/TableCellComponentRegistry.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/generator/TableConfig.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/generator/TableGenerator.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/generator/TableSource.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/index.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/moduleConnection/Action.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/moduleConnection/Column.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/moduleConnection/TableDestroy.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/moduleConnection/TableRowClick.d.ts +0 -0
- /package/dist/{src → core/src}/baseTable/moduleConnection/generator/GTable.d.ts +0 -0
- /package/dist/{src → core/src}/composables/UseState.d.ts +0 -0
- /package/dist/{src → core/src}/composables/index.d.ts +0 -0
- /package/dist/{src → core/src}/constants/Constants.d.ts +0 -0
- /package/dist/{src → core/src}/constants/index.d.ts +0 -0
- /package/dist/{src → core/src}/crudService/index.d.ts +0 -0
- /package/dist/{src → core/src}/dateHandling/Constants.d.ts +0 -0
- /package/dist/{src → core/src}/dateHandling/JalaliDateSetup.d.ts +0 -0
- /package/dist/{src → core/src}/dateHandling/Model.d.ts +0 -0
- /package/dist/{src → core/src}/dateHandling/Utils.d.ts +0 -0
- /package/dist/{src → core/src}/dateHandling/index.d.ts +0 -0
- /package/dist/{src → core/src}/debounce/DebounceAction.d.ts +0 -0
- /package/dist/{src → core/src}/debounce/DebounceService.d.ts +0 -0
- /package/dist/{src → core/src}/debounce/index.d.ts +0 -0
- /package/dist/{src → core/src}/deviceManagement/Constants.d.ts +0 -0
- /package/dist/{src → core/src}/deviceManagement/Visibility.d.ts +0 -0
- /package/dist/{src → core/src}/deviceManagement/VisibilityManager.d.ts +0 -0
- /package/dist/{src → core/src}/deviceManagement/index.d.ts +0 -0
- /package/dist/{src → core/src}/errorHandling/ErrorHandler.d.ts +0 -0
- /package/dist/{src → core/src}/errorHandling/HandleError.d.ts +0 -0
- /package/dist/{src → core/src}/errorHandling/index.d.ts +0 -0
- /package/dist/{src → core/src}/eventSystem/CustomEventDispatcher.d.ts +0 -0
- /package/dist/{src → core/src}/eventSystem/Model.d.ts +0 -0
- /package/dist/{src → core/src}/eventSystem/OnEvent.d.ts +0 -0
- /package/dist/{src → core/src}/eventSystem/index.d.ts +0 -0
- /package/dist/{src → core/src}/feedbackHandling/FailureFeedback.d.ts +0 -0
- /package/dist/{src → core/src}/feedbackHandling/Feedback.d.ts +0 -0
- /package/dist/{src → core/src}/feedbackHandling/HandleFeedback.d.ts +0 -0
- /package/dist/{src → core/src}/feedbackHandling/InfoFeedback.d.ts +0 -0
- /package/dist/{src → core/src}/feedbackHandling/SuccessFeedback.d.ts +0 -0
- /package/dist/{src → core/src}/feedbackHandling/WarningFeedback.d.ts +0 -0
- /package/dist/{src → core/src}/feedbackHandling/index.d.ts +0 -0
- /package/dist/{src → core/src}/httpClient/ApiBuilder.d.ts +0 -0
- /package/dist/{src → core/src}/httpClient/HttpClient.d.ts +0 -0
- /package/dist/{src → core/src}/httpClient/Interceptor.d.ts +0 -0
- /package/dist/{src → core/src}/httpClient/index.d.ts +0 -0
- /package/dist/{src → core/src}/initializer/ApplicationInitializer.d.ts +0 -0
- /package/dist/{src → core/src}/initializer/Initializer.d.ts +0 -0
- /package/dist/{src → core/src}/initializer/index.d.ts +0 -0
- /package/dist/{src → core/src}/json/index.d.ts +0 -0
- /package/dist/{src → core/src}/layout/Constants.d.ts +0 -0
- /package/dist/{src → core/src}/layout/Toast.d.ts +0 -0
- /package/dist/{src → core/src}/layout/index.d.ts +0 -0
- /package/dist/{src → core/src}/lib/Constants.d.ts +0 -0
- /package/dist/{src → core/src}/lib/index.d.ts +0 -0
- /package/dist/{src → core/src}/observables/AbstractSubject.d.ts +0 -0
- /package/dist/{src → core/src}/observables/BehaviorSubject.d.ts +0 -0
- /package/dist/{src → core/src}/observables/Observer.d.ts +0 -0
- /package/dist/{src → core/src}/observables/Subject.d.ts +0 -0
- /package/dist/{src → core/src}/observables/index.d.ts +0 -0
- /package/dist/{src → core/src}/process/Proccess.d.ts +0 -0
- /package/dist/{src → core/src}/process/ProcessManager.d.ts +0 -0
- /package/dist/{src → core/src}/process/index.d.ts +0 -0
- /package/dist/{src → core/src}/repository/Params.d.ts +0 -0
- /package/dist/{src → core/src}/repository/Repository.d.ts +0 -0
- /package/dist/{src → core/src}/repository/SyncDetail.d.ts +0 -0
- /package/dist/{src → core/src}/repository/index.d.ts +0 -0
- /package/dist/{src → core/src}/repository/model.d.ts +0 -0
- /package/dist/{src → core/src}/routeGuard/RouteGuard.d.ts +0 -0
- /package/dist/{src → core/src}/routeGuard/index.d.ts +0 -0
- /package/dist/{src → core/src}/search/client/ClientArraySearch.d.ts +0 -0
- /package/dist/{src → core/src}/search/client/ClientSearch.d.ts +0 -0
- /package/dist/{src → core/src}/search/index.d.ts +0 -0
- /package/dist/{src → core/src}/sort/SortDetail.d.ts +0 -0
- /package/dist/{src → core/src}/sort/client/Sorter.d.ts +0 -0
- /package/dist/{src → core/src}/sort/index.d.ts +0 -0
- /package/dist/{src → core/src}/sort/strategies/SimpleSort.d.ts +0 -0
- /package/dist/{src → core/src}/sort/strategies/SortStrategy.d.ts +0 -0
- /package/dist/{src → core/src}/types/Global.d.ts +0 -0
- /package/dist/{src → core/src}/types/index.d.ts +0 -0
- /package/dist/{src → core/src}/validators/Validator.d.ts +0 -0
- /package/dist/{src → core/src}/validators/index.d.ts +0 -0
- /package/dist/{src → core/src}/webSocket/Constants.d.ts +0 -0
- /package/dist/{src → core/src}/webSocket/Model.d.ts +0 -0
- /package/dist/{src → core/src}/webSocket/WebSocketService.d.ts +0 -0
- /package/dist/{src → core/src}/webSocket/index.d.ts +0 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { toRaw } from "vue";
|
|
2
|
+
import type { Nullable } from "../types";
|
|
3
|
+
import { InputControlData } from "./InputControlData";
|
|
4
|
+
import { isEmpty } from "../Utils";
|
|
5
|
+
import { type Validator } from "../validators";
|
|
6
|
+
|
|
7
|
+
export class InputControl<T> {
|
|
8
|
+
private initialData: Nullable<InputControlData<T>> = null;
|
|
9
|
+
private data = new InputControlData<T>();
|
|
10
|
+
private _validators: Validator<T>[] = [];
|
|
11
|
+
private _id = Math.random();
|
|
12
|
+
|
|
13
|
+
constructor(name: string, value: Nullable<T>) {
|
|
14
|
+
this.data.value = value;
|
|
15
|
+
this.data.name = name;
|
|
16
|
+
if (this.shouldRunValidation()) {
|
|
17
|
+
this.runValidation(true);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private shouldRunValidation(): boolean {
|
|
22
|
+
if (this.data.hasCustomValidationCheck) return false;
|
|
23
|
+
if (this.data.isRequired) return true;
|
|
24
|
+
return !isEmpty(this.data.value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public async runValidation(isBlur: boolean = false) {
|
|
28
|
+
for (const validator of this._validators) {
|
|
29
|
+
const validationMessage = await validator.validate(this.data.value);
|
|
30
|
+
if (validationMessage) {
|
|
31
|
+
this.setFormToInvalidState(isBlur, validationMessage);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
this.setFormToValidState();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private setFormToInvalidState(
|
|
39
|
+
isBlur: boolean,
|
|
40
|
+
validationMessage: string,
|
|
41
|
+
) {
|
|
42
|
+
this.data.isValid = false;
|
|
43
|
+
if (this.data.isChangeSensitive || isBlur) {
|
|
44
|
+
this.setNotValidMessage(validationMessage);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private setFormToValidState() {
|
|
49
|
+
this.data.isValid = true;
|
|
50
|
+
this.setNotValidMessage('');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public reset() {
|
|
54
|
+
if (this.initialData) {
|
|
55
|
+
this.data = structuredClone(toRaw(this.initialData));
|
|
56
|
+
} else {
|
|
57
|
+
console.warn(
|
|
58
|
+
"The " +
|
|
59
|
+
this.data.name +
|
|
60
|
+
`input control has no initial data,
|
|
61
|
+
the initial data will be available after calling the [markAsInitial] method on this instance`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public markAsInitial() {
|
|
67
|
+
this.initialData = structuredClone(toRaw(this.data));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public setValidators(validators: Validator<T>[]) {
|
|
71
|
+
this._validators = validators;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public getChangeSensitive() {
|
|
75
|
+
return this.data.isChangeSensitive;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public setChangeSensitive(isChangeSensitive: boolean) {
|
|
79
|
+
if (isChangeSensitive && this.data.shouldRemoveValidationMessageOnInteract) {
|
|
80
|
+
throw new Error("Input control " + this.getName() + " can not be both change sensitive and remove validation meessage on interact");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.data.isChangeSensitive = isChangeSensitive;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public getIsBlurSensitive(): boolean {
|
|
87
|
+
return this.data.isBlurSensitive;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public setIsBlurSensitive(isBlurSensitive: boolean) {
|
|
91
|
+
this.data.isBlurSensitive = isBlurSensitive;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public getIsRequired(): boolean {
|
|
95
|
+
return this.data.isRequired;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public setIsRequired(isRequired: boolean) {
|
|
99
|
+
this.data.isRequired = isRequired;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public getIsValid() {
|
|
103
|
+
return this.data.isValid;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public setIsValid(isValid: boolean) {
|
|
107
|
+
this.data.isValid = isValid;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public getIsIncludeInRequestBody(): boolean {
|
|
111
|
+
return this.data.isIncludeInRequestBody;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public setIsIncludeInRequestBody(isIncludeInRequestBody: boolean) {
|
|
115
|
+
this.data.isIncludeInRequestBody = isIncludeInRequestBody;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public getNotValidMessage() {
|
|
119
|
+
return this.data.notValidMessage;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public setNotValidMessage(notValidMessage: string) {
|
|
123
|
+
this.data.notValidMessage = notValidMessage;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public getName() {
|
|
127
|
+
return this.data.name;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public setName(name: string) {
|
|
131
|
+
this.data.name = name;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public setId(id: number) {
|
|
135
|
+
this._id = id;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public getId(): number {
|
|
139
|
+
return this._id;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public getIsEmptySensitive(): boolean {
|
|
143
|
+
return this.data.isEmptySensitive;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public setIsEmptySensitive(value: boolean) {
|
|
147
|
+
this.data.isEmptySensitive = value;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public setHasCustomValidationCheck(hasCustomCheck: boolean) {
|
|
151
|
+
this.data.hasCustomValidationCheck = hasCustomCheck;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public setShouldRemoveValidationOnInteract(value: boolean) {
|
|
155
|
+
if (value && this.data.isChangeSensitive) {
|
|
156
|
+
throw new Error("Input control " + this.getName() + " can not be both change sensitive and remove validation meessage on interact");
|
|
157
|
+
}
|
|
158
|
+
this.data.shouldRemoveValidationMessageOnInteract = value;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public getShouldRemoveValidationOnInteract() {
|
|
162
|
+
return this.data.shouldRemoveValidationMessageOnInteract;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public hasCustomValidationCheck() {
|
|
166
|
+
return this.data.hasCustomValidationCheck;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public set value(value: Nullable<T>) {
|
|
170
|
+
this.data.value = value;
|
|
171
|
+
if (this.shouldRunValidation()) {
|
|
172
|
+
this.runValidation();
|
|
173
|
+
}
|
|
174
|
+
if (this.getShouldRemoveValidationOnInteract()) {
|
|
175
|
+
this.setNotValidMessage("");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public get value() {
|
|
180
|
+
return this.data.value;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { InputControl } from "./InputControl";
|
|
2
|
+
import type { Validator } from "../validators";
|
|
3
|
+
|
|
4
|
+
export class InputControlBuilder<T> {
|
|
5
|
+
private _inputControl: InputControl<T>;
|
|
6
|
+
|
|
7
|
+
constructor(inputControl: InputControl<T>) {
|
|
8
|
+
this._inputControl = inputControl;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public setValidators(validators: Validator<T>[]) {
|
|
12
|
+
this._inputControl.setValidators(validators);
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public setChangeSensitive() {
|
|
17
|
+
this._inputControl.setChangeSensitive(true);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public setRequired() {
|
|
22
|
+
this._inputControl.setIsRequired(true);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public setValid() {
|
|
27
|
+
this._inputControl.setIsValid(true);
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public setBlurSensitive() {
|
|
32
|
+
this._inputControl.setIsBlurSensitive(true);
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public setId(id: number) {
|
|
37
|
+
this._inputControl.setId(id);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public removeEmptySensitive() {
|
|
42
|
+
this._inputControl.setIsEmptySensitive(false);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public setHasCustomValidationCheck() {
|
|
47
|
+
this._inputControl.setHasCustomValidationCheck(true);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public removeErrorOnInteract() {
|
|
52
|
+
this._inputControl.setShouldRemoveValidationOnInteract(true);
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public build(): InputControl<T> {
|
|
57
|
+
return this._inputControl;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Nullable } from '../types'
|
|
2
|
+
|
|
3
|
+
export class InputControlData<T> {
|
|
4
|
+
public value: Nullable<T> = null
|
|
5
|
+
public initialValue: Nullable<T> = null
|
|
6
|
+
public name: string = ''
|
|
7
|
+
public isValid: boolean = false
|
|
8
|
+
public isBlurSensitive: boolean = false
|
|
9
|
+
public isRequired: boolean = false
|
|
10
|
+
public isIncludeInRequestBody: boolean = true
|
|
11
|
+
public isChangeSensitive: boolean = false
|
|
12
|
+
public notValidMessage: string = ''
|
|
13
|
+
public isEmptySensitive: boolean = true;
|
|
14
|
+
public hasCustomValidationCheck: boolean = false;
|
|
15
|
+
public shouldRemoveValidationMessageOnInteract = false;
|
|
16
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { DirectiveBinding } from "vue";
|
|
2
|
+
import type { MountedDirective } from "../baseDirective";
|
|
3
|
+
import type { BeforeUnMountDirective } from "../baseDirective";
|
|
4
|
+
import { InputControl } from "./InputControl";
|
|
5
|
+
|
|
6
|
+
export class TouchSensitiveControl
|
|
7
|
+
implements MountedDirective, BeforeUnMountDirective
|
|
8
|
+
{
|
|
9
|
+
|
|
10
|
+
public mounted = (
|
|
11
|
+
element: HTMLInputElement,
|
|
12
|
+
binding: DirectiveBinding<InputControl<unknown>>,
|
|
13
|
+
) => {
|
|
14
|
+
if (!binding.value) return;
|
|
15
|
+
|
|
16
|
+
if (!binding.value.getIsBlurSensitive()) return;
|
|
17
|
+
|
|
18
|
+
element.addEventListener('click', this.handleFocus.bind(this, binding.value))
|
|
19
|
+
|
|
20
|
+
element.addEventListener(
|
|
21
|
+
"blur",
|
|
22
|
+
this.handleBlur.bind(this, binding.value),
|
|
23
|
+
true,
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
public beforeUnMount = (
|
|
28
|
+
element: HTMLInputElement,
|
|
29
|
+
binding: DirectiveBinding<InputControl<unknown>>,
|
|
30
|
+
) => {
|
|
31
|
+
element!.removeEventListener(
|
|
32
|
+
"blur",
|
|
33
|
+
this.handleBlur.bind(this, binding.value),
|
|
34
|
+
);
|
|
35
|
+
element!.removeEventListener('click', this.handleFocus.bind(this, binding.value))
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
private handleBlur(inputControl: InputControl<unknown>) {
|
|
39
|
+
inputControl!.runValidation(true);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private handleFocus(inputControl: InputControl<unknown>) {
|
|
43
|
+
if (inputControl.value || inputControl.getIsEmptySensitive()) return;
|
|
44
|
+
|
|
45
|
+
inputControl.setNotValidMessage('');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { reactive, ref, watch } from "vue";
|
|
2
|
+
import { FormManager } from "./FormManager";
|
|
3
|
+
import { FormValidationStatus } from "../constants";
|
|
4
|
+
|
|
5
|
+
export function useForm(form: FormManager, hasCustomValidation = false) {
|
|
6
|
+
const reactiveForm = reactive<FormManager>(form);
|
|
7
|
+
const validationStatus = ref<FormValidationStatus>(
|
|
8
|
+
FormValidationStatus.Invalid,
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
watch(
|
|
12
|
+
() => reactiveForm.getInputControlsAsArray(),
|
|
13
|
+
() => {
|
|
14
|
+
if (hasCustomValidation) return;
|
|
15
|
+
reactiveForm.runValidation();
|
|
16
|
+
if (reactiveForm.getIsValid()) {
|
|
17
|
+
validationStatus.value = FormValidationStatus.Valid;
|
|
18
|
+
} else {
|
|
19
|
+
validationStatus.value = FormValidationStatus.Invalid;
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
immediate: true,
|
|
24
|
+
deep: true,
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
reactiveForm,
|
|
30
|
+
validationStatus,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { InputControl } from "./InputControl";
|
|
2
|
+
export { InputControlBuilder } from "./InputControlBuilder";
|
|
3
|
+
export { InputControlData } from "./InputControlData";
|
|
4
|
+
export { TouchSensitiveControl } from "./TouchSensitiveForm";
|
|
5
|
+
export { FormManager } from "./FormManager";
|
|
6
|
+
export { useForm } from "./UseForm";
|
|
7
|
+
export { BaseRequestBodyFilter } from "./BaseRequestBodyFilter"
|
|
8
|
+
export { type RequestBodyFilter } from "./RequestBodyFilter"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Nullable } from '../types'
|
|
2
|
+
import type { Schedule } from './Schedule'
|
|
3
|
+
|
|
4
|
+
export class Scheduler {
|
|
5
|
+
private timerId: Nullable<ReturnType<typeof setTimeout>> = null
|
|
6
|
+
private readonly schedule: Schedule;
|
|
7
|
+
|
|
8
|
+
constructor(scheduler: Schedule) {
|
|
9
|
+
this.setupInterval = this.setupInterval.bind(this);
|
|
10
|
+
this.schedule = scheduler;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public setupInterval(intervalInMilliseconds: number) {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
15
|
+
const thisReference = this;
|
|
16
|
+
this.timerId = setTimeout(async function autoRefresh() {
|
|
17
|
+
await thisReference.schedule.runAction()
|
|
18
|
+
thisReference.timerId = setTimeout(() => {
|
|
19
|
+
autoRefresh()
|
|
20
|
+
}, intervalInMilliseconds);
|
|
21
|
+
}, intervalInMilliseconds);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public clearInterval() {
|
|
25
|
+
if (this.timerId) {
|
|
26
|
+
clearInterval(this.timerId);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { SortDetail } from "../sort";
|
|
2
|
+
import { BaseModel } from "../BaseModel";
|
|
3
|
+
import { LoadingStatus, SortOrder, TableConstants } from "../constants";
|
|
4
|
+
import { type Accessible, AccessLevel } from "../accessHandling";
|
|
5
|
+
import type { TableHeaderSchema } from "./TableHeaderSchema";
|
|
6
|
+
import type { TableService } from "./TableService";
|
|
7
|
+
import type { TableAction } from "./TableAction";
|
|
8
|
+
import type { Nullable } from "../types";
|
|
9
|
+
import type { TableSummarySchema } from "./TableSummarySchema.ts";
|
|
10
|
+
|
|
11
|
+
export abstract class BaseTable<Model extends BaseModel> {
|
|
12
|
+
protected service: TableService<Model>;
|
|
13
|
+
private accessService: AccessLevel;
|
|
14
|
+
protected currentPage: number = 1;
|
|
15
|
+
protected currentPageSize: number = 20;
|
|
16
|
+
private currentSortDetail: SortDetail<Model> = new SortDetail(
|
|
17
|
+
"id",
|
|
18
|
+
SortOrder.DESC,
|
|
19
|
+
);
|
|
20
|
+
protected loadedRows: Model[] = [];
|
|
21
|
+
public headerSchema: TableHeaderSchema<Model>[] = [];
|
|
22
|
+
|
|
23
|
+
protected constructor(service: TableService<Model>) {
|
|
24
|
+
this.service = service;
|
|
25
|
+
this.accessService = AccessLevel.GetInstance();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public addHeader(schema: TableHeaderSchema<Model>) {
|
|
29
|
+
this.headerSchema.push(schema);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public async load() {
|
|
33
|
+
this.headerSchema = this.filterItemsBaseOnAccessLevel(
|
|
34
|
+
await this.loadHeader(),
|
|
35
|
+
);
|
|
36
|
+
await this.loadRows();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
protected filterItemsBaseOnAccessLevel<T>(items: Accessible[]): T[] {
|
|
40
|
+
return items.filter((item) => {
|
|
41
|
+
if (item.hasAccess) {
|
|
42
|
+
return item.hasAccess();
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}) as T[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public async sort(sortDetail: SortDetail<Model>) {
|
|
49
|
+
if (!this.shouldSendSortRequest(sortDetail)) return;
|
|
50
|
+
this.currentSortDetail = sortDetail;
|
|
51
|
+
this.loadedRows = (await this.handleSort(this.currentSortDetail)).items;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private shouldSendSortRequest(sortDetail: SortDetail<Model>): boolean {
|
|
55
|
+
return (
|
|
56
|
+
sortDetail.key !== this.currentSortDetail.key ||
|
|
57
|
+
sortDetail.order !== this.currentSortDetail.order
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public async paginate(nextPage: number, pageSize: number) {
|
|
62
|
+
if (!this.shouldSendPaginationRequest(nextPage, pageSize)) return;
|
|
63
|
+
this.currentPage = nextPage;
|
|
64
|
+
this.currentPageSize = pageSize;
|
|
65
|
+
this.loadedRows = (
|
|
66
|
+
await this.handlePagination(this.currentPage, this.currentPageSize)
|
|
67
|
+
).items;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private shouldSendPaginationRequest(
|
|
71
|
+
nextPage: number,
|
|
72
|
+
pageSize: number,
|
|
73
|
+
): boolean {
|
|
74
|
+
return this.currentPage !== nextPage || this.currentPageSize !== pageSize;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
protected async loadRows() {
|
|
78
|
+
this.loadedRows = (await this.service.fetchRows()).items;
|
|
79
|
+
return this.loadedRows;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public getData() {
|
|
83
|
+
return this.service.getData();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
protected async handleSort(sortDetail: SortDetail<Model>) {
|
|
87
|
+
return await this.service.sort(sortDetail);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
protected async handlePagination(nextPage: number, pageSize: number) {
|
|
91
|
+
return await this.service.paginate(nextPage, pageSize);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public getItemCountPerPage(): number {
|
|
95
|
+
return TableConstants.DEFAULT_ITEM_COUNT_PER_PAGE;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public isLoading() {
|
|
99
|
+
const loadingStatuses = this.getLoadingStatuses();
|
|
100
|
+
return (
|
|
101
|
+
loadingStatuses.has(LoadingStatus.Search) ||
|
|
102
|
+
loadingStatuses.has(LoadingStatus.FetchList) ||
|
|
103
|
+
loadingStatuses.has(LoadingStatus.Sort) ||
|
|
104
|
+
loadingStatuses.has(LoadingStatus.FetchLastItems) ||
|
|
105
|
+
loadingStatuses.has(LoadingStatus.FetchPreviousItems)
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
protected getLoadingStatuses() {
|
|
110
|
+
return this.getData().loadingStatus;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public hasAnyAction() {
|
|
114
|
+
for (const row of this.loadedRows) {
|
|
115
|
+
if (this.getAccessedActions(row).length) return true;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public getAccessedActions(row: Model): TableAction<Model>[] {
|
|
121
|
+
return this.filterItemsBaseOnAccessLevel(this.getActions(row));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
protected getActions(row: Model): TableAction<Model>[] {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public getScrollDetail(): Nullable<boolean | { x?: number; y?: number }> {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public isExpandable() {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public async handleClick(row: Model) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public async handleMetaClick(row: Model) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public async handleDoubleClick(row: Model) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public async onDestroy() {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public async loadHeader(): Promise<TableHeaderSchema<Model>[]> {
|
|
153
|
+
throw new Error("No header provided for the table.");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public loadSummarySchema(): TableSummarySchema {
|
|
157
|
+
return {
|
|
158
|
+
summaryTitle: "",
|
|
159
|
+
summaryItems: [],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TableHeaderSchema } from "./TableHeaderSchema";
|
|
2
|
+
import { BaseModel } from "../BaseModel";
|
|
3
|
+
import { CellType, HeaderType, TableHeaderAlign } from "../constants";
|
|
4
|
+
|
|
5
|
+
export const TABLE_COLUMN_DEFAULT_WIDTH = "150px";
|
|
6
|
+
export const TABLE_COLUMN_DEFAULT_COLSPAN = 2;
|
|
7
|
+
|
|
8
|
+
export const TABLE_ACTION_COLUMN: TableHeaderSchema<BaseModel> = {
|
|
9
|
+
path: "id",
|
|
10
|
+
key: "id",
|
|
11
|
+
title: "عملیات",
|
|
12
|
+
colspan: TABLE_COLUMN_DEFAULT_COLSPAN,
|
|
13
|
+
width: TABLE_COLUMN_DEFAULT_WIDTH,
|
|
14
|
+
cellType: CellType.ACTION,
|
|
15
|
+
align: TableHeaderAlign.Center,
|
|
16
|
+
headerType: HeaderType.Text,
|
|
17
|
+
accessLevel: null,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const TABLE_COLUMN_DEFAULT_VALUES = {
|
|
21
|
+
width: TABLE_COLUMN_DEFAULT_WIDTH,
|
|
22
|
+
align: TableHeaderAlign.Center,
|
|
23
|
+
headerType: HeaderType.Text,
|
|
24
|
+
cellType: CellType.Text,
|
|
25
|
+
colspan: TABLE_COLUMN_DEFAULT_COLSPAN,
|
|
26
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { BaseTable } from './BaseTable'
|
|
2
|
+
import { BehaviorSubject } from '../observables/BehaviorSubject'
|
|
3
|
+
import { type SortDetail } from '../sort'
|
|
4
|
+
import type { BaseModel } from '../BaseModel'
|
|
5
|
+
import type { TableService } from './TableService'
|
|
6
|
+
|
|
7
|
+
export abstract class SelectableTable<
|
|
8
|
+
Model extends BaseModel,
|
|
9
|
+
> extends BaseTable<Model> {
|
|
10
|
+
public selectedRows: BehaviorSubject<Map<number, Model>> =
|
|
11
|
+
new BehaviorSubject(new Map<number, Model>());
|
|
12
|
+
|
|
13
|
+
constructor(service: TableService<Model>) {
|
|
14
|
+
super(service);
|
|
15
|
+
this.rowSelect = this.rowSelect.bind(this);
|
|
16
|
+
this.selectAll = this.selectAll.bind(this);
|
|
17
|
+
this.isEveryRowSelected = this.isEveryRowSelected.bind(this);
|
|
18
|
+
this.handlePagination = this.handlePagination.bind(this);
|
|
19
|
+
this.clearAllSelectedItems = this.clearAllSelectedItems.bind(this);
|
|
20
|
+
this.getSelectedRows = this.getSelectedRows.bind(this);
|
|
21
|
+
this.getSelectedRowsAsArray = this.getSelectedRowsAsArray.bind(this);
|
|
22
|
+
this.getSelectedRowIds = this.getSelectedRowIds.bind(this);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public rowSelect(row: Model) {
|
|
26
|
+
if (this.getSelectedRowsValue().has(row.id)) {
|
|
27
|
+
this.getSelectedRowsValue().delete(row.id);
|
|
28
|
+
this.selectedRows.next(this.selectedRows.getValue());
|
|
29
|
+
} else {
|
|
30
|
+
this.selectedRows.getValue().set(row.id, row);
|
|
31
|
+
this.selectedRows.next(this.selectedRows.getValue());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public selectAll() {
|
|
36
|
+
if (this.isEveryRowSelected()) {
|
|
37
|
+
this.clearAllSelectedItems();
|
|
38
|
+
} else {
|
|
39
|
+
for (const row of this.loadedRows) {
|
|
40
|
+
this.selectedRows.getValue().set(row.id, row);
|
|
41
|
+
this.selectedRows.next(this.selectedRows.getValue());
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private isEveryRowSelected() {
|
|
47
|
+
return (
|
|
48
|
+
this.getSelectedRowsValue().size === this.currentPageSize ||
|
|
49
|
+
this.loadedRows.length === this.getSelectedRowsValue().size
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected override async handlePagination(
|
|
54
|
+
nextPage: number,
|
|
55
|
+
pageSize: number,
|
|
56
|
+
) {
|
|
57
|
+
this.clearAllSelectedItems();
|
|
58
|
+
return await super.handlePagination(nextPage, pageSize);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected override async handleSort(sortDetail: SortDetail<Model>) {
|
|
62
|
+
this.clearAllSelectedItems();
|
|
63
|
+
return await super.handleSort(sortDetail);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public clearAllSelectedItems() {
|
|
67
|
+
this.selectedRows.getValue().clear();
|
|
68
|
+
this.selectedRows.next(this.selectedRows.getValue());
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public getSelectedRows() {
|
|
72
|
+
return this.selectedRows;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public getSelectedRowsAsArray() {
|
|
76
|
+
return Array.from(this.selectedRows.getValue().values());
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public getSelectedRowIds() {
|
|
80
|
+
return Array.from(this.selectedRows.getValue().keys());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public getSelectedRowsValue() {
|
|
84
|
+
return this.selectedRows.getValue();
|
|
85
|
+
}
|
|
86
|
+
}
|