-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathEditModal.razor
More file actions
1213 lines (1168 loc) · 71.4 KB
/
Copy pathEditModal.razor
File metadata and controls
1213 lines (1168 loc) · 71.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@using AzureNamingTool.Helpers
@using AzureNamingTool.Models
@using AzureNamingTool.Services
@using AzureNamingTool.Services.Interfaces
@using Microsoft.AspNetCore.Html
@using System.Text.RegularExpressions
@inject IJSRuntime JsRuntime
@inject IToastService toastService
@inject ILogger<EditModal> Logger
@inject StateContainer state
@inject ProtectedSessionStorage session
@inject ServicesHelper ServicesHelper
<div class="modern-modal-content">
<div class="modern-modal-body">
<div class="modern-card">
<div class="modern-card-header" style="@headerstyle">
<h3 class="modern-modal-title">@title</h3>
</div>
<div class="modern-card-body">
<div style="margin-bottom: 1rem;">
<label for="itemName" class="modern-form-label">Name</label>
<input title="Name" value="@itemName" type="text" class="modern-form-input" id="name" @onchange="@((ui) => { itemName = (string)ui.Value!;})" />
</div>
<div>
<p>
@((MarkupString)message)
</p>
@if (type == "ResourceType")
{
if (Convert.ToBoolean(config.ResourceTypeEditingAllowed) && !isDangerAlertDismissed)
{
<div class="alert alert-danger alert-dismissible fade show" style="margin-bottom: 1rem;" role="alert">
<h4>ATTENTION</h4>
<div style="margin-bottom: 1rem;">
<p>
Resource Type settings are configured by the Azure Naming Tool team and match the Azure portal validation requirements. Overriding these values may result in invalid names for a resource.
</p>
<p class="modern-font-semibold">
Please see the <a href="https://github.com/mspnp/AzureNamingTool/wiki/Resource-Type-Editing" target="_blank">Resource Type Editing documentation</a> for guidance on metadata editing.
</p>
</div>
<div>
<button type="button" class="close btn btn-light" @onclick="DismissDangerAlert" aria-label="Dismiss">
<span aria-hidden="true">Dismiss</span>
</button>
</div>
</div>
}
else if (!isWarningAlertDismissed)
{
<div class="alert alert-warning alert-dismissible fade show" style="margin-bottom: 1rem;" role="alert">
<h4>NOTE</h4>
<div style="margin-bottom: 1rem;">
Resource Type settings are disabled by default. You can allow the editing of these values by enabling the "Resource Type Editing" setting in the Admin section.
</div>
<div>
<button type="button" class="close btn btn-light" @onclick="DismissWarningAlert" aria-label="Dismiss">
<span aria-hidden="true">Dismiss</span>
</button>
</div>
</div>
}
}
</div>
<div class="modern-card" style="margin-bottom: 1rem;">
<div class="modern-card-header">
Configuration
</div>
<div class="modern-card-body">
<div style="margin-bottom: 1rem;">
This section allows you to modify the configuration.
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
@namelabel
</label>
<div>
@if ((isProtectedName) || ((type == "ResourceType") && (!Convert.ToBoolean(config.ResourceTypeEditingAllowed))))
{
<input title="Name" value="@itemName" disabled type="text" class="modern-form-input" id="name" />
}
else
{
<input title="Name" value="@itemName" type="text" class="modern-form-input" id="name" @onchange="@((ui) => { itemName = (string)ui.Value!;})" />
}
</div>
</div>
@if (type != "ResourceComponent")
{
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Short Name
</label>
<div>
@if (((type == "ResourceType") && (!Convert.ToBoolean(config.ResourceTypeEditingAllowed))))
{
<input title="Short Name" disabled value="@itemShortName" type="text" class="modern-form-input" id="shortname" />
}
else
{
<input title="Short Name" value="@itemShortName" type="text" class="modern-form-input" id="shortname" @onchange="@((ui) => { itemShortName = (string)ui.Value!;})" />
}
</div>
</div>
}
@if ((type == "ResourceComponent") || ((type == "ResourceType") && (Convert.ToBoolean(config.ResourceTypeEditingAllowed))))
{
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Description
</label>
<div>
<input title="Description" value="@itemDescription" type="text" class="modern-form-input" id="maxlength" @onchange="@((ui) => { itemDescription = (string)ui.Value!;})" />
</div>
</div>
@if ((type == "ResourceComponent") && (itemIsCustom))
{
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Field Type
</label>
<select @bind="itemComponentType" class="modern-form-select">
<option value="standard">Standard - User selects an option from a pre-defined list</option>
<option value="freetext">Free Form / Random</option>
</select>
</div>
@if (itemComponentType == "freetext")
{
<div class="modern-card-body" style="margin-bottom: 1rem;">
<div>
<label class="modern-form-label">
Generate Random Value
</label>
<div style="margin-bottom: 1rem;">
By default, Free Form allows any value. If enabled, this setting to generate a random value for the component.
</div>
<div>
<label class="modern-toggle-switch" title="Allow Random Value Generation">
<input type="checkbox" checked="@itemEnforceRandom" @oninput='args => ComponentSettingChanged(args, "enforcerandom")'>
<span class="modern-toggle-slider"></span>
</label>
<span class="align-text-top ms-2"> Enable</span>
</div>
</div>
@if (itemEnforceRandom)
{
<div style="margin-top: 1rem;">
<label class="modern-form-label">
Generate Alphanumeric Values
</label>
<div style="margin-bottom: 1rem;">
If enabled, the tool will generate a random alphanumeric value for the component. If disabled, only letters will be generated.
</div>
<div>
<label class="modern-toggle-switch" title="Alphanumeric">
<input type="checkbox" checked="@itemAlphanumeric" @oninput='args => ComponentSettingChanged(args, "alphanumeric")'>
<span class="modern-toggle-slider"></span>
</label>
<span class="align-text-top ms-2"> Enable</span>
</div>
</div>
}
</div>
}
}
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Minimum Length
</label>
<div>
<input title="Minimum Length" value="@itemMinLength" type="text" class="modern-form-input" id="minlength" @onchange="@((ui) => { itemMinLength = (string)ui.Value!;})" onkeypress="return (event.charCode !=8 && event.charCode ==0 || (event.charCode >= 48 && event.charCode <= 57))" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Maximum Length
</label>
<div>
<input title="Maximum Length" value="@itemMaxLength" type="text" class="modern-form-input" id="maxlength" @onchange="@((ui) => { itemMaxLength = (string)ui.Value!;})" onkeypress="return (event.charCode !=8 && event.charCode ==0 || (event.charCode >= 48 && event.charCode <= 57))" />
</div>
</div>
@if (type == "ResourceComponent")
{
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Apply Delimiter Before
</label>
<div style="margin-bottom: 1rem;">
If disabled, this setting will not add the current delimiter BEFORE the component value.
</div>
<div>
<label class="modern-toggle-switch" title="Apply Delimiter">
<input type="checkbox" checked="@itemApplyDelimiterBefore" @oninput='args => ComponentSettingChanged(args, "applydelimiterbefore")'>
<span class="modern-toggle-slider"></span>
</label>
<span class="align-text-top ms-2"> Enable</span>
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Apply Delimiter After
</label>
<div style="margin-bottom: 1rem;">
If disabled, this setting will not add the current delimiter AFTER the component value.
</div>
<div>
<label class="modern-toggle-switch" title="Apply Delimiter">
<input type="checkbox" checked="@itemApplyDelimiterAfter" @oninput='args => ComponentSettingChanged(args, "applydelimiterafter")'>
<span class="modern-toggle-slider"></span>
</label>
<span class="align-text-top ms-2"> Enable</span>
</div>
</div>
}
if (type == "ResourceType")
{
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Apply Delimiter
</label>
<div style="margin-bottom: 1rem;">
If disabled, the current delimiter will not be used for name generation.
</div>
<div>
<label class="modern-toggle-switch" title="Apply Delimiter">
<input type="checkbox" checked="@itemApplyDelimiter" @oninput='args => ComponentSettingChanged(args, "applydelimiter")'>
<span class="modern-toggle-slider"></span>
</label>
<span class="align-text-top ms-2"> Enable</span>
</div>
</div>
<div id="typemetdadatacontainer" class="modern-card" style="margin-bottom: 1rem;">
<div class="modern-card-header collapsible @(GetCollapseClass("typemetdadata"))" @onclick="@(() => ToggleCollapse("typemetdadata"))">
<span class="oi oi-chevron-bottom" aria-hidden="true"></span> Resource Type Metadata
</div>
<div class="modern-card-body @(GetCollapseClass("typemetdadata"))" id="typemetdadata">
<div style="margin-bottom: 1rem;">
<p>
This section allows you to edit the Resouce Type metadata.
</p>
<div class="alert alert-danger" style="margin-bottom: 1rem;" role="alert">
<h4>ATTENTION</h4>
<span class="modern-font-semibold">Please see the <a href="https://github.com/mspnp/AzureNamingTool/wiki/Resource-Type-Editing" target="_blank">Resource Type Editing documentation</a> for guidance on metadata editing.</span>
</div>
</div>
<div style="margin-bottom: 1rem;">
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Regex
</label>
<div style="margin-bottom: 1rem;">
Regex to apply to generated names.
</div>
<div>
<input title="RegEx" value="@itemRegEx" type="text" class="modern-form-input" id="regex" @onchange="@((ui) => { itemRegEx = (string)ui.Value!;})" />
</div>
</div>
<label class="modern-form-label">
Scope
</label>
<div>
<input title="Scope" value="@itemScope" type="text" class="modern-form-input" id="scope" @onchange="@((ui) => { itemScope = (string)ui.Value!;})" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Valid Text
</label>
<div>
<input title="Valid Text" value="@itemValidText" type="text" class="modern-form-input" id="validtext" @onchange="@((ui) => { itemValidText = (string)ui.Value!;})" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Invalid Text
</label>
<div>
<input title="Invalid Text" value="@itemInvalidText" type="text" class="modern-form-input" id="invalidtext" @onchange="@((ui) => { itemInvalidText = (string)ui.Value!;})" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Invalid Characters
</label>
<div>
<input title="Invalid Characters" value="@itemInvalidCharacters" type="text" class="modern-form-input" id="invalidcharacters" @onchange="@((ui) => { itemInvalidCharacters = (string)ui.Value!;})" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Invalid Characters Start
</label>
<div>
<input title="Invalid Characters Start" value="@itemInvalidCharactersStart" type="text" class="modern-form-input" id="invalidcharactersstart" @onchange="@((ui) => { itemInvalidCharactersStart = (string)ui.Value!;})" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Invalid Characters End
</label>
<div>
<input title="Invalid Characters End" value="@itemInvalidCharactersEnd" type="text" class="modern-form-input" id="invalidcharactersend" @onchange="@((ui) => { itemInvalidCharactersEnd = (string)ui.Value!;})" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Invalid Characters Consecutive
</label>
<div>
<input title="Invalid Characters Consecutive" value="@itemInvalidCharactersConsecutive" type="text" class="modern-form-input" id="invalidcharactersconsecutive" @onchange="@((ui) => { itemInvalidCharactersConsecutive = (string)ui.Value!;})" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Static Values
</label>
<div>
<input title="Static Values" value="@itemStaticValues" type="text" class="modern-form-input" id="staticvalues" @onchange="@((ui) => { itemStaticValues = (string)ui.Value!;})" />
</div>
</div>
</div>
</div>
}
}
else
{
@if ((type == "ResourceType") && (!Convert.ToBoolean(config.ResourceTypeEditingAllowed)))
{
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Apply Delimiter
</label>
<div style="margin-bottom: 1rem;">
If disabled, the current delimiter will not be used for name generation.
</div>
<div>
@if (itemApplyDelimiter)
{
<span class="fst-italic">ENABLED</span>
}
else
{
<span class="fst-italic">DISABLED</span>
}
</div>
</div>
<div id="typemetdadatadisabledcontainer" class="modern-card" style="margin-bottom: 1rem;">
<div class="modern-card-header collapsible @(GetCollapseClass("typemetdadatadisabled"))" @onclick="@(() => ToggleCollapse("typemetdadatadisabled"))">
<span class="oi oi-chevron-bottom" aria-hidden="true"></span> Resource Type Metadata
</div>
<div class="modern-card-body @(GetCollapseClass("typemetdadatadisabled"))" id="typemetdadatadisabled">
<div style="margin-bottom: 1rem;">
This section allows you to view the Resouce Type metadata.
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Regex
</label>
<div style="margin-bottom: 1rem;">
Regex to apply to generated names.
</div>
<div>
<input title="RegEx" value="@itemRegEx" type="text" disabled class="modern-form-input" id="regex" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Scope
</label>
<div>
<input title="Scope" value="@itemScope" type="text" disabled class="modern-form-input" id="scope" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Valid Text
</label>
<div>
<input title="Valid Text" value="@itemValidText" type="text" disabled class="modern-form-input" id="validtext" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Invalid Text
</label>
<div>
<input title="Invalid Text" value="@itemInvalidText" type="text" disabled class="modern-form-input" id="invalidtext" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Invalid Characters
</label>
<div>
<input title="Invalid Characters" value="@itemInvalidCharacters" type="text" disabled class="modern-form-input" id="invalidcharacters" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Invalid Characters Start
</label>
<div>
<input title="Invalid Characters Start" value="@itemInvalidCharactersStart" type="text" disabled class="modern-form-input" id="invalidcharactersstart" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Invalid Characters End
</label>
<div>
<input title="Invalid Characters End" value="@itemInvalidCharactersEnd" type="text" disabled class="modern-form-input" id="invalidcharactersend" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Invalid Characters Consecutive
</label>
<div>
<input title="Invalid Characters Consecutive" value="@itemInvalidCharactersConsecutive" type="text" disabled class="modern-form-input" id="invalidcharactersconsecutive" />
</div>
</div>
<div style="margin-bottom: 1rem;">
<label class="modern-form-label">
Static Values
</label>
<div>
<input title="Static Values" value="@itemStaticValues" type="text" disabled class="modern-form-input" id="staticvalues" />
</div>
</div>
</div>
</div>
}
}
</div>
</div>
@if (type == "ResourceComponent")
{
<div id="globallyoptionalcontainer" class="modern-card" style="margin-bottom: 1rem;">
<div class="modern-card-header collapsible @(GetCollapseClass("globallyoptional"))" @onclick="@(() => ToggleCollapse("globallyoptional"))">
<span class="oi oi-chevron-bottom" aria-hidden="true"></span> Globally Optional Configuration
</div>
<div class="modern-card-body @(GetCollapseClass("globallyoptional"))" id="globallyoptional">
<div style="margin-bottom: 1rem;">
This section allows you to add/remove the component as OPTIONAL for all resource types.
</div>
<table class="table @theme.ThemeStyle">
<tbody>
<tr>
<td>
This option will ADD the component as OPTIONAL for all resource types.
</td>
<td>
<button type="button" class="modern-btn-success w-100" @onclick="@(e => FormAction("ResourceComponent","optional-add"))" style="min-width:42px;" title="Add as OPTIONAL for all Resource types">
ADD
</button>
</td>
</tr>
<tr>
<td>
This option will REMOVE the component from OPTIONAL for all resource types.
</td>
<td>
<button type="button" class="modern-btn-danger w-100" @onclick="@(e => FormAction("ResourceComponent","optional-remove"))" style="min-width:42px;" title="Remove as OPTIONAL for all Resource types">
REMOVE
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="globallyexcludecontainer" class="modern-card" style="margin-bottom: 1rem;">
<div class="modern-card-header collapsible @(GetCollapseClass("globallyexclude"))" @onclick="@(() => ToggleCollapse("globallyexclude"))">
<span class="oi oi-chevron-bottom" aria-hidden="true"></span> Globally Exclude Configuration
</div>
<div class="modern-card-body @(GetCollapseClass("globallyexclude"))" id="globallyexclude">
<div style="margin-bottom: 1rem;">
This section allows you to add/remove the component as EXCLUDE for all resource types.
</div>
<table class="table">
<tbody>
<tr>
<td>
This option will ADD the component as EXCLUDE for all resource types.
</td>
<td>
<button type="button" class="modern-btn-success w-100" @onclick="@(e => FormAction("ResourceComponent","exclude-add"))" style="min-width:42px;" title="Add as EXCLUDE for all Resource types">
ADD
</button>
</td>
</tr>
<tr>
<td>
This option will REMOVE the component from EXCLUDE for all resource types.
</td>
<td>
<button type="button" class="modern-btn-danger w-100" @onclick="@(e => FormAction("ResourceComponent","exclude-remove"))" style="min-width:42px;" title="Remove as EXCLUDE for all Resource types">
REMOVE
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
}
@if ((type == "ResourceType") && (GeneralHelper.IsNotNull(resourceComponents)))
{
<div id="optional" class="modern-card" style="margin-bottom: 1rem;">
<div class="modern-card-header collapsible @(GetCollapseClass("optionalcomponents"))" @onclick="@(() => ToggleCollapse("optionalcomponents"))">
<span class="oi oi-chevron-bottom" aria-hidden="true"></span> Optional Components
</div>
<div class="modern-card-body @(GetCollapseClass("optionalcomponents"))" id="optionalcomponents">
@foreach (ResourceComponent resourceComponent in resourceComponents)
{
if (resourceComponent.Name != "ResourceType")
{
<div class="form-check">
@if (optional.ToLower().Split(',').Contains(GeneralHelper.NormalizeName(resourceComponent.Name, true)))
{
<input title="Optional Component" class="form-check-input" type="checkbox" value="" id="optional-@GeneralHelper.NormalizeName(resourceComponent.Name, true)" checked>
<label class="form-check-label" for="optional-@GeneralHelper.NormalizeName(resourceComponent.Name, true)">
@resourceComponent.DisplayName
</label>
}
else
{
<input title="Optional Component" class="form-check-input" type="checkbox" value="" id="optional-@GeneralHelper.NormalizeName(resourceComponent.Name, true)">
<label class="form-check-label" for="optional-@GeneralHelper.NormalizeName(resourceComponent.Name, true)">
@resourceComponent.DisplayName
</label>
}
</div>
}
}
</div>
</div>
<div id="excluded" class="modern-card" style="margin-bottom: 1rem;">
<div class="modern-card-header collapsible @(GetCollapseClass("excludedcomponents"))" @onclick="@(() => ToggleCollapse("excludedcomponents"))">
<span class="oi oi-chevron-bottom" aria-hidden="true"></span> Excluded Components
</div>
<div class="modern-card-body @(GetCollapseClass("excludedcomponents"))" id="excludedcomponents">
@foreach (ResourceComponent resourceComponent in resourceComponents)
{
//@if (resourceComponent.Name != "ResourceType")
//{
<div class="form-check">
@if (exclude.ToLower().Split(',').Contains(GeneralHelper.NormalizeName(resourceComponent.Name, true)))
{
<input title="Excluded Component" class="form-check-input" type="checkbox" id="exclude-@GeneralHelper.NormalizeName(resourceComponent.Name, true)" checked>
<label class="form-check-label" for="exclude-@GeneralHelper.NormalizeName(resourceComponent.Name, true)">
@resourceComponent.DisplayName
</label>
}
else
{
<input title="Excluded Component" class="form-check-input" type="checkbox" id="exclude-@GeneralHelper.NormalizeName(resourceComponent.Name, true)">
<label class="form-check-label" for="exclude-@GeneralHelper.NormalizeName(resourceComponent.Name, true)">
@resourceComponent.DisplayName
</label>
}
</div>
//}
}
</div>
</div>
}
</div>
</div>
</div>
<div class="modern-modal-footer">
<button title="Save" @onclick="Save" class="modern-btn-success">Update</button>
<button title="Cancel" @onclick="Cancel" class="modern-btn-secondary">Close</button>
</div>
</div>
@code {
[CascadingParameter] BlazoredModalInstance ModalInstance { get; set; } = new();
[Parameter] public ThemeInfo theme { get; set; } = new();
[CascadingParameter]
public IModalService? Modal { get; set; }
[Parameter] public int id { get; set; } = 0;
[Parameter] public string title { get; set; } = String.Empty;
[Parameter] public string message { get; set; } = String.Empty;
[Parameter] public string type { get; set; } = String.Empty;
[Parameter] public bool isProtectedName { get; set; } = false;
[Parameter] public string parentcomponent { get; set; } = String.Empty;
[Parameter] public string headerstyle { get; set; } = String.Empty;
[Parameter] public bool admin { get; set; } = false;
[Parameter] public ServicesData servicesData { get; set; } = new();
[Inject]
public IResourceComponentService? ResourceComponentService { get; set; }
[Inject]
public IAdminUserService? AdminUserService { get; set; }
[Inject]
public IResourceEnvironmentService? ResourceEnvironmentService { get; set; }
[Inject]
public IResourceLocationService? ResourceLocationService { get; set; }
[Inject]
public IResourceOrgService? ResourceOrgService { get; set; }
[Inject]
public IResourceProjAppSvcService? ResourceProjAppSvcService { get; set; }
[Inject]
public IResourceTypeService? ResourceTypeService { get; set; }
[Inject]
public IResourceUnitDeptService? ResourceUnitDeptService { get; set; }
[Inject]
public IResourceFunctionService? ResourceFunctionService { get; set; }
[Inject]
public IResourceDelimiterService? ResourceDelimiterService { get; set; }
[Inject]
public ICustomComponentService? CustomComponentService { get; set; }
[Inject]
public IAdminLogService? AdminLogService { get; set; }
private ServiceResponse serviceResponse = new();
private bool isDangerAlertDismissed = false;
private bool isWarningAlertDismissed = false;
private string itemName = String.Empty;
private string itemDisplayName = String.Empty;
private string itemShortName = String.Empty;
private string itemDescription = String.Empty;
private string itemRegEx = String.Empty;
private string itemMinLength = String.Empty;
private string itemMaxLength = String.Empty;
private string itemMinLengthOriginal = String.Empty;
private string itemMaxLengthOriginal = String.Empty;
private string itemScope = "global";
private string itemValidText = String.Empty;
private string itemInvalidText = String.Empty;
private string itemInvalidCharacters = String.Empty;
private string itemInvalidCharactersStart = String.Empty;
private string itemInvalidCharactersEnd = String.Empty;
private string itemInvalidCharactersConsecutive = String.Empty;
private string itemStaticValues = String.Empty;
private bool itemIsCustom = false;
private string itemComponentType = "standard";
private bool itemIsFreeText = false;
private bool itemOriginalStandard = false;
private bool itemEnforceRandom = false;
private bool itemAlphanumeric = true;
private bool itemApplyDelimiterBefore = true; // Used to determine if the delimiter will be added before the component
private bool itemApplyDelimiterAfter = true; // Used to determine if the delimiter will be added after the component
private bool itemApplyDelimiter = true; // Used to determine if the delimiter is applied to the resource type (all components)
private List<ResourceComponent> resourceComponents = new();
private string optional = String.Empty;
private string exclude = String.Empty;
private bool ischecked = false;
private string currentuser = String.Empty;
private string namelabel = "Name";
private ResponseMessage responseMessage = new();
private SiteConfiguration config = ConfigurationHelper.GetConfigurationData();
protected override async void OnInitialized()
{
if (GeneralHelper.IsNotNull(servicesData))
{
servicesData = await ServicesHelper.LoadServicesData(servicesData, true);
}
switch (type)
{
case "ResourceComponent":
ResourceComponent resourceComponent = servicesData.ResourceComponents!.Find(x => x.Id == id)!;
itemName = resourceComponent.Name;
itemDisplayName = resourceComponent.DisplayName;
itemDescription = resourceComponent.Description;
itemMinLength = resourceComponent.MinLength;
itemMinLengthOriginal = itemMinLength;
itemMaxLength = resourceComponent.MaxLength;
itemMaxLengthOriginal = itemMaxLength;
itemIsCustom = resourceComponent.IsCustom;
itemIsFreeText = resourceComponent.IsFreeText;
if (itemIsFreeText)
{
itemComponentType = "freetext";
}
itemOriginalStandard = !resourceComponent.IsFreeText;
itemEnforceRandom = resourceComponent.EnforceRandom;
itemAlphanumeric = resourceComponent.Alphanumeric;
itemApplyDelimiterBefore = resourceComponent.ApplyDelimiterBefore;
itemApplyDelimiterAfter = resourceComponent.ApplyDelimiterAfter;
break;
case "ResourceEnvironment":
ResourceEnvironment resourceEnvironment = servicesData.ResourceEnvironments!.Find(x => x.Id == id)!;
itemName = resourceEnvironment.Name;
itemShortName = resourceEnvironment.ShortName;
break;
case "ResourceLocation":
ResourceLocation resourceLocation = servicesData.ResourceLocations!.Find(x => x.Id == id)!;
itemName = resourceLocation.Name;
itemShortName = resourceLocation.ShortName;
break;
case "ResourceOrg":
ResourceOrg resourceOrg = servicesData.ResourceOrgs!.Find(x => x.Id == id)!;
itemName = resourceOrg.Name;
itemShortName = resourceOrg.ShortName;
break;
case "ResourceProjAppSvc":
ResourceProjAppSvc resourceProjAppSvc = servicesData.ResourceProjAppSvcs!.Find(x => x.Id == id)!;
itemName = resourceProjAppSvc.Name;
itemShortName = resourceProjAppSvc.ShortName;
break;
case "ResourceType":
serviceResponse = await ResourceTypeService.GetItemAsync(id);
ResourceType resourceType = servicesData.ResourceTypes!.Find(x => x.Id == id)!;
itemName = resourceType.Resource;
namelabel = "Resource";
itemShortName = resourceType.ShortName;
itemDescription = resourceType.Description ?? String.Empty;
optional = resourceType.Optional;
exclude = resourceType.Exclude;
itemRegEx = resourceType.Regx;
itemMinLength = resourceType.LengthMin;
itemMinLengthOriginal = itemMinLength;
itemMaxLength = resourceType.LengthMax;
itemMaxLengthOriginal = itemMaxLength;
itemApplyDelimiter = resourceType.ApplyDelimiter;
itemScope = resourceType.Scope;
itemValidText = resourceType.ValidText;
itemInvalidText = resourceType.InvalidText;
itemInvalidCharacters = resourceType.InvalidCharacters;
itemInvalidCharactersStart = resourceType.InvalidCharactersStart;
itemInvalidCharactersEnd = resourceType.InvalidCharactersEnd;
itemInvalidCharactersConsecutive = resourceType.InvalidCharactersConsecutive;
itemStaticValues = resourceType.StaticValues;
resourceComponents = servicesData.ResourceComponents!.OrderBy(x => x.Name).ToList();
break;
case "ResourceUnitDept":
ResourceUnitDept resourceUnitDept = servicesData.ResourceUnitDepts!.Find(x => x.Id == id)!;
itemName = resourceUnitDept.Name;
itemShortName = resourceUnitDept.ShortName;
break;
case "ResourceFunction":
ResourceFunction resourceFunction = servicesData.ResourceFunctions!.Find(x => x.Id == id)!;
itemName = resourceFunction.Name;
itemShortName = resourceFunction.ShortName;
break;
case "CustomComponent":
CustomComponent customComponent = servicesData.CustomComponents!.Find(x => x.Id == id)!;
itemName = customComponent.Name;
itemShortName = customComponent.ShortName;
break;
}
currentuser = await IdentityHelper.GetCurrentUser(session);
StateHasChanged();
}
async Task Save()
{
try
{
bool valid = false;
if (type == "ResourceComponent")
{
// Make sure the min/max length is valid
if (Convert.ToInt32(itemMaxLength) >= Convert.ToInt32(itemMinLength))
{
if (!String.IsNullOrEmpty(itemName))
{
valid = true;
// Check if the user modified the min/max lengths and warn them to update their options
if ((itemMinLength != itemMinLengthOriginal) || (itemMaxLength != itemMaxLengthOriginal))
{
toastService.ShowInfo("You have modified the min/max length. You will need to verify the existing options meet the new length requirements!");
}
ResourceComponent resourceComponent = servicesData.ResourceComponents!.Find(x => x.Id == id)!;
// Update any references in the custom components configuration to be the new custom component type name
var customcomponents = (List<CustomComponent>)servicesData.CustomComponents!.FindAll(x => GeneralHelper.NormalizeName(x.ParentComponent, true) == GeneralHelper.NormalizeName(resourceComponent.Name, true));
foreach (var customcomponent in customcomponents)
{
customcomponent.ParentComponent = GeneralHelper.NormalizeName(itemName, true);
serviceResponse = await CustomComponentService.PostItemAsync(customcomponent);
}
resourceComponent.Name = itemName;
if (resourceComponent.IsCustom)
{
resourceComponent.DisplayName = itemName;
if (itemComponentType == "freetext")
{
resourceComponent.IsFreeText = true;
}
else
{
resourceComponent.IsFreeText = false;
}
resourceComponent.EnforceRandom = itemEnforceRandom;
resourceComponent.Alphanumeric = itemAlphanumeric;
}
else
{
resourceComponent.DisplayName = itemDisplayName;
}
resourceComponent.Description = itemDescription;
resourceComponent.MinLength = itemMinLength;
resourceComponent.MaxLength = itemMaxLength;
resourceComponent.ApplyDelimiterBefore = itemApplyDelimiterBefore;
resourceComponent.ApplyDelimiterAfter = itemApplyDelimiterAfter;
// Check if the user is changing from Standard to Free Text.
if ((itemOriginalStandard) && (resourceComponent.IsFreeText))
{
bool confirm = false;
confirm = await ModalHelper.ShowConfirmationModal(Modal!, "ATTENTION", "<div style='margin: 1.5rem 0;'>This will update the custom component to free text and remove the current component options! This cannot be un-done!</div><div style='margin: 1.5rem 0;'>Are you sure?</div>", "bg-danger", theme);
if (confirm)
{
serviceResponse = await CustomComponentService.DeleteByParentComponentIdAsync((int)resourceComponent.Id);
serviceResponse = await ResourceComponentService.PostItemAsync(resourceComponent);
}
else
{
valid = false;
}
}
else
{
serviceResponse = await ResourceComponentService.PostItemAsync(resourceComponent);
}
}
else
{
toastService.ShowError("You must enter a name!");
}
}
else
{
toastService.ShowError("The Maximum Length must equal/greater than the Minimum length!");
}
}
else
{
if ((!String.IsNullOrEmpty(itemName)) && (!String.IsNullOrEmpty(itemShortName)))
{
if (await ValidationHelper.ValidateShortName(ResourceComponentService!, type, itemShortName, this.parentcomponent))
{
try
{
// Check the regex is valid
Regex regx = new(itemRegEx);
}
catch (Exception)
{
toastService.ShowError("The Regex is not valid. Please review the code and try again!");
return;
}
valid = true;
switch (type)
{
case "ResourceEnvironment":
ResourceEnvironment resourceEnvironment = servicesData.ResourceEnvironments!.Find(x => x.Id == id)!;
resourceEnvironment.Name = itemName;
resourceEnvironment.ShortName = itemShortName;
serviceResponse = await ResourceEnvironmentService.PostItemAsync(resourceEnvironment);
break;
case "ResourceLocation":
ResourceLocation resourceLocation = servicesData.ResourceLocations!.Find(x => x.Id == id)!;
resourceLocation.ShortName = itemShortName;
serviceResponse = await ResourceLocationService.PostItemAsync(resourceLocation);
break;
case "ResourceOrg":
ResourceOrg resourceOrg = servicesData.ResourceOrgs!.Find(x => x.Id == id)!;
resourceOrg.Name = itemName;
resourceOrg.ShortName = itemShortName;
serviceResponse = await ResourceOrgService.PostItemAsync(resourceOrg);
break;
case "ResourceProjAppSvc":
ResourceProjAppSvc resourceProjAppSvc = servicesData.ResourceProjAppSvcs!.Find(x => x.Id == id)!;
resourceProjAppSvc.Name = itemName;
resourceProjAppSvc.ShortName = itemShortName;
serviceResponse = await ResourceProjAppSvcService.PostItemAsync(resourceProjAppSvc);
break;
case "ResourceType":
ResourceType resourceType = servicesData.ResourceTypes!.Find(x => x.Id == id)!;
resourceType.ShortName = itemShortName;
resourceType.Description = itemDescription;
resourceType.Optional = "";
resourceType.Exclude = "";
resourceType.ApplyDelimiter = itemApplyDelimiter;
if (!String.IsNullOrEmpty(itemMinLength.ToString()))
{
if (ValidationHelper.CheckNumeric(itemMinLength.ToString()))
{
resourceType.LengthMin = itemMinLength.ToString();
}
}
if (!String.IsNullOrEmpty(itemMaxLength.ToString()))
{
if (ValidationHelper.CheckNumeric(itemMaxLength.ToString()))
{
resourceType.LengthMax = itemMaxLength.ToString();
}
}
resourceType.Regx = itemRegEx;
resourceType.Scope = itemScope;
resourceType.ValidText = itemValidText;
resourceType.InvalidText = itemInvalidText;
resourceType.InvalidCharacters = itemInvalidCharacters;
resourceType.InvalidCharactersStart = itemInvalidCharactersStart;
resourceType.InvalidCharactersEnd = itemInvalidCharactersEnd;
resourceType.InvalidCharactersConsecutive = itemInvalidCharactersConsecutive;
resourceType.StaticValues = itemStaticValues;
// Update the Optional and Exclude components
foreach (ResourceComponent resourceComponent in resourceComponents)
{
if (resourceComponent.Name != "ResourceType")
{
// Optional
ischecked = false;
ischecked = await JsRuntime.InvokeAsync<bool>("IsElementChecked", "optional-" + GeneralHelper.NormalizeName(resourceComponent.Name, true));
if (ischecked)
{
List<string> currentoptional = new List<string>(resourceType.Optional.Split(','));
if (!currentoptional.Contains(resourceComponent.Name))
{
currentoptional.Add(GeneralHelper.NormalizeName(resourceComponent.Name, true));
resourceType.Optional = String.Join(",", currentoptional.ToArray());
}
}
}
// Exclude
ischecked = false;
ischecked = await JsRuntime.InvokeAsync<bool>("IsElementChecked", "exclude-" + GeneralHelper.NormalizeName(resourceComponent.Name, true));
if (ischecked)
{
List<string> currentexclude = new List<string>(resourceType.Exclude.Split(','));
if (!currentexclude.Contains(resourceComponent.Name))
{
currentexclude.Add(GeneralHelper.NormalizeName(resourceComponent.Name, true));
resourceType.Exclude = String.Join(",", currentexclude.ToArray());
}
}
}
serviceResponse = await ResourceTypeService.PostItemAsync(resourceType);
break;
case "ResourceUnitDept":
ResourceUnitDept resourceUnitDept = servicesData.ResourceUnitDepts!.Find(x => x.Id == id)!;
resourceUnitDept.Name = itemName;
resourceUnitDept.ShortName = itemShortName;
serviceResponse = await ResourceUnitDeptService.PostItemAsync(resourceUnitDept);
break;
case "ResourceFunction":
ResourceFunction resourceFunction = servicesData.ResourceFunctions!.Find(x => x.Id == id)!;
resourceFunction.Name = itemName;
resourceFunction.ShortName = itemShortName;
serviceResponse = await ResourceFunctionService.PostItemAsync(resourceFunction);
break;
case "CustomComponent":
CustomComponent customComponent = servicesData.CustomComponents!.Find(x => x.Id == id)!;
customComponent.Name = itemName;
customComponent.ShortName = itemShortName;
serviceResponse = await CustomComponentService.PostItemAsync(customComponent);
break;
}
}
else
{
toastService.ShowError("You must enter a valid short name!");
}
}
else
{
toastService.ShowError("You must enter a name and short name!");
}
}
if (valid)
{
if (serviceResponse.Success)
{
await ModalInstance.CloseAsync();
toastService.ShowSuccess(GeneralHelper.NormalizeName(type, false) + " updated!");
await AdminLogService?.PostItemAsync(new AdminLogMessage() { Title = "SUCCESS", Message = "(" + GeneralHelper.NormalizeName(type, false) + ") " + itemName + " updated!", Source = currentuser });
}
else
{
toastService.ShowError("There was an error updating the " + GeneralHelper.NormalizeName(type, false) + "! " + serviceResponse.ResponseObject);
}
}