Просмотр исходного кода

PRS MOBILE - additions to Digital forms (label styling, popup comment editor)

Nick-PRSDigital@bitbucket.org 2 лет назад
Родитель
Сommit
d876bbb973

+ 1 - 1
prs.mobile/comal.timesheets.Android/Resources/Resource.designer.cs

@@ -14,7 +14,7 @@ namespace comal.timesheets.Droid
 {
 	
 	
-	[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "13.1.0.5")]
+	[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "13.0.0.73")]
 	public partial class Resource
 	{
 		

+ 11 - 0
prs.mobile/comal.timesheets/DigitalForms/CustomUserControls/DataButtonControl.cs

@@ -14,5 +14,16 @@ namespace comal.timesheets
         public Dictionary<Guid, string> LookupFieldOptions = new Dictionary<Guid, string>()
             ;
         public Guid ChosenID = Guid.Empty;
+
+        public DataButtonControl()
+        {
+            BackgroundColor = Color.FromHex("#15C7C1");
+            FontAttributes = FontAttributes.Bold;
+            TextColor = Color.White;
+            CornerRadius = 5;
+            Padding = 1;
+            HorizontalOptions = LayoutOptions.FillAndExpand;
+            VerticalOptions = LayoutOptions.Center;            
+        }
     }
 }

+ 27 - 1
prs.mobile/comal.timesheets/DigitalForms/CustomUserControls/DigitalFormsHeader.xaml.cs

@@ -1,4 +1,5 @@
-using System;
+using InABox.Core;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -6,6 +7,7 @@ using System.Threading.Tasks;
 
 using Xamarin.Forms;
 using Xamarin.Forms.Xaml;
+using static Android.Content.ClipData;
 
 namespace comal.timesheets
 {
@@ -67,7 +69,31 @@ namespace comal.timesheets
             expandImage.IsVisible = true;
         }
 
+        public void SetHeaderStyle(DFLayoutHeader label)
+        { 
+            headerBtn.FontAttributes = label.Style.IsBold ? FontAttributes.Bold
+                : label.Style.IsItalic ? FontAttributes.Italic
+                : FontAttributes.None;
 
+            headerBtn.FontSize = label.Style.FontSize > 5 && label.Style.FontSize < 37 ? label.Style.FontSize
+                : Device.GetNamedSize(NamedSize.Medium, headerBtn);
+
+            headerBtn.TextColor = label.Style.ForegroundColour;
+
+            headerBtn.BackgroundColor = label.Style.BackgroundColour;
+
+            headerBtn.HorizontalOptions = label.Style.HorizontalTextAlignment == DFLayoutAlignment.Start ? LayoutOptions.Start
+                : label.Style.HorizontalTextAlignment == DFLayoutAlignment.Middle ? LayoutOptions.Center
+                : label.Style.HorizontalTextAlignment == DFLayoutAlignment.End ? LayoutOptions.End
+                : label.Style.HorizontalTextAlignment == DFLayoutAlignment.Stretch ? LayoutOptions.FillAndExpand
+                : LayoutOptions.StartAndExpand;
+
+            headerBtn.VerticalOptions = label.Style.VerticalTextAlignment == DFLayoutAlignment.Start ? LayoutOptions.Start
+                : label.Style.VerticalTextAlignment == DFLayoutAlignment.Middle ? LayoutOptions.Center
+                : label.Style.VerticalTextAlignment == DFLayoutAlignment.End ? LayoutOptions.End
+                : label.Style.VerticalTextAlignment == DFLayoutAlignment.Stretch ? LayoutOptions.FillAndExpand
+                : LayoutOptions.Center;
+        }
 
     }
 }

+ 90 - 37
prs.mobile/comal.timesheets/DigitalForms/Renderer/QAFormViewer.cs

@@ -14,6 +14,7 @@ using comal.timesheets.Tasks;
 using Comal.Classes;
 using PRSClasses;
 using Newtonsoft.Json;
+using Java.Security.Cert;
 
 namespace comal.timesheets.QAForms
 {
@@ -137,9 +138,14 @@ namespace comal.timesheets.QAForms
                         def.SetValue(RowDefinition.HeightProperty, 60);
                     }
                 }
-                else if (row == "*")
+                else if (row.Contains("*"))
                 {
-                    def = new RowDefinition { Height = new GridLength(1, GridUnitType.Star) };
+                    if (int.TryParse(row.Substring(0, row.IndexOf("*")), out int result))
+                    {
+                        def = new RowDefinition { Height = new GridLength(result, GridUnitType.Star) };
+                    }
+                    else
+                        def = new RowDefinition { Height = new GridLength(1, GridUnitType.Star) };
                 }
                 Device.BeginInvokeOnMainThread(() => { RowDefinitions.Add(def); });
             }
@@ -151,9 +157,14 @@ namespace comal.timesheets.QAForms
                 ColumnDefinition def = new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) };
                 if (int.TryParse(col, out int colWidth))
                     def = new ColumnDefinition { Width = new GridLength(colWidth, GridUnitType.Absolute) };
-                else if (col == "*")
+                else if (col.Contains("*"))
                 {
-                    def = new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) };
+                    if (int.TryParse(col.Substring(0, col.IndexOf("*")), out int result))
+                    {
+                        def = new ColumnDefinition { Width = new GridLength(result, GridUnitType.Star) };
+                    }
+                    else
+                        def = new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) };
                 }
                 Device.BeginInvokeOnMainThread(() => { ColumnDefinitions.Add(def); });
             }
@@ -258,12 +269,14 @@ namespace comal.timesheets.QAForms
             {
                 FormatAndAddView(LoadHeader(element), element, false);
             }
+
         }
 
         private View LoadHeader(DFLayoutControl element)
         {
             DFLayoutHeader dFLayoutHeader = (DFLayoutHeader)element;
             DigitalFormsHeader header = new DigitalFormsHeader(dFLayoutHeader.Collapsed);
+            header.SetHeaderStyle(dFLayoutHeader);
             if (dFLayoutHeader.Collapsed)
                 header = AddNumberToHeader(header);
 
@@ -396,7 +409,7 @@ namespace comal.timesheets.QAForms
             {
                 dfLayout.ChangeField(dfLayoutBooleanField.Name);
             };
-            
+
             return new Tuple<View, Boolean>(item, dfLayoutBooleanField.Properties.Required);
         }
 
@@ -405,17 +418,39 @@ namespace comal.timesheets.QAForms
             DFLayoutLabel label = element as DFLayoutLabel;
             Label item = new Label();
             item.Text = label.Caption;
-            item.FontSize = Device.GetNamedSize(NamedSize.Medium, item);
             item.TextColor = Color.Black;
-            item.LineBreakMode = LineBreakMode.WordWrap;
+            item.LineBreakMode = label.Style.TextWrapping == true ? LineBreakMode.WordWrap : LineBreakMode.NoWrap;
             item.VerticalOptions = LayoutOptions.FillAndExpand;
-            item.VerticalTextAlignment = TextAlignment.Center;
             item.MinimumHeightRequest = 60;
+            item.BackgroundColor = label.Style.BackgroundColour;
+
+            item.FontAttributes = label.Style.IsBold ? FontAttributes.Bold
+                : label.Style.IsItalic ? FontAttributes.Italic
+                : FontAttributes.None;
+            item.TextDecorations = label.Style.Underline == UnderlineType.Single || label.Style.Underline == UnderlineType.Double ?
+                TextDecorations.Underline : TextDecorations.None;
+
+            item.FontSize = label.Style.FontSize > 5 && label.Style.FontSize < 37 ? label.Style.FontSize
+                : Device.GetNamedSize(NamedSize.Medium, item);
+
+            item.TextColor = label.Style.ForegroundColour;
+
             if (ColumnDefinitions.Count == 1)
             {
                 item.HorizontalOptions = LayoutOptions.CenterAndExpand;
                 item.HorizontalTextAlignment = TextAlignment.Center;
-            }        
+            }
+
+            item.HorizontalTextAlignment = label.Style.HorizontalTextAlignment == DFLayoutAlignment.Start ? TextAlignment.Start
+                : label.Style.HorizontalTextAlignment == DFLayoutAlignment.Middle ? TextAlignment.Center
+                : label.Style.HorizontalTextAlignment == DFLayoutAlignment.End ? TextAlignment.End
+                : item.HorizontalTextAlignment;
+
+            item.VerticalTextAlignment = label.Style.VerticalTextAlignment == DFLayoutAlignment.Start ? TextAlignment.Start
+                : label.Style.HorizontalTextAlignment == DFLayoutAlignment.Middle ? TextAlignment.Center
+                : label.Style.HorizontalTextAlignment == DFLayoutAlignment.End ? TextAlignment.End
+                : TextAlignment.Center;
+
             return new Tuple<View, Boolean>(item, false);
         }
 
@@ -431,26 +466,48 @@ namespace comal.timesheets.QAForms
             if (element is DFLayoutStringField)
             {
                 DFLayoutStringField dfLayoutStringField = element as DFLayoutStringField;
+
                 item.TextColor = Color.Black;
                 item.Placeholder = "Enter answer";
                 isrequired = dfLayoutStringField.Properties.Required;
                 issecure = dfLayoutStringField.Properties.Secure;
+
+                DataButtonControl button = new DataButtonControl();
+                button.Clicked += (s, e) =>
+                {
+                    PopupEditor edt = new PopupEditor(button.Data);
+                    edt.OnPopupEdtSaved += (text) =>
+                    {
+                        button.Data = text;
+                        button.Text = text.Length > 25 ? text.Substring(0, 25) + "..." : text;
+                        dfLayout.ChangeField(dfLayoutStringField.Name);
+                    };
+                    Navigation.PushAsync(edt);
+                };
+                button.Text = "Edit";
+
                 if (loadData.TryGetValue(dfLayoutStringField.Name, out value))
                 {
-                    item.Text = value;
+                    item.Text = value;           
+                    button.Text = value.Length > 25 ? value.Substring(0, 25) + "..." : value;
                 }
                 if (loadRetainedForm)
                 {
                     if (RetainedResults.Results.TryGetValue(dfLayoutStringField.Name, out value))
                     {
                         item.Text = value;
+                        button.Text = value.Length > 25 ? value.Substring(0, 25) + "..." : value;
                     }
                 }
                 item.TextChanged += (object sender, TextChangedEventArgs e) =>
                 {
                     dfLayout.ChangeField(dfLayoutStringField.Name);
                 };
-                view = item;
+
+                if (dfLayoutStringField.Properties.PopupEditor)
+                    view = button;
+                else
+                    view = item;
             }
 
             else if (element is DFLayoutIntegerField)
@@ -548,7 +605,7 @@ namespace comal.timesheets.QAForms
             item.DateSelected += (object sender, DateChangedEventArgs e) =>
             {
                 dfLayout.ChangeField(dfLayoutDateField.Name);
-            };           
+            };
 
             return new Tuple<View, Boolean>(item, dfLayoutDateField.Properties.Required);
         }
@@ -585,7 +642,7 @@ namespace comal.timesheets.QAForms
         {
             View view = null;
             try
-            {             
+            {
                 string value = "";
 
                 var isrequired = false;
@@ -791,14 +848,7 @@ namespace comal.timesheets.QAForms
             DataButtonControl button = new DataButtonControl()
             {
                 Text = "Choose Option",
-                HorizontalOptions = LayoutOptions.FillAndExpand,
-                VerticalOptions = LayoutOptions.Center,
                 Margin = 0,
-                BackgroundColor = Color.FromHex("#15C7C1"),
-                FontAttributes = FontAttributes.Bold,
-                TextColor = Color.White,
-                CornerRadius = 5,
-                Padding = 1,
                 ExtraData = additionalPropertyValues,
                 LookupFieldOptions = lookupFieldOptions
             };
@@ -855,14 +905,6 @@ namespace comal.timesheets.QAForms
             DataButtonControl button = new DataButtonControl()
             {
                 Text = "Choose Option",
-                HorizontalOptions = LayoutOptions.FillAndExpand,
-                VerticalOptions = LayoutOptions.Center,
-                Margin = 0,
-                BackgroundColor = Color.FromHex("#15C7C1"),
-                FontAttributes = FontAttributes.Bold,
-                TextColor = Color.White,
-                CornerRadius = 5,
-                Padding = 1,
             };
             button.Clicked += (object sender, EventArgs eventArgs) =>
             {
@@ -1172,11 +1214,6 @@ namespace comal.timesheets.QAForms
             DataButtonControl button = new DataButtonControl
             {
                 Text = "Add Signatures",
-                TextColor = Color.White,
-                HorizontalOptions = LayoutOptions.FillAndExpand,
-                CornerRadius = 0,
-                BackgroundColor = Color.FromHex("#15C7C1"),
-                FontAttributes = FontAttributes.Bold
             };
             if (loadData.TryGetValue(dfLayoutMultiSignaturePad.Name, out value))
             {
@@ -1334,7 +1371,10 @@ namespace comal.timesheets.QAForms
             string userInput = "";
             if (field is DFLayoutStringField || field is DFLayoutIntegerField || field is DFLayoutDoubleField)
             {
-                userInput = (view as Editor).Text;
+                if (field is DFLayoutStringField && (field as DFLayoutStringField).Properties.PopupEditor)
+                    userInput = (view as DataButtonControl).Data;
+                else
+                    userInput = (view as Editor).Text;
             }
             else if (field is DFLayoutBooleanField)
             {
@@ -1822,7 +1862,15 @@ namespace comal.timesheets.QAForms
                 (view as CustomBoolean).Value = (bool)value;
 
             else if (field is DFLayoutStringField || field is DFLayoutIntegerField || field is DFLayoutDoubleField)
-                (view as Editor).Text = value.ToString();
+            {
+                if (field is DFLayoutStringField && (field as DFLayoutStringField).Properties.PopupEditor)
+                {
+                    (view as DataButtonControl).Data = value.ToString();
+                    (view as DataButtonControl).Text = value.ToString();
+                }                  
+                else
+                    (view as Editor).Text = value.ToString();
+            }             
 
             else if (field is DFLayoutDateField)
                 (view as DatePicker).Date = (DateTime)(value as DateTime?);
@@ -1891,8 +1939,13 @@ namespace comal.timesheets.QAForms
                 return (view as CustomBoolean).Value;
 
             if (field is DFLayoutStringField)
-                return (view as Editor).Text;
-
+            {
+                if ((field as DFLayoutStringField).Properties.PopupEditor)
+                    return (view as DataButtonControl).Data;
+                else
+                    return (view as Editor).Text;
+            }
+                
             else if (field is DFLayoutIntegerField)
                 return int.Parse((view as Editor).Text);
 

+ 34 - 0
prs.mobile/comal.timesheets/PopupEditor.xaml

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
+             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+             x:Class="comal.timesheets.PopupEditor"
+             >
+    
+    <NavigationPage.TitleView>
+        <Grid Margin="0" Padding="0">
+            <Grid.ColumnDefinitions>
+                <ColumnDefinition Width="*"/>
+                <ColumnDefinition Width="*"/>
+                <ColumnDefinition Width="*"/>
+            </Grid.ColumnDefinitions>
+            <Button Grid.Column="0" HorizontalOptions="Start" VerticalOptions="Center" TextColor="White" BackgroundColor="Transparent" Margin="0" Padding="0"
+                Text="Cancel" Clicked="CancelBtn_Clicked"/>
+            <Label Grid.Column="1"  Text="Enter text" VerticalOptions="Center" x:Name="titleLbl"
+                   HorizontalOptions="Center" HorizontalTextAlignment="Center" TextColor="White" FontSize="Medium" FontAttributes="Bold"/>
+            <Button Grid.Column="2" HorizontalOptions="End" VerticalOptions="Center" TextColor="White" BackgroundColor="Transparent" Margin="0" Padding="0"
+                Text="Save" Clicked="SaveBtn_Clicked"/>
+        </Grid>
+    </NavigationPage.TitleView> 
+    
+    <ContentPage.Content>
+        <Grid>
+            <Grid.RowDefinitions>
+                <RowDefinition Height="auto"/>
+            </Grid.RowDefinitions>
+            <Frame Grid.Row="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
+                <Editor  x:Name="textEdt" AutoSize="TextChanges" Placeholder="Enter Text"
+                    HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
+            </Frame>
+        </Grid>
+    </ContentPage.Content>
+</ContentPage>

+ 36 - 0
prs.mobile/comal.timesheets/PopupEditor.xaml.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using Xamarin.Forms;
+using Xamarin.Forms.Xaml;
+
+namespace comal.timesheets
+{
+	public delegate void PopupEditorSaved(string text);
+	[XamlCompilation(XamlCompilationOptions.Compile)]
+	public partial class PopupEditor : ContentPage
+	{
+		public event PopupEditorSaved OnPopupEdtSaved;
+		public PopupEditor(string text = "")
+		{
+			InitializeComponent();
+			NavigationPage.SetHasBackButton(this, false);
+			textEdt.Text = text;
+		}
+
+		private void CancelBtn_Clicked(object sender, EventArgs e)
+		{
+			Navigation.PopAsync();
+		}
+
+		private void SaveBtn_Clicked(object sender, EventArgs e)
+		{
+			OnPopupEdtSaved(textEdt.Text);
+            Navigation.PopAsync();
+        }
+
+    }
+}

+ 10 - 0
prs.mobile/comal.timesheets/comal.timesheets.projitems

@@ -229,6 +229,10 @@
       <DependentUpon>MyDetailsPage.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="$(MSBuildThisFileDirectory)PopupEditor.xaml.cs">
+      <DependentUpon>PopupEditor.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Include="$(MSBuildThisFileDirectory)PurchaseOrderDetails.xaml.cs">
       <DependentUpon>PurchaseOrderDetails.xaml</DependentUpon>
       <SubType>Code</SubType>
@@ -1009,4 +1013,10 @@
       <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
     </EmbeddedResource>
   </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="$(MSBuildThisFileDirectory)PopupEditor.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+  </ItemGroup>
 </Project>