From bdbce79e386d31a91265b79f998ff58e6276cd4e Mon Sep 17 00:00:00 2001 From: Stefan Roelofs Date: Sat, 27 Mar 2021 23:24:40 +0100 Subject: [PATCH] ViewModel updates --- .../ViewModels/AddCommandViewModel.cs | 36 +++++--------- .../ViewModels/AddSensorViewModel.cs | 48 +++++++------------ .../ViewModels/CommandSettingsViewModel.cs | 17 ++++--- .../ViewModels/SensorSettingsViewModel.cs | 36 +++++++------- 4 files changed, 58 insertions(+), 79 deletions(-) diff --git a/UserInterface/ViewModels/AddCommandViewModel.cs b/UserInterface/ViewModels/AddCommandViewModel.cs index 133bfca..31d593a 100644 --- a/UserInterface/ViewModels/AddCommandViewModel.cs +++ b/UserInterface/ViewModels/AddCommandViewModel.cs @@ -1,34 +1,24 @@ using hass_workstation_service.Communication.InterProcesCommunication.Models; using ReactiveUI; -using System; -using System.Collections.Generic; -using System.Text; namespace UserInterface.ViewModels { public class AddCommandViewModel : ViewModelBase { - private AvailableCommands selectedType; - private string description; + private AvailableCommands _selectedType; + private string _name; + private string _description; + private bool _showCommandInput; + private bool _showKeyInput; + private string _moreInfoLink; - public string Description { get => description; set => this.RaiseAndSetIfChanged(ref description, value); } - public bool ShowCommandInput { get => showCommandInput; set => this.RaiseAndSetIfChanged(ref showCommandInput, value); } - public bool ShowKeyInput { get => showKeyInput; set => this.RaiseAndSetIfChanged(ref showKeyInput, value); } - - private string moreInfoLink; - private bool showCommandInput; - private bool showKeyInput; - - public string MoreInfoLink - { - get { return moreInfoLink; } - set { this.RaiseAndSetIfChanged(ref moreInfoLink, value); } - } - - public AvailableCommands SelectedType { get => selectedType; set => this.RaiseAndSetIfChanged(ref selectedType, value); } - - public string Name { get; set; } + public AvailableCommands SelectedType { get => _selectedType; set => this.RaiseAndSetIfChanged(ref _selectedType, value); } + public string Name { get => _name; set => this.RaiseAndSetIfChanged(ref _name, value); } + public string Description { get => _description; set => this.RaiseAndSetIfChanged(ref _description, value); } + public bool ShowCommandInput { get => _showCommandInput; set => this.RaiseAndSetIfChanged(ref _showCommandInput, value); } + public bool ShowKeyInput { get => _showKeyInput; set => this.RaiseAndSetIfChanged(ref _showKeyInput, value); } + public string MoreInfoLink { get => _moreInfoLink; set => this.RaiseAndSetIfChanged(ref _moreInfoLink, value); } public string Command { get; set; } public string Key { get; set; } } -} +} \ No newline at end of file diff --git a/UserInterface/ViewModels/AddSensorViewModel.cs b/UserInterface/ViewModels/AddSensorViewModel.cs index e3303f6..6c04b9a 100644 --- a/UserInterface/ViewModels/AddSensorViewModel.cs +++ b/UserInterface/ViewModels/AddSensorViewModel.cs @@ -1,40 +1,28 @@ using hass_workstation_service.Communication.InterProcesCommunication.Models; using ReactiveUI; -using System; -using System.Collections.Generic; -using System.Text; namespace UserInterface.ViewModels { public class AddSensorViewModel : ViewModelBase { - private AvailableSensors selectedType; - private string description; - private bool showQueryInput; - - public string Description { get => description; set => this.RaiseAndSetIfChanged(ref description, value); } - public bool ShowQueryInput { get => showQueryInput; set => this.RaiseAndSetIfChanged(ref showQueryInput, value); } - public bool ShowWindowNameInput { get => showWindowNameInput; set => this.RaiseAndSetIfChanged(ref showWindowNameInput, value); } - - public bool ShowDetectionModeOptions { get => showDetectionModeOptions; set => this.RaiseAndSetIfChanged(ref showDetectionModeOptions, value); } - - private string moreInfoLink; - private int updateInterval; - private bool showWindowNameInput; - private bool showDetectionModeOptions; - - public string MoreInfoLink - { - get { return moreInfoLink; } - set { this.RaiseAndSetIfChanged(ref moreInfoLink, value); } - } - - - public AvailableSensors SelectedType { get => selectedType; set => this.RaiseAndSetIfChanged(ref selectedType, value); } - - public string Name { get; set; } + private AvailableSensors _selectedType; + private string _name; + private int _updateInterval; + private string _description; + private bool _showQueryInput; + private bool _showWindowNameInput; + private bool _showDetectionModeOptions; + private string _moreInfoLink; + + public AvailableSensors SelectedType { get => _selectedType; set => this.RaiseAndSetIfChanged(ref _selectedType, value); } + public string Name { get => _name; set => this.RaiseAndSetIfChanged(ref _name, value); } + public int UpdateInterval { get => _updateInterval; set => this.RaiseAndSetIfChanged(ref _updateInterval, value); } + public string Description { get => _description; set => this.RaiseAndSetIfChanged(ref _description, value); } + public bool ShowQueryInput { get => _showQueryInput; set => this.RaiseAndSetIfChanged(ref _showQueryInput, value); } + public bool ShowWindowNameInput { get => _showWindowNameInput; set => this.RaiseAndSetIfChanged(ref _showWindowNameInput, value); } + public bool ShowDetectionModeOptions { get => _showDetectionModeOptions; set => this.RaiseAndSetIfChanged(ref _showDetectionModeOptions, value); } + public string MoreInfoLink { get => _moreInfoLink; set => this.RaiseAndSetIfChanged(ref _moreInfoLink, value); } public string Query { get; set; } public string WindowName { get; set; } - public int UpdateInterval { get => updateInterval; set => this.RaiseAndSetIfChanged(ref updateInterval, value); } } -} +} \ No newline at end of file diff --git a/UserInterface/ViewModels/CommandSettingsViewModel.cs b/UserInterface/ViewModels/CommandSettingsViewModel.cs index 4477508..ac7eb8a 100644 --- a/UserInterface/ViewModels/CommandSettingsViewModel.cs +++ b/UserInterface/ViewModels/CommandSettingsViewModel.cs @@ -1,15 +1,20 @@ -using ReactiveUI; +using hass_workstation_service.Communication.InterProcesCommunication.Models; +using ReactiveUI; using System; using System.Collections.Generic; -using System.Text; namespace UserInterface.ViewModels { public class CommandSettingsViewModel : ViewModelBase { - private ICollection configuredCommands; + private ICollection _configuredCommands; + + public ICollection ConfiguredCommands + { + get => _configuredCommands; + set => this.RaiseAndSetIfChanged(ref _configuredCommands, value); + } - public ICollection ConfiguredCommands { get => configuredCommands; set => this.RaiseAndSetIfChanged(ref configuredCommands, value); } public void TriggerUpdate() { this.RaisePropertyChanged(); @@ -19,7 +24,7 @@ namespace UserInterface.ViewModels public class CommandViewModel : ViewModelBase { public Guid Id { get; set; } - public string Type { get; set; } + public AvailableCommands Type { get; set; } public string Name { get; set; } } -} +} \ No newline at end of file diff --git a/UserInterface/ViewModels/SensorSettingsViewModel.cs b/UserInterface/ViewModels/SensorSettingsViewModel.cs index 1939bf6..2a52fd0 100644 --- a/UserInterface/ViewModels/SensorSettingsViewModel.cs +++ b/UserInterface/ViewModels/SensorSettingsViewModel.cs @@ -1,15 +1,20 @@ -using ReactiveUI; +using hass_workstation_service.Communication.InterProcesCommunication.Models; +using ReactiveUI; using System; using System.Collections.Generic; -using System.Text; namespace UserInterface.ViewModels { public class SensorSettingsViewModel : ViewModelBase { - private ICollection configuredSensors; + private ICollection _configuredSensors; + + public ICollection ConfiguredSensors + { + get => _configuredSensors; + set => this.RaiseAndSetIfChanged(ref _configuredSensors, value); + } - public ICollection ConfiguredSensors { get => configuredSensors; set => this.RaiseAndSetIfChanged(ref configuredSensors, value); } public void TriggerUpdate() { this.RaisePropertyChanged(); @@ -21,30 +26,21 @@ namespace UserInterface.ViewModels private string _value; public Guid Id { get; set; } - public string Type { get; set; } + public AvailableSensors Type { get; set; } public string Name { get; set; } public int UpdateInterval { get; set; } public string Value { - get => _value; set + get => _value; + set { this.RaiseAndSetIfChanged(ref _value, value); - this.RaisePropertyChanged("ValueString"); + this.RaisePropertyChanged(nameof(ValueString)); } } + public string UnitOfMeasurement { get; set; } - public string ValueString - { - get - { - if (!string.IsNullOrWhiteSpace(_value)) - { - return _value + " " + UnitOfMeasurement; - } - else return ""; - - } - } + public string ValueString => string.IsNullOrWhiteSpace(_value) ? string.Empty : $"{_value} {UnitOfMeasurement}"; } -} +} \ No newline at end of file