-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FR-163 - started adding support for external calendar feeds
- Loading branch information
reven
committed
Apr 22, 2023
1 parent
d4d93c2
commit a5bc7d7
Showing
22 changed files
with
762 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
@namespace Fenrus.Components | ||
|
||
@inherits Fenrus.Pages.CommonPage<Fenrus.Models.CalendarFeed> | ||
|
||
<FenrusPage Title="@lblTitle" Icon="fa-solid fa-puzzle-piece" PageDescription="@lblDescription"> | ||
<Body> | ||
|
||
<FenrusTable TItem="Models.CalendarFeed" Data=@Items @ref="Table"> | ||
<ToolBar> | ||
<FenrusTableButton Label="@lblAdd" Icon="fa-solid fa-plus" Clicked="() => Add()" /> | ||
</ToolBar> | ||
<Columns> | ||
<FenrusTableColumn TItem="Models.CalendarFeed" ColumnName="Name"> | ||
<Header>@lblName</Header> | ||
<Cell Context="item"> | ||
<i class="fa-solid fa-puzzle-piece"></i> | ||
<a href="#" @onclick="() => Edit(item)" @onclick:preventDefault="true">@item.Name</a> | ||
</Cell> | ||
</FenrusTableColumn> | ||
<FenrusTableColumn TItem="Models.CalendarFeed" ColumnName="Enabled" Width="10rem"> | ||
<Header>@lblEnabled</Header> | ||
<Cell Context="item"> | ||
<FenrusSwitch Value="@item.Enabled" ValueChanged="@((value) => ItemEnabled(item, value))"></FenrusSwitch> | ||
</Cell> | ||
</FenrusTableColumn> | ||
<FenrusTableColumn TItem="Models.CalendarFeed" ColumnName="Actions" Width="10rem"> | ||
<Header></Header> | ||
<Cell Context="item"> | ||
<div class="actions"> | ||
<a title="@lblEdit" class="fa-solid fa-pen-to-square" @onclick="() => Edit(item)"></a> | ||
<span title="@lblDelete" class="fa-solid fa-trash" @onclick="() => Remove(item)"></span> | ||
</div> | ||
</Cell> | ||
</FenrusTableColumn> | ||
</Columns> | ||
</FenrusTable> | ||
|
||
</Body> | ||
</FenrusPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using Fenrus.Components.SideEditors; | ||
using Fenrus.Models; | ||
using Fenrus.Pages; | ||
|
||
namespace Fenrus.Components; | ||
|
||
/// <summary> | ||
/// Page for Calendars | ||
/// </summary> | ||
public partial class PageCalendar : CommonPage<Models.CalendarFeed> | ||
{ | ||
public List<Models.CalendarFeed> Items { get; set; } = new(); | ||
|
||
private FenrusTable<Models.CalendarFeed> Table { get; set; } | ||
|
||
private string lblTitle, lblDescription; | ||
|
||
protected override Task PostGotUser() | ||
{ | ||
lblTitle = Translator.Instant("Pages.Calendar.Title" + (IsSystem ? "-System" : string.Empty)); | ||
lblDescription = Translator.Instant("Pages.Calendar.Labels.PageDescription" + (IsSystem ? "-System" : string.Empty)); | ||
var service = new CalendarFeedService(); | ||
Items = (IsSystem ? service.GetAllSystem() : service.GetAllForUser(UserUid)).OrderBy(x => x.Name).ToList(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
/// <summary> | ||
/// Enables an item | ||
/// </summary> | ||
/// <param name="item">the item being enabled</param> | ||
/// <param name="enabled">the enabled state</param> | ||
private void ItemEnabled(CalendarFeed item, bool enabled) | ||
{ | ||
item.Enabled = enabled; | ||
new CalendarFeedService().Enable(item.Uid, enabled); | ||
} | ||
|
||
protected override bool DoDelete(CalendarFeed item) | ||
{ | ||
var service = new CalendarFeedService(); | ||
service.Delete(item.Uid); | ||
Items = Items.Where(x => x.Uid != item.Uid).ToList(); | ||
Table.SetData(Items); | ||
return true; | ||
} | ||
/// <summary> | ||
/// Edits a calendar feed | ||
/// </summary> | ||
/// <param name="feed">the calendar feed being edited</param> | ||
private async Task Edit(CalendarFeed feed) | ||
{ | ||
var result = await Popup.OpenEditor<CalendarFeedEditor, CalendarFeed>(Translator, feed, new () | ||
{ | ||
{ nameof(CalendarFeedEditor.IsSystem), IsSystem }, | ||
{ nameof(CalendarFeedEditor.Settings), Settings } | ||
}); | ||
if (result.Success == false) | ||
return; | ||
feed.Name = result.Data.Name; | ||
feed.Url = result.Data.Url; | ||
feed.Type = result.Data.Type; | ||
Items = Items.OrderBy(x => x.Name).ToList(); | ||
Table.SetData(Items); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a new calendar feed | ||
/// </summary> | ||
protected override async Task Add() | ||
{ | ||
var result = await Popup.OpenEditor<CalendarFeedEditor, CalendarFeed>(Translator, null, new () | ||
{ | ||
{ nameof(CalendarFeedEditor.IsSystem), IsSystem }, | ||
{ nameof(CalendarFeedEditor.Settings), Settings } | ||
}); | ||
if (result.Success == false) | ||
return; | ||
Items.Add(result.Data); | ||
Items = Items.OrderBy(x => x.Name).ToList(); | ||
Table.SetData(Items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Components/SideEditors/CalendarFeedEditor/CalendarFeedEditor.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@namespace Fenrus.Components.SideEditors | ||
@using Fenrus.Models | ||
@inherits SideEditorBase | ||
|
||
<SideEditor Title=@Title @ref=Editor> | ||
<Buttons> | ||
<button class="btn" @onclick="() => Save()">@lblSave</button> | ||
<button class="btn" @onclick="() => Cancel()">@lblCancel</button> | ||
</Buttons> | ||
<Body> | ||
<InputText Page="Calendar" Label="Name" @bind-Value="@Model.Name" /> | ||
<InputText Page="Calendar" Label="Url" @bind-Value="@Model.Url" /> | ||
<InputSelect Page="Calendar" TItem="CalendarFeedType" Label="Type" @bind-Value="@Model.Type"> | ||
<InputSelectOption TItem="CalendarFeedType" StringValue="iCal" Label="iCal" /> | ||
</InputSelect> | ||
</Body> | ||
</SideEditor> |
132 changes: 132 additions & 0 deletions
132
Components/SideEditors/CalendarFeedEditor/CalendarFeedEditor.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using Fenrus.Models; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace Fenrus.Components.SideEditors; | ||
|
||
/// <summary> | ||
/// Calendar Feed Editor | ||
/// </summary> | ||
public partial class CalendarFeedEditor: SideEditorBase | ||
{ | ||
/// <summary> | ||
/// Gets or sets the item this is editing, leave null for a new item | ||
/// </summary> | ||
[Parameter] public CalendarFeed? Item { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the callback when this editor is saved | ||
/// </summary> | ||
[Parameter] public EventCallback<CalendarFeed> OnSaved { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the callback when this editor is canceled | ||
/// </summary> | ||
[Parameter] public EventCallback OnCanceled { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets if this is a system calendar feed | ||
/// </summary> | ||
[Parameter] public bool IsSystem { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the user settings | ||
/// </summary> | ||
[Parameter] public UserSettings Settings { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the bound model the user is editing | ||
/// </summary> | ||
private CalendarFeed Model; | ||
|
||
/// <summary> | ||
/// Gets or sets the title of the editor | ||
/// </summary> | ||
private string Title; | ||
|
||
/// <summary> | ||
/// Gets or sets if this is an editor for a new item | ||
/// </summary> | ||
private bool IsNew; | ||
|
||
/// <summary> | ||
/// Gets or sets the side editor instance | ||
/// </summary> | ||
private SideEditor Editor { get; set; } | ||
|
||
private string Icon { get; set; } | ||
|
||
private string lblSave, lblCancel; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
Model = new(); | ||
IsNew = false; | ||
this.lblSave = Translator.Instant("Labels.Save"); | ||
this.lblCancel = Translator.Instant("Labels.Cancel"); | ||
|
||
if (Item != null) | ||
{ | ||
Title = Translator.Instant("Pages.Calendar.Labels.EditCalendarFeed"); | ||
Model.Name = Item.Name; | ||
Model.Uid = Item.Uid; | ||
Model.Url = Item.Url; | ||
Model.Type = Item.Type; | ||
Model.Enabled = Item.Enabled; | ||
} | ||
else | ||
{ | ||
Title = Translator.Instant("Pages.Calendar.Labels.NewCalendarFeed"); | ||
Model.Name = string.Empty; | ||
Model.Uid = Guid.NewGuid(); | ||
Model.Url = string.Empty; | ||
Model.Type = CalendarFeedType.iCal; | ||
Model.Enabled = true; | ||
IsNew = true; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Save the editor | ||
/// </summary> | ||
async Task Save() | ||
{ | ||
// validate | ||
if (await Editor.Validate() == false) | ||
return; | ||
|
||
if (this.Model.Uid == Guid.Empty) | ||
this.Model.Uid = Guid.NewGuid(); | ||
|
||
string saveImage = ImageHelper.SaveImageFromBase64(Icon); | ||
|
||
var service = new CalendarFeedService(); | ||
if (IsNew) | ||
{ | ||
Model.Uid = Guid.NewGuid(); | ||
Model.IsSystem = IsSystem; | ||
|
||
Model.UserUid = IsSystem ? Guid.Empty : Settings.UserUid; | ||
service.Add(Model); | ||
} | ||
else | ||
{ | ||
var existing = service.GetByUid(this.Model.Uid); | ||
existing.Enabled = Model.Enabled; | ||
existing.IsSystem = IsSystem; | ||
|
||
existing.Name = Model.Name; | ||
existing.Url = Model.Url; | ||
service.Update(existing); | ||
} | ||
|
||
await OnSaved.InvokeAsync(Model); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Cancels the editor | ||
/// </summary> | ||
/// <returns>a task to await</returns> | ||
Task Cancel() | ||
=> OnCanceled.InvokeAsync(); | ||
} |
1 change: 0 additions & 1 deletion
1
Components/SideEditors/SearchEngineEditor/SearchEngineEditor.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.