132 lines
5.0 KiB
Plaintext
132 lines
5.0 KiB
Plaintext
@using Interfaces
|
|
@using Oqtane.Modules.Controls
|
|
@using SZUAbsolventenverein.Module.BlackBoard.Services
|
|
@using SZUAbsolventenverein.Module.BlackBoard.Models
|
|
|
|
@namespace SZUAbsolventenverein.Module.BlackBoard
|
|
@inherits ModuleBase
|
|
@inject IBlackBoardService BlackBoardService
|
|
@inject NavigationManager NavigationManager
|
|
@inject IStringLocalizer<Edit> Localizer
|
|
@inject IReportUI ReportingComponent
|
|
|
|
<form @ref="form" class="@(validated ? " was-validated" : "needs-validation")" novalidate>
|
|
<div class="container">
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="name" HelpText="Enter a name" ResourceKey="Name">Name: </Label>
|
|
<div class="col-sm-9">
|
|
<input id="name" class="form-control" @bind="@_blackBoard.Name" required/>
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="image" HelpText="Enter a description" ResourceKey="Description">Beschreibung: </Label>
|
|
<div class="col-sm-9">
|
|
<FileManager AnonymizeUploadFilenames="true" id="image" UploadMultiple="false" ShowSuccess="true" FileId="@_blackBoard.ImageID" OnSelectFile="@OnFileSelected"/>
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="" For="description" HelpText="Enter a description" ResourceKey="Description">Beschreibung: </Label>
|
|
<RichTextEditor @ref="RichTextEditorHtml" Content="@_blackBoard.Description" id="description" Placeholder="Enter a description: "/>
|
|
</div>
|
|
</div>
|
|
<button type="button" class="btn btn-success" @onclick="Save">@Localizer["Save"]</button>
|
|
<NavLink class="btn btn-secondary" href="@NavigateUrl()">@Localizer["Cancel"]</NavLink>
|
|
|
|
@if (ReportingComponent != null)
|
|
{
|
|
<DynamicComponent Type="@ReportingComponent.ReportType" Parameters="@_parameters"/>
|
|
}
|
|
|
|
<br/><br/>
|
|
@if (PageState.Action == "Edit")
|
|
{
|
|
<AuditInfo CreatedBy="@_blackBoard.CreatedBy" CreatedOn="@_blackBoard.CreatedOn" ModifiedBy="@_blackBoard.ModifiedBy" ModifiedOn="@_blackBoard.ModifiedOn"></AuditInfo>
|
|
}
|
|
</form>
|
|
|
|
@code {
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit;
|
|
|
|
public override string RenderMode => RenderModes.Interactive;
|
|
|
|
public override string Actions => "Add,Edit";
|
|
|
|
public override string Title => "Manage BlackBoard";
|
|
|
|
public override List<Resource> Resources => [new Stylesheet("_content/SZUAbsolventenverein.Module.BlackBoard/Module.css")];
|
|
|
|
private RichTextEditor RichTextEditorHtml;
|
|
private ElementReference form;
|
|
private bool validated;
|
|
|
|
private int _id;
|
|
|
|
// TODO
|
|
private BlackBoard _blackBoard = new BlackBoard();
|
|
private Dictionary<string, object> _parameters = new Dictionary<string, object>();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
if (PageState.Action == "Edit")
|
|
{
|
|
_id = Int32.Parse(PageState.QueryString["id"]);
|
|
_blackBoard = await BlackBoardService.GetBlackBoardAsync(_id, ModuleState.ModuleId);
|
|
if (_blackBoard != null)
|
|
{
|
|
_parameters = ReportingComponent.ConstructParameterList(_blackBoard, RenderModeBoundary);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Loading BlackBoard {BlackBoardId} {Error}", _id, ex.Message);
|
|
AddModuleMessage(Localizer["Message.LoadError"], MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private Task OnFileSelected(int fileId)
|
|
{
|
|
Console.WriteLine("File Selected: " + fileId);
|
|
_blackBoard.ImageID = fileId;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private async Task Save()
|
|
{
|
|
try
|
|
{
|
|
validated = true;
|
|
var interop = new Oqtane.UI.Interop(JSRuntime);
|
|
if (await interop.FormValid(form))
|
|
{
|
|
_blackBoard.Description = await RichTextEditorHtml.GetHtml();
|
|
if (PageState.Action == "Add")
|
|
{
|
|
_blackBoard.ModuleId = ModuleState.ModuleId;
|
|
_blackBoard = await BlackBoardService.AddBlackBoardAsync(_blackBoard);
|
|
await logger.LogInformation("BlackBoard Added {BlackBoard}", _blackBoard);
|
|
}
|
|
else
|
|
{
|
|
await BlackBoardService.UpdateBlackBoardAsync(_blackBoard);
|
|
await logger.LogInformation("BlackBoard Updated {BlackBoard}", _blackBoard);
|
|
}
|
|
|
|
NavigationManager.NavigateTo(NavigateUrl());
|
|
}
|
|
else
|
|
{
|
|
AddModuleMessage(Localizer["Message.SaveValidation"], MessageType.Warning);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Saving BlackBoard {Error}", ex.Message);
|
|
AddModuleMessage(Localizer["Message.SaveError"], MessageType.Error);
|
|
}
|
|
}
|
|
|
|
}
|