123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- using InABox.Core;
- using InABox.DynamicGrid;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace InABox.Wpf.Dashboard.Editor;
- internal class CoreColumnEditItem : BaseObject
- {
- [EditorSequence(1)]
- public string ColumnName { get; set; } = "";
- [EditorSequence(2)]
- [ComboLookupEditor(typeof(PropertyTypeLookups), Visible = Core.Visible.Default)]
- public Type DataType { get; set; } = typeof(string);
- internal class PropertyTypeLookups : LookupGenerator<object>
- {
- private static IEnumerable<Type> Types => [
- typeof(string),
- typeof(int),
- typeof(bool),
- typeof(DateTime),
- typeof(TimeSpan),
- typeof(double),
- ];
- public PropertyTypeLookups(object[] items) : base(items)
- {
- foreach(var type in Types)
- {
- AddValue(type, type.Name);
- }
- }
- }
- }
- internal class DynamicDashboardAdditionalTableEditItem : BaseObject
- {
- [EditorSequence(1)]
- public string Name { get; set; } = "";
- [EditorSequence(2)]
- [ListEditor]
- public List<CoreColumnEditItem> Columns { get; set; } = new();
- [EditorSequence(3)]
- [ScriptEditor]
- public string Script { get; set; } = "";
- public DynamicDashboardAdditionalTableEditItem()
- {
- }
- public DynamicDashboardAdditionalTableEditItem(DynamicDashboardAdditionalTable table)
- {
- Name = table.Key;
- Columns = table.Columns.ToList(x => new CoreColumnEditItem
- {
- DataType = x.DataType,
- ColumnName = x.ColumnName
- });
- Script = table.Script ?? "";
- }
- public DynamicDashboardAdditionalTable ToTable()
- {
- return new DynamicDashboardAdditionalTable
- {
- Key = Name,
- Columns = Columns.ToList(x => new CoreColumn
- {
- ColumnName = x.ColumnName,
- DataType = x.DataType
- }),
- Script = Script.IsNullOrWhiteSpace() ? null : Script
- };
- }
- }
- internal class DynamicDashboardAdditionalTableGrid : DynamicItemsListGrid<DynamicDashboardAdditionalTableEditItem>
- {
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- base.DoReconfigure(options);
- options.AddRows = true;
- options.EditRows = true;
- options.DeleteRows = true;
- }
- protected override void CustomiseEditor(IDynamicEditorForm form, DynamicDashboardAdditionalTableEditItem[] items, DynamicGridColumn column, BaseEditor editor)
- {
- base.CustomiseEditor(form, items, column, editor);
- var item = items[0];
- if(column.ColumnName == nameof(DynamicDashboardAdditionalTableEditItem.Script) && editor is ScriptEditor scriptEditor)
- {
- scriptEditor.Type = ScriptEditorType.TemplateEditor;
- scriptEditor.OnEditorClicked += () =>
- {
- var script = item.Script.NotWhiteSpaceOr()
- ?? DynamicDashboardAdditionalTable.DefaultScript();
- var editor = new ScriptEditorWindow(script, SyntaxLanguage.CSharp);
- if (editor.ShowDialog() == true)
- {
- form.SetEditorValue(column.ColumnName, editor.Script);
- item.Script = editor.Script;
- }
- };
- }
- }
- }
|