|
23 | 23 | break; |
24 | 24 | case "AlbumContents": |
25 | 25 | <AutoQueryGrid @ref="addToAlbumGrid" Model="Album" Apis="Apis.AutoQuery<QueryAlbums>()" |
26 | | - RowSelected="AddAlbumRowSelected"> |
| 26 | + RowSelected="AddAlbumRowSelected"> |
27 | 27 | </AutoQueryGrid> |
28 | 28 | break; |
29 | 29 | } |
30 | 30 |
|
31 | 31 | <ModalDialog Id="addModal" Show=@showAddDiaglog Close="CloseModal"> |
32 | 32 | <ErrorSummary Status="api?.Error" /> |
33 | | - @if(addArtifactsToggle) |
| 33 | + @if (addArtifactsToggle) |
34 | 34 | { |
35 | | - <AutoQueryGrid Model="Artifact" |
| 35 | + <AutoQueryGrid Model="Artifact" |
36 | 36 | @ref="allArtifactsGrid" |
37 | | - Apis="Apis.AutoQuery<QueryArtifacts>()" |
38 | | - ShowCopyApiUrl="false" |
39 | | - ShowDownloadCsv="false" |
40 | | - ShowPreferences="false" |
41 | | - RowSelected="SelectAddRow"> |
42 | | - <ToolbarButtons> |
43 | | - <div class="flex items-center justify-between"> |
44 | | - <span class="px-2">Remove</span> |
45 | | - <Toggle @bind-Value="addArtifactsToggle"></Toggle> |
46 | | - <span class="px-2">Add</span> |
47 | | - </div> |
48 | | - </ToolbarButtons> |
49 | | - <Columns> |
50 | | - <Column Field="(Artifact x) => x.FilePath"> |
51 | | - <Template> |
52 | | - <img src="https://cdn.diffusion.works@(context.FilePath)" |
53 | | - class="m-auto h-48 @(IsInAlbum(context) == true ? "rounded-xl border-2 border-fuchsia-700" : "rounded-xl border-2 border-transparent")" |
54 | | - alt=@context.Prompt /> |
55 | | - </Template> |
56 | | - </Column> |
57 | | - </Columns> |
58 | | - </AutoQueryGrid> |
| 37 | + Apis="Apis.AutoQuery<QueryArtifacts>()" |
| 38 | + ShowCopyApiUrl="false" |
| 39 | + ShowDownloadCsv="false" |
| 40 | + ShowPreferences="false" |
| 41 | + RowSelected="SelectAddRow"> |
| 42 | + <ToolbarButtons> |
| 43 | + <div class="flex items-center justify-between"> |
| 44 | + <span class="px-2">Remove</span> |
| 45 | + <Toggle @bind-Value="addArtifactsToggle"></Toggle> |
| 46 | + <span class="px-2">Add</span> |
| 47 | + </div> |
| 48 | + </ToolbarButtons> |
| 49 | + <Columns> |
| 50 | + <Column Field="(Artifact x) => x.FilePath"> |
| 51 | + <Template> |
| 52 | + <img src="https://cdn.diffusion.works@(context.FilePath)" |
| 53 | + class="m-auto h-48 @(IsInAlbum(context) == true ? "rounded-xl border-2 border-fuchsia-700" : "rounded-xl border-2 border-transparent")" |
| 54 | + alt=@context.Prompt /> |
| 55 | + </Template> |
| 56 | + </Column> |
| 57 | + </Columns> |
| 58 | + </AutoQueryGrid> |
59 | 59 | } |
60 | 60 | else |
61 | 61 | { |
62 | | - <AutoQueryGrid Model="AlbumArtifact" |
63 | | - @ref="albumArtifactsGrid" |
64 | | - Apis="Apis.AutoQuery<QueryAlbumArtifacts>()" |
65 | | - ConfigureQuery="ConfigureQuery" |
66 | | - RowSelected="SelectRemoveFromAlbum" |
67 | | - ShowCopyApiUrl="false" |
68 | | - ShowDownloadCsv="false" |
69 | | - ShowPreferences="false"> |
70 | | - <ToolbarButtons> |
71 | | - <div class="flex items-center justify-between"> |
72 | | - <span class="px-2">Remove</span> |
73 | | - <Toggle @bind-Value="addArtifactsToggle"></Toggle> |
74 | | - <span class="px-2">Add</span> |
75 | | - </div> |
76 | | - </ToolbarButtons> |
77 | | - <Columns> |
78 | | - <Column Field="(AlbumArtifact x) => x.Artifact"> |
79 | | - <Template> |
80 | | - <img src="https://cdn.diffusion.works@(context.Artifact?.FilePath)" |
81 | | - class="m-auto h-48 @(IsInAlbum(context.Artifact) == true ? "rounded-xl border-2 border-transparent" : "rounded-xl border-2 border-fuchsia-700")" |
82 | | - alt=@context.Artifact?.Prompt /> |
83 | | - </Template> |
84 | | - </Column> |
85 | | - </Columns> |
86 | | - </AutoQueryGrid> |
| 62 | + <AutoQueryGrid Model="AlbumArtifact" |
| 63 | + @ref="albumArtifactsGrid" |
| 64 | + Apis="Apis.AutoQuery<QueryAlbumArtifacts>()" |
| 65 | + ConfigureQuery="ConfigureQuery" |
| 66 | + RowSelected="SelectRemoveFromAlbum" |
| 67 | + ShowCopyApiUrl="false" |
| 68 | + ShowDownloadCsv="false" |
| 69 | + ShowPreferences="false"> |
| 70 | + <ToolbarButtons> |
| 71 | + <div class="flex items-center justify-between"> |
| 72 | + <span class="px-2">Remove</span> |
| 73 | + <Toggle @bind-Value="addArtifactsToggle"></Toggle> |
| 74 | + <span class="px-2">Add</span> |
| 75 | + </div> |
| 76 | + </ToolbarButtons> |
| 77 | + <Columns> |
| 78 | + <Column Field="(AlbumArtifact x) => x.Artifact"> |
| 79 | + <Template> |
| 80 | + <img src="https://cdn.diffusion.works@(context.Artifact?.FilePath)" |
| 81 | + class="m-auto h-48 @(IsInAlbum(context.Artifact!) == true ? "rounded-xl border-2 border-transparent" : "rounded-xl border-2 border-fuchsia-700")" |
| 82 | + alt=@context.Artifact?.Prompt /> |
| 83 | + </Template> |
| 84 | + </Column> |
| 85 | + </Columns> |
| 86 | + </AutoQueryGrid> |
87 | 87 | } |
88 | | -<div class="mt-4 px-4 py-3 bg-gray-50 dark:bg-gray-900 text-right sm:px-6"> |
89 | | - <div class="flex justify-end items-center"> |
90 | | - <SecondaryButton class="mr-2" @onclick="CloseModal">Cancel</SecondaryButton> |
91 | | - <PrimaryButton @onclick="SaveChanges">Save</PrimaryButton> |
| 88 | + <div class="mt-4 px-4 py-3 bg-gray-50 dark:bg-gray-900 text-right sm:px-6"> |
| 89 | + <div class="flex justify-end items-center"> |
| 90 | + <SecondaryButton class="mr-2" @onclick="CloseModal">Cancel</SecondaryButton> |
| 91 | + <PrimaryButton @onclick="SaveChanges">Save</PrimaryButton> |
| 92 | + </div> |
92 | 93 | </div> |
93 | | -</div> |
94 | 94 | </ModalDialog> |
95 | 95 |
|
96 | 96 |
|
|
107 | 107 | string editPanelRemove = "show"; |
108 | 108 | bool showAddDiaglog = false; |
109 | 109 | bool addArtifactsToggle = false; |
110 | | - AutoQueryGrid<Album> addToAlbumGrid; |
111 | | - AutoQueryGrid<Album> removeFromAlbumGrid; |
| 110 | + AutoQueryGrid<Album>? addToAlbumGrid; |
| 111 | + AutoQueryGrid<Album>? removeFromAlbumGrid; |
112 | 112 |
|
113 | | - AutoQueryGrid<Artifact> allArtifactsGrid; |
114 | | - AutoQueryGrid<AlbumArtifact> albumArtifactsGrid; |
| 113 | + AutoQueryGrid<Artifact>? allArtifactsGrid; |
| 114 | + AutoQueryGrid<AlbumArtifact>? albumArtifactsGrid; |
115 | 115 | Album? managedAlbum; |
116 | 116 |
|
117 | 117 | List<Artifact> addToAlbum = new(); |
118 | 118 | List<Artifact> removeFromAlbum = new(); |
119 | 119 |
|
120 | | - ApiResult<Album> api; |
| 120 | + ApiResult<Album>? api; |
121 | 121 |
|
122 | | - async Task CloseModal() |
| 122 | + void CloseModal() |
123 | 123 | { |
124 | 124 | showAddDiaglog = false; |
125 | 125 | var url = NavigationManager.Uri.SetQueryParam("skip", null).SetQueryParam("edit", null); |
|
129 | 129 |
|
130 | 130 | async Task SaveChanges() |
131 | 131 | { |
132 | | - var request = new UpdateAlbum |
133 | | - { |
134 | | - Id = managedAlbum.Id |
135 | | - }; |
| 132 | + var request = new UpdateAlbum { |
| 133 | + Id = managedAlbum!.Id |
| 134 | + }; |
136 | 135 | request.AddArtifactIds = addToAlbum.Select(x => x.Id).ToList(); |
137 | 136 | request.RemoveArtifactIds = removeFromAlbum.Select(x => x.Id).ToList(); |
138 | 137 | api = await ApiAsync(request); |
139 | 138 |
|
140 | 139 | if (api.Succeeded) |
141 | 140 | { |
142 | 141 | managedAlbum = null; |
143 | | - await CloseModal(); |
| 142 | + CloseModal(); |
144 | 143 | } |
145 | | - |
146 | 144 | } |
147 | 145 |
|
148 | 146 | async Task ToggleManageAlbumGrids(MouseEventArgs args) |
149 | 147 | { |
150 | 148 | addArtifactsToggle = !addArtifactsToggle; |
151 | | - if(albumArtifactsGrid != null) |
| 149 | + if (albumArtifactsGrid != null) |
152 | 150 | await albumArtifactsGrid.RefreshAsync(); |
153 | 151 | } |
154 | 152 |
|
155 | 153 | void ConfigureQuery(QueryBase query) |
156 | 154 | { |
157 | | - if(managedAlbum == null) |
| 155 | + if (managedAlbum == null) |
158 | 156 | return; |
159 | 157 | query.AddQueryParam("ArtifactIds", managedAlbum.Artifacts.Select(x => x.ArtifactId).Join(",")); |
160 | 158 | } |
161 | 159 |
|
162 | 160 | bool IsInAlbum(Artifact artifact) |
163 | 161 | { |
164 | | - if(managedAlbum == null) |
| 162 | + if (managedAlbum == null) |
165 | 163 | return false; |
166 | | - return (managedAlbum.Artifacts.Any(x => x.ArtifactId == artifact.Id) && |
167 | | - removeFromAlbum.All(x => x.Id != artifact.Id)) || |
| 164 | + return (managedAlbum.Artifacts.Any(x => x.ArtifactId == artifact.Id) && |
| 165 | + removeFromAlbum.All(x => x.Id != artifact.Id)) || |
168 | 166 | addToAlbum.Any(x => x.Id == artifact.Id); |
169 | 167 | } |
170 | 168 |
|
171 | 169 | async Task AddAlbumRowSelected(Album album) |
172 | 170 | { |
173 | 171 | showAddDiaglog = true; |
174 | 172 | managedAlbum = album; |
175 | | - if(albumArtifactsGrid != null) |
| 173 | + if (albumArtifactsGrid != null) |
176 | 174 | await albumArtifactsGrid.RefreshAsync(); |
177 | | - if(allArtifactsGrid != null) |
| 175 | + if (allArtifactsGrid != null) |
178 | 176 | await allArtifactsGrid.RefreshAsync(); |
179 | 177 | } |
180 | 178 |
|
|
0 commit comments