@@ -11,6 +11,8 @@ import { RedirectsService } from "@skybrud-redirects/service";
11
11
import { REDIRECTS_ADD_REDIRECT_MODAL } from "@skybrud-redirects/modals/add" ;
12
12
import { REDIRECTS_EDIT_REDIRECT_MODAL } from "@skybrud-redirects/modals/edit" ;
13
13
14
+ import { RedirectsDashboardLoadEvent } from "@skybrud-redirects/events" ;
15
+
14
16
function ucfirst ( value ) {
15
17
return String ( value ) . charAt ( 0 ) . toUpperCase ( ) + String ( value ) . slice ( 1 ) ;
16
18
}
@@ -87,6 +89,31 @@ export class RedirectsDashboardElement extends UmbElementMixin(LitElement) {
87
89
{ name : this . localize . term ( "redirects_url" ) , value : "url" }
88
90
] ;
89
91
92
+ this . addButton = {
93
+ alias : "add" ,
94
+ label : this . localize . term ( "redirects_addRedirect" ) ,
95
+ action : this . add ,
96
+ look : "primary" ,
97
+ color : "positive" ,
98
+ subButtons : [ ]
99
+ } ;
100
+
101
+ this . reloadButton = {
102
+ alias : "reload" ,
103
+ label : this . localize . term ( "redirects_reload" ) ,
104
+ action : this . reload ,
105
+ look : "outline" ,
106
+ color : "default" ,
107
+ subButtons : [ ]
108
+ } ;
109
+
110
+ this . dashboard = {
111
+ addButton : this . addButton ,
112
+ reloadButton : this . reloadButton ,
113
+ buttons : [ this . addButton , this . reloadButton ] ,
114
+ requestUpdate : self . requestUpdate
115
+ } ;
116
+
90
117
RedirectsService . getRootNodes ( ) . then ( function ( res ) {
91
118
92
119
const temp = [
@@ -112,6 +139,10 @@ export class RedirectsDashboardElement extends UmbElementMixin(LitElement) {
112
139
this . _notificationContext = instance ;
113
140
} ) ;
114
141
142
+ window . dispatchEvent ( new RedirectsDashboardLoadEvent ( "redirects.onDashboardLoad" , {
143
+ dashboard : self . dashboard
144
+ } ) ) ;
145
+
115
146
}
116
147
117
148
updateRedirects ( page ) {
@@ -132,6 +163,7 @@ export class RedirectsDashboardElement extends UmbElementMixin(LitElement) {
132
163
self . pagination = res . data . pagination ;
133
164
self . loading = false ;
134
165
self . refreshing = false ;
166
+ self . reloadButton . state = null ;
135
167
self . requestUpdate ( ) ;
136
168
} , 200 ) ;
137
169
} ) ;
@@ -207,6 +239,7 @@ export class RedirectsDashboardElement extends UmbElementMixin(LitElement) {
207
239
208
240
reload ( ) {
209
241
this . refreshing = true ;
242
+ this . reloadButton . state = "waiting" ;
210
243
this . updateRedirects ( ) ;
211
244
}
212
245
@@ -270,7 +303,6 @@ export class RedirectsDashboardElement extends UmbElementMixin(LitElement) {
270
303
}
271
304
272
305
renderDestinationWarning ( item ) {
273
- console . log ( item . url + " => " , item ) ;
274
306
if ( item . destination . null ) return html `<small class= \"warning\"> ${ this . localize . term ( "redirects_deleted" ) } </ small> ` ;
275
307
if ( item . destination . trashed ) return html `<small class= \"warning\"> ${ this . localize . term ( "redirects_trashed" ) } </ small> ` ;
276
308
if ( item . destination . published === false ) return html `<small class= \"warning\"> ${ this . localize . term ( "redirects_unpublished" ) } </ small> ` ;
@@ -295,13 +327,28 @@ export class RedirectsDashboardElement extends UmbElementMixin(LitElement) {
295
327
</ uui- select>
296
328
<uui- input id= "search" label = "${ typeToSearch } " style= "flex: 1;" placeholder= "${ typeToSearch } " @keyup = ${ this . onKeyUp } > </ uui- input>
297
329
</ div>
298
- <div style= "justify-self: right;" >
299
- <uui- butto n look= "primary" color = "positive" label= "Add" @click = ${ this . add } >
300
- ${ this . localize . term ( "redirects_addRedirect" ) }
301
- </ uui- butto n>
302
- <uui- butto n look= "outline" color = "default" label= "Reload" state= "${ this . refreshing ? 'waiting' : '' } " @click = ${ this . reload } >
303
- ${ this . localize . term ( "redirects_reload" ) }
304
- </ uui- butto n>
330
+ <div style= "justify-self: right; display: flex; gap: 10px;" >
331
+ ${ repeat ( this . dashboard . buttons , ( button ) => button . alias , ( button ) => html `
332
+ <uui- butto n- group>
333
+ <uui- butto n look= "${ button . look } " color = "${ button . color } " label= "${ button . label } " state= "${ button . state } " @click = ${ button . action } >
334
+ ${ button . label }
335
+ </ uui- butto n>
336
+ ${ when ( button . subButtons ?. length > 0 , ( ) => html `
337
+ <uui- butto n popovertarget= "my-popover" look = "${ button . look } " color = "${ button . color } ">
338
+ <uui- symbol- mor e> </ uui- symbol- mor e>
339
+ </ uui- butto n>
340
+ <uui- popover- container id= "my-popover" placement = "botto m- end">
341
+ <div style= "display: flex; flex-direction: column;" >
342
+ ${ repeat ( button . subButtons , ( sub ) => sub . alias , ( sub ) => html `
343
+ <uui- butto n look= "${ sub . look } " label = "${ sub . label } " @click = ${ sub . action } >
344
+ ${ sub . label }
345
+ </ uui- butto n>
346
+ ` ) }
347
+ </ div>
348
+ </ uui- popover- container>
349
+ ` ) }
350
+ </ uui- butto n- group>
351
+ ` ) }
305
352
</ div>
306
353
</ div>
307
354
${ when ( this . redirects ?. length > 0 , ( ) => html `
@@ -378,6 +425,9 @@ export class RedirectsDashboardElement extends UmbElementMixin(LitElement) {
378
425
: host > div {
379
426
padding : 20px ;
380
427
}
428
+ uui-symbol-more {
429
+ fill : # fff ;
430
+ }
381
431
.warning {
382
432
color : red;
383
433
}
0 commit comments