Skip to content

Commit a5a00e2

Browse files
authored
Merge pull request #7178 from microting/copilot/add-mat-icon-to-menu-items
Add optional Material Design icons to navigation menu items
2 parents 53581e8 + 9d61437 commit a5a00e2

File tree

14 files changed

+124
-5
lines changed

14 files changed

+124
-5
lines changed

eFormAPI/eFormAPI.Web/Abstractions/IMenuService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
SOFTWARE.
2323
*/
2424
using System.Threading.Tasks;
25-
using Microting.eFormApi.BasePn.Infrastructure.Models.Application;
2625
using Microting.eFormApi.BasePn.Infrastructure.Models.API;
2726
using eFormAPI.Web.Services.NavigationMenu;
2827
using System.Collections.Generic;
28+
using MenuModel = eFormAPI.Web.Infrastructure.Models.Menu.MenuModel;
2929

3030
namespace eFormAPI.Web.Abstractions;
3131

eFormAPI/eFormAPI.Web/Controllers/MenuController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2525
using eFormAPI.Web.Abstractions;
2626
using Microsoft.AspNetCore.Authorization;
2727
using Microsoft.AspNetCore.Mvc;
28-
using Microting.eFormApi.BasePn.Infrastructure.Models.Application;
2928
using Microting.eFormApi.BasePn.Infrastructure.Models.API;
3029
using eFormAPI.Web.Services.NavigationMenu;
3130
using System.Collections.Generic;
31+
using MenuModel = eFormAPI.Web.Infrastructure.Models.Menu.MenuModel;
3232

3333
namespace eFormAPI.Web.Controllers;
3434

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2007 - 2021 Microting A/S
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
namespace eFormAPI.Web.Infrastructure.Models.Menu;
26+
27+
using System.Collections.Generic;
28+
29+
public class MenuItemModel
30+
{
31+
public string Name { get; set; }
32+
public string LocaleName { get; set; }
33+
public string E2EId { get; set; }
34+
public string Link { get; set; }
35+
public string Icon { get; set; }
36+
public int Position { get; set; }
37+
public bool IsInternalLink { get; set; }
38+
public List<string> Guards { get; set; } = new List<string>();
39+
public List<MenuItemModel> MenuItems { get; set; } = new List<MenuItemModel>();
40+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2007 - 2021 Microting A/S
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
namespace eFormAPI.Web.Infrastructure.Models.Menu;
26+
27+
using System.Collections.Generic;
28+
29+
public class MenuModel
30+
{
31+
public List<MenuItemModel> LeftMenu { get; set; } = new List<MenuItemModel>();
32+
public List<MenuItemModel> RightMenu { get; set; } = new List<MenuItemModel>();
33+
}

eFormAPI/eFormAPI.Web/Services/MenuService.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ namespace eFormAPI.Web.Services;
3737
using Microsoft.Extensions.Logging;
3838
using Microting.eFormApi.BasePn.Infrastructure.Database.Entities;
3939
using Microting.eFormApi.BasePn.Infrastructure.Models.API;
40-
using Microting.eFormApi.BasePn.Infrastructure.Models.Application;
4140
using System;
4241
using System.Collections.Generic;
4342
using System.Linq;
@@ -46,6 +45,8 @@ namespace eFormAPI.Web.Services;
4645
using Microting.EformAngularFrontendBase.Infrastructure.Const;
4746
using Microting.EformAngularFrontendBase.Infrastructure.Data;
4847
using Microting.EformAngularFrontendBase.Infrastructure.Data.Entities.Menu;
48+
using MenuItemModel = eFormAPI.Web.Infrastructure.Models.Menu.MenuItemModel;
49+
using MenuModel = eFormAPI.Web.Infrastructure.Models.Menu.MenuModel;
4950

5051
public class MenuService(
5152
ILogger<MenuService> logger,
@@ -177,6 +178,7 @@ public async Task<OperationDataResult<NavigationMenuModel>> GetCurrentNavigation
177178
ParentId = x.ParentId,
178179
Position = x.Position,
179180
IsInternalLink = x.IsInternalLink,
181+
Icon = x.IconName,
180182
Translations = dbContext.MenuItemTranslations
181183
.Where(p => p.MenuItemId == x.Id)
182184
.Select(p => new NavigationMenuTranslationModel
@@ -202,6 +204,7 @@ public async Task<OperationDataResult<NavigationMenuModel>> GetCurrentNavigation
202204
RelatedTemplateItemId = p.MenuTemplateId,
203205
ParentId = p.ParentId,
204206
Position = p.Position,
207+
Icon = p.IconName,
205208
Translations = dbContext.MenuItemTranslations
206209
.Where(k => k.MenuItemId == p.Id)
207210
.Select(k => new NavigationMenuTranslationModel
@@ -278,6 +281,7 @@ public async Task<OperationDataResult<MenuModel>> GetCurrentUserMenu()
278281
LocaleName = currentLocale,
279282
E2EId = x.E2EId,
280283
Link = x.Link,
284+
Icon = x.IconName,
281285
Guards = dbContext.MenuTemplatePermissions
282286
.Include(y => y.Permission)
283287
.Where(d => d.MenuTemplateId == x.MenuTemplateId)
@@ -308,6 +312,7 @@ public async Task<OperationDataResult<MenuModel>> GetCurrentUserMenu()
308312
LocaleName = currentLocale,
309313
E2EId = p.E2EId,
310314
Link = p.Link,
315+
Icon = p.IconName,
311316
Guards = dbContext.MenuTemplatePermissions
312317
.Include(y => y.Permission)
313318
.Where(d => d.MenuTemplateId == p.MenuTemplateId)
@@ -372,7 +377,7 @@ public async Task<OperationDataResult<MenuModel>> GetCurrentUserMenu()
372377
foreach (var pluginMenu in Program.EnabledPlugins.Select(plugin => plugin.HeaderMenu(serviceProvider)))
373378
{
374379
//result.LeftMenu.AddRange(pluginMenu.LeftMenu);
375-
result.RightMenu.AddRange(pluginMenu.RightMenu);
380+
result.RightMenu.AddRange(ConvertToLocalMenuItemModel(pluginMenu.RightMenu));
376381
}
377382

378383
return new OperationDataResult<MenuModel>(true, result);
@@ -387,6 +392,21 @@ public async Task<OperationDataResult<MenuModel>> GetCurrentUserMenu()
387392
}
388393
}
389394

395+
private List<MenuItemModel> ConvertToLocalMenuItemModel(List<Microting.eFormApi.BasePn.Infrastructure.Models.Application.MenuItemModel> externalModels)
396+
{
397+
return externalModels.Select(x => new MenuItemModel
398+
{
399+
Name = x.Name,
400+
LocaleName = x.LocaleName,
401+
E2EId = x.E2EId,
402+
Link = x.Link,
403+
Position = x.Position,
404+
IsInternalLink = x.IsInternalLink,
405+
Guards = x.Guards,
406+
MenuItems = ConvertToLocalMenuItemModel(x.MenuItems)
407+
}).ToList();
408+
}
409+
390410
public async Task<OperationResult> ResetCurrentUserMenu()
391411
{
392412
// Step 1. Firstly remove all menu items from database

eFormAPI/eFormAPI.Web/Services/NavigationMenu/Builder/MenuItemBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public MenuItem Build()
5959
Type = MenuItemModel.Type,
6060
Link = MenuItemModel.Link,
6161
E2EId = MenuItemModel.E2EId,
62-
IsInternalLink = MenuItemModel.IsInternalLink
62+
IsInternalLink = MenuItemModel.IsInternalLink,
63+
IconName = MenuItemModel.Icon
6364
};
6465

6566
foreach (var behavior in _behaviors.Where(behavior => behavior.IsExecute()))

eFormAPI/eFormAPI.Web/Services/NavigationMenu/NavigationMenuItemModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ public class NavigationMenuItemModel
4747
= new List<NavigationMenuTranslationModel>();
4848

4949
public bool IsInternalLink { get; set; }
50+
public string Icon { get; set; }
5051
}

eFormAPI/eFormAPI.Web/Services/NavigationMenu/NavigationMenuTemplateItemModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ public class NavigationMenuTemplateItemModel
3535
public int? RelatedTemplateItemId { get; set; }
3636
public List<NavigationMenuTranslationModel> Translations { get; set; }
3737
= new List<NavigationMenuTranslationModel>();
38+
public string Icon { get; set; }
3839
}

eform-client/src/app/common/models/navigation-menu/navigation-menu.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class NavigationMenuTemplateItemModel {
1818
link: string;
1919
collapsed: boolean;
2020
translations: NavigationMenuTranslationModel[];
21+
icon?: string;
2122
}
2223

2324
export class NavigationMenuItemModel {
@@ -34,6 +35,7 @@ export class NavigationMenuItemModel {
3435
securityGroupsIds: number[];
3536
translations: NavigationMenuTranslationModel[];
3637
isInternalLink: boolean = true;
38+
icon?: string;
3739
}
3840

3941
export class NavigationMenuTranslationModel {

eform-client/src/app/common/models/user/user-menu.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export class MenuItemModel {
1111
isInternalLink: boolean;
1212
menuItems: Array<MenuItemModel> = [];
1313
guards: Array<string> = [];
14+
icon?: string;
1415
}

0 commit comments

Comments
 (0)