From d0be7524d3b1ad322095987d0653a6eef8436bc4 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sat, 1 Aug 2015 21:23:56 +0200 Subject: [PATCH 1/6] Make some classes ICloneable; implement SettingsRepositoryViewModel. --- Tests/Controller/SettingsRepositoryTest.cs | 22 -- Tests/Tests.csproj | 2 +- .../ViewModels/SettingsRepositoryViewModel.cs | 36 -- .../SettingsRepositoryViewModelTest.cs | 71 ++++ .../Controller/Elements/CustomText.cs | 7 + .../Controller/Elements/ElementBase.cs | 13 +- .../Controller/Elements/SelectEachDay.cs | 5 + .../Controller/Elements/SelectFirstDay.cs | 5 + .../Controller/Elements/SelectLastDay.cs | 5 + zaaReloaded2/Controller/Settings.cs | 24 +- zaaReloaded2/Controller/SettingsRepository.cs | 11 +- zaaReloaded2/ViewModels/ElementViewModel.cs | 2 +- .../ViewModels/SettingsRepositoryViewModel.cs | 330 ++++++++++++++++++ zaaReloaded2/ViewModels/SettingsViewModel.cs | 11 +- zaaReloaded2/zaaReloaded2.csproj | 1 + 15 files changed, 478 insertions(+), 67 deletions(-) delete mode 100755 Tests/ViewModels/SettingsRepositoryViewModel.cs create mode 100755 Tests/ViewModels/SettingsRepositoryViewModelTest.cs create mode 100755 zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs diff --git a/Tests/Controller/SettingsRepositoryTest.cs b/Tests/Controller/SettingsRepositoryTest.cs index 687aa36..e6b789a 100755 --- a/Tests/Controller/SettingsRepositoryTest.cs +++ b/Tests/Controller/SettingsRepositoryTest.cs @@ -56,27 +56,5 @@ namespace Tests.Controller Assert.AreEqual(1, sr.SettingsList.Count); Assert.AreEqual(testName, sr.SettingsList[0].Name); } - - [Test] - public void CreateDefaultSettings() - { - SettingsRepository sr = new SettingsRepository(); - sr.SettingsList.Add(new Settings("test1", null)); - sr.SettingsList.Add(new Settings("test2", null)); - sr.SettingsList.Add(new Settings("test3", null)); - sr.ResetDefault(); - - // Assert that there are now only the 2 default settings - Assert.AreEqual(2, sr.SettingsList.Count); - - Assert.AreEqual( - zaaReloaded2.Properties.Settings.Default.SettingsNameWard, - sr.SettingsList[0].Name, - "Settings for ward expected as #1 (index 0) in list"); - Assert.AreEqual( - zaaReloaded2.Properties.Settings.Default.SettingsNameClinic, - sr.SettingsList[1].Name, - "Settings for outpatient clinic expected as #2 (index 1) in list"); - } } } diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 4caecda..fb63329 100755 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -91,7 +91,7 @@ - + diff --git a/Tests/ViewModels/SettingsRepositoryViewModel.cs b/Tests/ViewModels/SettingsRepositoryViewModel.cs deleted file mode 100755 index badb4ef..0000000 --- a/Tests/ViewModels/SettingsRepositoryViewModel.cs +++ /dev/null @@ -1,36 +0,0 @@ -/* SettingsRepositoryViewModel.cs - * part of zaaReloaded2 - * - * Copyright 2015 Daniel Kraus - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using NUnit.Framework; -using zaaReloaded2.Controller; - -namespace Tests.ViewModels -{ - [TestFixture] - class SettingsRepositoryViewModel - { - [Test] - public void CannotDeleteDefaultSettings() - { - - } - } -} diff --git a/Tests/ViewModels/SettingsRepositoryViewModelTest.cs b/Tests/ViewModels/SettingsRepositoryViewModelTest.cs new file mode 100755 index 0000000..2adb414 --- /dev/null +++ b/Tests/ViewModels/SettingsRepositoryViewModelTest.cs @@ -0,0 +1,71 @@ +/* SettingsRepositoryViewModel.cs + * part of zaaReloaded2 + * + * Copyright 2015 Daniel Kraus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using zaaReloaded2.Controller; +using zaaReloaded2.ViewModels; + +namespace Tests.ViewModels +{ + [TestFixture] + class SettingsRepositoryViewModelTest + { + SettingsRepositoryViewModel _vm; + const string TESTNAME = "hello world"; + + [SetUp] + public void SetUp() + { + SettingsRepository rep = new SettingsRepository(); + rep.SettingsList.Add(new Settings(TESTNAME)); + _vm = new SettingsRepositoryViewModel(rep); + } + + [Test] + public void CanDeleteNonDefaultSettings() + { + _vm.SettingsList[_vm.SettingsList.Count - 1].IsSelected = true; + Assert.IsTrue(_vm.DeleteSettingsCommand.CanExecute(null)); + } + + [Test] + public void CannotDeleteDefaultSettings() + { + _vm.SettingsList[0].IsSelected = true; + Assert.IsFalse(_vm.DeleteSettingsCommand.CanExecute(null)); + } + + [Test] + public void CopySettings() + { + SettingsViewModel orig = _vm.SettingsList[0]; + orig.IsSelected = true; + _vm.CopySettingsCommand.Execute(null); + SettingsViewModel copy = _vm.SettingsList[_vm.SettingsList.Count-1]; + + // Make sure we have a new object + Assert.AreNotSame(orig, copy); + Assert.AreNotSame(orig.RevealModelObject(), copy.RevealModelObject()); + + Assert.AreEqual(String.Format("Kopie von {0}", orig.Name), copy.Name); + } + } +} diff --git a/zaaReloaded2/Controller/Elements/CustomText.cs b/zaaReloaded2/Controller/Elements/CustomText.cs index f3ebe9f..cbe1576 100755 --- a/zaaReloaded2/Controller/Elements/CustomText.cs +++ b/zaaReloaded2/Controller/Elements/CustomText.cs @@ -36,5 +36,12 @@ namespace zaaReloaded2.Controller.Elements { formatter.WriteParagraph(Content); } + + protected override ElementBase CreateInstance() + { + CustomText clone = new CustomText(); + clone.Content = Content; + return clone; + } } } diff --git a/zaaReloaded2/Controller/Elements/ElementBase.cs b/zaaReloaded2/Controller/Elements/ElementBase.cs index ae91011..ce13628 100755 --- a/zaaReloaded2/Controller/Elements/ElementBase.cs +++ b/zaaReloaded2/Controller/Elements/ElementBase.cs @@ -28,7 +28,7 @@ namespace zaaReloaded2.Controller.Elements /// Base class for formatting elements. /// [Serializable] - public abstract class ElementBase + public abstract class ElementBase : ICloneable { /// /// Returns the label for this formatting element. @@ -44,5 +44,16 @@ namespace zaaReloaded2.Controller.Elements /// Element belongs to. The Formatter object provides access /// to the current Word document etc. abstract public void Run(zaaReloaded2.Formatter.Formatter formatter); + + public object Clone() + { + return CreateInstance(); + } + + /// + /// Creates a new instance that can be used for cloning. + /// + /// New instance of a derived class. + protected abstract ElementBase CreateInstance(); } } diff --git a/zaaReloaded2/Controller/Elements/SelectEachDay.cs b/zaaReloaded2/Controller/Elements/SelectEachDay.cs index ef42a56..eed0093 100755 --- a/zaaReloaded2/Controller/Elements/SelectEachDay.cs +++ b/zaaReloaded2/Controller/Elements/SelectEachDay.cs @@ -43,5 +43,10 @@ namespace zaaReloaded2.Controller.Elements public SelectEachDay(IList formatElements) : base(formatElements) { } + + protected override ElementBase CreateInstance() + { + return new SelectEachDay(); + } } } diff --git a/zaaReloaded2/Controller/Elements/SelectFirstDay.cs b/zaaReloaded2/Controller/Elements/SelectFirstDay.cs index 930a585..f635948 100755 --- a/zaaReloaded2/Controller/Elements/SelectFirstDay.cs +++ b/zaaReloaded2/Controller/Elements/SelectFirstDay.cs @@ -47,5 +47,10 @@ namespace zaaReloaded2.Controller.Elements public SelectFirstDay(IList formatElements) : base(formatElements) { } + + protected override ElementBase CreateInstance() + { + return new SelectFirstDay(); + } } } diff --git a/zaaReloaded2/Controller/Elements/SelectLastDay.cs b/zaaReloaded2/Controller/Elements/SelectLastDay.cs index 2e2230d..2f5107a 100755 --- a/zaaReloaded2/Controller/Elements/SelectLastDay.cs +++ b/zaaReloaded2/Controller/Elements/SelectLastDay.cs @@ -48,5 +48,10 @@ namespace zaaReloaded2.Controller.Elements public SelectLastDay(IList formatElements) : base(formatElements) { } + + protected override ElementBase CreateInstance() + { + return new SelectLastDay(); + } } } diff --git a/zaaReloaded2/Controller/Settings.cs b/zaaReloaded2/Controller/Settings.cs index d4a120a..ba595ed 100755 --- a/zaaReloaded2/Controller/Settings.cs +++ b/zaaReloaded2/Controller/Settings.cs @@ -28,7 +28,7 @@ namespace zaaReloaded2.Controller /// Holds settings related to controlling laboratory output. /// [Serializable] - public class Settings + public class Settings : ICloneable { #region Properties @@ -49,13 +49,19 @@ namespace zaaReloaded2.Controller #endregion - #region Constructor + #region Constructors public Settings() { Elements = new List(); } + public Settings(string name) + : this() + { + Name = name; + } + /// /// Creates a new Settings object with an initial /// set of elements. @@ -94,5 +100,19 @@ namespace zaaReloaded2.Controller } #endregion + + #region Implementation of ICloneable + + public object Clone() + { + Settings clone = new Settings( + String.Format("Kopie von {0}", Name), + Elements.Select(e => e.Clone() as ElementBase).ToList() + ); + clone.ReferenceStyle = ReferenceStyle; + return clone; + } + + #endregion } } diff --git a/zaaReloaded2/Controller/SettingsRepository.cs b/zaaReloaded2/Controller/SettingsRepository.cs index 64ce8e4..0cf5cd4 100755 --- a/zaaReloaded2/Controller/SettingsRepository.cs +++ b/zaaReloaded2/Controller/SettingsRepository.cs @@ -62,22 +62,27 @@ namespace zaaReloaded2.Controller #endregion - #region Constructor + #region Constructors + /// + /// Creates a new instance of a settings repository that will + /// contain a default set of settings. + /// public SettingsRepository() { SettingsList = new List(); + CreateDefault(); } #endregion - #region Public methods + #region Private methods /// /// Resets the Settings contained in this SettingsRepository /// to the default set of settings. /// - public void ResetDefault() + private void CreateDefault() { SettingsList.Clear(); diff --git a/zaaReloaded2/ViewModels/ElementViewModel.cs b/zaaReloaded2/ViewModels/ElementViewModel.cs index b46a9e8..a14a865 100755 --- a/zaaReloaded2/ViewModels/ElementViewModel.cs +++ b/zaaReloaded2/ViewModels/ElementViewModel.cs @@ -26,7 +26,7 @@ using System.Collections.ObjectModel; namespace zaaReloaded2.ViewModels { - abstract class ElementViewModel : ViewModelBase + public abstract class ElementViewModel : ViewModelBase { #region Properties diff --git a/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs b/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs new file mode 100755 index 0000000..24ea5b1 --- /dev/null +++ b/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs @@ -0,0 +1,330 @@ +/* SettingsRepositoryViewModel.cs + * part of zaaReloaded2 + * + * Copyright 2015 Daniel Kraus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Bovender.Mvvm; +using Bovender.Mvvm.ViewModels; +using Bovender.Mvvm.Messaging; +using zaaReloaded2.Controller; + +namespace zaaReloaded2.ViewModels +{ + public class SettingsRepositoryViewModel : ViewModelBase + { + #region Properties + + public IList SettingsList { get; private set; } + + public SettingsViewModel Selected { get; private set; } + + #endregion + + #region Commands + + public DelegatingCommand AddSettingsCommand + { + get + { + if (_addSettingsCommand == null) + { + _addSettingsCommand = new DelegatingCommand( + param => DoAddSettings()); + } + return _addSettingsCommand; + } + } + + public DelegatingCommand EditSettingsCommand + { + get + { + if (_editSettingsCommand == null) + { + _editSettingsCommand = new DelegatingCommand( + param => DoEditSettings(), + param => CanEditSettings()); + } + return _editSettingsCommand; + } + } + + public DelegatingCommand UseSettingsCommand + { + get + { + if (_useSettingsCommand == null) + { + _useSettingsCommand = new DelegatingCommand( + param => DoUseSettings(), + param => CanUseSettings()); + } + return _useSettingsCommand; + } + } + + public DelegatingCommand DeleteSettingsCommand + { + get + { + if (_deleteSettingsCommand == null) + { + _deleteSettingsCommand = new DelegatingCommand( + param => DoDeleteSettings(), + param => CanDeleteSettings()); + } + return _deleteSettingsCommand; + } + } + + public DelegatingCommand CopySettingsCommand + { + get + { + if (_copySettingsCommand == null) + { + _copySettingsCommand = new DelegatingCommand( + param => DoCopySettings()); + } + return _copySettingsCommand; + } + } + + public DelegatingCommand ResetSettingsCommand + { + get + { + if (_resetSettingsCommand == null) + { + _resetSettingsCommand = new DelegatingCommand( + param => DoResetSettings()); + } + return _resetSettingsCommand; + } + } + + #endregion + + #region Messages + + Message EditSettingsMessage + { + get + { + if (_editSettingsMessage == null) + { + _editSettingsMessage = new Message(); + } + return _editSettingsMessage; + } + } + + Message UseSettingsMessage + { + get + { + if (_useSettingsMessage == null) + { + _useSettingsMessage = new Message(); + } + return _useSettingsMessage; + } + } + + Message ConfirmDeleteSettingsMessage + { + get + { + if (_confirmDeleteSettingsMessage == null) + { + _confirmDeleteSettingsMessage = new Message(); + } + return _confirmDeleteSettingsMessage; + } + } + + Message ConfirmResetSettingsMessage + { + get + { + if (_confirmResetSettingsMessage == null) + { + _confirmResetSettingsMessage = new Message(); + } + return _confirmResetSettingsMessage; + } + } + + #endregion + + #region Constructors + + public SettingsRepositoryViewModel(SettingsRepository repository) + { + _repository = repository; + SettingsList = new List(); + foreach (Settings s in repository.SettingsList) + { + SettingsViewModel vm = new SettingsViewModel(s); + vm.PropertyChanged += SettingsViewModel_PropertyChanged; + SettingsList.Add(vm); + } + } + + #endregion + + #region Private methods + + void DoEditSettings() + { + if (CanEditSettings()) + { + EditSettingsMessage.Send(new ViewModelMessageContent(Selected)); + } + } + + bool CanEditSettings() + { + return Selected != null && !IsDefaultSettings(); + } + + void DoUseSettings() + { + UseSettingsMessage.Send(new ViewModelMessageContent(Selected)); + } + + bool CanUseSettings() + { + return Selected != null; + } + + void DoAddSettings() + { + Settings s = new Settings("Neu"); + SettingsViewModel vm = new SettingsViewModel(s); + _repository.SettingsList.Add(s); + SettingsList.Add(vm); + vm.IsSelected = true; + } + + bool CanDeleteSettings() + { + return Selected != null && !IsDefaultSettings(); + } + + void DoDeleteSettings() + { + if (CanDeleteSettings()) + { + ConfirmDeleteSettingsMessage.Send( + new ViewModelMessageContent(Selected), + param => ConfirmDeleteSettings(param)); + } + } + + void ConfirmDeleteSettings(ViewModelMessageContent content) + { + SettingsViewModel vm = content.ViewModel as SettingsViewModel; + if (CanDeleteSettings() && content.Confirmed) + { + _repository.SettingsList.Remove(vm.RevealModelObject() as Settings); + SettingsList.Remove(vm); + } + } + + void DoResetSettings() + { + ConfirmResetSettingsMessage.Send( + new ViewModelMessageContent(this), + param => ConfirmResetSettings(param)); + } + + void ConfirmResetSettings(ViewModelMessageContent content) + { + if (content.Confirmed) + { + + } + } + + void DoCopySettings() + { + if (Selected != null) + { + SettingsViewModel copy = Selected.Clone() as SettingsViewModel; + SettingsList.Add(copy); + _repository.SettingsList.Add(copy.RevealModelObject() as Settings); + } + } + + void SettingsViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + SettingsViewModel vm = sender as SettingsViewModel; + if (vm != null && e.PropertyName == "IsSelected") + { + Selected = vm.IsSelected ? vm : null; + } + } + + /// + /// Determines whether the selected SettingsViewModel belongs + /// to one of the default settings. + /// + bool IsDefaultSettings() + { + if (Selected != null) + { + return + (Selected.Name == zaaReloaded2.Properties.Settings.Default.SettingsNameClinic + || Selected.Name == zaaReloaded2.Properties.Settings.Default.SettingsNameWard); + } + else + { + return false; + } + } + + #endregion + + #region Implementation of ViewModelBase + + public override object RevealModelObject() + { + return _repository; + } + + #endregion + + #region Fields + + SettingsRepository _repository; + DelegatingCommand _useSettingsCommand; + DelegatingCommand _addSettingsCommand; + DelegatingCommand _editSettingsCommand; + DelegatingCommand _deleteSettingsCommand; + DelegatingCommand _resetSettingsCommand; + DelegatingCommand _copySettingsCommand; + Message _confirmDeleteSettingsMessage; + Message _confirmResetSettingsMessage; + Message _editSettingsMessage; + Message _useSettingsMessage; + + #endregion + } +} diff --git a/zaaReloaded2/ViewModels/SettingsViewModel.cs b/zaaReloaded2/ViewModels/SettingsViewModel.cs index 6ab8849..b573097 100755 --- a/zaaReloaded2/ViewModels/SettingsViewModel.cs +++ b/zaaReloaded2/ViewModels/SettingsViewModel.cs @@ -31,7 +31,7 @@ namespace zaaReloaded2.ViewModels /// /// View model for the zaaReloaded2.Controller.Settings class. /// - class SettingsViewModel : ViewModelBase + public class SettingsViewModel : ViewModelBase, ICloneable { #region Properties @@ -238,6 +238,15 @@ namespace zaaReloaded2.ViewModels #endregion + #region Implementation of ICloneable + + public object Clone() + { + return new SettingsViewModel(_settings.Clone() as Settings); + } + + #endregion + #region Fields Settings _settings; diff --git a/zaaReloaded2/zaaReloaded2.csproj b/zaaReloaded2/zaaReloaded2.csproj index 0258aff..07a446a 100755 --- a/zaaReloaded2/zaaReloaded2.csproj +++ b/zaaReloaded2/zaaReloaded2.csproj @@ -222,6 +222,7 @@ + AboutView.xaml From 286ddb16415b359906dbee4f54fe838cf31fbc9a Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sun, 2 Aug 2015 07:11:16 +0200 Subject: [PATCH 2/6] Fix cloning of SettingsViewModels. --- .../SettingsRepositoryViewModelTest.cs | 1 + .../ViewModels/SettingsRepositoryViewModel.cs | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Tests/ViewModels/SettingsRepositoryViewModelTest.cs b/Tests/ViewModels/SettingsRepositoryViewModelTest.cs index 2adb414..ff434a1 100755 --- a/Tests/ViewModels/SettingsRepositoryViewModelTest.cs +++ b/Tests/ViewModels/SettingsRepositoryViewModelTest.cs @@ -66,6 +66,7 @@ namespace Tests.ViewModels Assert.AreNotSame(orig.RevealModelObject(), copy.RevealModelObject()); Assert.AreEqual(String.Format("Kopie von {0}", orig.Name), copy.Name); + Assert.IsTrue(copy.IsSelected); } } } diff --git a/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs b/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs index 24ea5b1..11a764b 100755 --- a/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs +++ b/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs @@ -182,8 +182,7 @@ namespace zaaReloaded2.ViewModels foreach (Settings s in repository.SettingsList) { SettingsViewModel vm = new SettingsViewModel(s); - vm.PropertyChanged += SettingsViewModel_PropertyChanged; - SettingsList.Add(vm); + AddSettingsViewModel(vm); } } @@ -268,8 +267,10 @@ namespace zaaReloaded2.ViewModels if (Selected != null) { SettingsViewModel copy = Selected.Clone() as SettingsViewModel; - SettingsList.Add(copy); _repository.SettingsList.Add(copy.RevealModelObject() as Settings); + AddSettingsViewModel(copy); + Selected.IsSelected = false; + copy.IsSelected = true; } } @@ -300,6 +301,17 @@ namespace zaaReloaded2.ViewModels } } + /// + /// Adds a settings view model to the collection and wires the + /// PropertyChanged event. + /// + /// SettingsViewModel to add. + void AddSettingsViewModel(SettingsViewModel settingsViewModel) + { + settingsViewModel.PropertyChanged += SettingsViewModel_PropertyChanged; + SettingsList.Add(settingsViewModel); + } + #endregion #region Implementation of ViewModelBase From 9fd0907310812991b868b17dd6fb0cdac1f95e5e Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sun, 2 Aug 2015 07:19:12 +0200 Subject: [PATCH 3/6] Implement unique IDs for settings. --- zaaReloaded2/Controller/Settings.cs | 7 +++++++ zaaReloaded2/Controller/SettingsRepository.cs | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/zaaReloaded2/Controller/Settings.cs b/zaaReloaded2/Controller/Settings.cs index ba595ed..46b1593 100755 --- a/zaaReloaded2/Controller/Settings.cs +++ b/zaaReloaded2/Controller/Settings.cs @@ -47,6 +47,12 @@ namespace zaaReloaded2.Controller /// public IList Elements { get; private set; } + /// + /// Gets the unique ID of this Settings object. The unique + /// ID is not included in deep-copying (cloning). + /// + public Guid Uid { get; private set; } + #endregion #region Constructors @@ -54,6 +60,7 @@ namespace zaaReloaded2.Controller public Settings() { Elements = new List(); + Uid = Guid.NewGuid(); } public Settings(string name) diff --git a/zaaReloaded2/Controller/SettingsRepository.cs b/zaaReloaded2/Controller/SettingsRepository.cs index 0cf5cd4..a8e55cb 100755 --- a/zaaReloaded2/Controller/SettingsRepository.cs +++ b/zaaReloaded2/Controller/SettingsRepository.cs @@ -76,6 +76,21 @@ namespace zaaReloaded2.Controller #endregion + #region Public methods + + /// + /// Looks up a Settings object contained in this repository + /// by unique ID. + /// + /// GUID to look for. + /// Settings object with this GUID, or null if the + /// GUID was not found. + public Settings FindByGuid(Guid uid) + { + return SettingsList.FirstOrDefault(s => s.Uid == uid); + } + #endregion + #region Private methods /// From 1e4c3681f2fa4612f5a8ad042d6cf4efc7fd2803 Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sun, 2 Aug 2015 21:51:58 +0200 Subject: [PATCH 4/6] Implement ElementPickerViewModel; initial SettingsViewModelTest. --- Tests/ViewModels/SettingsViewModelTest.cs | 12 +- zaaReloaded2/ViewModels/CategoryViewModel.cs | 46 +++++++ .../ViewModels/ControlElementViewModel.cs | 11 ++ .../ViewModels/ElementPickerViewModel.cs | 122 ++++++++++++++++++ zaaReloaded2/ViewModels/SettingsViewModel.cs | 49 +++++-- zaaReloaded2/zaaReloaded2.csproj | 2 + 6 files changed, 230 insertions(+), 12 deletions(-) create mode 100755 zaaReloaded2/ViewModels/CategoryViewModel.cs create mode 100755 zaaReloaded2/ViewModels/ElementPickerViewModel.cs diff --git a/Tests/ViewModels/SettingsViewModelTest.cs b/Tests/ViewModels/SettingsViewModelTest.cs index f06d5d8..65a1d56 100755 --- a/Tests/ViewModels/SettingsViewModelTest.cs +++ b/Tests/ViewModels/SettingsViewModelTest.cs @@ -22,6 +22,7 @@ using System.Text; using NUnit.Framework; using zaaReloaded2.ViewModels; using zaaReloaded2.Controller; +using zaaReloaded2.Controller.Elements; namespace Tests.ViewModels { @@ -51,7 +52,16 @@ namespace Tests.ViewModels [Test] public void CannotAddChildElementToFormatElement() { - + ControlElementViewModel parent = new ControlElementViewModel( + new SelectFirstDay()); + _settingsVM.AddElementViewModel(parent); + parent.IsSelected = true; + Assert.IsTrue(_settingsVM.AddChildElementCommand.CanExecute(null)); + FormatElementViewModel child = new FormatElementViewModel(new Items()); + parent.AddChildElement(child); + parent.IsSelected = false; + child.IsSelected = true; + Assert.IsFalse(_settingsVM.AddChildElementCommand.CanExecute(null)); } [Test] diff --git a/zaaReloaded2/ViewModels/CategoryViewModel.cs b/zaaReloaded2/ViewModels/CategoryViewModel.cs new file mode 100755 index 0000000..8402275 --- /dev/null +++ b/zaaReloaded2/ViewModels/CategoryViewModel.cs @@ -0,0 +1,46 @@ +/* CategoryViewModel.cs + * part of zaaReloaded2 + * + * Copyright 2015 Daniel Kraus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Bovender.Mvvm.ViewModels; + +namespace zaaReloaded2.ViewModels +{ + /// + /// A simple view model that can be used to categorize items + /// in a tree view. It has a custom DisplayString and holds + /// a collection of child view model items. + /// + class CategoryViewModel : ViewModelBase + { + public IEnumerable Children { get; private set; } + + public CategoryViewModel(string name, IEnumerable children) + { + DisplayString = name; + Children = children; + } + + public override object RevealModelObject() + { + throw new NotImplementedException(); + } + } +} diff --git a/zaaReloaded2/ViewModels/ControlElementViewModel.cs b/zaaReloaded2/ViewModels/ControlElementViewModel.cs index 1826c42..c5452b1 100755 --- a/zaaReloaded2/ViewModels/ControlElementViewModel.cs +++ b/zaaReloaded2/ViewModels/ControlElementViewModel.cs @@ -46,5 +46,16 @@ namespace zaaReloaded2.ViewModels { } #endregion + + #region Public methods + + public void AddChildElement(FormatElementViewModel viewModel) + { + Elements.Add(viewModel); + ControlElementBase e = Element as ControlElementBase; + e.FormatElements.Add(viewModel.RevealModelObject() as FormatElementBase); + } + + #endregion } } diff --git a/zaaReloaded2/ViewModels/ElementPickerViewModel.cs b/zaaReloaded2/ViewModels/ElementPickerViewModel.cs new file mode 100755 index 0000000..24d75eb --- /dev/null +++ b/zaaReloaded2/ViewModels/ElementPickerViewModel.cs @@ -0,0 +1,122 @@ +/* ElementPickerViewModel.cs + * part of zaaReloaded2 + * + * Copyright 2015 Daniel Kraus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Bovender.Mvvm; +using Bovender.Mvvm.Messaging; +using Bovender.Mvvm.ViewModels; +using System.Collections.ObjectModel; +using zaaReloaded2.Controller.Elements; + +namespace zaaReloaded2.ViewModels +{ + /// + /// View model that presents a list of zaaReloaded2.Contorller.Elements.ElementBase + /// classes to choose from. + /// + class ElementPickerViewModel : ViewModelBase + { + #region Properties + + /// + /// A two-dimensional tree + /// + public IList AvailableElements { get; private set; } + + #endregion + + #region Constructors + + public ElementPickerViewModel(SettingsViewModel caller, bool allowControlElements) + { + _caller = caller; + AvailableElements = new List(); + if (allowControlElements) + { + AvailableElements.Add( + new CategoryViewModel( + "Kontroll-Elemente", + new Collection() + { + CreateControlElementViewModel(new SelectFirstDay()), + CreateControlElementViewModel(new SelectLastDay()), + CreateControlElementViewModel(new SelectEachDay()) + } + ) + ); + } + AvailableElements.Add( + new CategoryViewModel( + "Ausgabe-Elemente", + new Collection() + { + CreateFormatElementViewModel("Laborparameter", new Items()), + CreateFormatElementViewModel("Beliebiger Text", new CustomText()), + } + ) + ); + } + + #endregion + + #region Private methods + + /// + /// Creates a new ControlElementViewModel that wraps a ControlElementBase + /// object. The display string of the ControlElementViewModel is taken + /// from the canonical Label of the control element. + /// + ViewModelBase CreateControlElementViewModel(ControlElementBase element) + { + ControlElementViewModel vm = new ControlElementViewModel(element); + vm.DisplayString = element.Label; + return vm; + } + + /// + /// Creates a new FormatElementViewModel that wraps a FormatElementBase + /// object and has a custom display string. The custom display string + /// is necessary because format elements do not have a canonical label. + /// + ViewModelBase CreateFormatElementViewModel(string name, FormatElementBase element) + { + FormatElementViewModel vm = new FormatElementViewModel(element); + vm.DisplayString = name; + return vm; + } + + #endregion + + #region Implementation ov ViewModelBase + + public override object RevealModelObject() + { + throw new NotImplementedException(); + } + + #endregion + + #region Fields + + SettingsViewModel _caller; + + #endregion + } +} diff --git a/zaaReloaded2/ViewModels/SettingsViewModel.cs b/zaaReloaded2/ViewModels/SettingsViewModel.cs index b573097..c662f1b 100755 --- a/zaaReloaded2/ViewModels/SettingsViewModel.cs +++ b/zaaReloaded2/ViewModels/SettingsViewModel.cs @@ -22,6 +22,7 @@ using System.Linq; using System.Text; using Bovender.Mvvm; using Bovender.Mvvm.ViewModels; +using Bovender.Mvvm.Messaging; using zaaReloaded2.Controller; using zaaReloaded2.Controller.Elements; using zaaReloaded2.Formatter; @@ -161,6 +162,20 @@ namespace zaaReloaded2.ViewModels } } + public DelegatingCommand AddChildElementCommand + { + get + { + if (_addChildElementCommand == null) + { + _addChildElementCommand = new DelegatingCommand( + param => DoAddChildElement(), + param => CanAddChildElement()); + } + return _addChildElementCommand; + } + } + public DelegatingCommand DeleteElementCommand { get @@ -191,10 +206,31 @@ namespace zaaReloaded2.ViewModels #endregion + #region Public methods + + /// + /// Wires the OnProperty changed event of an ElementViewModel's + /// wrapped model and adds the view model to the Elements collection. + /// + public void AddElementViewModel(ElementViewModel elementViewModel) + { + elementViewModel.PropertyChanged += ElementViewModel_PropertyChanged; + Elements.Add(elementViewModel); + } + + #endregion + #region Private methods void DoAddElement() { } + void DoAddChildElement() { } + + bool CanAddChildElement() + { + return SelectedElement is ControlElementViewModel; + } + void DoDeleteElement() { } bool CanDeleteElement() { return _selectedElement != null; } @@ -203,17 +239,6 @@ namespace zaaReloaded2.ViewModels bool CanCopyElement() { return _selectedElement != null; } - /// - /// Internal function that creates wires the OnProperty changed event - /// of an ElementViewModel's wrapped model and adds the view model - /// to the Elements collection. - /// - void AddElementViewModel(ElementViewModel elementViewModel) - { - elementViewModel.PropertyChanged += ElementViewModel_PropertyChanged; - Elements.Add(elementViewModel); - } - /// /// Sets or unsets the SelectedElement property whenever the IsSelected /// property of an ElementViewModel changes. @@ -251,8 +276,10 @@ namespace zaaReloaded2.ViewModels Settings _settings; DelegatingCommand _addElementCommand; + DelegatingCommand _addChildElementCommand; DelegatingCommand _deleteElementCommand; DelegatingCommand _copyElementCommand; + List _elements; ElementViewModel _selectedElement; EnumProvider _referenceStyle; diff --git a/zaaReloaded2/zaaReloaded2.csproj b/zaaReloaded2/zaaReloaded2.csproj index 07a446a..d595215 100755 --- a/zaaReloaded2/zaaReloaded2.csproj +++ b/zaaReloaded2/zaaReloaded2.csproj @@ -219,6 +219,8 @@ + + From 23acb130196bd20e2ede441aa6c781e14d0fb8de Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sun, 2 Aug 2015 22:01:51 +0200 Subject: [PATCH 5/6] Improve Daniel's style. --- zaaReloaded2/Formatter/DanielsStyle.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/zaaReloaded2/Formatter/DanielsStyle.cs b/zaaReloaded2/Formatter/DanielsStyle.cs index a2ab215..03ed7ff 100755 --- a/zaaReloaded2/Formatter/DanielsStyle.cs +++ b/zaaReloaded2/Formatter/DanielsStyle.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Office.Interop.Word; +using System.Text.RegularExpressions; namespace zaaReloaded2.Formatter { @@ -32,6 +33,7 @@ namespace zaaReloaded2.Formatter { FixWords(document); FormatDiagnoses(selection); + FixSalutation(document); } static void FormatDiagnoses(Selection selection) @@ -59,6 +61,7 @@ namespace zaaReloaded2.Formatter static void FixWords(Document document) { Find find = document.Range().Find; + find.Execute2007(FindText: "Körperlicher Untersuchungsbefund", ReplaceWith: "Körperl. Untersuchung", Replace: WdReplace.wdReplaceAll); find.Execute2007(FindText: "Dr.D.Kraus", ReplaceWith: "Dr. D. Kraus", Replace: WdReplace.wdReplaceAll); find.Execute2007(FindText: "Z. n.", ReplaceWith: "Z.n.", Replace: WdReplace.wdReplaceAll); find.Execute2007(FindText: "Zust. n.", ReplaceWith: "Z.n.", Replace: WdReplace.wdReplaceAll); @@ -66,6 +69,23 @@ namespace zaaReloaded2.Formatter find.Execute2007(FindText: "Assistent der Klinik", ReplaceWith: "Internist/Nephrologe", Replace: WdReplace.wdReplaceAll); find.Execute2007(FindText: "Professor Dr.", ReplaceWith: "Prof. Dr.", Replace: WdReplace.wdReplaceAll); find.Execute2007(FindText: "mmHg", ReplaceWith: "mm Hg", Replace: WdReplace.wdReplaceAll); + find.Execute2007(FindText: "RR ", ReplaceWith: "", Replace: WdReplace.wdReplaceAll); + find.Execute2007(FindText: "HF ", ReplaceWith: "", Replace: WdReplace.wdReplaceAll); + find.Execute2007(FindText: "TAC-Spiegel", ReplaceWith: "Tacrolimus-Talspiegel", Replace: WdReplace.wdReplaceAll); + find.Execute2007(FindText: "4-7", ReplaceWith: "4 bis 7", Replace: WdReplace.wdReplaceAll); + find.Execute2007(FindText: "5-8", ReplaceWith: "5 bis 8", Replace: WdReplace.wdReplaceAll); + find.Execute2007(FindText: "8-10", ReplaceWith: "8 bis 10", Replace: WdReplace.wdReplaceAll); + } + + static void FixSalutation(Document document) + { + Regex sal = new Regex(@"^Mit.*(freundl|kolleg)"); + Regex med = new Regex(@"^((Häusl|Empf).*Medikat)|Therapieempf"); + foreach (Paragraph p in document.Paragraphs) + { + if (sal.IsMatch(p.Range.Text)) p.Range.Text = "Mit freundlichen, kollegialen Grüßen,"; + if (med.IsMatch(p.Range.Text)) p.Range.Text = "Aktuelle Medikation:"; + } } } } From e4edd0f197eb7bf321da0eeb41faea7abbd8117c Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Sun, 2 Aug 2015 22:04:58 +0200 Subject: [PATCH 6/6] Prepare release 2.0.0-alpha.4. --- HISTORY.md | 1 + www/versioninfo.txt | 6 +++--- zaaReloaded2/VERSION | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index bef6fd8..e002098 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,4 @@ + Version 2.0.0-alpha.3 (2015-07-31) ======================================================================== diff --git a/www/versioninfo.txt b/www/versioninfo.txt index 8e94de9..51f57b2 100644 --- a/www/versioninfo.txt +++ b/www/versioninfo.txt @@ -1,4 +1,4 @@ -2.0.0-alpha.3 -http://zaa.nephrowiki.de/downloads/zaaReloaded-2.0.0-alpha.3.exe -c9bb1062acdf2d8181a3915e34d5cfe96d26934a publish/release/zaaReloaded-2.0.0-alpha.3.exe +2.0.0-alpha.4 +http://zaa.nephrowiki.de/downloads/zaaReloaded-2.0.0-alpha.4.exe +3f511ac90dbfbb14318948a3be1d1f9d2eb059d1 publish/release/zaaReloaded-2.0.0-alpha.4.exe diff --git a/zaaReloaded2/VERSION b/zaaReloaded2/VERSION index 4f67e82..a4c6686 100755 --- a/zaaReloaded2/VERSION +++ b/zaaReloaded2/VERSION @@ -1,2 +1,2 @@ -2.0.0-alpha.3 -2.0.0.3 +2.0.0-alpha.4 +2.0.0.4