Skip to content

Commit 4fae44e

Browse files
Refactor Launcher region and amend docs
1 parent 056889b commit 4fae44e

File tree

7 files changed

+43
-13
lines changed

7 files changed

+43
-13
lines changed

docs/articles/launcher/launcher.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,30 @@ External modules are integrated with the `<embed>` tag; the external web-page mu
4949
}
5050

5151
````
52+
53+
### Region
54+
55+
To define a region in the launcher configuration, you can use the `Regions` property. This allows you to specify
56+
which region should be loaded and where it shoud be placed in the launcher.
57+
58+
The region must define its own size using `css`, if that's a requirement for you. Otherwise the launcher will set an automatic size based on
59+
the available space.
60+
61+
````json
62+
{
63+
"Regions": [
64+
{
65+
"Region": "Right",
66+
"Name": "MyRegionName"
67+
}
68+
]
69+
}
70+
71+
````
72+
**Note**: This will work under the following conditions:
73+
1. You have created an [ASP.net Partial View](https://learn.microsoft.com/en-us/aspnet/core/mvc/views/partial?view=aspnetcore-10.0#declare-partial-views).
74+
2. You used the `LauncherRegionAttribute` in your partial view.
75+
3. The name you used in your `LauncherRegion()` is the same in the configuration.
76+
4. You have placed the partial view inside a folder called `Pages`.
77+
5. The project in which you defined your partial view support Razor Pages and references the Launcher package or project.
78+

src/Moryx.Launcher/Config/LauncherRegionConfig.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ public class LauncherRegionConfig
1717
[DataMember]
1818
public LauncherRegion Region { get; set; }
1919

20+
/// <summary>
21+
/// The name of the region for the launcher
22+
/// </summary>
23+
2024
[DataMember]
21-
public string PluginName { get; set; }
25+
public string Name { get; set; }
2226
}
2327

2428
public enum LauncherRegion

src/Moryx.Launcher/IShellNavigator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ public interface IShellNavigator
1818
/// <summary>
1919
/// Get the region configuration
2020
/// </summary>
21-
LauncherRegionItem GetRegion(LauncherRegion region);
21+
RegionItem GetRegion(LauncherRegion region);
2222
}

src/Moryx/Modules/LauncherPluginAttribute.cs renamed to src/Moryx.Launcher/LauncherRegionAttribute.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
// Copyright (c) 2026 Phoenix Contact GmbH & Co. KG
22
// Licensed under the Apache License, Version 2.0
33

4-
namespace Moryx.Modules;
54

65
/// <summary>
76
/// Decorator for partial view (Region)
87
/// </summary>
98
/// <remarks>
10-
/// Export view as plugin under given name
9+
/// Export view as region under given name
1110
/// </remarks>
12-
public class LauncherPluginAttribute(string name) : Attribute
11+
public class LauncherRegionAttribute(string name) : Attribute
1312
{
1413
/// <summary>
15-
/// Unique name of the plugin
14+
/// Unique name of the region
1615
/// </summary>
1716
public string Name { get; } = name;
1817

src/Moryx.Launcher/Pages/Shared/_Layout.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189
@RenderBody()
190190
</main>
191191
</div>
192-
@if (_navigator.GetRegion(LauncherRegion.Right) is LauncherRegionItem rightRegion)
192+
@if (_navigator.GetRegion(LauncherRegion.Right) is RegionItem rightRegion)
193193
{
194194
<aside class="tw-flex-initial tw-overflow-hidden">@await Html.PartialAsync(rightRegion.PartialView)</aside>
195195
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Moryx.Launcher;
55

6-
public class LauncherRegionItem
6+
public class RegionItem
77
{
88
/// <summary>
99
/// Name of the partial for the given region

src/Moryx.Launcher/ShellNavigator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,24 @@ private async Task<CompiledPageActionDescriptor[]> CompiledPageActionDescriptors
109109
}
110110

111111
/// <inheritdoc />
112-
public LauncherRegionItem GetRegion(LauncherRegion region)
112+
public RegionItem GetRegion(LauncherRegion region)
113113
{
114-
var config = _launcherConfig.Regions?.FirstOrDefault(x => x.Region == region);
114+
var config = _launcherConfig.Regions.FirstOrDefault(x => x.Region == region);
115115
if (config is null)
116116
{
117117
return null;
118118
}
119119

120120
var partialViewAssembly = ReflectionTool.GetAssemblies();
121-
var launcherPluginTypes = partialViewAssembly.SelectMany(x => x.GetTypes().Where(t => t.IsClass && t.GetCustomAttribute<LauncherPluginAttribute>() != null));
122-
var launcherPluginType = launcherPluginTypes.FirstOrDefault(x => config.PluginName == x.GetCustomAttribute<LauncherPluginAttribute>().Name);
121+
var launcherPluginTypes = partialViewAssembly.SelectMany(x => x.GetTypes().Where(t => t.IsClass && t.GetCustomAttribute<LauncherRegionAttribute>() != null));
122+
var launcherPluginType = launcherPluginTypes.FirstOrDefault(x => config.Name == x.GetCustomAttribute<LauncherRegionAttribute>().Name);
123123
if (launcherPluginType is null)
124124
{
125125
return null;
126126
}
127127
// the name of the Pages/_MyPartialView.cshtml when compiled is ex: ...Pages__MyPartialView
128128
var viewName = launcherPluginType.Name[("Pages_".Length)..];
129-
return new LauncherRegionItem { PartialView = viewName };
129+
return new RegionItem { PartialView = viewName };
130130
}
131131

132132
private ExternalModuleItem[] LoadExternalModules()

0 commit comments

Comments
 (0)