From 09f0caeac3f501220ff3076679f16eca9e11bf6e Mon Sep 17 00:00:00 2001 From: Lars van der Lee Date: Sat, 24 Jul 2021 00:20:32 +0100 Subject: [PATCH] Load old logs, export to .md, buttons, close tabs --- .../Interfaces/IBaseDiaryEntry.cs | 9 -- RevolveTestDiaryXf/Interfaces/IDebrief.cs | 14 --- RevolveTestDiaryXf/Interfaces/IDiaryEntry.cs | 10 -- RevolveTestDiaryXf/Interfaces/IDiaryGoal.cs | 16 --- RevolveTestDiaryXf/Interfaces/ILocation.cs | 13 -- RevolveTestDiaryXf/Interfaces/IPerson.cs | 13 -- RevolveTestDiaryXf/Interfaces/ISession.cs | 17 --- RevolveTestDiaryXf/Interfaces/ITestDay.cs | 27 ----- RevolveTestDiaryXf/Models/Debrief.cs | 17 ++- RevolveTestDiaryXf/Models/DiaryEntry.cs | 19 ++- RevolveTestDiaryXf/Models/DiaryGoal.cs | 11 +- RevolveTestDiaryXf/Models/Person.cs | 16 ++- RevolveTestDiaryXf/Models/Session.cs | 23 ++-- RevolveTestDiaryXf/Models/TestDay.cs | 113 ++++++++++++++---- RevolveTestDiaryXf/Models/TestLocation.cs | 12 +- .../PublishProfiles/FolderProfile.pubxml | 3 +- .../PublishProfiles/FolderProfile.pubxml.user | 2 +- RevolveTestDiaryXf/RevolveTestDiaryXf.csproj | 2 +- .../ViewModels/MainWindowViewModel.cs | 65 ++++++++-- RevolveTestDiaryXf/Views/MainWindow.axaml | 28 +++-- 20 files changed, 226 insertions(+), 204 deletions(-) delete mode 100644 RevolveTestDiaryXf/Interfaces/IBaseDiaryEntry.cs delete mode 100644 RevolveTestDiaryXf/Interfaces/IDebrief.cs delete mode 100644 RevolveTestDiaryXf/Interfaces/IDiaryEntry.cs delete mode 100644 RevolveTestDiaryXf/Interfaces/IDiaryGoal.cs delete mode 100644 RevolveTestDiaryXf/Interfaces/ILocation.cs delete mode 100644 RevolveTestDiaryXf/Interfaces/IPerson.cs delete mode 100644 RevolveTestDiaryXf/Interfaces/ISession.cs delete mode 100644 RevolveTestDiaryXf/Interfaces/ITestDay.cs diff --git a/RevolveTestDiaryXf/Interfaces/IBaseDiaryEntry.cs b/RevolveTestDiaryXf/Interfaces/IBaseDiaryEntry.cs deleted file mode 100644 index cef43b7..0000000 --- a/RevolveTestDiaryXf/Interfaces/IBaseDiaryEntry.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace RevolveTestDiaryXf.Interfaces -{ - public interface IBaseDiaryEntry - { - DateTime Timestamp { get; set; } - } -} diff --git a/RevolveTestDiaryXf/Interfaces/IDebrief.cs b/RevolveTestDiaryXf/Interfaces/IDebrief.cs deleted file mode 100644 index ae01a91..0000000 --- a/RevolveTestDiaryXf/Interfaces/IDebrief.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace RevolveTestDiaryXf.Interfaces -{ - public interface IDebrief - { - event EventHandler TriggerAutoSaveEvent; - string WhatWentWell { get; set; } - string WhatCanBeImproved { get; set; } - string IssuesDiscovered { get; set; } - } -} diff --git a/RevolveTestDiaryXf/Interfaces/IDiaryEntry.cs b/RevolveTestDiaryXf/Interfaces/IDiaryEntry.cs deleted file mode 100644 index a10ff74..0000000 --- a/RevolveTestDiaryXf/Interfaces/IDiaryEntry.cs +++ /dev/null @@ -1,10 +0,0 @@ -using RevolveTestDiaryXf.Enums; - -namespace RevolveTestDiaryXf.Interfaces -{ - public interface IDiaryEntry : IBaseDiaryEntry - { - EntryType EntryType { get; set; } - string Body { get; set; } - } -} diff --git a/RevolveTestDiaryXf/Interfaces/IDiaryGoal.cs b/RevolveTestDiaryXf/Interfaces/IDiaryGoal.cs deleted file mode 100644 index dba0d2a..0000000 --- a/RevolveTestDiaryXf/Interfaces/IDiaryGoal.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RevolveTestDiaryXf.Interfaces -{ - public interface IDiaryGoal - { - event EventHandler TriggerAutoSaveEvent; - bool Achieved { get; set; } - - string Goal { get; set; } - } -} diff --git a/RevolveTestDiaryXf/Interfaces/ILocation.cs b/RevolveTestDiaryXf/Interfaces/ILocation.cs deleted file mode 100644 index 5a384d8..0000000 --- a/RevolveTestDiaryXf/Interfaces/ILocation.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RevolveTestDiaryXf.Interfaces -{ - public interface ILocation - { - string Location { get; set; } - } -} diff --git a/RevolveTestDiaryXf/Interfaces/IPerson.cs b/RevolveTestDiaryXf/Interfaces/IPerson.cs deleted file mode 100644 index 953f561..0000000 --- a/RevolveTestDiaryXf/Interfaces/IPerson.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RevolveTestDiaryXf.Interfaces -{ - public interface IPerson - { - string Name { get; set; } - } -} diff --git a/RevolveTestDiaryXf/Interfaces/ISession.cs b/RevolveTestDiaryXf/Interfaces/ISession.cs deleted file mode 100644 index 8a87bb1..0000000 --- a/RevolveTestDiaryXf/Interfaces/ISession.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RevolveTestDiaryXf.Interfaces -{ - public interface ISession : IBaseDiaryEntry - { - event EventHandler TriggerAutoSaveEvent; - string Title { get; set; } - ObservableCollection SessionEntries { get; set; } - void AddDiaryEntryCommand(); - } -} diff --git a/RevolveTestDiaryXf/Interfaces/ITestDay.cs b/RevolveTestDiaryXf/Interfaces/ITestDay.cs deleted file mode 100644 index bec8337..0000000 --- a/RevolveTestDiaryXf/Interfaces/ITestDay.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RevolveTestDiaryXf.Interfaces -{ - public interface ITestDay : IBaseDiaryEntry - { - event EventHandler TriggerAutoSaveEvent; - IPerson EsoAsr { get; set; } - - ILocation Location { get; set; } - - IDebrief Debrief { get; set; } - - ObservableCollection Goals { get; set; } - - ObservableCollection Sessions { get; set; } - - void AddGoalCommand(); - - void AddSessionCommand(); - } -} diff --git a/RevolveTestDiaryXf/Models/Debrief.cs b/RevolveTestDiaryXf/Models/Debrief.cs index ca3a27a..153e4c4 100644 --- a/RevolveTestDiaryXf/Models/Debrief.cs +++ b/RevolveTestDiaryXf/Models/Debrief.cs @@ -1,11 +1,8 @@ -using RevolveTestDiaryXf.Interfaces; -using System; -using System.Collections.Generic; -using System.Text; +using System; namespace RevolveTestDiaryXf.Models { - public class Debrief : IDebrief + public class Debrief { private string whatWentWell; @@ -15,6 +12,14 @@ public string WhatWentWell set { whatWentWell = value; TriggerAutoSaveEvent?.Invoke(this, this); } } + public Debrief() { } + public Debrief(string whatWentWell, string whatCanBeImproved, string issuesDiscovered) + { + WhatWentWell = whatWentWell; + WhatCanBeImproved = whatCanBeImproved; + IssuesDiscovered = issuesDiscovered; + } + private string whatCanBeImproved; public string WhatCanBeImproved @@ -32,6 +37,6 @@ public string IssuesDiscovered } - public event EventHandler TriggerAutoSaveEvent; + public event EventHandler TriggerAutoSaveEvent; } } diff --git a/RevolveTestDiaryXf/Models/DiaryEntry.cs b/RevolveTestDiaryXf/Models/DiaryEntry.cs index 559e166..e208e85 100644 --- a/RevolveTestDiaryXf/Models/DiaryEntry.cs +++ b/RevolveTestDiaryXf/Models/DiaryEntry.cs @@ -1,15 +1,30 @@ using RevolveTestDiaryXf.Enums; -using RevolveTestDiaryXf.Interfaces; using System; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text.Json.Serialization; namespace RevolveTestDiaryXf.Models { - public class DiaryEntry : IDiaryEntry + public class DiaryEntry { public DateTime Timestamp { get; set; } + public DiaryEntry(DateTime timestamp, EntryType entryType, string body) + { + Timestamp = timestamp; + EntryType = entryType; + Body = body; + } + public DiaryEntry() + { + + } + public string TimestampString => Timestamp.ToShortTimeString(); + [JsonIgnore] + public ObservableCollection EntryTypes => new ObservableCollection(Enum.GetValues(typeof(EntryType)).Cast()); public EntryType EntryType { get; set; } public string Body { get; set; } diff --git a/RevolveTestDiaryXf/Models/DiaryGoal.cs b/RevolveTestDiaryXf/Models/DiaryGoal.cs index a0d92b3..8838a84 100644 --- a/RevolveTestDiaryXf/Models/DiaryGoal.cs +++ b/RevolveTestDiaryXf/Models/DiaryGoal.cs @@ -1,9 +1,8 @@ -using RevolveTestDiaryXf.Interfaces; -using System; +using System; namespace RevolveTestDiaryXf.Models { - public class DiaryGoal : IDiaryGoal + public class DiaryGoal { private bool achieved; @@ -36,6 +35,10 @@ public DiaryGoal(string goal) Achieved = false; } - public event EventHandler TriggerAutoSaveEvent; + public DiaryGoal() + { + + } + public event EventHandler TriggerAutoSaveEvent; } } diff --git a/RevolveTestDiaryXf/Models/Person.cs b/RevolveTestDiaryXf/Models/Person.cs index 74d5b11..3e11230 100644 --- a/RevolveTestDiaryXf/Models/Person.cs +++ b/RevolveTestDiaryXf/Models/Person.cs @@ -1,13 +1,6 @@ -using RevolveTestDiaryXf.Interfaces; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace RevolveTestDiaryXf.Models +namespace RevolveTestDiaryXf.Models { - public class Person : IPerson + public class Person { public string Name { get; set; } @@ -15,5 +8,10 @@ public Person(string name) { Name = name; } + + public Person() + { + + } } } diff --git a/RevolveTestDiaryXf/Models/Session.cs b/RevolveTestDiaryXf/Models/Session.cs index e05674b..496298f 100644 --- a/RevolveTestDiaryXf/Models/Session.cs +++ b/RevolveTestDiaryXf/Models/Session.cs @@ -1,24 +1,22 @@ using ReactiveUI; using RevolveTestDiaryXf.Enums; -using RevolveTestDiaryXf.Interfaces; using RevolveTestDiaryXf.ViewModels; using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Text.Json.Serialization; namespace RevolveTestDiaryXf.Models { - public class Session : ViewModelBase, ISession + public class Session : ViewModelBase { public DateTime Timestamp { get; set; } + public string Title { get; set; } - public ObservableCollection SessionEntries { get; set; } + public ObservableCollection SessionEntries { get; set; } private string newEntryBody; - + [JsonIgnore] public string NewEntryBody { get { return newEntryBody; } @@ -27,23 +25,26 @@ public string NewEntryBody private EntryType entryType; - public event EventHandler TriggerAutoSaveEvent; - + public event EventHandler TriggerAutoSaveEvent; + [JsonIgnore] public EntryType NewEntryType { get { return entryType; } set { entryType = value; } } + [JsonIgnore] public ObservableCollection EntryTypes => new ObservableCollection(Enum.GetValues(typeof(EntryType)).Cast()); public Session(string title) { Timestamp = DateTime.Now; Title = title; - SessionEntries = new ObservableCollection(); + SessionEntries = new ObservableCollection(); } + public Session() { } + public void AddDiaryEntryCommand() { var diaryEntry = new DiaryEntry(NewEntryType, NewEntryBody); @@ -52,7 +53,7 @@ public void AddDiaryEntryCommand() TriggerAutoSaveEvent?.Invoke(this, this); } - public void AddDiaryEntry(IDiaryEntry entry) + public void AddDiaryEntry(DiaryEntry entry) { SessionEntries.Add(entry); this.RaisePropertyChanged(nameof(SessionEntries)); diff --git a/RevolveTestDiaryXf/Models/TestDay.cs b/RevolveTestDiaryXf/Models/TestDay.cs index c8a1457..4953a00 100644 --- a/RevolveTestDiaryXf/Models/TestDay.cs +++ b/RevolveTestDiaryXf/Models/TestDay.cs @@ -1,46 +1,50 @@ -using Avalonia.Controls.Selection; +using Avalonia.Controls; using ReactiveUI; -using RevolveTestDiaryXf.Interfaces; using RevolveTestDiaryXf.ViewModels; +using RevolveTestDiaryXf.Views; using System; -using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; +using System.Text; +using System.Text.Json.Serialization; namespace RevolveTestDiaryXf.Models { - public class TestDay : ViewModelBase, ITestDay + public class TestDay : ViewModelBase { public DateTime Timestamp { get; set; } - public IPerson EsoAsr { get; set; } + public Person EsoAsr { get; set; } - public ILocation Location { get; set; } - public IDebrief Debrief { get; set; } + public TestLocation Location { get; set; } + public Debrief Debrief { get; set; } - public ObservableCollection Goals { get; set; } - public SelectionModel SelectionGoals { get; } + public ObservableCollection Goals { get; set; } private string newGoalBody; + [JsonIgnore] public string NewGoalBody { get { return newGoalBody; } set { this.RaiseAndSetIfChanged(ref newGoalBody, value); } } - public ObservableCollection Sessions { get; set; } + public ObservableCollection Sessions { get; set; } private string newSessionTitle; - public event EventHandler TriggerAutoSaveEvent; + public event EventHandler TriggerAutoSaveEvent; + public event EventHandler CloseTestDayEvent; + [JsonIgnore] public string NewSessionTitle { get { return newSessionTitle; } set { this.RaiseAndSetIfChanged(ref newSessionTitle, value); } } - public TestDay(ILocation location, IPerson esoAsr) + public TestDay(TestLocation location, Person esoAsr) { Location = location; Timestamp = DateTime.Now; @@ -48,17 +52,25 @@ public TestDay(ILocation location, IPerson esoAsr) Debrief = new Debrief(); Debrief.TriggerAutoSaveEvent += TriggerAutoSaveFromDebrief; - Goals = new ObservableCollection(); - Sessions = new ObservableCollection(); - SelectionGoals = new SelectionModel(); - SelectionGoals.SelectionChanged += SelectionGoalsChanged; - + Goals = new ObservableCollection(); + Sessions = new ObservableCollection(); } + public TestDay(DateTime timestamp, Person esoAsr, TestLocation location, Debrief debrief, ObservableCollection goals, string newGoalBody, ObservableCollection sessions, string newSessionTitle) + { + Timestamp = timestamp; + EsoAsr = esoAsr; + Location = location; + Debrief = debrief; + Goals = goals; + NewGoalBody = newGoalBody; + Sessions = sessions; + NewSessionTitle = newSessionTitle; + } - private void SelectionGoalsChanged(object? sender, SelectionModelSelectionChangedEventArgs e) + public TestDay() { - return; + } public void AddGoalCommand() @@ -69,7 +81,7 @@ public void AddGoalCommand() AddGoal(goal); TriggerAutoSaveEvent.Invoke(this, this); } - public void AddGoal(IDiaryGoal goal) + public void AddGoal(DiaryGoal goal) { Goals.Add(goal); this.RaisePropertyChanged(nameof(Goals)); @@ -84,25 +96,78 @@ public void AddSessionCommand() TriggerAutoSaveEvent.Invoke(this, this); } - private void TriggerAutoSaveFromSession(object? sender, ISession e) + private void TriggerAutoSaveFromSession(object? sender, Session e) { TriggerAutoSaveEvent.Invoke(this, this); } - private void TriggerAutoSaveFromGoal(object? sender, IDiaryGoal e) + private void TriggerAutoSaveFromGoal(object? sender, DiaryGoal e) { TriggerAutoSaveEvent.Invoke(this, this); } - private void TriggerAutoSaveFromDebrief(object? sender, IDebrief e) + private void TriggerAutoSaveFromDebrief(object? sender, Debrief e) { TriggerAutoSaveEvent.Invoke(this, this); } - public void AddSession(ISession session) + public void AddSession(Session session) { Sessions.Add(session); this.RaisePropertyChanged(nameof(Sessions)); } + + public void CloseTestDay() + { + CloseTestDayEvent?.Invoke(this, this); + } + + public async void ExportToMarkdown() + { + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filters.Add(new FileDialogFilter() { Name = "MarkDown", Extensions = { "md" } }); + var fileName = await saveFileDialog.ShowAsync(MainWindow.Instance); + if (fileName == null) + return; + + var stringBuilder = new StringBuilder(); + + stringBuilder.AppendLine($"# {Timestamp}"); + stringBuilder.AppendLine(""); + // Goals + stringBuilder.AppendLine($"## Goals"); + foreach (var goal in Goals) + { + stringBuilder.AppendLine($"- [{(goal.Achieved ? "X" : " ")}] {goal.Goal}"); + } + stringBuilder.AppendLine(""); + // Sessions + stringBuilder.AppendLine($"## Sessions"); + foreach (var session in Sessions) + { + stringBuilder.AppendLine($"### {session.Timestamp} - {session.Title}"); + + foreach (var entry in session.SessionEntries) + { + var tabs = entry.EntryType == Enums.EntryType.EVENT || entry.EntryType == Enums.EntryType.ISSUE ? "\t\t" : "\t"; + stringBuilder.AppendLine($"* {entry.Timestamp} - {entry.EntryType}:{tabs}{entry.Body}"); + } + stringBuilder.AppendLine(""); + } + + //Debrief + stringBuilder.AppendLine($"## Debrief"); + stringBuilder.AppendLine(""); + stringBuilder.AppendLine("### What went well today?"); + stringBuilder.AppendLine(Debrief.WhatWentWell); + stringBuilder.AppendLine(""); + stringBuilder.AppendLine("### What can be improved on from today?"); + stringBuilder.AppendLine(Debrief.WhatCanBeImproved); + stringBuilder.AppendLine(""); + stringBuilder.AppendLine("### What issues did we discover?"); + stringBuilder.AppendLine(Debrief.IssuesDiscovered); + + File.WriteAllTextAsync(fileName, stringBuilder.ToString()); + } } } diff --git a/RevolveTestDiaryXf/Models/TestLocation.cs b/RevolveTestDiaryXf/Models/TestLocation.cs index 34d6b24..1f59aa4 100644 --- a/RevolveTestDiaryXf/Models/TestLocation.cs +++ b/RevolveTestDiaryXf/Models/TestLocation.cs @@ -1,19 +1,17 @@ -using RevolveTestDiaryXf.Interfaces; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + namespace RevolveTestDiaryXf.Models { - public class TestLocation : ILocation + public class TestLocation { public string Location { get; set; } public TestLocation(string location) { Location = location; } + public TestLocation() + { + } } } diff --git a/RevolveTestDiaryXf/Properties/PublishProfiles/FolderProfile.pubxml b/RevolveTestDiaryXf/Properties/PublishProfiles/FolderProfile.pubxml index 2495057..24526d0 100644 --- a/RevolveTestDiaryXf/Properties/PublishProfiles/FolderProfile.pubxml +++ b/RevolveTestDiaryXf/Properties/PublishProfiles/FolderProfile.pubxml @@ -10,7 +10,8 @@ https://go.microsoft.com/fwlink/?LinkID=208121. FileSystem netcoreapp3.1 false - linux-x64 + win-x86 True + False \ No newline at end of file diff --git a/RevolveTestDiaryXf/Properties/PublishProfiles/FolderProfile.pubxml.user b/RevolveTestDiaryXf/Properties/PublishProfiles/FolderProfile.pubxml.user index 0fe2d53..245d7f6 100644 --- a/RevolveTestDiaryXf/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/RevolveTestDiaryXf/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - True|2021-07-22T22:40:30.9776005Z;True|2021-07-22T23:39:18.5301353+01:00;True|2021-07-22T23:29:19.7722048+01:00;True|2021-07-22T23:28:55.1739726+01:00;True|2021-07-22T23:28:30.5225280+01:00;True|2021-07-22T23:26:31.3242797+01:00;True|2021-07-22T23:24:51.1262948+01:00;False|2021-07-22T23:24:11.4380470+01:00;True|2021-07-22T23:22:47.8896701+01:00;False|2021-07-22T23:21:01.9118945+01:00;True|2021-07-22T23:20:02.2727035+01:00;True|2021-07-22T23:19:19.2709540+01:00;True|2021-07-22T23:16:55.5922301+01:00;True|2021-07-22T23:15:51.4190974+01:00;False|2021-07-22T23:15:03.3156239+01:00;True|2021-07-22T23:14:19.7324710+01:00;True|2021-07-22T23:12:31.5976603+01:00;False|2021-07-22T23:11:48.1206383+01:00;True|2021-07-22T23:10:44.0144142+01:00;True|2021-07-22T23:09:34.5315819+01:00;True|2021-07-22T23:08:20.5062411+01:00;True|2021-07-22T23:07:46.8030011+01:00;True|2021-07-22T22:59:53.1099845+01:00;True|2021-07-22T22:52:25.1583748+01:00;True|2021-07-22T22:52:05.8567743+01:00;True|2021-07-22T22:36:16.6413609+01:00;True|2021-07-22T22:29:15.6562188+01:00;True|2021-07-20T23:59:57.3230195+01:00;True|2021-07-20T23:59:06.2065642+01:00; + True|2021-07-23T23:19:50.3698139Z;True|2021-07-24T00:19:21.3372652+01:00;True|2021-07-22T23:40:30.9776005+01:00;True|2021-07-22T23:39:18.5301353+01:00;True|2021-07-22T23:29:19.7722048+01:00;True|2021-07-22T23:28:55.1739726+01:00;True|2021-07-22T23:28:30.5225280+01:00;True|2021-07-22T23:26:31.3242797+01:00;True|2021-07-22T23:24:51.1262948+01:00;False|2021-07-22T23:24:11.4380470+01:00;True|2021-07-22T23:22:47.8896701+01:00;False|2021-07-22T23:21:01.9118945+01:00;True|2021-07-22T23:20:02.2727035+01:00;True|2021-07-22T23:19:19.2709540+01:00;True|2021-07-22T23:16:55.5922301+01:00;True|2021-07-22T23:15:51.4190974+01:00;False|2021-07-22T23:15:03.3156239+01:00;True|2021-07-22T23:14:19.7324710+01:00;True|2021-07-22T23:12:31.5976603+01:00;False|2021-07-22T23:11:48.1206383+01:00;True|2021-07-22T23:10:44.0144142+01:00;True|2021-07-22T23:09:34.5315819+01:00;True|2021-07-22T23:08:20.5062411+01:00;True|2021-07-22T23:07:46.8030011+01:00;True|2021-07-22T22:59:53.1099845+01:00;True|2021-07-22T22:52:25.1583748+01:00;True|2021-07-22T22:52:05.8567743+01:00;True|2021-07-22T22:36:16.6413609+01:00;True|2021-07-22T22:29:15.6562188+01:00;True|2021-07-20T23:59:57.3230195+01:00;True|2021-07-20T23:59:06.2065642+01:00; \ No newline at end of file diff --git a/RevolveTestDiaryXf/RevolveTestDiaryXf.csproj b/RevolveTestDiaryXf/RevolveTestDiaryXf.csproj index 29490a8..04a1faa 100644 --- a/RevolveTestDiaryXf/RevolveTestDiaryXf.csproj +++ b/RevolveTestDiaryXf/RevolveTestDiaryXf.csproj @@ -7,7 +7,7 @@ RevolveTestDiaryXf.Program - 2.1.0 + 3.0.0 Revolve NTNU Revolve NTNU diff --git a/RevolveTestDiaryXf/ViewModels/MainWindowViewModel.cs b/RevolveTestDiaryXf/ViewModels/MainWindowViewModel.cs index f8f7731..f88c765 100644 --- a/RevolveTestDiaryXf/ViewModels/MainWindowViewModel.cs +++ b/RevolveTestDiaryXf/ViewModels/MainWindowViewModel.cs @@ -1,25 +1,19 @@ using Avalonia.Controls; using Microsoft.VisualBasic.FileIO; using ReactiveUI; -using RevolveTestDiaryXf.Interfaces; using RevolveTestDiaryXf.Models; using RevolveTestDiaryXf.Views; using System.Collections.ObjectModel; using System.IO; -using System.Linq; using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; namespace RevolveTestDiaryXf.ViewModels { class MainWindowViewModel : ViewModelBase { - private SynchronizationContext _syncContext = SynchronizationContext.Current; + private ObservableCollection testDays; - private ObservableCollection testDays; - - public ObservableCollection TestDays + public ObservableCollection TestDays { get { @@ -31,17 +25,27 @@ public ObservableCollection TestDays } } + private TestDay _selectedTestDay; + + public TestDay SelectedTestDay + { + get { return _selectedTestDay; } + set { _selectedTestDay = value; } + } + + public MainWindowViewModel() { var testDay = new TestDay(new TestLocation("NONE"), new Person("ESO/ASR")); testDay.TriggerAutoSaveEvent += SaveTestDay; - TestDays = new ObservableCollection + testDay.CloseTestDayEvent += CloseTestDay; + TestDays = new ObservableCollection { testDay }; } - public async void SaveTestDay(object sender, ITestDay testDay) + public async void SaveTestDay(object sender, TestDay testDay) { var folder = Path.Combine(SpecialDirectories.MyDocuments, "RevolveTestDiary"); if (!Directory.Exists(folder)) @@ -54,7 +58,7 @@ public async void SaveTestDay(object sender, ITestDay testDay) if (file == null || testDay == null) return; - var options = new JsonSerializerOptions { WriteIndented = true }; + var options = new JsonSerializerOptions { WriteIndented = true, }; var jsonString = JsonSerializer.Serialize(testDay, options); await File.WriteAllTextAsync(Path.Combine(folder, file), jsonString); @@ -68,9 +72,33 @@ public void SaveAllTestDaysCommand() } } - public void AddDebriefCommand() + public async void LoadTestDayFromFileCommand() { + OpenFileDialog openFileDialog = new OpenFileDialog(); + var files = await openFileDialog.ShowAsync(MainWindow.Instance); + foreach (var file in files) + { + if (File.Exists(file)) + { + using (var stream = File.OpenRead(file)) + { + if (stream != null) + { + try + { + TestDay testDay = await JsonSerializer.DeserializeAsync(stream, typeof(TestDay)) as TestDay; + if (testDay != null) + TestDays.Add(testDay); + } + catch (JsonException e) + { + // Invalid JSON file, carry on I guess + } + } + } + } + } } public void NewDayCommand() @@ -79,5 +107,18 @@ public void NewDayCommand() testDay.TriggerAutoSaveEvent += SaveTestDay; TestDays.Add(testDay); } + + public void CloseTestDay(object sender, TestDay testDay) + { + if (testDay != null && TestDays.Contains(testDay)) + { + TestDays.Remove(testDay); + } + } + + public void ExportTestDayCommand() + { + SelectedTestDay?.ExportToMarkdown(); + } } } diff --git a/RevolveTestDiaryXf/Views/MainWindow.axaml b/RevolveTestDiaryXf/Views/MainWindow.axaml index d0f74fd..be1a69d 100644 --- a/RevolveTestDiaryXf/Views/MainWindow.axaml +++ b/RevolveTestDiaryXf/Views/MainWindow.axaml @@ -6,7 +6,7 @@ mc:Ignorable="d" x:Class="RevolveTestDiaryXf.Views.MainWindow" Title="RevolveTestDiaryXf" - xmlns:local="clr-namespace:Interfaces" Height="1000" Width="960" + xmlns:local="clr-namespace:Interfaces" Height="700" Width="960" Icon="resm:RevolveTestDiaryXf.Resources.rtd_xf.ico">