Skip to content

Commit 97b9f98

Browse files
committed
feat: add log page, general improvements and minor bugs
1 parent da25d7b commit 97b9f98

11 files changed

Lines changed: 687 additions & 216 deletions

src/WebExpress.WebApp.Test/WebControl/UnitTestControlWebAppHeaderSettings.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public class UnitTestControlWebAppHeaderSettings
1515
/// Tests the id property of the web app header settings control.
1616
/// </summary>
1717
[Theory]
18-
[InlineData(null, false, "<div class=\"wx-webui-dropdown ms-2\" role=\"button\" data-icon=\"fas fa-cog\" data-buttonCss=\"btn-dark\" data-menuCss=\"dropdown-menu-end\"><div id=\"Settings\" class=\"wx-dropdown-header\" role=\"heading\"></div><div class=\"wx-dropdown-item\"></div></div>")]
19-
[InlineData("id", false, "<div id=\"id\" class=\"wx-webui-dropdown ms-2\" role=\"button\" data-icon=\"fas fa-cog\" data-buttonCss=\"btn-dark\" data-menuCss=\"dropdown-menu-end\"><div id=\"Settings\" class=\"wx-dropdown-header\" role=\"heading\"></div><div class=\"wx-dropdown-item\"></div></div>")]
20-
[InlineData("id", true, "")]
18+
[InlineData(null, false, "<div class=\"wx-webui-dropdown ms-2\" role=\"button\" data-icon=\"fas fa-cog\" data-buttonCss=\"btn-dark\" data-menuCss=\"dropdown-menu-end\"><div id=\"Settings\" class=\"wx-dropdown-header\" role=\"heading\"></div><div class=\"wx-dropdown-item\" data-icon=\"fas fa-cog\" data-uri=\"/server/app/webexpress.webapp/setting/system/log\">General settings</div><div class=\"wx-dropdown-item\"></div></div>")]
19+
[InlineData("id", false, "<div id=\"id\" class=\"wx-webui-dropdown ms-2\" role=\"button\" data-icon=\"fas fa-cog\" data-buttonCss=\"btn-dark\" data-menuCss=\"dropdown-menu-end\"><div id=\"Settings\" class=\"wx-dropdown-header\" role=\"heading\"></div><div class=\"wx-dropdown-item\" data-icon=\"fas fa-cog\" data-uri=\"/server/app/webexpress.webapp/setting/system/log\">General settings</div><div class=\"wx-dropdown-item\"></div></div>")]
20+
[InlineData("id", true, "<div id=\"id\" class=\"wx-webui-dropdown ms-2\" role=\"button\" data-icon=\"fas fa-cog\" data-buttonCss=\"btn-dark\" data-menuCss=\"dropdown-menu-end\"><div class=\"wx-dropdown-item\" data-icon=\"fas fa-cog\" data-uri=\"/server/app/webexpress.webapp/setting/system/log\">General settings</div></div>")]
2121
public void Id(string id, bool empty, string expected)
2222
{
2323
// preconditions
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using WebExpress.WebApp.WebControl;
5+
using WebExpress.WebApp.WebScope;
6+
using WebExpress.WebApp.WebSettingPage;
7+
using WebExpress.WebCore.Internationalization;
8+
using WebExpress.WebCore.WebAttribute;
9+
using WebExpress.WebCore.WebLog;
10+
using WebExpress.WebCore.WebPage;
11+
using WebExpress.WebCore.WebSettingPage;
12+
using WebExpress.WebUI.Internationalization;
13+
using WebExpress.WebUI.WebControl;
14+
using WebExpress.WebUI.WebIcon;
15+
16+
namespace WebExpress.WebApp.WWW.Setting.System
17+
{
18+
/// <summary>
19+
/// Logging settings page.
20+
/// </summary>
21+
[WebIcon<IconFileMedicalAlt>]
22+
[Title("webexpress.webapp:setting.titel.log.label")]
23+
[SettingCategory<SettingCategoryGeneral>()]
24+
[SettingGroup<SettingGroupGeneral>()]
25+
[SettingSection(SettingSection.Secondary)]
26+
[Scope<IScopeAdmin>]
27+
public sealed class Log : ISettingPage<VisualTreeWebAppSetting>, IScopeAdmin
28+
{
29+
private readonly ILogManager _logManager;
30+
31+
/// <summary>
32+
/// Initializes a new instance of the class.
33+
/// </summary>
34+
/// <param name="logManager">The log manager.</param>
35+
public Log(ILogManager logManager)
36+
{
37+
_logManager = logManager;
38+
}
39+
40+
/// <summary>
41+
/// Processing of the resource.
42+
/// </summary>
43+
/// <param name="renderContext">The context for rendering the page.</param>
44+
/// <param name="visualTree">The visual tree of the web application.</param>
45+
public void Process(IRenderContext renderContext, VisualTreeWebAppSetting visualTree)
46+
{
47+
var downloadUri = renderContext.Request.Uri.Concat("download");
48+
var log = _logManager?.DefaultLog.Filename;
49+
var file = new FileInfo(log);
50+
var fileSize = string.Format
51+
(
52+
new FileSizeFormatProvider()
53+
{
54+
Culture = renderContext?.Request?.Culture
55+
},
56+
"{0:fs}",
57+
file.Exists ? file.Length : 0
58+
);
59+
60+
var deleteForm = new ControlModalFormConfirmDelete("delte_log")
61+
{
62+
Header = I18N.Translate
63+
(
64+
renderContext,
65+
"webexpress.webapp:setting.logfile.delete.header"
66+
),
67+
Content = new ControlFormItemStaticText()
68+
{
69+
Text = I18N.Translate
70+
(
71+
renderContext,
72+
"webexpress.webapp:setting.logfile.delete.description"
73+
)
74+
}
75+
};
76+
77+
deleteForm.Confirm += (s, e) =>
78+
{
79+
File.Delete(log);
80+
};
81+
82+
var switchOnForm = new ControlModalFormConfirm("swichon_log")
83+
{
84+
// Header = this.I18N("webexpress.webapp", "setting.logfile.switchon.header"),
85+
// Content = new ControlFormItemStaticText() { Text = this.I18N("webexpress.webapp", "setting.logfile.switchon.description") },
86+
// SubmitButtonIcon = new PropertyIcon(TypeIcon.PowerOff),
87+
// SubmitButtonColor = new PropertyColorButton(TypeColorButton.Success),
88+
// SubmitButtonLabel = this.I18N("webexpress.webapp", "setting.logfile.switchon.label")
89+
};
90+
91+
switchOnForm.Confirm += (s, e) =>
92+
{
93+
// context.PluginContext.Host.Log.LogMode = LogMode.Override;
94+
// context.PluginContext.Host.Log.Info(this.I18N("webexpress.webapp", "setting.logfile.switchon.success"));
95+
};
96+
97+
var info = new ControlTable()
98+
{
99+
Striped = TypeStripedTable.Row
100+
}
101+
.AddColumn("")
102+
.AddColumn("")
103+
.AddColumn("")
104+
.AddRow
105+
(
106+
new ControlTableCell()
107+
{
108+
Text = I18N.Translate
109+
(
110+
renderContext, "webexpress.webapp:setting.logfile.path"
111+
)
112+
},
113+
new ControlTableCell()
114+
{
115+
Text = log,
116+
//Format = TypeFormatText.Code
117+
},
118+
downloadUri != null && file.Exists
119+
? new ControlTableCellPanel()
120+
.Add(new ControlButtonLink()
121+
{
122+
Text = I18N.Translate
123+
(
124+
renderContext,
125+
"webexpress.webapp:setting.logfile.download"
126+
),
127+
Icon = new IconDownload(),
128+
BackgroundColor = new PropertyColorButton(TypeColorButton.Primary),
129+
Uri = downloadUri
130+
})
131+
: new ControlTableCell()
132+
)
133+
.AddRow
134+
(
135+
new ControlTableCell()
136+
{
137+
Text = I18N.Translate
138+
(
139+
renderContext,
140+
"webexpress.webapp:setting.logfile.size"
141+
)
142+
},
143+
new ControlTableCell()
144+
{
145+
Text = file.Exists ? fileSize : "n.a."
146+
//Format = TypeFormatText.Code
147+
},
148+
file.Exists
149+
? new ControlTableCellPanel()
150+
.Add(new ControlButton()
151+
{
152+
Text = I18N.Translate
153+
(
154+
renderContext,
155+
"webexpress.webapp:setting.logfile.delete.label"
156+
),
157+
//Modal = new PropertyModal(TypeModal.Modal, deleteForm),
158+
Icon = new IconTrashAlt(),
159+
BackgroundColor = new PropertyColorButton(TypeColorButton.Danger)
160+
})
161+
: new ControlTableCell()
162+
)
163+
.AddRow
164+
(
165+
new ControlTableCell()
166+
{
167+
Text = I18N.Translate
168+
(
169+
renderContext,
170+
"webexpress.webapp:setting.logfile.modus"
171+
)
172+
},
173+
new ControlTableCell()
174+
{
175+
Text = _logManager?.DefaultLog.LogMode.ToString()
176+
//Format = TypeFormatText.Code
177+
},
178+
_logManager?.DefaultLog.LogMode == LogMode.Off
179+
? new ControlTableCellPanel()
180+
.Add(new ControlButton()
181+
{
182+
Text = I18N.Translate
183+
(
184+
renderContext,
185+
"webexpress.webapp:setting.logfile.switchon.label"
186+
),
187+
//Modal = new PropertyModal(TypeModal.Modal, switchOnForm),
188+
Icon = new IconPowerOff(),
189+
BackgroundColor = new PropertyColorButton(TypeColorButton.Success)
190+
})
191+
: new ControlTableCell()
192+
);
193+
194+
visualTree.Content.MainPanel
195+
.AddPrimary(new ControlText()
196+
{
197+
Text = I18N.Translate
198+
(
199+
renderContext,
200+
"webexpress.webapp:setting.logfile.label"
201+
),
202+
TextColor = new PropertyColorText(TypeColorText.Info),
203+
Margin = new PropertySpacingMargin(PropertySpacing.Space.Two)
204+
})
205+
.AddPrimary(info);
206+
207+
if (file.Exists)
208+
{
209+
var content = File.ReadLines(log).TakeLast(100);
210+
211+
visualTree.Content.MainPanel
212+
.AddPrimary(new ControlText()
213+
{
214+
Text = I18N.Translate
215+
(
216+
renderContext,
217+
"webexpress.webapp:setting.logfile.extract"
218+
),
219+
Format = TypeFormatText.H3
220+
})
221+
.AddPrimary(new ControlText()
222+
{
223+
Text = string.Join("<br/>", content.Reverse()),
224+
Format = TypeFormatText.Code
225+
});
226+
}
227+
}
228+
}
229+
}
230+

src/WebExpress.WebApp/WebControl/ControlWebAppHeadline.cs

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace WebExpress.WebApp.WebControl
1313
/// <summary>
1414
/// Headline for an web app.
1515
/// </summary>
16-
public class ControlWebAppHeadline : Control
16+
public class ControlWebAppHeadline : Control, IControlWebAppHeadline
1717
{
1818
private readonly List<IControl> _prologue = [];
1919
private readonly List<IControl> _preferences = [];
@@ -49,7 +49,7 @@ public class ControlWebAppHeadline : Control
4949
/// <summary>
5050
/// Returns the more control.
5151
/// </summary>
52-
public ControlWebAppHeadlineMore More { get; } = new ControlWebAppHeadlineMore("wx-content-main-headline-more")
52+
public IControlWebAppHeadlineMore More { get; } = new ControlWebAppHeadlineMore("wx-content-main-headline-more")
5353
{
5454
};
5555

@@ -66,90 +66,120 @@ public ControlWebAppHeadline(string id = null)
6666
/// Adds items to the prologue area.
6767
/// </summary>
6868
/// <param name="items">The items to add to the prologue area.</param>
69-
public void AddPrologue(params IControl[] items)
69+
/// <returns>The current instance for method chaining.</returns>
70+
public IControlWebAppHeadline AddPrologue(params IControl[] items)
7071
{
7172
_prologue.AddRange(items);
73+
74+
return this;
7275
}
7376

7477
/// <summary>
7578
/// Removes an item from the prologue area.
7679
/// </summary>
7780
/// <param name="item">The item to remove from the prologue area.</param>
78-
public void RemovePrologue(IControl item)
81+
/// <returns>The current instance for method chaining.</returns>
82+
public IControlWebAppHeadline RemovePrologue(IControl item)
7983
{
8084
_prologue.Remove(item);
85+
86+
return this;
8187
}
8288

8389
/// <summary>
8490
/// Adds items to the preferences area.
8591
/// </summary>
8692
/// <param name="items">The items to add to the preferences area.</param>
87-
public void AddPreferences(params IControl[] items)
93+
/// <returns>The current instance for method chaining.</returns>
94+
public IControlWebAppHeadline AddPreferences(params IControl[] items)
8895
{
8996
_preferences.AddRange(items);
97+
98+
return this;
9099
}
91100

92101
/// <summary>
93102
/// Removes an item from the preferences area.
94103
/// </summary>
95104
/// <param name="item">The item to remove from the preferences area.</param>
96-
public void RemovePreference(IControl item)
105+
/// <returns>The current instance for method chaining.</returns>
106+
public IControlWebAppHeadline RemovePreference(IControl item)
97107
{
98108
_preferences.Remove(item);
109+
110+
return this;
99111
}
100112

101113
/// <summary>
102114
/// Adds items to the primary area.
103115
/// </summary>
104116
/// <param name="items">The items to add to the primary area.</param>
105-
public void AddPrimary(params IControl[] items)
117+
/// <returns>The current instance for method chaining.</returns>
118+
public IControlWebAppHeadline AddPrimary(params IControl[] items)
106119
{
107120
_primary.AddRange(items);
121+
122+
return this;
108123
}
109124

110125
/// <summary>
111126
/// Removes an item from the primary area.
112127
/// </summary>
113128
/// <param name="item">The item to remove from the primary area.</param>
114-
public void RemovePrimary(IControl item)
129+
/// <returns>The current instance for method chaining.</returns>
130+
public IControlWebAppHeadline RemovePrimary(IControl item)
115131
{
116132
_primary.Remove(item);
133+
134+
return this;
117135
}
118136

119137
/// <summary>
120138
/// Adds items to the secondary area.
121139
/// </summary>
122140
/// <param name="items">The items to add to the secondary area.</param>
123-
public void AddSecondary(params IControl[] items)
141+
/// <returns>The current instance for method chaining.</returns>
142+
public IControlWebAppHeadline AddSecondary(params IControl[] items)
124143
{
125144
_secondary.AddRange(items);
145+
146+
return this;
126147
}
127148

128149
/// <summary>
129150
/// Removes an item from the secondary area.
130151
/// </summary>
131152
/// <param name="item">The item to remove from the secondary area.</param>
132-
public void RemoveSecondary(IControl item)
153+
/// <returns>The current instance for method chaining.</returns>
154+
public IControlWebAppHeadline RemoveSecondary(IControl item)
133155
{
134156
_secondary.Remove(item);
157+
158+
return this;
135159
}
136160

137161
/// <summary>
138162
/// Adds items to the metadata area.
139163
/// </summary>
140164
/// <param name="items">The items to add to the metadata area.</param>
141-
public void AddMetadata(params IControl[] items)
165+
/// <returns>The current instance for method chaining.</returns>
166+
public IControlWebAppHeadline AddMetadata(params IControl[] items)
142167
{
143168
_metadata.AddRange(items);
169+
170+
return this;
144171
}
145172

146173
/// <summary>
147174
/// Removes an item from the metadata area.
148175
/// </summary>
149176
/// <param name="item">The item to remove from the metadata area.</param>
150-
public void RemoveMetadata(IControl item)
177+
/// <returns>The current instance for method chaining.</returns>
178+
public IControlWebAppHeadline RemoveMetadata(IControl item)
151179
{
152180
_metadata.Remove(item);
181+
182+
return this;
153183
}
154184

155185
/// <summary>

0 commit comments

Comments
 (0)