Implement ItemComment view model and view.

- NEU: Optionale Kommentare zu Laborwerten.
This commit is contained in:
Daniel Kraus 2015-08-30 20:32:37 +02:00
parent 02b4bc07a3
commit 9068dde1c3
11 changed files with 288 additions and 9 deletions

View File

@ -48,13 +48,13 @@ namespace Tests.Controller.Comments
public void BuildingCommentRaisesEvent()
{
ItemComment i = CommentPool.Default.GetCommentFor("item \"<>\"");
bool eventRaised = false;
int eventRaised = 0;
CommentPool.Default.FillInComment += (sender, args) =>
{
eventRaised = true;
eventRaised += 1;
};
string comment = i.BuildComment();
Assert.IsTrue(eventRaised);
Assert.AreEqual(1, eventRaised);
}
}
}

View File

@ -16,9 +16,6 @@
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Microsoft.Office.Interop.Word;
using zaaReloaded2.LabModel;
@ -26,7 +23,6 @@ using zaaReloaded2.Formatter;
using zaa = zaaReloaded2.Controller.Elements;
using zaaReloaded2.Controller.Comments;
using System.Text.RegularExpressions;
using zaaReloaded2.Controller.Comments;
namespace Tests.Controller.Elements
{

View File

@ -98,6 +98,7 @@
<Compile Include="Importer\ZaaImporter\TimePointTest.cs" />
<Compile Include="TestHelpers.cs" />
<Compile Include="ViewModels\ElementPickerViewModelTest.cs" />
<Compile Include="ViewModels\ItemCommentViewModelTest.cs" />
<Compile Include="ViewModels\SettingsRepositoryViewModelTest.cs" />
<Compile Include="ViewModels\SettingsViewModelTest.cs" />
</ItemGroup>

View File

@ -0,0 +1,42 @@
/* ItemCommentViewModelTest.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.Comments;
using zaaReloaded2.ViewModels;
namespace Tests.ViewModels
{
[TestFixture]
class ItemCommentViewModelTest
{
[Test]
public void Properties()
{
ItemComment comment = new ItemComment("item", "pre", "val", "suf");
ItemCommentViewModel vm = new ItemCommentViewModel(comment);
Assert.AreEqual(comment.Item, vm.Item);
Assert.AreEqual(comment.Prefix, vm.Prefix);
Assert.AreEqual(comment.Suffix, vm.Suffix);
Assert.AreEqual(comment.Value, vm.Value);
}
}
}

View File

@ -78,6 +78,16 @@ namespace zaaReloaded2.Controller.Comments
#region Methods
/// <summary>
/// Clear the pool of ItemComments and sets the event handler
/// to null.
/// </summary>
public void Reset()
{
_itemComments.Clear();
FillInComment = null;
}
/// <summary>
/// Retrieves the ItemComment for a given definitionString;
/// creates a new ItemComment object if necessary.
@ -103,7 +113,7 @@ namespace zaaReloaded2.Controller.Comments
#endregion
#region Pribate methods
#region Private methods
protected virtual void itemComment_FillInComment(object sender, ItemCommentEventArgs e)
{

View File

@ -224,7 +224,7 @@ namespace zaaReloaded2.Controller.Elements
string _caption;
List<string> _items;
static readonly Regex _wildcard = new Regex(@"(?<material>[^-]+-)?\*");
static readonly Regex _wildcard = new Regex(@"^(?<material>[^-]+-)?\*$");
#endregion
}

View File

@ -31,6 +31,7 @@ using zaaReloaded2.ViewModels;
using zaaReloaded2.Importer.ZaaImporter;
using zaaReloaded2.Formatter;
using zaaReloaded2.Controller;
using zaaReloaded2.Controller.Comments;
using Word = Microsoft.Office.Interop.Word;
using Bovender.Mvvm.Actions;
using Bovender.Mvvm.Messaging;
@ -201,6 +202,8 @@ namespace zaaReloaded2
Globals.ThisAddIn.Application.ActiveDocument);
formatter.Settings = settings;
formatter.Laboratory = importer.Laboratory;
CommentPool.Default.Reset();
CommentPool.Default.FillInComment += CommentPool_FillInComment;
try
{
formatter.Run();
@ -215,6 +218,16 @@ namespace zaaReloaded2
}
}
void CommentPool_FillInComment(object sender, ItemCommentEventArgs e)
{
ItemCommentViewModel vm = new ItemCommentViewModel(e.Comment);
vm.CancelMessage.Sent += (cancelSender, cancelArgs) =>
{
e.IsCancelled = true;
};
vm.InjectInto<ItemCommentView>().ShowDialog();
}
void DoChooseSettings()
{
SettingsRepository repository = SettingsRepository.Load();

View File

@ -0,0 +1,126 @@
/* ItemCommentViewModel.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.Comments;
namespace zaaReloaded2.ViewModels
{
/// <summary>
/// View model for zaaReloaded2.Controller.Comments.ItemComment.
/// </summary>
public class ItemCommentViewModel : ViewModelBase
{
#region Properties
public string Item { get { return _itemComment.Item; } }
public string Prefix { get { return _itemComment.Prefix; } }
public string Value
{
get
{
return _itemComment.Value;
}
set
{
_itemComment.Value = value;
OnPropertyChanged("Value");
}
}
public string Suffix { get { return _itemComment.Suffix; } }
#endregion
#region Commands
DelegatingCommand CancelCommand
{
get
{
if (_cancelCommand == null)
{
_cancelCommand = new DelegatingCommand(
param => DoCancel());
}
return _cancelCommand;
}
}
#endregion
#region Message
public Message<ViewModelMessageContent> CancelMessage
{
get
{
if (_cancelMessage == null)
{
_cancelMessage = new Message<ViewModelMessageContent>();
}
return _cancelMessage;
}
}
#endregion
#region Constructor
public ItemCommentViewModel(ItemComment itemComment)
{
_itemComment = itemComment;
}
#endregion
#region Implementation of ViewModelBase
public override object RevealModelObject()
{
return _itemComment;
}
#endregion
#region Private methods
void DoCancel()
{
CancelMessage.Send(new ViewModelMessageContent(this));
DoCloseView();
}
#endregion
#region Fields
DelegatingCommand _cancelCommand;
Message<ViewModelMessageContent> _cancelMessage;
ItemComment _itemComment;
#endregion
}
}

View File

@ -0,0 +1,50 @@
<!--
ItemCommentView.xaml
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.
-->
<Window x:Class="zaaReloaded2.Views.ItemCommentView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="clr-namespace:Bovender.Mvvm.Views.Settings;assembly=Bovender"
ResizeMode="CanResizeWithGrip" ShowInTaskbar="False"
WindowStyle="ToolWindow" Topmost="True"
SizeToContent="WidthAndHeight"
b:WindowState.CenterScreen="True" b:WindowState.Save="True"
Title="Kommentar angeben"
FocusManager.FocusedElement="{Binding ElementName=ValueTextBox}"
>
<Window.Resources>
<ResourceDictionary Source="/zaaReloaded2;component/Style.xaml" />
</Window.Resources>
<DockPanel Margin="10">
<Label DockPanel.Dock="Top" Content="{Binding Item}"
FontSize="16" FontWeight="Bold"
Target="{Binding ElementName=ValueTextBox}" Padding="0" />
<UniformGrid DockPanel.Dock="Bottom" HorizontalAlignment="Right" Columns="2" Rows="1" Margin="0 10 0 0">
<Button Content="OK" Command="{Binding CloseViewCommand}" IsDefault="True" Margin="0 0 5 0" />
<Button Content="Abbrechen" Command="{Binding CancelCommand}" IsCancel="True" Margin="5 0 0 0" />
</UniformGrid>
<DockPanel Margin="0 10 0 10">
<TextBlock DockPanel.Dock="Left" Text="{Binding Prefix}" VerticalAlignment="Center" />
<TextBlock DockPanel.Dock="Right" Text="{Binding Suffix}" VerticalAlignment="Center" />
<TextBox Text="Binding Value,Mode=TwoWay,UpdateSourceTrigger=LostFocus}"
MinWidth="120" MaxWidth="240" VerticalAlignment="Center"
x:Name="ValueTextBox" Margin="5 0 5 0" />
</DockPanel>
</DockPanel>
</Window>

View File

@ -0,0 +1,33 @@
/* ItemCommentView.xaml.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.Windows;
namespace zaaReloaded2.Views
{
/// <summary>
/// Interaction logic for ItemCommentView.xaml
/// </summary>
public partial class ItemCommentView : Window
{
public ItemCommentView()
{
InitializeComponent();
}
}
}

View File

@ -257,7 +257,11 @@
<Compile Include="ViewModels\FormatElementViewModel.cs" />
<Compile Include="ViewModels\ControlElementViewModel.cs" />
<Compile Include="ViewModels\IoErrorViewModel.cs" />
<Compile Include="ViewModels\ItemCommentViewModel.cs" />
<Compile Include="ViewModels\SettingsRepositoryViewModel.cs" />
<Compile Include="Views\ItemCommentView.xaml.cs">
<DependentUpon>ItemCommentView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\IoErrorView.xaml.cs">
<DependentUpon>IoErrorView.xaml</DependentUpon>
</Compile>
@ -343,6 +347,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Resource>
<Page Include="Views\ItemCommentView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\IoErrorView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>