@blueprint-ts/core 1.1.1 → 1.2.0
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/CHANGELOG.md +17 -0
- package/package.json +1 -1
- package/src/service/pagination/BasePaginator.ts +36 -0
- package/src/service/pagination/InfiniteScroller.ts +2 -2
- package/src/service/pagination/PageAwarePaginator.ts +124 -0
- package/src/service/pagination/Paginator.ts +9 -147
- package/src/service/pagination/StatePaginator.ts +92 -0
- package/src/service/pagination/contracts/BaseViewDriverContract.ts +6 -0
- package/src/service/pagination/contracts/BaseViewDriverFactoryContract.ts +5 -0
- package/src/service/pagination/contracts/StatePaginationDataDriverContract.ts +5 -0
- package/src/service/pagination/contracts/ViewDriverContract.ts +3 -5
- package/src/service/pagination/dtos/StatePaginationDataDto.ts +19 -0
- package/src/service/pagination/factories/VueBaseViewDriverFactory.ts +9 -0
- package/src/service/pagination/frontendDrivers/VueBaseViewDriver.ts +28 -0
- package/src/service/pagination/index.ts +34 -2
- package/src/vue/forms/PropertyAwareArray.ts +4 -4
- package/src/vue/state/State.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
## v1.2.0 - 2026-01-25
|
|
2
|
+
|
|
3
|
+
# [1.2.0](/compare/v1.1.2...v1.2.0) (2026-01-25)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* Added state paginator feature 87a9466
|
|
9
|
+
## v1.1.2 - 2026-01-09
|
|
10
|
+
|
|
11
|
+
## [1.1.2](/compare/v1.1.1...v1.1.2) (2026-01-09)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* Adjusted PropertyAware type 893f705
|
|
17
|
+
* Change @ts-expect-error to @ts-ignore to prevent errors in consuming projects 346a5b0
|
|
1
18
|
## v1.1.1 - 2026-01-08
|
|
2
19
|
|
|
3
20
|
## [1.1.1](/compare/v1.1.0...v1.1.1) (2026-01-08)
|
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { PaginationDataDto } from './dtos/PaginationDataDto'
|
|
2
|
+
import { type BaseViewDriverContract } from './contracts/BaseViewDriverContract'
|
|
3
|
+
import { type PaginatorLoadDataOptions } from './contracts/PaginatorLoadDataOptions'
|
|
4
|
+
|
|
5
|
+
export abstract class BasePaginator<ResourceInterface, ViewDriver extends BaseViewDriverContract<ResourceInterface[]>> {
|
|
6
|
+
protected initialized: boolean = false
|
|
7
|
+
|
|
8
|
+
protected abstract viewDriver: ViewDriver
|
|
9
|
+
|
|
10
|
+
public constructor(protected dataDriver: unknown) {}
|
|
11
|
+
|
|
12
|
+
public isInitialized(): boolean {
|
|
13
|
+
return this.initialized
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public flush(): void {
|
|
17
|
+
this.viewDriver.setData([])
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public getPageData(): ResourceInterface[] {
|
|
21
|
+
return this.viewDriver.getData()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public getTotal(): number {
|
|
25
|
+
return this.viewDriver.getTotal()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected passDataToViewDriver(dto: PaginationDataDto<ResourceInterface[]>, options?: PaginatorLoadDataOptions): void {
|
|
29
|
+
if (options?.flush) {
|
|
30
|
+
this.flush()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this.viewDriver.setData(dto.getData())
|
|
34
|
+
this.viewDriver.setTotal(dto.getTotal())
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PageAwarePaginator } from './PageAwarePaginator'
|
|
2
2
|
import { PaginationDataDto } from './dtos/PaginationDataDto'
|
|
3
3
|
import { type PaginatorLoadDataOptions } from './contracts/PaginatorLoadDataOptions'
|
|
4
4
|
|
|
5
|
-
export class InfiniteScroller<ResourceInterface> extends
|
|
5
|
+
export class InfiniteScroller<ResourceInterface> extends PageAwarePaginator<ResourceInterface> {
|
|
6
6
|
protected override passDataToViewDriver(dto: PaginationDataDto<ResourceInterface[]>, options: PaginatorLoadDataOptions = {}) {
|
|
7
7
|
const { flush = false, replace = false } = options
|
|
8
8
|
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { PaginationDataDto } from './dtos/PaginationDataDto'
|
|
2
|
+
import { type ViewDriverContract } from './contracts/ViewDriverContract'
|
|
3
|
+
import { type ViewDriverFactoryContract } from './contracts/ViewDriverFactoryContract'
|
|
4
|
+
import { type PaginatorLoadDataOptions } from './contracts/PaginatorLoadDataOptions'
|
|
5
|
+
import { type PaginationDataDriverContract } from './contracts/PaginationDataDriverContract'
|
|
6
|
+
import { BasePaginator } from './BasePaginator'
|
|
7
|
+
|
|
8
|
+
export interface PageAwarePaginatorOptions {
|
|
9
|
+
viewDriverFactory?: ViewDriverFactoryContract
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class PageAwarePaginator<ResourceInterface> extends BasePaginator<ResourceInterface, ViewDriverContract<ResourceInterface[]>> {
|
|
13
|
+
protected static viewDriverFactory: ViewDriverFactoryContract
|
|
14
|
+
|
|
15
|
+
protected override viewDriver: ViewDriverContract<ResourceInterface[]>
|
|
16
|
+
|
|
17
|
+
public static setViewDriverFactory(value: ViewDriverFactoryContract): void {
|
|
18
|
+
PageAwarePaginator.viewDriverFactory = value
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public constructor(
|
|
22
|
+
protected override dataDriver: PaginationDataDriverContract<ResourceInterface[]>,
|
|
23
|
+
pageNumber: number = 1,
|
|
24
|
+
pageSize: number = 10,
|
|
25
|
+
options?: PageAwarePaginatorOptions
|
|
26
|
+
) {
|
|
27
|
+
super(dataDriver)
|
|
28
|
+
this.viewDriver = options?.viewDriverFactory
|
|
29
|
+
? options.viewDriverFactory.make<ResourceInterface>(pageNumber, pageSize)
|
|
30
|
+
: PageAwarePaginator.viewDriverFactory.make<ResourceInterface>(pageNumber, pageSize)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public setDataDriver(dataDriver: PaginationDataDriverContract<ResourceInterface[]>): this {
|
|
34
|
+
this.dataDriver = dataDriver
|
|
35
|
+
|
|
36
|
+
return this
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public getDataDriver(): PaginationDataDriverContract<ResourceInterface[]> {
|
|
40
|
+
return this.dataDriver
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public init(pageNumber: number, pageSize: number): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
44
|
+
this.initialized = true
|
|
45
|
+
|
|
46
|
+
if (pageNumber && pageSize) {
|
|
47
|
+
return this.loadData(pageNumber, pageSize)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return this.loadData(this.getCurrentPage(), this.getPageSize())
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public refresh(pageNumber?: number, options?: PaginatorLoadDataOptions): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
54
|
+
if (pageNumber !== undefined) {
|
|
55
|
+
return this.setPage(pageNumber, options)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return this.loadData(this.getCurrentPage(), this.getPageSize(), options)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public setPage(pageNumber: number, options?: PaginatorLoadDataOptions): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
62
|
+
this.viewDriver.setPage(pageNumber)
|
|
63
|
+
|
|
64
|
+
return this.loadData(this.viewDriver.getCurrentPage(), this.viewDriver.getPageSize(), options)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public getLastPage(): number {
|
|
68
|
+
return this.viewDriver.getLastPage()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public toNextPage(): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
72
|
+
return this.setPage(this.getCurrentPage() + 1)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public toFirstPage(): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
76
|
+
return this.setPage(1)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public toLastPage(): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
80
|
+
return this.setPage(this.viewDriver.getLastPage())
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public toPreviousPage(): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
84
|
+
return this.setPage(this.getCurrentPage() - 1)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public getCurrentPage(): number {
|
|
88
|
+
return this.viewDriver.getCurrentPage()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public getFromItemNumber(): number {
|
|
92
|
+
return (this.getCurrentPage() - 1) * this.getPageSize() + 1
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public getToItemNumber(): number {
|
|
96
|
+
return this.getCurrentPage() * this.getPageSize()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public getPageSize(): number {
|
|
100
|
+
return this.viewDriver.getPageSize()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public setPageSize(pageSize: number): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
104
|
+
this.viewDriver.setPageSize(pageSize)
|
|
105
|
+
|
|
106
|
+
if (this.getCurrentPage() * pageSize > this.getTotal()) {
|
|
107
|
+
return this.setPage(1)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return this.loadData(this.viewDriver.getCurrentPage(), this.viewDriver.getPageSize())
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public getPages(): number[] {
|
|
114
|
+
return this.viewDriver.getPages()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
protected loadData(pageNumber: number, pageSize: number, options?: PaginatorLoadDataOptions): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
118
|
+
return this.dataDriver.get(pageNumber, pageSize).then((value: PaginationDataDto<ResourceInterface[]>) => {
|
|
119
|
+
this.passDataToViewDriver(value, options)
|
|
120
|
+
|
|
121
|
+
return value
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -1,149 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type ViewDriverContract } from './contracts/ViewDriverContract'
|
|
3
|
-
import { type ViewDriverFactoryContract } from './contracts/ViewDriverFactoryContract'
|
|
4
|
-
import { type PaginatorLoadDataOptions } from './contracts/PaginatorLoadDataOptions'
|
|
5
|
-
import { type PaginationDataDriverContract } from './contracts/PaginationDataDriverContract'
|
|
1
|
+
import { PageAwarePaginator, type PageAwarePaginatorOptions } from './PageAwarePaginator'
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Use PageAwarePaginator instead. This alias is kept for backward compatibility.
|
|
5
|
+
*/
|
|
6
|
+
export const Paginator = PageAwarePaginator
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
protected viewDriver: ViewDriverContract<ResourceInterface[]>
|
|
17
|
-
|
|
18
|
-
public static setViewDriverFactory(value: ViewDriverFactoryContract): void {
|
|
19
|
-
Paginator.viewDriverFactory = value
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public constructor(
|
|
23
|
-
protected dataDriver: PaginationDataDriverContract<ResourceInterface[]>,
|
|
24
|
-
pageNumber: number = 1,
|
|
25
|
-
pageSize: number = 10,
|
|
26
|
-
options?: PaginatorOptions
|
|
27
|
-
) {
|
|
28
|
-
this.viewDriver = options?.viewDriverFactory
|
|
29
|
-
? options.viewDriverFactory.make<ResourceInterface>(pageNumber, pageSize)
|
|
30
|
-
: Paginator.viewDriverFactory.make<ResourceInterface>(pageNumber, pageSize)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public setDataDriver(dataDriver: PaginationDataDriverContract<ResourceInterface[]>): this {
|
|
34
|
-
this.dataDriver = dataDriver
|
|
35
|
-
|
|
36
|
-
return this
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public getDataDriver(): PaginationDataDriverContract<ResourceInterface[]> {
|
|
40
|
-
return this.dataDriver
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public init(pageNumber: number, pageSize: number): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
44
|
-
this.initialized = true
|
|
45
|
-
|
|
46
|
-
if (pageNumber && pageSize) {
|
|
47
|
-
return this.loadData(pageNumber, pageSize)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return this.loadData(this.getCurrentPage(), this.getPageSize())
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public refresh(pageNumber?: number, options?: PaginatorLoadDataOptions): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
54
|
-
if (pageNumber !== undefined) {
|
|
55
|
-
return this.setPage(pageNumber, options)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return this.loadData(this.getCurrentPage(), this.getPageSize(), options)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public flush(): void {
|
|
62
|
-
this.viewDriver.setData([])
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public setPage(pageNumber: number, options?: PaginatorLoadDataOptions): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
66
|
-
this.viewDriver.setPage(pageNumber)
|
|
67
|
-
|
|
68
|
-
return this.loadData(this.viewDriver.getCurrentPage(), this.viewDriver.getPageSize(), options)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public isInitialized(): boolean {
|
|
72
|
-
return this.initialized
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public getLastPage(): number {
|
|
76
|
-
return this.viewDriver.getLastPage()
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public toNextPage(): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
80
|
-
return this.setPage(this.getCurrentPage() + 1)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public toFirstPage(): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
84
|
-
return this.setPage(1)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public toLastPage(): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
88
|
-
return this.setPage(this.viewDriver.getLastPage())
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
public toPreviousPage(): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
92
|
-
return this.setPage(this.getCurrentPage() - 1)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
public getPageData(): ResourceInterface[] {
|
|
96
|
-
return this.viewDriver.getData()
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
public getCurrentPage(): number {
|
|
100
|
-
return this.viewDriver.getCurrentPage()
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
public getFromItemNumber(): number {
|
|
104
|
-
return (this.getCurrentPage() - 1) * this.getPageSize() + 1
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public getToItemNumber(): number {
|
|
108
|
-
return this.getCurrentPage() * this.getPageSize()
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public getTotal(): number {
|
|
112
|
-
return this.viewDriver.getTotal()
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
public getPageSize(): number {
|
|
116
|
-
return this.viewDriver.getPageSize()
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public setPageSize(pageSize: number): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
120
|
-
this.viewDriver.setPageSize(pageSize)
|
|
121
|
-
|
|
122
|
-
if (this.getCurrentPage() * pageSize > this.getTotal()) {
|
|
123
|
-
return this.setPage(1)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return this.loadData(this.viewDriver.getCurrentPage(), this.viewDriver.getPageSize())
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public getPages(): number[] {
|
|
130
|
-
return this.viewDriver.getPages()
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
protected loadData(pageNumber: number, pageSize: number, options?: PaginatorLoadDataOptions): Promise<PaginationDataDto<ResourceInterface[]>> {
|
|
134
|
-
return this.dataDriver.get(pageNumber, pageSize).then((value: PaginationDataDto<ResourceInterface[]>) => {
|
|
135
|
-
this.passDataToViewDriver(value, options)
|
|
136
|
-
|
|
137
|
-
return value
|
|
138
|
-
})
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
protected passDataToViewDriver(dto: PaginationDataDto<ResourceInterface[]>, options?: PaginatorLoadDataOptions): void {
|
|
142
|
-
if (options?.flush) {
|
|
143
|
-
this.flush()
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
this.viewDriver.setData(dto.getData())
|
|
147
|
-
this.viewDriver.setTotal(dto.getTotal())
|
|
148
|
-
}
|
|
149
|
-
}
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Use PageAwarePaginatorOptions instead. This alias is kept for backward compatibility.
|
|
10
|
+
*/
|
|
11
|
+
export type PaginatorOptions = PageAwarePaginatorOptions
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { StatePaginationDataDto } from './dtos/StatePaginationDataDto'
|
|
2
|
+
import { type BaseViewDriverContract } from './contracts/BaseViewDriverContract'
|
|
3
|
+
import { type BaseViewDriverFactoryContract } from './contracts/BaseViewDriverFactoryContract'
|
|
4
|
+
import { type PaginatorLoadDataOptions } from './contracts/PaginatorLoadDataOptions'
|
|
5
|
+
import { type StatePaginationDataDriverContract } from './contracts/StatePaginationDataDriverContract'
|
|
6
|
+
import { BasePaginator } from './BasePaginator'
|
|
7
|
+
|
|
8
|
+
export interface StatePaginatorOptions {
|
|
9
|
+
viewDriverFactory?: BaseViewDriverFactoryContract
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class StatePaginator<ResourceInterface> extends BasePaginator<ResourceInterface, BaseViewDriverContract<ResourceInterface[]>> {
|
|
13
|
+
protected static viewDriverFactory: BaseViewDriverFactoryContract
|
|
14
|
+
|
|
15
|
+
protected override viewDriver: BaseViewDriverContract<ResourceInterface[]>
|
|
16
|
+
|
|
17
|
+
protected currentState: string | null = null
|
|
18
|
+
|
|
19
|
+
public static setViewDriverFactory(value: BaseViewDriverFactoryContract): void {
|
|
20
|
+
StatePaginator.viewDriverFactory = value
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public constructor(
|
|
24
|
+
protected override dataDriver: StatePaginationDataDriverContract<ResourceInterface[]>,
|
|
25
|
+
options?: StatePaginatorOptions
|
|
26
|
+
) {
|
|
27
|
+
super(dataDriver)
|
|
28
|
+
this.viewDriver = options?.viewDriverFactory
|
|
29
|
+
? options.viewDriverFactory.make<ResourceInterface>()
|
|
30
|
+
: StatePaginator.viewDriverFactory.make<ResourceInterface>()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public setDataDriver(dataDriver: StatePaginationDataDriverContract<ResourceInterface[]>): this {
|
|
34
|
+
this.dataDriver = dataDriver
|
|
35
|
+
|
|
36
|
+
return this
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public getDataDriver(): StatePaginationDataDriverContract<ResourceInterface[]> {
|
|
40
|
+
return this.dataDriver
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public init(): Promise<StatePaginationDataDto<ResourceInterface[]>> {
|
|
44
|
+
this.initialized = true
|
|
45
|
+
this.currentState = null
|
|
46
|
+
|
|
47
|
+
return this.loadData()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public refresh(options?: PaginatorLoadDataOptions): Promise<StatePaginationDataDto<ResourceInterface[]>> {
|
|
51
|
+
this.currentState = null
|
|
52
|
+
|
|
53
|
+
return this.loadData({ ...options, flush: true })
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public loadNext(): Promise<StatePaginationDataDto<ResourceInterface[]>> {
|
|
57
|
+
return this.loadData()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public hasNextPage(): boolean {
|
|
61
|
+
return this.currentState !== null
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public getCurrentState(): string | null {
|
|
65
|
+
return this.currentState
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
protected loadData(options?: PaginatorLoadDataOptions): Promise<StatePaginationDataDto<ResourceInterface[]>> {
|
|
69
|
+
return this.dataDriver.get(this.currentState).then((value: StatePaginationDataDto<ResourceInterface[]>) => {
|
|
70
|
+
this.currentState = value.getState()
|
|
71
|
+
this.passStateDataToViewDriver(value, options)
|
|
72
|
+
|
|
73
|
+
return value
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
protected passStateDataToViewDriver(dto: StatePaginationDataDto<ResourceInterface[]>, options?: PaginatorLoadDataOptions): void {
|
|
78
|
+
const { flush = false, replace = false } = options || {}
|
|
79
|
+
|
|
80
|
+
if (flush) {
|
|
81
|
+
this.flush()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (replace) {
|
|
85
|
+
this.viewDriver.setData(dto.getData())
|
|
86
|
+
} else {
|
|
87
|
+
this.viewDriver.setData(this.viewDriver.getData().concat(dto.getData()))
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.viewDriver.setTotal(dto.getTotal())
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
getData(): ResourceInterface
|
|
1
|
+
import { type BaseViewDriverContract } from './BaseViewDriverContract'
|
|
2
|
+
|
|
3
|
+
export interface ViewDriverContract<ResourceInterface> extends BaseViewDriverContract<ResourceInterface> {
|
|
5
4
|
getCurrentPage(): number
|
|
6
5
|
setPage(value: number): void
|
|
7
6
|
setPageSize(value: number): void
|
|
8
7
|
getPageSize(): number
|
|
9
8
|
getLastPage(): number
|
|
10
9
|
getPages(): number[]
|
|
11
|
-
getTotal(): number
|
|
12
10
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PaginationDataDto } from './PaginationDataDto'
|
|
2
|
+
|
|
3
|
+
export class StatePaginationDataDto<ResourceInterface> extends PaginationDataDto<ResourceInterface> {
|
|
4
|
+
public constructor(
|
|
5
|
+
data: ResourceInterface,
|
|
6
|
+
total: number,
|
|
7
|
+
protected state: string | null = null
|
|
8
|
+
) {
|
|
9
|
+
super(data, total)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public getState(): string | null {
|
|
13
|
+
return this.state
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public hasNextPage(): boolean {
|
|
17
|
+
return this.state !== null
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type BaseViewDriverFactoryContract } from '../contracts/BaseViewDriverFactoryContract'
|
|
2
|
+
import { type BaseViewDriverContract } from '../contracts/BaseViewDriverContract'
|
|
3
|
+
import { VueBaseViewDriver } from '../frontendDrivers/VueBaseViewDriver'
|
|
4
|
+
|
|
5
|
+
export class VueBaseViewDriverFactory implements BaseViewDriverFactoryContract {
|
|
6
|
+
public make<ResourceInterface>(): BaseViewDriverContract<ResourceInterface[]> {
|
|
7
|
+
return new VueBaseViewDriver<ResourceInterface>()
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ref, type Ref } from 'vue'
|
|
2
|
+
import { type BaseViewDriverContract } from '../contracts/BaseViewDriverContract'
|
|
3
|
+
|
|
4
|
+
export class VueBaseViewDriver<ResourceInterface> implements BaseViewDriverContract<ResourceInterface[]> {
|
|
5
|
+
protected dataRef: Ref<ResourceInterface[]>
|
|
6
|
+
protected totalRef: Ref<number>
|
|
7
|
+
|
|
8
|
+
public constructor() {
|
|
9
|
+
this.dataRef = ref([]) as Ref<ResourceInterface[]>
|
|
10
|
+
this.totalRef = ref<number>(0)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public setData(data: ResourceInterface[]): void {
|
|
14
|
+
this.dataRef.value = data
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public getData(): ResourceInterface[] {
|
|
18
|
+
return this.dataRef.value
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public setTotal(value: number): void {
|
|
22
|
+
this.totalRef.value = value
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public getTotal(): number {
|
|
26
|
+
return this.totalRef.value
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,16 +1,48 @@
|
|
|
1
1
|
import { PaginationDataDto } from './dtos/PaginationDataDto'
|
|
2
|
+
import { StatePaginationDataDto } from './dtos/StatePaginationDataDto'
|
|
2
3
|
import { VuePaginationDriver } from './frontendDrivers/VuePaginationDriver'
|
|
4
|
+
import { VueBaseViewDriver } from './frontendDrivers/VueBaseViewDriver'
|
|
3
5
|
import { Paginator } from './Paginator'
|
|
6
|
+
import { BasePaginator } from './BasePaginator'
|
|
7
|
+
import { PageAwarePaginator } from './PageAwarePaginator'
|
|
8
|
+
import { StatePaginator } from './StatePaginator'
|
|
4
9
|
import { InfiniteScroller } from './InfiniteScroller'
|
|
5
10
|
import { VuePaginationDriverFactory } from './factories/VuePaginationDriverFactory'
|
|
11
|
+
import { VueBaseViewDriverFactory } from './factories/VueBaseViewDriverFactory'
|
|
6
12
|
import { type PaginateableRequestContract } from './contracts/PaginateableRequestContract'
|
|
7
13
|
import { type PaginationResponseContract } from './contracts/PaginationResponseContract'
|
|
8
14
|
import { type PaginationDataDriverContract } from './contracts/PaginationDataDriverContract'
|
|
15
|
+
import { type StatePaginationDataDriverContract } from './contracts/StatePaginationDataDriverContract'
|
|
9
16
|
import { getDisplayablePages } from '../../helpers'
|
|
10
17
|
import { ArrayDriver } from './dataDrivers/ArrayDriver'
|
|
18
|
+
import { type BaseViewDriverContract } from './contracts/BaseViewDriverContract'
|
|
11
19
|
import { type ViewDriverContract } from './contracts/ViewDriverContract'
|
|
20
|
+
import { type BaseViewDriverFactoryContract } from './contracts/BaseViewDriverFactoryContract'
|
|
12
21
|
import { type ViewDriverFactoryContract } from './contracts/ViewDriverFactoryContract'
|
|
13
22
|
|
|
14
|
-
export {
|
|
23
|
+
export {
|
|
24
|
+
PaginationDataDto,
|
|
25
|
+
StatePaginationDataDto,
|
|
26
|
+
VuePaginationDriver,
|
|
27
|
+
VueBaseViewDriver,
|
|
28
|
+
Paginator,
|
|
29
|
+
BasePaginator,
|
|
30
|
+
PageAwarePaginator,
|
|
31
|
+
StatePaginator,
|
|
32
|
+
InfiniteScroller,
|
|
33
|
+
VuePaginationDriverFactory,
|
|
34
|
+
VueBaseViewDriverFactory,
|
|
35
|
+
getDisplayablePages,
|
|
36
|
+
ArrayDriver
|
|
37
|
+
}
|
|
15
38
|
|
|
16
|
-
export type {
|
|
39
|
+
export type {
|
|
40
|
+
PaginationDataDriverContract,
|
|
41
|
+
StatePaginationDataDriverContract,
|
|
42
|
+
PaginationResponseContract,
|
|
43
|
+
PaginateableRequestContract,
|
|
44
|
+
BaseViewDriverContract,
|
|
45
|
+
ViewDriverContract,
|
|
46
|
+
BaseViewDriverFactoryContract,
|
|
47
|
+
ViewDriverFactoryContract
|
|
48
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { type WritableComputedRef } from 'vue'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Repräsentiert eine reaktive Property mit model.value Zugriff
|
|
3
5
|
*/
|
|
4
6
|
export interface PropertyAwareField<T> {
|
|
5
|
-
model:
|
|
6
|
-
value: T
|
|
7
|
-
}
|
|
7
|
+
model: WritableComputedRef<T>
|
|
8
8
|
errors: any[]
|
|
9
9
|
suggestions: any[]
|
|
10
10
|
dirty: boolean
|
|
@@ -15,7 +15,7 @@ export interface PropertyAwareField<T> {
|
|
|
15
15
|
* Jedes Feld vom Typ T wird zu einem PropertyAwareField<T>
|
|
16
16
|
*/
|
|
17
17
|
export type PropertyAware<T> = {
|
|
18
|
-
[K in keyof T]:
|
|
18
|
+
[K in keyof T]: PropertyAwareField<T[K]>
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Extends Array with property awareness.
|
package/src/vue/state/State.ts
CHANGED
|
@@ -262,7 +262,7 @@ export abstract class State<T extends object> {
|
|
|
262
262
|
|
|
263
263
|
for (let i = 1; i < pathParts.length; i++) {
|
|
264
264
|
if (!obj || typeof obj !== 'object') return undefined
|
|
265
|
-
// @ts-
|
|
265
|
+
// @ts-ignore: obj is guaranteed to be an object at this point
|
|
266
266
|
obj = (obj as any)[pathParts[i]]
|
|
267
267
|
}
|
|
268
268
|
|