1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
+ using System . Linq ;
4
5
using System . Text . Json . Nodes ;
5
6
using System . Threading ;
6
7
using System . Threading . Tasks ;
9
10
using Altinn . Studio . Designer . Events ;
10
11
using Altinn . Studio . Designer . Filters ;
11
12
using Altinn . Studio . Designer . Helpers ;
12
- using Altinn . Studio . Designer . Infrastructure . GitRepository ;
13
13
using Altinn . Studio . Designer . Models ;
14
14
using Altinn . Studio . Designer . Models . Dto ;
15
15
using Altinn . Studio . Designer . Services . Interfaces ;
@@ -32,7 +32,6 @@ public class AppDevelopmentController : Controller
32
32
private readonly IAppDevelopmentService _appDevelopmentService ;
33
33
private readonly IRepository _repository ;
34
34
private readonly ISourceControl _sourceControl ;
35
- private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory ;
36
35
private readonly ApplicationInsightsSettings _applicationInsightsSettings ;
37
36
private readonly IMediator _mediator ;
38
37
@@ -43,15 +42,13 @@ public class AppDevelopmentController : Controller
43
42
/// <param name="appDevelopmentService">The app development service</param>
44
43
/// <param name="repositoryService">The application repository service</param>
45
44
/// <param name="sourceControl">The source control service.</param>
46
- /// <param name="altinnGitRepositoryFactory"></param>
47
45
/// <param name="applicationInsightsSettings">An <see cref="ApplicationInsightsSettings"/></param>
48
46
/// <param name="mediator"></param>
49
- public AppDevelopmentController ( IAppDevelopmentService appDevelopmentService , IRepository repositoryService , ISourceControl sourceControl , IAltinnGitRepositoryFactory altinnGitRepositoryFactory , ApplicationInsightsSettings applicationInsightsSettings , IMediator mediator )
47
+ public AppDevelopmentController ( IAppDevelopmentService appDevelopmentService , IRepository repositoryService , ISourceControl sourceControl , ApplicationInsightsSettings applicationInsightsSettings , IMediator mediator )
50
48
{
51
49
_appDevelopmentService = appDevelopmentService ;
52
50
_repository = repositoryService ;
53
51
_sourceControl = sourceControl ;
54
- _altinnGitRepositoryFactory = altinnGitRepositoryFactory ;
55
52
_applicationInsightsSettings = applicationInsightsSettings ;
56
53
_mediator = mediator ;
57
54
}
@@ -123,8 +120,17 @@ public async Task<ActionResult> SaveFormLayout(string org, string app, [FromQuer
123
120
124
121
if ( formLayoutPayload . ComponentIdsChange is not null && ! string . IsNullOrEmpty ( layoutSetName ) )
125
122
{
126
- foreach ( var componentIdChange in formLayoutPayload . ComponentIdsChange )
123
+ foreach ( var componentIdChange in formLayoutPayload . ComponentIdsChange . Where ( ( componentIdChange ) => componentIdChange . OldComponentId != componentIdChange . NewComponentId ) )
127
124
{
125
+ if ( componentIdChange . NewComponentId == null )
126
+ {
127
+ await _mediator . Publish ( new ComponentDeletedEvent
128
+ {
129
+ ComponentId = componentIdChange . OldComponentId ,
130
+ LayoutSetName = layoutSetName ,
131
+ EditingContext = editingContext
132
+ } , cancellationToken ) ;
133
+ }
128
134
await _mediator . Publish ( new ComponentIdChangedEvent
129
135
{
130
136
OldComponentId = componentIdChange . OldComponentId ,
@@ -159,16 +165,26 @@ await _mediator.Publish(new LayoutPageAddedEvent
159
165
/// <param name="app">Application identifier which is unique within an organisation.</param>
160
166
/// <param name="layoutSetName">The name of the layout set the specific layout belongs to</param>
161
167
/// <param name="layoutName">The form layout to be deleted</param>
168
+ /// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is cancelled.</param>
162
169
/// <returns>A success message if the save was successful</returns>
163
170
[ HttpDelete ]
164
171
[ Route ( "form-layout/{layoutName}" ) ]
165
- public ActionResult DeleteFormLayout ( string org , string app , [ FromQuery ] string layoutSetName , [ FromRoute ] string layoutName )
172
+ public async Task < ActionResult > DeleteFormLayout ( string org , string app , [ FromQuery ] string layoutSetName , [ FromRoute ] string layoutName , CancellationToken cancellationToken )
166
173
{
167
174
try
168
175
{
169
176
string developer = AuthenticationHelper . GetDeveloperUserName ( HttpContext ) ;
170
177
var editingContext = AltinnRepoEditingContext . FromOrgRepoDeveloper ( org , app , developer ) ;
178
+
179
+ await _mediator . Publish ( new LayoutPageDeletedEvent
180
+ {
181
+ EditingContext = editingContext ,
182
+ LayoutSetName = layoutSetName ,
183
+ LayoutName = layoutName ,
184
+ } , cancellationToken ) ;
185
+
171
186
_appDevelopmentService . DeleteFormLayout ( editingContext , layoutSetName , layoutName ) ;
187
+
172
188
return Ok ( ) ;
173
189
}
174
190
catch ( FileNotFoundException exception )
@@ -402,13 +418,15 @@ public async Task<ActionResult> DeleteLayoutSet(string org, string app, [FromRou
402
418
{
403
419
string developer = AuthenticationHelper . GetDeveloperUserName ( HttpContext ) ;
404
420
var editingContext = AltinnRepoEditingContext . FromOrgRepoDeveloper ( org , app , developer ) ;
405
- LayoutSets layoutSets = await _appDevelopmentService . DeleteLayoutSet ( editingContext , layoutSetIdToUpdate , cancellationToken ) ;
406
421
407
422
await _mediator . Publish ( new LayoutSetDeletedEvent
408
423
{
409
424
EditingContext = editingContext ,
410
- LayoutSetId = layoutSetIdToUpdate
425
+ LayoutSetName = layoutSetIdToUpdate
411
426
} , cancellationToken ) ;
427
+
428
+ LayoutSets layoutSets = await _appDevelopmentService . DeleteLayoutSet ( editingContext , layoutSetIdToUpdate , cancellationToken ) ;
429
+
412
430
return Ok ( layoutSets ) ;
413
431
}
414
432
@@ -543,20 +561,6 @@ public ActionResult GetWidgetSettings(string org, string app)
543
561
return Ok ( widgetSettings ) ;
544
562
}
545
563
546
- [ HttpGet ]
547
- [ Route ( "option-list-ids" ) ]
548
- public ActionResult GetOptionListIds ( string org , string app )
549
- {
550
- string developer = AuthenticationHelper . GetDeveloperUserName ( HttpContext ) ;
551
- AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory . GetAltinnAppGitRepository ( org , app , developer ) ;
552
- string [ ] optionListIds = altinnAppGitRepository . GetOptionsListIds ( ) ;
553
- if ( optionListIds . Length == 0 )
554
- {
555
- return NoContent ( ) ;
556
- }
557
- return Ok ( optionListIds ) ;
558
- }
559
-
560
564
[ HttpGet ( "app-version" ) ]
561
565
public VersionResponse GetAppVersion ( string org , string app )
562
566
{
0 commit comments