Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions schema/v1/ScriptRunnerSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@
"properties": {
"options": {
"type": "string"
},
"searchable": {
"type": "boolean"
},
"optionsGeneratorCommand":
{
"type": "string"
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/ScriptRunner/ScriptRunner.GUI/Parameters/CheckboxControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Avalonia.Controls;

namespace ScriptRunner.GUI;

public class CheckboxControl : IControlRecord
{
public Control Control { get; set; }
public string CheckedValue { get; set; } = "true";
public string UncheckedValue { get; set; } = "false";
public string GetFormattedValue()
{
return ((CheckBox)Control).IsChecked == true ? CheckedValue: UncheckedValue;
}

public string Name { get; set; }
public bool MaskingRequired { get; set; }
}
30 changes: 30 additions & 0 deletions src/ScriptRunner/ScriptRunner.GUI/Parameters/DatePickerControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Globalization;
using Avalonia.Controls;

namespace ScriptRunner.GUI;

public class DatePickerControl : IControlRecord
{
public Control Control { get; set; }

public string GetFormattedValue()
{
var selectedDateTime = Control switch
{
DatePicker dp => dp.SelectedDate?.DateTime,
CalendarDatePicker cdp => cdp.SelectedDate?.Date,
_ => null
};
if (string.IsNullOrWhiteSpace(Format) == false && selectedDateTime is {} value)
{
return value.ToString(Format, Culture);
}
return selectedDateTime?.ToString() ?? string.Empty;
}

public string Name { get; set; }
public bool MaskingRequired { get; set; }

public string? Format { get; set; }
public CultureInfo Culture { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Avalonia.Controls;
using ScriptRunner.GUI.Views;

namespace ScriptRunner.GUI;

public class DirectoryPickerControl : IControlRecord
{
public Control Control { get; set; }

public string GetFormattedValue()
{
return ((DirectoryPicker)Control).DirPath;
}

public string Name { get; set; }
public bool MaskingRequired { get; set; }
}
23 changes: 23 additions & 0 deletions src/ScriptRunner/ScriptRunner.GUI/Parameters/DropdownControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Avalonia.Controls;
using ScriptRunner.GUI.Views;

namespace ScriptRunner.GUI;

public class DropdownControl : IControlRecord
{
public Control Control { get; set; }
public Control InputControl { get; set; }

public string GetFormattedValue()
{
return InputControl switch
{
ComboBox cb => cb.SelectedItem?.ToString(),
SearchableComboBox acb => acb.SelectedItem,
_ => ""
} ?? string.Empty;
}

public string Name { get; set; }
public bool MaskingRequired { get; set; }
}
40 changes: 40 additions & 0 deletions src/ScriptRunner/ScriptRunner.GUI/Parameters/FileContent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Avalonia.Controls;

namespace ScriptRunner.GUI;

public class FileContent : IControlRecord
{
private readonly string _extension;
public Control Control { get; set; }
public string FileName { get; set; }

public FileContent(string extension)
{
_extension = extension;
FileName = Path.GetTempFileName() + "." + extension;
}

public string GetFormattedValue()
{
var fileContent = ((TextBox)Control).Text;
var hash = string.IsNullOrWhiteSpace(fileContent)? "EMPTY" : ComputeSHA256(fileContent).Substring(0,10);
FileName = Path.Combine(Path.GetTempPath(), hash + "." + _extension);
File.WriteAllText(FileName, fileContent, Encoding.UTF8);
return FileName;
}

static string ComputeSHA256(string input)
{
using var sha256 = SHA256.Create();
byte[] bytes = Encoding.UTF8.GetBytes(input);
byte[] hashBytes = sha256.ComputeHash(bytes);
return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
}

public string Name { get; set; }
public bool MaskingRequired { get; set; }
}
17 changes: 17 additions & 0 deletions src/ScriptRunner/ScriptRunner.GUI/Parameters/FilePickerControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Avalonia.Controls;
using ScriptRunner.GUI.Views;

namespace ScriptRunner.GUI;

public class FilePickerControl : IControlRecord
{
public Control Control { get; set; }

public string GetFormattedValue()
{
return ((FilePicker)Control).FilePath;
}

public string Name { get; set; }
public bool MaskingRequired { get; set; }
}
14 changes: 14 additions & 0 deletions src/ScriptRunner/ScriptRunner.GUI/Parameters/IControlRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Avalonia.Controls;

namespace ScriptRunner.GUI;

public interface IControlRecord
{
Control Control { get; set; }

string GetFormattedValue();

public string Name { get; set; }

public bool MaskingRequired { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Globalization;
using Avalonia.Data;
using Avalonia.Data.Converters;
using Avalonia.Media;
using ScriptRunner.GUI.ViewModels;

namespace ScriptRunner.GUI;

public class JobStatusToColorConverter: IValueConverter
{

public static JobStatusToColorConverter Instance { get; } = new();
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is RunningJobStatus status)
{
return status switch
{
RunningJobStatus.NotStarted => new SolidColorBrush(Colors.Black),
RunningJobStatus.Running => new SolidColorBrush(Colors.LightGreen),
RunningJobStatus.Cancelled => new SolidColorBrush(Colors.Yellow),
RunningJobStatus.Failed => new SolidColorBrush(Colors.Red),
RunningJobStatus.Finished => new SolidColorBrush(Colors.Gray),
_ => throw new ArgumentOutOfRangeException()
};
}

return new BindingNotification(new InvalidCastException(), BindingErrorType.Error);
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
29 changes: 29 additions & 0 deletions src/ScriptRunner/ScriptRunner.GUI/Parameters/MultiSelectControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using Avalonia.Controls;

namespace ScriptRunner.GUI;

public class MultiSelectControl : IControlRecord
{
public Control Control { get; set; }

public string GetFormattedValue()
{
var selectedItems = ((ListBox)Control).SelectedItems;
var copy = new List<string>();
foreach (var item in selectedItems)
{
if (item.ToString() is { } nonNullItem)
{
copy.Add(nonNullItem);
}
}

return string.Join(Delimiter, copy);
}

public string Name { get; set; }
public bool MaskingRequired { get; set; }
public string Delimiter { get; set; }

}
16 changes: 16 additions & 0 deletions src/ScriptRunner/ScriptRunner.GUI/Parameters/NumericControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Avalonia.Controls;

namespace ScriptRunner.GUI;

public class NumericControl : IControlRecord
{
public Control Control { get; set; }

public string GetFormattedValue()
{
return ((NumericUpDown)Control).Text;
}

public string Name { get; set; }
public bool MaskingRequired { get; set; }
}
11 changes: 11 additions & 0 deletions src/ScriptRunner/ScriptRunner.GUI/Parameters/ParamsPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using Avalonia.Controls;

namespace ScriptRunner.GUI;

public class ParamsPanel
{
public Panel Panel { get; set; }

public IEnumerable<IControlRecord> ControlRecords { get; set; }
}
Loading
Loading