aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-12 20:38:57 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-12 20:38:57 +0200
commit14e4bd850fa6730eecd7d15bd7044f364b41c986 (patch)
tree4e1945a18def6d1c91f239b2b4dbf6e11c0d51db /Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels
parent775f0015321f91aa5be3aca079e289e89d4719f5 (diff)
downloadTango-14e4bd850fa6730eecd7d15bd7044f364b41c986.tar.gz
Tango-14e4bd850fa6730eecd7d15bd7044f364b41c986.zip
Working on data store view.
Diffstat (limited to 'Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels')
-rw-r--r--Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs2
-rw-r--r--Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs216
2 files changed, 202 insertions, 16 deletions
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs
index 63e3f22d9..61eef2bdc 100644
--- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs
+++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/ConfigurationViewVM.cs
@@ -44,6 +44,8 @@ namespace Tango.FSE.MachineConfiguration.ViewModels
using (NotificationProvider.PushTaskItem("Loading machine configuration..."))
{
EditingComposition = msg.EditingComposition;
+ EditingComposition.Machine.ForceVersionUpdateChanged += (x, value) => { if (value) EditingComposition.Machine.SuspendVersionUpdate = false; };
+ EditingComposition.Machine.SuspendVersionUpdateChanged += (x, value) => { if (value) EditingComposition.Machine.ForceVersionUpdate = false; };
}
}
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs
index 4a75c137b..76aee9cde 100644
--- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs
+++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs
@@ -1,12 +1,17 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Windows.Data;
+using Tango.Core.Commands;
using Tango.Core.DI;
+using Tango.DataStore;
using Tango.DataStore.Editing;
using Tango.FSE.Common;
using Tango.FSE.Common.DataStore;
+using Tango.FSE.MachineConfiguration.Dialogs;
using Tango.FSE.MachineConfiguration.Messages;
using static Tango.SharedUI.Controls.NavigationControl;
@@ -15,6 +20,8 @@ namespace Tango.FSE.MachineConfiguration.ViewModels
public class DataStoreViewVM : FSEViewModel, INavigationViewModel
{
private String machineGuid;
+ private ICollectionView _selectedCollectionView;
+ private ICollectionView _collectionsView;
[TangoInject]
private IDataStoreProvider DataStoreProvider { get; set; }
@@ -30,7 +37,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels
public DataStoreCollectionModel SelectedCollection
{
get { return _selectedCollection; }
- set { _selectedCollection = value; RaisePropertyChangedAuto(); }
+ set { _selectedCollection = value; RaisePropertyChangedAuto(); OnSelectedCollectionChanged(); }
}
private DataStoreItemModel _selectedItem;
@@ -40,16 +47,134 @@ namespace Tango.FSE.MachineConfiguration.ViewModels
set { _selectedItem = value; RaisePropertyChangedAuto(); }
}
- private bool _isLoading;
- public bool IsLoading
+ private String _filter;
+ public String Filter
{
- get { return _isLoading; }
- set { _isLoading = value; RaisePropertyChangedAuto(); }
+ get { return _filter; }
+ set { _filter = value; RaisePropertyChangedAuto(); _selectedCollectionView?.Refresh(); }
}
+ public RelayCommand<DataStoreItemModel> RemoveItemCommand { get; set; }
+ public RelayCommand<DataStoreCollectionModel> RemoveCollectionCommand { get; set; }
+ public RelayCommand AddItemCommand { get; set; }
+ public RelayCommand AddCollectionCommand { get; set; }
+ public RelayCommand<DataStoreItemModel> EditItemCommand { get; set; }
+ public RelayCommand SaveCommand { get; set; }
+ public RelayCommand ReloadCommand { get; set; }
+
public DataStoreViewVM()
{
RegisterForMessage<EditingCompositionLoadedMessage>(OnEditingCompositionLoaded);
+ RemoveItemCommand = new RelayCommand<DataStoreItemModel>(RemoveItem);
+ RemoveCollectionCommand = new RelayCommand<DataStoreCollectionModel>(RemoveCollection);
+ AddItemCommand = new RelayCommand(AddItem);
+ AddCollectionCommand = new RelayCommand(AddCollection);
+ EditItemCommand = new RelayCommand<DataStoreItemModel>(EditItem);
+ SaveCommand = new RelayCommand(SaveModel);
+ ReloadCommand = new RelayCommand(ReloadDataStore);
+ }
+
+ private async void ReloadDataStore()
+ {
+ if (DataStore != null)
+ {
+ if (DataStore.Collections.SelectMany(x => x.Items).Any(x => x.HasDifference))
+ {
+ if (!await NotificationProvider.ShowWarningQuestion("Reloading the data store will discard all the current changes. Are you sure?", "RELOAD"))
+ {
+ return;
+ }
+ }
+ }
+
+ await LoadDataStore();
+ }
+
+ private async void EditItem(DataStoreItemModel item)
+ {
+ var vm = await NotificationProvider.ShowDialog<DataStoreItemEditDialogViewVM>(new DataStoreItemEditDialogViewVM() { Item = item, EnableTypeChange = !item.IsGlobal });
+
+ if (vm.DialogResult)
+ {
+ item.IsDeleted = false;
+ item.IsGlobal = false;
+ item.Type = vm.Type;
+ item.Value = vm.Value;
+ }
+ }
+
+ private async void AddCollection()
+ {
+ var result = await NotificationProvider.ShowInputBox("Add Collection", "Please enter the collection name", MaterialDesignThemes.Wpf.PackIconKind.Collection, null, null, 20, null, null, (input) =>
+ {
+ if (DataStore.Collections.ToList().Exists(x => x.Name.ToLower() == input.ToLower()))
+ {
+ return "The specified collection already exists.";
+ }
+
+ return null;
+ });
+
+ if (result.Confirmed)
+ {
+ if (DataStore.Collections.ToList().Exists(x => x.Name.ToLower() == result.Input.ToLower()))
+ {
+ await NotificationProvider.ShowError("The specified collection already exists.");
+ AddCollection();
+ return;
+ }
+
+ DataStore.Collections.Add(new DataStoreCollectionModel()
+ {
+ Name = result.Input
+ });
+
+ SelectedCollection = DataStore.Collections.Last();
+ }
+ }
+
+ private async void AddItem()
+ {
+ var result = await NotificationProvider.ShowInputBox("Add Item", "Please enter the item key", MaterialDesignThemes.Wpf.PackIconKind.KeyAdd, null, null, 20, null, null, (input) =>
+ {
+ if (SelectedCollection.Items.ToList().Exists(x => x.Key.ToLower() == input.ToLower()))
+ {
+ return "The specified key already exists in the collection.";
+ }
+
+ return null;
+ });
+
+ if (result.Confirmed)
+ {
+ if (SelectedCollection.Items.ToList().Exists(x => x.Key == result.Input))
+ {
+ await NotificationProvider.ShowError("The specified key already exists in the collection.");
+ AddItem();
+ return;
+ }
+
+ SelectedCollection.Items.Add(new DataStoreItemModel()
+ {
+ Date = DateTime.UtcNow,
+ Guid = Guid.NewGuid().ToString(),
+ Key = result.Input,
+ Type = DataType.Int32,
+ Value = 10
+ });
+ }
+ }
+
+ private void RemoveCollection(DataStoreCollectionModel collection)
+ {
+ collection.IsDeleted = true;
+ _collectionsView?.Refresh();
+ }
+
+ private void RemoveItem(DataStoreItemModel item)
+ {
+ item.IsDeleted = true;
+ _selectedCollectionView.Refresh();
}
private void OnEditingCompositionLoaded(EditingCompositionLoadedMessage obj)
@@ -58,28 +183,87 @@ namespace Tango.FSE.MachineConfiguration.ViewModels
machineGuid = obj.EditingComposition.Machine.Guid;
}
- public async override void OnNavigatedTo()
+ private void OnSelectedCollectionChanged()
{
- base.OnNavigatedTo();
+ if (SelectedCollection != null)
+ {
+ _selectedCollectionView = CollectionViewSource.GetDefaultView(SelectedCollection.Items);
+ _selectedCollectionView.Filter = (x) => FilterItems(x as DataStoreItemModel);
+ _selectedCollectionView.Refresh();
+ }
+ }
- if (DataStore == null)
+ private bool FilterItems(DataStoreItemModel itemModel)
+ {
+ return (!itemModel.IsDeleted || itemModel.GlobalItem != null) && (String.IsNullOrWhiteSpace(Filter) || itemModel.Key.ToLower().Contains(Filter.ToLower()));
+ }
+
+ private async void SaveModel()
+ {
+ try
{
- try
+ using (NotificationProvider.PushTaskItem("Updating data store..."))
{
- IsLoading = true;
- IsFree = false;
- DataStore = await DataStoreProvider.GetDataStoreModel(machineGuid);
+ await DataStoreProvider.UpdateDataStoreModel(DataStore, machineGuid);
}
- catch (Exception ex)
+
+ if (MachineProvider.IsPPCAvailable)
{
- LogManager.Log(ex, "Error loading data store.");
+ await NotificationProvider.ShowSuccess("The connected machine is now synchronized with the data store.");
}
- finally
+ else
{
- IsLoading = false;
+ await NotificationProvider.ShowInfo("Data store save successfully.\nThe machine will be updated on the next synchronization pass.");
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error saving data store.");
+ await NotificationProvider.ShowError($"Error occurred while trying to save the data store.\n{ex.FlattenMessage()}");
+ return;
+ }
+
+ await LoadDataStore();
+ }
+
+ private async Task LoadDataStore()
+ {
+ try
+ {
+ using (NotificationProvider.PushTaskItem("Loading data store..."))
+ {
+ IsFree = false;
+ var dataStore = await DataStoreProvider.GetDataStoreModel(machineGuid);
+
+ _collectionsView = CollectionViewSource.GetDefaultView(dataStore.Collections);
+ _collectionsView.Filter = (x) => { return !(x as DataStoreCollectionModel).IsDeleted; };
+ _collectionsView.Refresh();
+
+ DataStore = dataStore;
+ SelectedCollection = DataStore.Collections.FirstOrDefault();
+
IsFree = true;
}
}
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error loading data store.");
+ if (await NotificationProvider.ShowWarningQuestion($"Error occurred while trying to load the data store.\n{ex.FlattenMessage()}", "RETRY", "CANCEL"))
+ {
+ await LoadDataStore();
+ return;
+ }
+ }
+ }
+
+ public async override void OnNavigatedTo()
+ {
+ base.OnNavigatedTo();
+
+ if (DataStore == null)
+ {
+ await LoadDataStore();
+ }
}
}
}