Implement bold font; make tests pass again.
- NEU: Überschriften und pathologische Werte werden fett gedruckt. - FIX: Kleinere Bugfixes.
This commit is contained in:
parent
39e8b1f81d
commit
32d4e8d955
@ -24,6 +24,7 @@ using Microsoft.Office.Interop.Word;
|
|||||||
using zaaReloaded2.LabModel;
|
using zaaReloaded2.LabModel;
|
||||||
using zaaReloaded2.Formatter;
|
using zaaReloaded2.Formatter;
|
||||||
using zaa = zaaReloaded2.Controller.Elements;
|
using zaa = zaaReloaded2.Controller.Elements;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace Tests.Controller.Elements
|
namespace Tests.Controller.Elements
|
||||||
{
|
{
|
||||||
@ -62,8 +63,10 @@ namespace Tests.Controller.Elements
|
|||||||
_formatter.Settings.Elements.Add(new zaa.Items("Na, K, Cl"));
|
_formatter.Settings.Elements.Add(new zaa.Items("Na, K, Cl"));
|
||||||
_formatter.Run();
|
_formatter.Run();
|
||||||
string expected = (
|
string expected = (
|
||||||
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) +
|
StripMarkup(
|
||||||
"Na 133, K 6 (5)\r\r").Replace(Environment.NewLine, "\r");
|
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) +
|
||||||
|
"Na 133, K 6 (5)\r\r").Replace(Environment.NewLine, "\r")
|
||||||
|
);
|
||||||
Assert.AreEqual(expected, _document.Range().Text);
|
Assert.AreEqual(expected, _document.Range().Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,8 +85,10 @@ namespace Tests.Controller.Elements
|
|||||||
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, K, Cl"));
|
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, K, Cl"));
|
||||||
_formatter.Run();
|
_formatter.Run();
|
||||||
string expected = (
|
string expected = (
|
||||||
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) +
|
StripMarkup(
|
||||||
"Klinische Chemie: Na 133, K 6 (5)\r\r").Replace(Environment.NewLine, "\r");
|
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) +
|
||||||
|
"Klinische Chemie: Na 133, K 6 (5)\r\r").Replace(Environment.NewLine, "\r")
|
||||||
|
);
|
||||||
Assert.AreEqual(expected, _document.Range().Text);
|
Assert.AreEqual(expected, _document.Range().Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +125,9 @@ namespace Tests.Controller.Elements
|
|||||||
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, *"));
|
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, *"));
|
||||||
_formatter.Run();
|
_formatter.Run();
|
||||||
string expected = (
|
string expected = (
|
||||||
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) +
|
StripMarkup(
|
||||||
|
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00))
|
||||||
|
) +
|
||||||
"Klinische Chemie: Na 133, Cl 110, K 6\r\r").Replace(Environment.NewLine, "\r");
|
"Klinische Chemie: Na 133, Cl 110, K 6\r\r").Replace(Environment.NewLine, "\r");
|
||||||
Assert.AreEqual(expected, _document.Range().Text);
|
Assert.AreEqual(expected, _document.Range().Text);
|
||||||
}
|
}
|
||||||
@ -142,7 +149,9 @@ namespace Tests.Controller.Elements
|
|||||||
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, SU-*"));
|
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, SU-*"));
|
||||||
_formatter.Run();
|
_formatter.Run();
|
||||||
string expected = (
|
string expected = (
|
||||||
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) +
|
StripMarkup(
|
||||||
|
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00))
|
||||||
|
)+
|
||||||
"Klinische Chemie: Na 133, SU-Protein 2,8\r\r").Replace(Environment.NewLine, "\r");
|
"Klinische Chemie: Na 133, SU-Protein 2,8\r\r").Replace(Environment.NewLine, "\r");
|
||||||
Assert.AreEqual(expected, _document.Range().Text);
|
Assert.AreEqual(expected, _document.Range().Text);
|
||||||
}
|
}
|
||||||
@ -164,10 +173,19 @@ namespace Tests.Controller.Elements
|
|||||||
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, SU-*, *"));
|
_formatter.Settings.Elements.Add(new zaa.Items("Klinische Chemie: Na, SU-*, *"));
|
||||||
_formatter.Run();
|
_formatter.Run();
|
||||||
string expected = (
|
string expected = (
|
||||||
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) +
|
StripMarkup(
|
||||||
|
TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00))
|
||||||
|
) +
|
||||||
"Klinische Chemie: Na 133, SU-Protein 2,8, Cl 110, U-Na 99\r\r")
|
"Klinische Chemie: Na 133, SU-Protein 2,8, Cl 110, U-Na 99\r\r")
|
||||||
.Replace(Environment.NewLine, "\r");
|
.Replace(Environment.NewLine, "\r");
|
||||||
Assert.AreEqual(expected, _document.Range().Text);
|
Assert.AreEqual(expected, _document.Range().Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static string StripMarkup(string s)
|
||||||
|
{
|
||||||
|
return _markupStripper.Replace(s, string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
static readonly Regex _markupStripper = new Regex(@"</?b>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using zaaReloaded2.Formatter;
|
using zaaReloaded2.Formatter;
|
||||||
|
using Microsoft.Office.Interop.Word;
|
||||||
|
|
||||||
namespace Tests.Formatter
|
namespace Tests.Formatter
|
||||||
{
|
{
|
||||||
@ -95,5 +96,13 @@ namespace Tests.Formatter
|
|||||||
Assert.IsFalse(_docWriter.HasBufferedText);
|
Assert.IsFalse(_docWriter.HasBufferedText);
|
||||||
Assert.AreEqual(String.Empty, _docWriter.ToString());
|
Assert.AreEqual(String.Empty, _docWriter.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TextMarkup()
|
||||||
|
{
|
||||||
|
_docWriter.Document = new Document();
|
||||||
|
_docWriter.WriteLine("This is not bold. <b>This is bold!</b>");
|
||||||
|
_docWriter.Flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,12 @@ namespace Tests.ViewModels
|
|||||||
Assert.AreNotSame(orig, copy);
|
Assert.AreNotSame(orig, copy);
|
||||||
Assert.AreNotSame(orig.RevealModelObject(), copy.RevealModelObject());
|
Assert.AreNotSame(orig.RevealModelObject(), copy.RevealModelObject());
|
||||||
|
|
||||||
Assert.AreEqual(String.Format("Kopie von {0}", orig.Name), copy.Name);
|
Assert.AreEqual(
|
||||||
|
String.Format(
|
||||||
|
"Kopie von {0}",
|
||||||
|
orig.Name.Replace(" (eingebaut)", String.Empty)
|
||||||
|
),
|
||||||
|
copy.Name);
|
||||||
Assert.IsTrue(copy.IsSelected);
|
Assert.IsTrue(copy.IsSelected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.Office.Interop.Word;
|
using Microsoft.Office.Interop.Word;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace zaaReloaded2.Formatter
|
namespace zaaReloaded2.Formatter
|
||||||
{
|
{
|
||||||
@ -59,6 +60,20 @@ namespace zaaReloaded2.Formatter
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string ParagraphStyle { get; set; }
|
public string ParagraphStyle { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns text without markup from the buffer.
|
||||||
|
/// </summary>
|
||||||
|
public string Text
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!HasBufferedText)
|
||||||
|
throw new InvalidOperationException("This DocumentWriter does not have any text.");
|
||||||
|
|
||||||
|
return _markupRegex.Replace(_buffer.ToString(), String.Empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@ -126,7 +141,7 @@ namespace zaaReloaded2.Formatter
|
|||||||
{
|
{
|
||||||
s.set_Style(ParagraphStyle);
|
s.set_Style(ParagraphStyle);
|
||||||
}
|
}
|
||||||
s.Range.Text = _buffer.ToString();
|
MarkupToDocument(_buffer.ToString());
|
||||||
}
|
}
|
||||||
if (Parent != null)
|
if (Parent != null)
|
||||||
{
|
{
|
||||||
@ -166,9 +181,40 @@ namespace zaaReloaded2.Formatter
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Private methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses a string containing markup (e.g., "<b>", "</b>")
|
||||||
|
/// and writes formatted text to the current Document.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text"></param>
|
||||||
|
void MarkupToDocument(string text)
|
||||||
|
{
|
||||||
|
string[] substrings = _markupRegex.Split(text);
|
||||||
|
foreach (string substring in substrings)
|
||||||
|
{
|
||||||
|
switch (substring)
|
||||||
|
{
|
||||||
|
case "<b>":
|
||||||
|
Document.ActiveWindow.Selection.Font.Bold = 1;
|
||||||
|
break;
|
||||||
|
case "</b>":
|
||||||
|
Document.ActiveWindow.Selection.Font.Bold = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Document.ActiveWindow.Selection.TypeText(substring);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
StringBuilder _buffer;
|
StringBuilder _buffer;
|
||||||
|
// Put pattern in parentheses so they will not be discarded by Regex.Split
|
||||||
|
static readonly Regex _markupRegex = new Regex(@"(</?b>)");
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -153,15 +153,20 @@ namespace zaaReloaded2.Formatter
|
|||||||
|
|
||||||
string name = IncludeMaterial ? LabItem.QualifiedName : LabItem.Name;
|
string name = IncludeMaterial ? LabItem.QualifiedName : LabItem.Name;
|
||||||
|
|
||||||
// Insert the formatted text into the document.
|
string output =
|
||||||
formatter.Write(
|
|
||||||
String.Format(
|
String.Format(
|
||||||
"{0} {1}{2}{3}",
|
"{0} {1}{2}{3}",
|
||||||
name,
|
name,
|
||||||
value,
|
value,
|
||||||
unit,
|
unit,
|
||||||
reference
|
reference
|
||||||
));
|
);
|
||||||
|
if (!LabItem.IsNormal)
|
||||||
|
{
|
||||||
|
output = String.Format("<b>{0}</b>", output);
|
||||||
|
}
|
||||||
|
|
||||||
|
formatter.Write(output);
|
||||||
HasBeenUsed = true;
|
HasBeenUsed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ namespace zaaReloaded2.Formatter
|
|||||||
|
|
||||||
static string FormatHeader(string text)
|
static string FormatHeader(string text)
|
||||||
{
|
{
|
||||||
return String.Format("{0}Laborwerte vom {1}:{2}",
|
return String.Format("{0}<b>Laborwerte vom {1}:</b>{2}",
|
||||||
Environment.NewLine,
|
Environment.NewLine,
|
||||||
text,
|
text,
|
||||||
Environment.NewLine
|
Environment.NewLine
|
||||||
|
@ -123,7 +123,8 @@ namespace zaaReloaded2.LabModel
|
|||||||
public bool HasUpperLimit { get; protected set; }
|
public bool HasUpperLimit { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is true if <see cref="Value"/> is normal.
|
/// Is true if <see cref="Value"/> is normal. Returns true
|
||||||
|
/// if no limits and no normal value are known.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsNormal
|
public bool IsNormal
|
||||||
{
|
{
|
||||||
@ -147,7 +148,7 @@ namespace zaaReloaded2.LabModel
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return (Value == Normal);
|
return String.IsNullOrEmpty(Normal) || (Value == Normal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -347,7 +347,7 @@ namespace zaaReloaded2.ViewModels
|
|||||||
picker.ElementChosenMessage.Sent += (sender, args) =>
|
picker.ElementChosenMessage.Sent += (sender, args) =>
|
||||||
{
|
{
|
||||||
ElementViewModel newVM = args.Content.ViewModel as ElementViewModel;
|
ElementViewModel newVM = args.Content.ViewModel as ElementViewModel;
|
||||||
if (IsTopLevelElement())
|
if (LastSelectedElement == null || IsTopLevelElement())
|
||||||
{
|
{
|
||||||
AddElementViewModel(newVM);
|
AddElementViewModel(newVM);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user