Notebook layout and episodes page
This commit is contained in:
@@ -14,12 +14,22 @@ namespace EstusShots.Gtk
|
||||
internal class MainWindow : Window
|
||||
{
|
||||
private const string ApiUrl = "http://localhost:5000/api/";
|
||||
|
||||
[UI] private readonly Label _infoLabel = null;
|
||||
[UI] public readonly Button LoadButton = null;
|
||||
[UI] public readonly Box LoadingSpinner = null;
|
||||
[UI] public readonly Button NewSeasonButton = null;
|
||||
[UI] public readonly Button AddEpisodeButton = null;
|
||||
[UI] public readonly Overlay SeasonsOverlay = null;
|
||||
[UI] public readonly Overlay EpisodesOverlay = null;
|
||||
[UI] public readonly TreeView SeasonsView = null;
|
||||
[UI] public readonly TreeView EpisodesTreeView = null;
|
||||
[UI] public readonly Notebook Navigation = null;
|
||||
[UI] public readonly Box EpisodesPage = null;
|
||||
|
||||
private EstusShotsClient Client { get; }
|
||||
private BindableListControl<Season> SeasonsControl { get; set; }
|
||||
private BindableListControl<Episode> EpisodesControl { get; set; }
|
||||
|
||||
public MainWindow() : this(new Builder("MainWindow.glade"))
|
||||
{
|
||||
@@ -28,40 +38,82 @@ namespace EstusShots.Gtk
|
||||
private MainWindow(Builder builder) : base(builder.GetObject("MainWindow").Handle)
|
||||
{
|
||||
builder.Autoconnect(this);
|
||||
Client = new EstusShotsClient("http://localhost:5000/api/");
|
||||
Client = new EstusShotsClient(ApiUrl);
|
||||
|
||||
DeleteEvent += Window_DeleteEvent;
|
||||
LoadButton.Clicked += LoadButtonClicked;
|
||||
NewSeasonButton.Clicked += NewSeasonButtonOnClicked;
|
||||
AddEpisodeButton.Clicked += AddEpisodeButtonOnClicked;
|
||||
|
||||
var seasonsColumns = new List<DataColumn>
|
||||
{
|
||||
new DataColumn(nameof(Season.DisplayName)) {Title = "Name"},
|
||||
new DataColumn(nameof(Season.Description)) {Title = "Description"},
|
||||
new DataColumn(nameof(Season.Start))
|
||||
{
|
||||
Title = "Start",
|
||||
Format = date => (date as DateTime?)?.ToString("dd.MM.yyyy hh:mm")
|
||||
}
|
||||
};
|
||||
SeasonsControl = new BindableListControl<Season>(seasonsColumns, nameof(Season.SeasonId), SeasonsView);
|
||||
SeasonsControl.OnSelectionChanged += SeasonsViewOnOnSelectionChanged;
|
||||
InitSeasonsControl();
|
||||
InitEpisodesControl();
|
||||
|
||||
// The episodes page is not shown, as long as no season is selected
|
||||
EpisodesPage.Hide();
|
||||
|
||||
Info("Application Started");
|
||||
|
||||
// No need to wait for the loading to finnish
|
||||
var _ = ReloadSeasons();
|
||||
}
|
||||
|
||||
private EstusShotsClient Client { get; }
|
||||
private BindableListControl<Season> SeasonsControl { get; }
|
||||
private void InitSeasonsControl()
|
||||
{
|
||||
var columns = new List<DataColumn>
|
||||
{
|
||||
new DataColumn(nameof(Season.DisplayName)) {Title = "Name"},
|
||||
new DataColumn(nameof(Season.Description)) {Title = "Description"},
|
||||
new DataColumn(nameof(Season.Start))
|
||||
{
|
||||
Title = "Start",
|
||||
Format = date => (date as DateTime?)?.ToString("dd.MM.yyyy")
|
||||
},
|
||||
new DataColumn(nameof(Season.End))
|
||||
{
|
||||
Title = "End",
|
||||
Format = date => (date as DateTime?)?.ToString("dd.MM.yyyy") ?? "Ongoing"
|
||||
}
|
||||
};
|
||||
SeasonsControl = new BindableListControl<Season>(columns, nameof(Season.SeasonId), SeasonsView);
|
||||
SeasonsControl.OnSelectionChanged += SeasonsViewOnOnSelectionChanged;
|
||||
}
|
||||
|
||||
private void InitEpisodesControl()
|
||||
{
|
||||
var columns = new List<DataColumn>
|
||||
{
|
||||
new DataColumn(nameof(Episode.DisplayName)) {Title = "Name"},
|
||||
new DataColumn(nameof(Episode.Title)) {Title = "Title"},
|
||||
new DataColumn(nameof(Episode.Date))
|
||||
{
|
||||
Title = "Date",
|
||||
Format = d => (d as DateTime?)?.ToString("dd.MM.yyyy")
|
||||
},
|
||||
new DataColumn(nameof(Episode.Start))
|
||||
{
|
||||
Title = "Start",
|
||||
Format = d => (d as DateTime?)?.ToString("HH:mm")
|
||||
|
||||
},
|
||||
new DataColumn(nameof(Episode.End))
|
||||
{
|
||||
Title = "End",
|
||||
Format = d => (d as DateTime?)?.ToString("HH:mm") ?? "Ongoing"
|
||||
}
|
||||
};
|
||||
EpisodesControl = new BindableListControl<Episode>(columns, nameof(Episode.EpisodeId), EpisodesTreeView);
|
||||
}
|
||||
|
||||
private async void SeasonsViewOnOnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (!(e.Selection is Season season)) return;
|
||||
using var _ = new LoadingMode(this);
|
||||
|
||||
// TODO this is test code
|
||||
EpisodesPage.Show();
|
||||
var parameter = new GetEpisodesParameter(season.SeasonId);
|
||||
var res = await Client.Episodes.GetEpisodes(parameter);
|
||||
EpisodesControl.Items = res.Data.Episodes;
|
||||
EpisodesControl.DataBind();
|
||||
Info($"{season.DisplayName}: {res.Data.Episodes.Count} episodes");
|
||||
}
|
||||
|
||||
@@ -86,6 +138,47 @@ namespace EstusShots.Gtk
|
||||
await ReloadSeasons();
|
||||
Info("Created new Season");
|
||||
}
|
||||
|
||||
private async void AddEpisodeButtonOnClicked(object sender, EventArgs e)
|
||||
{
|
||||
if (SeasonsControl.SelectedItem == null) return;
|
||||
using var _ = new LoadingMode(this);
|
||||
|
||||
var season = SeasonsControl.SelectedItem;
|
||||
|
||||
// Some random test data
|
||||
var rand = new Random();
|
||||
var start = new DateTime(
|
||||
DateTime.Today.Year,
|
||||
DateTime.Today.Month,
|
||||
DateTime.Today.Day,
|
||||
DateTime.Today.Hour + rand.Next(0, 12),
|
||||
DateTime.Today.Minute + rand.Next(0, 59),
|
||||
DateTime.Today.Second
|
||||
);
|
||||
var end = start.AddHours(rand.Next(2, 4));
|
||||
|
||||
var ep = new Episode
|
||||
{
|
||||
SeasonId = season.SeasonId,
|
||||
Number = EpisodesControl.Items.Any() ? EpisodesControl.Items.Max(x => x.Number) + 1 : 1,
|
||||
Title = $"An Episode in season '{season.Game}'",
|
||||
Date = DateTime.Today,
|
||||
Start = start,
|
||||
End = end
|
||||
};
|
||||
|
||||
var parameter = new SaveEpisodeParameter(ep);
|
||||
var res = await Client.Episodes.SaveEpisode(parameter);
|
||||
|
||||
if (!res.OperationResult.Success)
|
||||
{
|
||||
Info($"Cannot add episode: {res.OperationResult.ShortMessage}");
|
||||
return;
|
||||
}
|
||||
|
||||
await ReloadEpisodes();
|
||||
}
|
||||
|
||||
private async void LoadButtonClicked(object sender, EventArgs a)
|
||||
{
|
||||
@@ -106,7 +199,23 @@ namespace EstusShots.Gtk
|
||||
|
||||
SeasonsControl.Items = res.Data.Seasons;
|
||||
SeasonsControl.DataBind();
|
||||
Info("List Refreshed");
|
||||
Info("Seasons Refreshed");
|
||||
}
|
||||
|
||||
private async Task ReloadEpisodes()
|
||||
{
|
||||
var seasonId = SeasonsControl.SelectedItem.SeasonId;
|
||||
var res = await Task.Factory.StartNew(
|
||||
() => Client.Episodes.GetEpisodes(new GetEpisodesParameter(seasonId)).Result);
|
||||
if (!res.OperationResult.Success)
|
||||
{
|
||||
_infoLabel.Text = $"Refresh Failed: {res.OperationResult.ShortMessage}";
|
||||
return;
|
||||
}
|
||||
|
||||
EpisodesControl.Items = res.Data.Episodes;
|
||||
EpisodesControl.DataBind();
|
||||
Info("Episodes Refreshed");
|
||||
}
|
||||
|
||||
private void Window_DeleteEvent(object sender, DeleteEventArgs a)
|
||||
@@ -118,6 +227,5 @@ namespace EstusShots.Gtk
|
||||
{
|
||||
_infoLabel.Text = message;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user