6
6
using Microsoft . AspNetCore . Components ;
7
7
using Microsoft . JSInterop ;
8
8
using RapidCMS . Core . Abstractions . Data ;
9
+ using RapidCMS . Core . Abstractions . UI ;
10
+ using RapidCMS . Core . Models . Configuration ;
9
11
using RapidCMS . Core . Models . Data ;
12
+ using RapidCMS . UI . Extensions ;
10
13
11
14
namespace RapidCMS . UI . Components . Editors ;
12
15
13
- public abstract class BasePicker : BaseDataEditor
16
+ public abstract class BasePicker : BaseDataEditor , IWantConfiguration < Picker >
14
17
{
15
18
protected string ? _searchTerm ;
16
19
protected int _currentPage = 1 ;
@@ -25,15 +28,19 @@ public abstract class BasePicker : BaseDataEditor
25
28
26
29
protected virtual bool IsMultiple { get ; set ; }
27
30
31
+ protected Picker Config { get ; set ; }
32
+
28
33
[ Inject ]
29
34
private IJSRuntime JsRuntime { get ; set ; } = null ! ;
30
35
31
36
private IRelationDataCollection RelationDataCollection
32
- => DataCollection as IRelationDataCollection
37
+ => DataCollection as IRelationDataCollection
33
38
?? throw new InvalidOperationException ( "Incorrect DataCollection assigned to Entity/iesPicker" ) ;
34
39
35
40
protected override async Task OnInitializedAsync ( )
36
41
{
42
+ Config = await this . GetConfigAsync ( ) ?? new ( ) ;
43
+
37
44
if ( DataCollection != null )
38
45
{
39
46
DataCollection . OnDataChange += UpdateOptionsAsync ;
@@ -83,14 +90,62 @@ protected async Task ResetViewAsync()
83
90
await UpdateOptionsAsync ( ) ;
84
91
}
85
92
93
+ protected async Task SelectAllAsync ( )
94
+ {
95
+ if ( RelationDataCollection == null )
96
+ {
97
+ return ;
98
+ }
99
+
100
+ var page = 1 ;
101
+ do
102
+ {
103
+ var view = View . Create ( Config . PageSize , page , null , null ) ;
104
+ var data = await RelationDataCollection . GetAvailableElementsAsync ( view ) ;
105
+
106
+ foreach ( var item in data )
107
+ {
108
+ RelationDataCollection . AddElement ( item . Id ) ;
109
+ }
110
+
111
+ if ( data . Count < Config . PageSize )
112
+ {
113
+ break ;
114
+ }
115
+ else
116
+ {
117
+ page ++ ;
118
+ }
119
+ }
120
+ while ( true ) ;
121
+
122
+ StateHasChanged ( ) ;
123
+ }
124
+
125
+ protected async Task UnselectAllAsync ( )
126
+ {
127
+ if ( RelationDataCollection == null )
128
+ {
129
+ return ;
130
+ }
131
+
132
+ var items = RelationDataCollection . GetCurrentRelatedElementIds ( ) ;
133
+ foreach ( var item in items )
134
+ {
135
+ RelationDataCollection . RemoveElement ( item ) ;
136
+ }
137
+
138
+ StateHasChanged ( ) ;
139
+ }
140
+
86
141
private async Task UpdateOptionsAsync ( )
87
142
{
88
143
if ( DataCollection == null )
89
144
{
90
145
return ;
91
146
}
92
147
93
- var view = View . Create ( 25 , _currentPage , _searchTerm , default ) ;
148
+ var view = View . Create ( Config . PageSize , _currentPage , _searchTerm , default ) ;
94
149
_options = await DataCollection . GetAvailableElementsAsync ( view ) ;
95
150
96
151
if ( view . MoreDataAvailable )
0 commit comments