Skip to content

Commit 42588cf

Browse files
order models and fix requests
1 parent 2cdcc86 commit 42588cf

4 files changed

Lines changed: 67 additions & 3 deletions

File tree

Cross-Platform/SignalGoTest.Desktop/App.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<Application.Resources>
77
<cmd:CommandsViewModel x:Key="CommandsViewModel"/>
88
</Application.Resources>
9+
910
<Application.Styles>
10-
1111
<StyleInclude Source="resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default"/>
1212
<StyleInclude Source="resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default"/>
1313
<Style Selector="Button">

Cross-Platform/SignalGoTest.Desktop/Views/ConnectionInfoView.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
</TextBox>
5353
<TreeView x:Name="TreeViewServices" BorderThickness="1" Background="White" Margin="0,5,0,0" Items="{Binding CurrentConnectionInfo.ItemsSource}" SelectedItem="{Binding SelectedTreeItem}" Grid.Row="1">
54+
5455
<TreeView.DataTemplates>
5556
<TreeDataTemplate DataType="{x:Type self:ServiceDetailsInterface}" ItemsSource="{Binding Methods}">
5657
<StackPanel Orientation="Horizontal">
@@ -142,8 +143,8 @@
142143
<ColumnDefinition Width="*"/>
143144
<ColumnDefinition Width="auto"/>
144145
</Grid.ColumnDefinitions>
145-
<TextBox x:Name="newRequestName" Text=""/>
146-
<Button x:Name="btnAddRequest" Content="Add" Grid.Column="1"/>
146+
<TextBox x:Name="newRequestName" Text="{Binding RequestName}"/>
147+
<Button x:Name="btnAddRequest" Command="{Binding AddNewRequestCommand}" Content="Add" Grid.Column="1"/>
147148
</Grid>
148149
<ListBox x:Name="lstRequests" Grid.Row="1" Items="{Binding SelectedItem.Requests,ElementName=TreeViewServices}" SelectedItem="{Binding ServiceDetailsRequestInfo,Mode=OneWayToSource}" SelectedIndex="0">
149150
<ListBox.ItemTemplate>

Cross-Platform/SignalGoTest.Models/ConnectionInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public List<object> ItemsSource
2323
items.AddRange(Items.Services);
2424
items.AddRange(Items.Callbacks);
2525
items.Add(Items.WebApiDetailsInfo);
26+
Items.ProjectDomainDetailsInfo.Models = Items.ProjectDomainDetailsInfo.Models.OrderBy(x => x.ObjectType == SignalGo.Shared.Helpers.SerializeObjectType.Enum).ThenBy(x => x.Name).ToList();
2627
items.Add(Items.ProjectDomainDetailsInfo);
2728
return items;
2829
}

Cross-Platform/SignalGoTest.ViewModels/ConnectionInfoViewModel.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using SignalGoTest.Models;
1212
using System;
1313
using System.Collections.Generic;
14+
using System.Collections.ObjectModel;
1415
using System.IO;
1516
using System.Linq;
1617
using System.Net;
@@ -52,11 +53,16 @@ public ConnectionInfoViewModel()
5253
});
5354
SendCommand = new Command(Send);
5455
HttpUpdateCommand = new Command(HttpUpdate);
56+
AddNewRequestCommand = new Command(AddNewRequest, () =>
57+
{
58+
return SelectedTreeItem is ServiceDetailsMethod;
59+
});
5560
}
5661

5762

5863
private bool _IsAlert;
5964
private string _SearchText = "";
65+
private string _RequestName;
6066
private object _SelectedTreeItem;
6167
public Command ConnectCommand { get; set; }
6268
public Command DisconnectCommand { get; set; }
@@ -65,6 +71,7 @@ public ConnectionInfoViewModel()
6571
public Command<ServiceDetailsParameterInfo> LoadFullTemplateCommand { get; set; }
6672
public Command SendCommand { get; set; }
6773
public Command HttpUpdateCommand { get; set; }
74+
public Command AddNewRequestCommand { get; set; }
6875

6976
public override bool IsBusy
7077
{
@@ -161,9 +168,23 @@ public object SelectedTreeItem
161168
{
162169
_SelectedTreeItem = value;
163170
OnPropertyChanged(nameof(SelectedTreeItem));
171+
AddNewRequestCommand.ValidateCanExecute();
164172
}
165173
}
166174

175+
public string RequestName
176+
{
177+
get
178+
{
179+
return _RequestName;
180+
}
181+
182+
set
183+
{
184+
_RequestName = value;
185+
OnPropertyChanged(nameof(RequestName));
186+
}
187+
}
167188

168189
private void Disconnect()
169190
{
@@ -236,6 +257,7 @@ public async void Connect()
236257

237258
BusyContent = "Receiving data...";
238259
ProviderDetailsInfo result = await provider.GetListOfServicesWithDetials(CurrentConnectionInfo.ServerAddress);
260+
result.ProjectDomainDetailsInfo.Models = result.ProjectDomainDetailsInfo.Models.OrderBy(x => x.ObjectType == SerializeObjectType.Enum).ThenBy(x => x.Name).ToList();
239261
ProviderDetailsInfo oldItems = currentView.Items;
240262
currentView.Items = result;
241263
currentView.OnPropertyChanged("ItemsSource");
@@ -472,6 +494,46 @@ public async void Send()
472494
}
473495
}
474496

497+
private async void AddNewRequest()
498+
{
499+
try
500+
{
501+
ServiceDetailsMethod selectedMethod = (ServiceDetailsMethod)SelectedTreeItem;
502+
if (selectedMethod == null)
503+
return;
504+
ObservableCollection<ServiceDetailsRequestInfo> requests = selectedMethod.Requests;
505+
string newName = RequestName.Trim();
506+
if (requests.Any(x => x.Name == newName) || string.IsNullOrEmpty(newName))
507+
{
508+
BusyContent = "name is exist or empty!";
509+
IsBusy = true;
510+
await Task.Delay(3000);
511+
return;
512+
}
513+
ServiceDetailsRequestInfo request = new ServiceDetailsRequestInfo() { Name = newName, Parameters = new List<ServiceDetailsParameterInfo>() };
514+
foreach (ServiceDetailsParameterInfo item in selectedMethod.Requests.FirstOrDefault().Parameters)
515+
{
516+
ServiceDetailsParameterInfo clone = item.Clone();
517+
clone.Value = null;
518+
clone.TemplateValue = "";
519+
request.Parameters.Add(clone);
520+
}
521+
requests.Add(request);
522+
RequestName = "";
523+
MainViewModel.This.Save();
524+
}
525+
catch (Exception ex)
526+
{
527+
BusyContent = ex.Message;
528+
IsBusy = true;
529+
await Task.Delay(3000);
530+
}
531+
finally
532+
{
533+
IsBusy = false;
534+
}
535+
}
536+
475537
private async void HttpUpdate()
476538
{
477539
try

0 commit comments

Comments
 (0)