@sarafapp/iron_core 1.0.64 → 1.0.67

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.
Files changed (152) hide show
  1. package/package.json +5 -2
  2. package/index.ts +0 -37
  3. package/src/BaseModel.ts +0 -127
  4. package/src/Utils.ts +0 -16
  5. package/src/accessHandling/AccessControl.ts +0 -33
  6. package/src/accessHandling/AccessLevel.ts +0 -52
  7. package/src/accessHandling/Accessible.ts +0 -3
  8. package/src/accessHandling/EveryDirectiveAccess.ts +0 -7
  9. package/src/accessHandling/SSO/AuthorizationDirective.ts +0 -65
  10. package/src/accessHandling/SSO/AuthorizationService.ts +0 -74
  11. package/src/accessHandling/SSO/EveryLevelAuthorizationDirective.ts +0 -7
  12. package/src/accessHandling/SSO/SomeLevelsAuthorizationDirective.ts +0 -7
  13. package/src/accessHandling/SomeDirectiveAccess.ts +0 -7
  14. package/src/accessHandling/index.ts +0 -9
  15. package/src/baseDirective/BeforeMountDirective.ts +0 -3
  16. package/src/baseDirective/BeforeUnMountDirective.ts +0 -3
  17. package/src/baseDirective/BeforeUpdateDirective.ts +0 -3
  18. package/src/baseDirective/CreatedDirective.ts +0 -3
  19. package/src/baseDirective/MountedDirective.ts +0 -3
  20. package/src/baseDirective/UnMountedDirective.ts +0 -3
  21. package/src/baseDirective/UpdateDirective.ts +0 -3
  22. package/src/baseDirective/index.ts +0 -7
  23. package/src/baseForm/BaseRequestBodyFilter.ts +0 -7
  24. package/src/baseForm/FormManager.ts +0 -95
  25. package/src/baseForm/InputControl.ts +0 -182
  26. package/src/baseForm/InputControlBuilder.ts +0 -59
  27. package/src/baseForm/InputControlData.ts +0 -16
  28. package/src/baseForm/RequestBodyFilter.ts +0 -3
  29. package/src/baseForm/TouchSensitiveForm.ts +0 -47
  30. package/src/baseForm/UseForm.ts +0 -32
  31. package/src/baseForm/index.ts +0 -8
  32. package/src/baseSchedule/Schedule.ts +0 -3
  33. package/src/baseSchedule/Scheduler.ts +0 -29
  34. package/src/baseSchedule/index.ts +0 -2
  35. package/src/baseTable/BaseTable.ts +0 -162
  36. package/src/baseTable/Constants.ts +0 -26
  37. package/src/baseTable/OnDestory.ts +0 -3
  38. package/src/baseTable/RowActionSource.ts +0 -5
  39. package/src/baseTable/RowClick.ts +0 -3
  40. package/src/baseTable/RowDoubleClick.ts +0 -3
  41. package/src/baseTable/RowMetaClick.ts +0 -3
  42. package/src/baseTable/SelectableTable.ts +0 -86
  43. package/src/baseTable/TableAction.ts +0 -10
  44. package/src/baseTable/TableHeaderSchema.ts +0 -44
  45. package/src/baseTable/TableLoader.ts +0 -3
  46. package/src/baseTable/TablePaginate.ts +0 -3
  47. package/src/baseTable/TableService.ts +0 -10
  48. package/src/baseTable/TableSort.ts +0 -5
  49. package/src/baseTable/TableSummarySchema.ts +0 -11
  50. package/src/baseTable/generator/SelectableTableGenerator.ts +0 -65
  51. package/src/baseTable/generator/TableCellComponentRegistry.ts +0 -15
  52. package/src/baseTable/generator/TableConfig.ts +0 -18
  53. package/src/baseTable/generator/TableGenerator.ts +0 -147
  54. package/src/baseTable/generator/TableSource.ts +0 -34
  55. package/src/baseTable/index.ts +0 -43
  56. package/src/baseTable/moduleConnection/Action.ts +0 -12
  57. package/src/baseTable/moduleConnection/Column.ts +0 -11
  58. package/src/baseTable/moduleConnection/Table.ts +0 -49
  59. package/src/baseTable/moduleConnection/TableDestroy.ts +0 -7
  60. package/src/baseTable/moduleConnection/TableRowClick.ts +0 -7
  61. package/src/baseTable/moduleConnection/generator/GColumn.ts +0 -10
  62. package/src/baseTable/moduleConnection/generator/GTable.ts +0 -11
  63. package/src/composables/UseCrud.ts +0 -53
  64. package/src/composables/UseData.ts +0 -70
  65. package/src/composables/UseLoadingStatus.ts +0 -65
  66. package/src/composables/UseParams.ts +0 -93
  67. package/src/composables/UseRepository.ts +0 -207
  68. package/src/composables/UseState.ts +0 -30
  69. package/src/composables/UseStaticTableService.ts +0 -45
  70. package/src/composables/index.ts +0 -7
  71. package/src/constants/Constants.ts +0 -126
  72. package/src/constants/index.ts +0 -19
  73. package/src/crudService/CrudService.ts +0 -121
  74. package/src/crudService/index.ts +0 -1
  75. package/src/dateHandling/Constants.ts +0 -5
  76. package/src/dateHandling/Converter.ts +0 -15
  77. package/src/dateHandling/JalaliDateSetup.ts +0 -42
  78. package/src/dateHandling/Model.ts +0 -27
  79. package/src/dateHandling/Utils.ts +0 -49
  80. package/src/dateHandling/index.ts +0 -5
  81. package/src/debounce/DebounceAction.ts +0 -4
  82. package/src/debounce/DebounceService.ts +0 -27
  83. package/src/debounce/index.ts +0 -2
  84. package/src/deviceManagement/Constants.ts +0 -4
  85. package/src/deviceManagement/Visibility.ts +0 -4
  86. package/src/deviceManagement/VisibilityManager.ts +0 -18
  87. package/src/deviceManagement/index.ts +0 -3
  88. package/src/errorHandling/ErrorHandler.ts +0 -3
  89. package/src/errorHandling/HandleError.ts +0 -20
  90. package/src/errorHandling/index.ts +0 -2
  91. package/src/eventSystem/CustomEventDispatcher.ts +0 -13
  92. package/src/eventSystem/Model.ts +0 -29
  93. package/src/eventSystem/OnEvent.ts +0 -25
  94. package/src/eventSystem/index.ts +0 -3
  95. package/src/feedbackHandling/FailureFeedback.ts +0 -3
  96. package/src/feedbackHandling/Feedback.ts +0 -34
  97. package/src/feedbackHandling/HandleFeedback.ts +0 -28
  98. package/src/feedbackHandling/InfoFeedback.ts +0 -3
  99. package/src/feedbackHandling/SuccessFeedback.ts +0 -3
  100. package/src/feedbackHandling/WarningFeedback.ts +0 -3
  101. package/src/feedbackHandling/index.ts +0 -6
  102. package/src/httpClient/ApiBuilder.ts +0 -57
  103. package/src/httpClient/ErrorHandlerRegistry.ts +0 -29
  104. package/src/httpClient/HttpClient.ts +0 -77
  105. package/src/httpClient/Interceptor.ts +0 -5
  106. package/src/httpClient/index.ts +0 -4
  107. package/src/initializer/ApplicationInitializer.ts +0 -15
  108. package/src/initializer/Initializer.ts +0 -3
  109. package/src/initializer/index.ts +0 -2
  110. package/src/json/JsonMapper.ts +0 -48
  111. package/src/json/index.ts +0 -1
  112. package/src/layout/Constants.ts +0 -11
  113. package/src/layout/DialogService.ts +0 -75
  114. package/src/layout/DrawerService.ts +0 -25
  115. package/src/layout/Toast.ts +0 -14
  116. package/src/layout/index.ts +0 -4
  117. package/src/lib/Constants.ts +0 -433
  118. package/src/lib/Formatter.ts +0 -68
  119. package/src/lib/Util.ts +0 -113
  120. package/src/lib/index.ts +0 -3
  121. package/src/observables/AbstractSubject.ts +0 -21
  122. package/src/observables/BehaviorSubject.ts +0 -58
  123. package/src/observables/Observer.ts +0 -3
  124. package/src/observables/Subject.ts +0 -9
  125. package/src/observables/index.ts +0 -4
  126. package/src/process/Proccess.ts +0 -21
  127. package/src/process/ProcessManager.ts +0 -31
  128. package/src/process/index.ts +0 -2
  129. package/src/repository/Params.ts +0 -10
  130. package/src/repository/Repository.ts +0 -44
  131. package/src/repository/SyncDetail.ts +0 -8
  132. package/src/repository/index.ts +0 -4
  133. package/src/repository/model.ts +0 -9
  134. package/src/routeGuard/RouteGuard.ts +0 -38
  135. package/src/routeGuard/index.ts +0 -1
  136. package/src/search/client/ClientArraySearch.ts +0 -25
  137. package/src/search/client/ClientSearch.ts +0 -3
  138. package/src/search/index.ts +0 -2
  139. package/src/sort/SortDetail.ts +0 -11
  140. package/src/sort/client/Sorter.ts +0 -28
  141. package/src/sort/index.ts +0 -4
  142. package/src/sort/strategies/SimpleSort.ts +0 -35
  143. package/src/sort/strategies/SortStrategy.ts +0 -4
  144. package/src/types/Global.ts +0 -1
  145. package/src/types/index.ts +0 -1
  146. package/src/validators/Validator.ts +0 -5
  147. package/src/validators/index.ts +0 -1
  148. package/src/webSocket/Constants.ts +0 -6
  149. package/src/webSocket/Model.ts +0 -16
  150. package/src/webSocket/WebSocketService.ts +0 -153
  151. package/src/webSocket/index.ts +0 -3
  152. package/vite.config.ts +0 -55
@@ -1,182 +0,0 @@
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
- }
@@ -1,59 +0,0 @@
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
- }
@@ -1,16 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- export interface RequestBodyFilter<T> {
2
- shouldBeInRequestBody(value: T): boolean
3
- }
@@ -1,47 +0,0 @@
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
- }
@@ -1,32 +0,0 @@
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
- }
@@ -1,8 +0,0 @@
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"
@@ -1,3 +0,0 @@
1
- export interface Schedule {
2
- runAction: () => Promise<unknown>
3
- }
@@ -1,29 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- export { type Schedule } from './Schedule'
2
- export { Scheduler } from './Scheduler'
@@ -1,162 +0,0 @@
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
- }
@@ -1,26 +0,0 @@
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
- };
@@ -1,3 +0,0 @@
1
- export interface Destroy {
2
- onDestroy(): Promise<void>;
3
- }
@@ -1,5 +0,0 @@
1
- import type { TableAction } from "./TableAction";
2
-
3
- export interface RowActionSource<Model, A> {
4
- getActions(): TableAction<Model, A>[];
5
- }
@@ -1,3 +0,0 @@
1
- export interface RowClick<Model> {
2
- handleClick(row: Model): Promise<void>;
3
- }
@@ -1,3 +0,0 @@
1
- export interface RowDoubleClick<Model> {
2
- handleDoubleClick(row: Model): Promise<void>;
3
- }
@@ -1,3 +0,0 @@
1
- export interface RowMetaClick<Model> {
2
- handleMetaClick(row: Model): Promise<void>;
3
- }
@@ -1,86 +0,0 @@
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
- }