Skip to content

Commit 826af24

Browse files
feat #404 Facelift for DomainSwitchingDialog and ModelClosingDialog
1 parent b40f5dc commit 826af24

8 files changed

Lines changed: 337 additions & 223 deletions

CDP4ShellDialogs/ViewModels/ModelClosingDialogViewModel.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,17 @@ namespace CDP4ShellDialogs.ViewModels
5353
public class ModelClosingDialogViewModel : DialogViewModelBase
5454
{
5555
/// <summary>
56-
/// Initializes a new instance of the <see cref="ModelClosingDialogViewModel"/> class.
56+
/// Backing field for the <see cref="SelectedRowSession"/> property.
57+
/// </summary>
58+
private ModelSelectionSessionRowViewModel selectedRowSession;
59+
60+
/// <summary>
61+
/// Backing field for the <see cref="IterationRows"/> property.
62+
/// </summary>
63+
private List<ModelSelectionIterationSetupRowViewModel> iterationRows;
64+
65+
/// <summary>
66+
/// Initializes a new instance of the <see cref="ModelClosingDialogViewModel"/> class.
5767
/// </summary>
5868
/// <param name="sessionAvailable">
5969
/// The session Available.
@@ -76,6 +86,24 @@ public ModelClosingDialogViewModel(IEnumerable<ISession> sessionAvailable)
7686
/// </summary>
7787
public DisposableReactiveList<ModelSelectionSessionRowViewModel> SessionsAvailable { get; private set; }
7888

89+
/// <summary>
90+
/// Gets or sets the selected source <see cref="ModelSelectionSessionRowViewModel"/>
91+
/// </summary>
92+
public ModelSelectionSessionRowViewModel SelectedRowSession
93+
{
94+
get => this.selectedRowSession;
95+
set => this.RaiseAndSetIfChanged(ref this.selectedRowSession, value);
96+
}
97+
98+
/// <summary>
99+
/// Gets the flat list of <see cref="ModelSelectionIterationSetupRowViewModel"/> of the <see cref="SelectedRowSession"/>
100+
/// </summary>
101+
public List<ModelSelectionIterationSetupRowViewModel> IterationRows
102+
{
103+
get => this.iterationRows;
104+
private set => this.RaiseAndSetIfChanged(ref this.iterationRows, value);
105+
}
106+
79107
/// <summary>
80108
/// Gets the list of <see cref="IterationSetup"/> selected
81109
/// </summary>
@@ -112,6 +140,21 @@ private void InitializeReactiveCommands()
112140
this.CancelCommand.Subscribe();
113141

114142
this.SelectedIterations.ItemsAdded.Subscribe(this.FilterIterationSelectionItems);
143+
144+
this.WhenAnyValue(x => x.SelectedRowSession).Subscribe(this.PopulateIterationRows);
145+
}
146+
147+
/// <summary>
148+
/// Populates the flat <see cref="IterationRows"/> from the <paramref name="session"/> and resets the current selection
149+
/// </summary>
150+
/// <param name="session">The selected <see cref="ModelSelectionSessionRowViewModel"/></param>
151+
private void PopulateIterationRows(ModelSelectionSessionRowViewModel session)
152+
{
153+
this.SelectedIterations.Clear();
154+
155+
this.IterationRows = session == null
156+
? new List<ModelSelectionIterationSetupRowViewModel>()
157+
: session.EngineeringModelSetupRowViewModels.SelectMany(m => m.IterationSetupRowViewModels).ToList();
115158
}
116159

117160
/// <summary>
@@ -195,6 +238,8 @@ private void PopulateSessionsRowViewModel(IEnumerable<ISession> sessions)
195238
// remove model rows that don't have any open iteration
196239
availableSession.EngineeringModelSetupRowViewModels.RemoveAllAndDispose(availableSession.EngineeringModelSetupRowViewModels.ToList().Where(x => !x.IterationSetupRowViewModels.Any()));
197240
}
241+
242+
this.SelectedRowSession = this.SessionsAvailable.FirstOrDefault();
198243
}
199244

200245
/// <summary>

CDP4ShellDialogs/ViewModels/ModelIterationDomainSwitchDialogViewModel.cs

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// <copyright file="ModelIterationDomainSwitchDialogViewModel.cs" company="Starion Group S.A.">
33
// Copyright (c) 2015-2022 Starion Group S.A.
44
//
5-
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary
5+
// Author: Sam Geren�, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Th�ate, Omar Elebiary
66
//
77
// This file is part of COMET-IME Community Edition.
88
// The COMET-IME Community Edition is the Starion Concurrent Design Desktop Application and Excel Integration
@@ -49,6 +49,16 @@ namespace CDP4ShellDialogs.ViewModels
4949
/// </summary>
5050
public class ModelIterationDomainSwitchDialogViewModel : DialogViewModelBase
5151
{
52+
/// <summary>
53+
/// Backing field for the <see cref="SelectedRowSession" /> property.
54+
/// </summary>
55+
private SwitchDomainSessionRowViewModel selectedRowSession;
56+
57+
/// <summary>
58+
/// Backing field for the <see cref="IterationRows" /> property.
59+
/// </summary>
60+
private List<SwitchDomainIterationSetupRowViewModel> iterationRows;
61+
5262
/// <summary>
5363
/// Initializes a new instance of the <see cref="ModelClosingDialogViewModel" /> class.
5464
/// </summary>
@@ -73,6 +83,24 @@ public ModelIterationDomainSwitchDialogViewModel(IEnumerable<ISession> sessionAv
7383
/// </summary>
7484
public DisposableReactiveList<SwitchDomainSessionRowViewModel> SessionsAvailable { get; private set; }
7585

86+
/// <summary>
87+
/// Gets or sets the selected source <see cref="SwitchDomainSessionRowViewModel" />
88+
/// </summary>
89+
public SwitchDomainSessionRowViewModel SelectedRowSession
90+
{
91+
get => this.selectedRowSession;
92+
set => this.RaiseAndSetIfChanged(ref this.selectedRowSession, value);
93+
}
94+
95+
/// <summary>
96+
/// Gets the flat list of <see cref="SwitchDomainIterationSetupRowViewModel" /> of the <see cref="SelectedRowSession" />
97+
/// </summary>
98+
public List<SwitchDomainIterationSetupRowViewModel> IterationRows
99+
{
100+
get => this.iterationRows;
101+
private set => this.RaiseAndSetIfChanged(ref this.iterationRows, value);
102+
}
103+
76104
/// <summary>
77105
/// Gets the list of <see cref="IterationSetup" /> selected
78106
/// </summary>
@@ -96,7 +124,7 @@ private void InitializeReactiveCommands()
96124
this.SelectedIterations = new ReactiveList<IViewModelBase<Thing>>();
97125
this.IsBusy = false;
98126

99-
var canOk = this.WhenAnyValue(x => x.SelectedIterations.Count, count => count != 0);
127+
var canOk = this.WhenAnyValue(x => x.IterationRows, rows => rows != null && rows.Count != 0);
100128

101129
this.SwitchCommand = ReactiveCommandCreator.CreateAsyncTask(this.ExecuteDomainSwitch, canOk, RxApp.MainThreadScheduler);
102130

@@ -110,6 +138,21 @@ private void InitializeReactiveCommands()
110138
this.CancelCommand = ReactiveCommandCreator.Create(this.ExecuteCancel);
111139

112140
this.SelectedIterations.ItemsAdded.Subscribe(this.FilterIterationSelectionItems);
141+
142+
this.WhenAnyValue(x => x.SelectedRowSession).Subscribe(this.PopulateIterationRows);
143+
}
144+
145+
/// <summary>
146+
/// Populates the flat <see cref="IterationRows" /> from the <paramref name="session" /> and resets the current selection
147+
/// </summary>
148+
/// <param name="session">The selected <see cref="SwitchDomainSessionRowViewModel" /></param>
149+
private void PopulateIterationRows(SwitchDomainSessionRowViewModel session)
150+
{
151+
this.SelectedIterations.Clear();
152+
153+
this.IterationRows = session == null
154+
? new List<SwitchDomainIterationSetupRowViewModel>()
155+
: session.EngineeringModelSetupRowViewModels.SelectMany(m => m.IterationSetupRowViewModels).ToList();
113156
}
114157

115158
/// <summary>
@@ -123,16 +166,22 @@ private async Task ExecuteDomainSwitch()
123166
this.IsBusy = true;
124167
this.LoadingMessage = "Switching...";
125168

126-
foreach (var iteration in this.SelectedIterations)
169+
foreach (var row in this.IterationRows)
127170
{
128-
var modelrow = (SwitchDomainIterationSetupRowViewModel)iteration;
129-
var session = modelrow.Session;
171+
var session = row.Session;
130172

131-
var openIteration = session.OpenIterations.Keys.FirstOrDefault(x => x.Iid == modelrow.IterationIid);
173+
var openIteration = session.OpenIterations.Keys.FirstOrDefault(x => x.Iid == row.IterationIid);
132174

133-
if (openIteration != null)
175+
if (openIteration == null || row.SelectedDomain == null)
134176
{
135-
session.SwitchDomain(modelrow.IterationIid, modelrow.SelectedDomain);
177+
continue;
178+
}
179+
180+
var currentDomain = session.QuerySelectedDomainOfExpertise(openIteration);
181+
182+
if (!Equals(currentDomain, row.SelectedDomain))
183+
{
184+
session.SwitchDomain(row.IterationIid, row.SelectedDomain);
136185
}
137186
}
138187

@@ -164,6 +213,8 @@ private void PopulateSessionsRowViewModel(IEnumerable<ISession> sessions)
164213
{
165214
this.SessionsAvailable.Add(new SwitchDomainSessionRowViewModel(session.RetrieveSiteDirectory(), session));
166215
}
216+
217+
this.SelectedRowSession = this.SessionsAvailable.FirstOrDefault();
167218
}
168219

169220
/// <summary>

CDP4ShellDialogs/ViewModels/ModelSelectionIterationSetupRowViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public ModelSelectionIterationSetupRowViewModel(IterationSetup iterationSetup, P
8080

8181
this.Name = "iteration_" + this.Thing.IterationNumber.ToString(CultureInfo.InvariantCulture);
8282

83+
this.ModelName = (this.Thing.Container as EngineeringModelSetup)?.Name;
84+
8385
this.FrozenOnDate = !this.Thing.FrozenOn.HasValue ? "Active" : this.Thing.FrozenOn.Value.ToString("yyyy-MM-dd HH:mm:ss");
8486
}
8587

@@ -88,6 +90,11 @@ public ModelSelectionIterationSetupRowViewModel(IterationSetup iterationSetup, P
8890
/// </summary>
8991
public string Name { get; private set; }
9092

93+
/// <summary>
94+
/// Gets the name of the <see cref="EngineeringModelSetup"/> that contains the <see cref="IterationSetup"/>
95+
/// </summary>
96+
public string ModelName { get; private set; }
97+
9198
/// <summary>
9299
/// Gets or sets the date at which the iteration was Frozen
93100
/// </summary>

CDP4ShellDialogs/ViewModels/SwitchDomainIterationSetupRowViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public SwitchDomainIterationSetupRowViewModel(IterationSetup iterationSetup, Par
8686

8787
this.Name = "iteration_" + this.Thing.IterationNumber.ToString(CultureInfo.InvariantCulture);
8888

89+
this.ModelName = (this.Thing.Container as EngineeringModelSetup)?.Name;
90+
8991
this.FrozenOnDate = !this.Thing.FrozenOn.HasValue ? "Active" : this.Thing.FrozenOn.Value.ToString("yyyy-MM-dd HH:mm:ss");
9092
}
9193

@@ -94,6 +96,11 @@ public SwitchDomainIterationSetupRowViewModel(IterationSetup iterationSetup, Par
9496
/// </summary>
9597
public string Name { get; private set; }
9698

99+
/// <summary>
100+
/// Gets the name of the <see cref="EngineeringModelSetup" /> that contains the <see cref="IterationSetup" />
101+
/// </summary>
102+
public string ModelName { get; private set; }
103+
97104
/// <summary>
98105
/// Gets or sets the date at which the iteration was Frozen
99106
/// </summary>

0 commit comments

Comments
 (0)