瀏覽代碼

Email template manager (INCOMPLETE)

Nick-PRSDigital@bitbucket.org 2 年之前
父節點
當前提交
e1fde8741d

+ 33 - 2
InABox.Core/DataModel/DataModelTemplate.cs

@@ -1,23 +1,54 @@
-namespace InABox.Core
+using InABox.Clients;
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace InABox.Core
 {
     public class DataModelTemplate : Entity, IRemotable, IPersistent, ISequenceable, ILicense<CoreLicense>
     {
         [TextBoxEditor(Visible = Core.Visible.Hidden, Editable = Editable.Hidden)]
         public string Model { get; set; }
 
+        [EditorSequence(1)]
         [TextBoxEditor]
         public string Name { get; set; }
 
-        [NullEditor]
+        [EditorSequence(2)]
+        [ExpressionEditor(null, Editable = Editable.Enabled)]
+        public string To { get; set; }
+
+        [EditorSequence(3)]
+        [ExpressionEditor(null, Editable = Editable.Enabled)]
+        public string CC { get; set; }
+
+        [EditorSequence(4)]
+        [ExpressionEditor(null, Editable = Editable.Enabled)]
+        public string BCC { get; set; }
+
+        [EditorSequence(5)]
+        [ExpressionEditor(null, Editable = Editable.Enabled)]
+        public string Subject { get; set; }
+
+        [EditorSequence(6)]
+        [ExpressionEditor(null, Editable = Editable.Enabled)]
+        public string AttachmentName { get; set; }
+
+        [EditorSequence(7)]
+        [ScriptEditor(SyntaxLanguage.HTML, Editable = Editable.Enabled)]
         public string Template { get; set; }
 
+        [EditorSequence(8)]
         [CheckBoxEditor]
         public bool Visible { get; set; }
 
+        [EditorSequence(9)]
         [CheckBoxEditor]
         public bool Default { get; set; }
 
         [NullEditor]
         public long Sequence { get; set; }
     }
+
+    
 }

+ 16 - 4
InABox.Core/Editors/ButtonEditor.cs

@@ -7,16 +7,19 @@ namespace InABox.Core
     {
         public String Data { get; set; }
     }
-    
+
+    public delegate ButtonEditorCommand OnCommandCreated();
     public abstract class ButtonEditorCommand
     {
         public abstract void Execute(object sender, ButtonEditorCommandArgs args);
     }
-    
+
+
     public class ButtonEditor : BaseEditor
     {
         private Type _commandtype;
-        
+
+        public event OnCommandCreated OnCommandCreate;
         public String Label { get; set; }
 
         public ButtonEditor(Type commandtype)
@@ -25,6 +28,8 @@ namespace InABox.Core
                 throw new InvalidCastException("Command must be of type ButtonEditorCommand");
 
             _commandtype = commandtype;
+
+
             Label = "Edit";
             Alignment = Alignment.NotSet;
         }
@@ -34,7 +39,14 @@ namespace InABox.Core
             return new ButtonEditor(_commandtype);
         }
 
-        public ButtonEditorCommand? CreateCommand() => Activator.CreateInstance(_commandtype) as ButtonEditorCommand;
+        public ButtonEditorCommand? CreateCommand()
+        {
+            var delegatecommand = OnCommandCreate?.Invoke();
+            if (delegatecommand != null)
+                return delegatecommand;
 
+            var command = Activator.CreateInstance(_commandtype) as ButtonEditorCommand;
+            return command;
+        }
     }
 }

+ 26 - 4
InABox.Core/Editors/ExpressionEditor.cs

@@ -11,6 +11,7 @@ namespace InABox.Core
         public List<string> GetVariables(object?[] items);
     }
 
+    public delegate DataModel GetVariables();
     public class ExpressionEditor : BaseEditor
     {
         /// <summary>
@@ -18,10 +19,12 @@ namespace InABox.Core
         /// </summary>
         public Type? ModelType { get; set; }
 
-        private IExpressionModelGenerator? _modelGenerator;
+        private IExpressionModelGenerator? _modelGenerator;        
 
         public Type? ModelGenerator { get; }
 
+        public event GetVariables OnGetVariables;
+
         [DoNotSerialize]
         [JsonIgnore]
         public List<string>? VariableNames { get; set; }
@@ -29,7 +32,7 @@ namespace InABox.Core
         public ExpressionEditor(Type? modelType, Type? modelGenerator = null)
         {
             ModelType = modelType;
-            if(modelGenerator != null)
+            if (modelGenerator != null)
             {
                 if (!typeof(IExpressionModelGenerator).IsAssignableFrom(modelGenerator))
                 {
@@ -48,7 +51,7 @@ namespace InABox.Core
         }
 
         public List<string> GetVariables(object?[] items)
-        {
+        {         
             if (VariableNames != null)
                 return VariableNames;
             if (ModelGenerator != null)
@@ -56,9 +59,28 @@ namespace InABox.Core
                 _modelGenerator ??= (Activator.CreateInstance(ModelGenerator) as IExpressionModelGenerator)!;
                 return _modelGenerator.GetVariables(items);
             }
-            if(ModelType != null)
+            if (ModelType != null)
                 return CoreExpression.GetModelVariables(ModelType);
+
+            var model = OnGetVariables?.Invoke();
+            if (model != null)
+                return GetVariablesFromDataModel(model);
             return new List<string>();
         }
+
+        private List<string> GetVariablesFromDataModel(DataModel model)
+        {
+            List<string> list = new List<string>();
+            foreach (var table in model.DefaultTables)
+            {
+                foreach (var col in table.Columns)
+                {
+                    if (col.ToString() != "ID")
+                        list.Add(table.ToString() + "." + col.ToString());
+                }
+            }
+            list.Sort();
+            return list;
+        }
     }
 }

+ 5 - 1
InABox.Core/Editors/ScriptEditor.cs

@@ -1,5 +1,8 @@
-namespace InABox.Core
+using System.Collections.Generic;
+
+namespace InABox.Core
 {
+    public delegate Dictionary<string, string[]> OnScriptEditorCalled();
     public enum SyntaxLanguage
     {
         CSharp,
@@ -10,6 +13,7 @@
 
     public class ScriptEditor : BaseEditor
     {
+        public event OnScriptEditorCalled OnScriptEditorCalled;
         public ScriptEditor(SyntaxLanguage language = SyntaxLanguage.CSharp)
         {
             Alignment = Alignment.NotSet;

+ 1 - 1
InABox.DynamicGrid/DynamicImportForm.xaml.cs

@@ -280,7 +280,7 @@ namespace InABox.DynamicGrid
                     "    }\r\n" +
                     "\r\n" +
                     "}";
-            var editor = new ScriptEditor(_importer.Script);
+            var editor = new ScriptEditorWindow(_importer.Script);
             if (editor.ShowDialog() == true) _importer.Script = editor.Script;
         }
 

+ 3 - 3
InABox.DynamicGrid/Editors/ScriptEditorControl.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 using System.ComponentModel;
 using System.Windows;
 using System.Windows.Controls;
@@ -13,12 +14,11 @@ namespace InABox.DynamicGrid
         private Button Editor;
 
         private string script = "";
-
+        public event OnScriptEditorCalled OnScriptEditorCalled;
         public ScriptEditorControl()
         {
             SyntaxLanguage = SyntaxLanguage.CSharp;
         }
-
         public SyntaxLanguage SyntaxLanguage { get; set; }
 
         protected override FrameworkElement CreateEditor()
@@ -38,7 +38,7 @@ namespace InABox.DynamicGrid
 
         private void Editor_Click(object sender, RoutedEventArgs e)
         {
-            var editor = new ScriptEditor(script, SyntaxLanguage);
+            var editor = new ScriptEditorWindow(script, SyntaxLanguage);
             if (editor.ShowDialog() == true)
             {
                 script = editor.Script;

+ 2 - 2
InABox.DynamicGrid/ScriptEditor.xaml

@@ -1,4 +1,4 @@
-<wpf:ThemableWindow x:Class="InABox.DynamicGrid.ScriptEditor"
+<wpf:ThemableWindow x:Class="InABox.DynamicGrid.ScriptEditorWindow"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -11,7 +11,7 @@
         Loaded="OnLoaded">
 
     <Window.CommandBindings>
-        <CommandBinding x:Name="SaveCommandBinding" Command="{x:Static local:ScriptEditor.SaveCommand}"
+        <CommandBinding x:Name="SaveCommandBinding" Command="{x:Static local:ScriptEditorWindow.SaveCommand}"
                         Executed="SaveCommandBinding_Executed"
                         CanExecute="SaveCommandBinding_CanExecute" />
     </Window.CommandBindings>

+ 5 - 5
InABox.DynamicGrid/ScriptEditor.xaml.cs

@@ -25,7 +25,7 @@ namespace InABox.DynamicGrid
     /// <summary>
     ///     Interaction logic for ScriptEditor.xaml
     /// </summary>
-    public partial class ScriptEditor : ThemableWindow
+    public partial class ScriptEditorWindow : ThemableWindow
     {
         public static RoutedCommand SaveCommand = new();
 
@@ -62,12 +62,12 @@ namespace InABox.DynamicGrid
         private readonly Dictionary<bool, Image> save = SetupImage(Properties.Resources.disk);
         private readonly Dictionary<bool, Image> undo = SetupImage(Properties.Resources.undo);
 
-        static ScriptEditor()
+        static ScriptEditorWindow()
         {
             SaveCommand.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control));
         }
 
-        public ScriptEditor(string script, SyntaxLanguage language = SyntaxLanguage.CSharp, string scriptTitle = "ScriptEditor")
+        public ScriptEditorWindow(string script, SyntaxLanguage language = SyntaxLanguage.CSharp, string scriptTitle = "ScriptEditor")
         {
             _language = language;
             _script = script;
@@ -210,13 +210,13 @@ namespace InABox.DynamicGrid
 
         #region Public Interface
 
-        public ScriptEditor ClearErrors()
+        public ScriptEditorWindow ClearErrors()
         {
             Errors.Items.Clear();
             return this;
         }
 
-        public ScriptEditor AddError(string error)
+        public ScriptEditorWindow AddError(string error)
         {
             Errors.Items.Add(error);
             return this;

+ 1 - 1
InABox.Reports/ReportGrid.cs

@@ -8,7 +8,7 @@ using InABox.Reports.Common;
 using InABox.WPF;
 using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
 using SaveFileDialog = Microsoft.Win32.SaveFileDialog;
-using ScriptEditor = InABox.DynamicGrid.ScriptEditor;
+using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
 
 namespace InABox.Reports
 {

+ 1 - 1
InABox.Reports/ReportUtils.cs

@@ -20,7 +20,7 @@ using InABox.Scripting;
 using InABox.WPF;
 using MessageBox = System.Windows.Forms.MessageBox;
 using SaveFileDialog = Microsoft.Win32.SaveFileDialog;
-using ScriptEditor = InABox.DynamicGrid.ScriptEditor;
+using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
 using XmlDocument = System.Xml.XmlDocument;
 
 namespace InABox.Reports