Skip to content

Commit

Permalink
#415 - Force data to show by marshalling to the UI thread (#430)
Browse files Browse the repository at this point in the history
* #415 - Force data to show by marshalling to the current thread

* Update datatype for template

* bump app version

* bump to 8

* remove thread spawning in loop. Format file
  • Loading branch information
john-s-morgan authored Aug 11, 2023
1 parent 6f07394 commit 6c5f003
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">

<Identity Name="ElectionGuard.Admin" Publisher="CN=Microsoft" Version="0.0.0.0" />
<Identity Name="ElectionGuard.Admin" Publisher="CN=Microsoft" Version="1.91.8.0" />

<mp:PhoneIdentity PhoneProductId="F7E69798-9268-43DC-A51E-3A95FA4992AD" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down Expand Up @@ -34,6 +34,8 @@
Square44x44Logo="$placeholder$.png"
BackgroundColor="transparent">
<uap:DefaultTile Square71x71Logo="$placeholder$.png" Wide310x150Logo="$placeholder$.png" Square310x310Logo="$placeholder$.png" />
<uap:InitialRotationPreference>
<uap:Rotation Preference="landscape"/></uap:InitialRotationPreference>
</uap:VisualElements>
</Application>
</Applications>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.Input;
using ElectionGuard.UI.Lib.Extensions;

namespace ElectionGuard.UI.ViewModels;

Expand All @@ -8,6 +9,32 @@ public partial class AdminHomeViewModel : BaseViewModel
private readonly ElectionService _electionService;
private readonly MultiTallyService _multiTallyService;
private readonly TallyService _tallyService;

[ObservableProperty]
private ObservableCollection<Election> _elections = new();

[ObservableProperty]
private ObservableCollection<KeyCeremonyRecord> _keyCeremonies = new();

[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(CreateElectionCommand))]
private bool _hasCompletedKeyCeremonies = false;

[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(CreateMultipleTalliesCommand))]
private bool _canCreateMultiTally = false;

[ObservableProperty]
private ObservableCollection<MultiTallyRecord> _multiTallies = new();

[ObservableProperty]
private Election? _currentElection;

[ObservableProperty]
private KeyCeremonyRecord? _currentKeyCeremony;

[ObservableProperty]
private MultiTallyRecord? _currentMultiTally;

public AdminHomeViewModel(
IServiceProvider serviceProvider,
Expand Down Expand Up @@ -36,19 +63,20 @@ public override async Task OnAppearing()
HasCompletedKeyCeremonies = keyCeremoniesCompleted > 0;
}

var elections = await _electionService.GetAllAsync();
var elections = await _electionService.GetAllAsync();

if (elections is not null)
{
Elections = new ObservableCollection<Election>(elections);
CanCreateMultiTally = Elections.Count > 1;
}

MultiTallies.Clear();
var multiTallies = await _multiTallyService.GetAllAsync();
var newMultiTallies = new List<MultiTallyRecord>();
foreach (var multiTally in multiTallies)
{
var addMultiTally = false;

// check each tally in the multitally to see if any are not complete / abandoned
foreach (var (tallyId, _, _) in multiTally.TallyIds)
{
Expand All @@ -60,36 +88,13 @@ public override async Task OnAppearing()
}
if (addMultiTally)
{
MultiTallies.Add(multiTally);
newMultiTallies.Add(multiTally);
}
}
}

[ObservableProperty]
private ObservableCollection<Election> _elections = new();

[ObservableProperty]
private ObservableCollection<KeyCeremonyRecord> _keyCeremonies = new();

[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(CreateElectionCommand))]
private bool _hasCompletedKeyCeremonies = false;

[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(CreateMultipleTalliesCommand))]
private bool _canCreateMultiTally = false;

[ObservableProperty]
private ObservableCollection<MultiTallyRecord> _multiTallies = new();

[ObservableProperty]
private Election? _currentElection;

[ObservableProperty]
private KeyCeremonyRecord? _currentKeyCeremony;

[ObservableProperty]
private MultiTallyRecord? _currentMultiTally;
MultiTallies.Clear();
MultiTallies.AddRange(newMultiTallies);
}

partial void OnCurrentMultiTallyChanged(MultiTallyRecord? value)
{
Expand Down Expand Up @@ -123,7 +128,7 @@ public async Task GoKeyCeremony()
await NavigationService.GoToPage(typeof(CreateKeyCeremonyAdminViewModel));
}

[RelayCommand(AllowConcurrentExecutions = true, CanExecute =nameof(HasCompletedKeyCeremonies))]
[RelayCommand(AllowConcurrentExecutions = true, CanExecute = nameof(HasCompletedKeyCeremonies))]
private async Task CreateElection()
{
await NavigationService.GoToPage(typeof(CreateElectionViewModel));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<controls:NoContentView Text="{helper:Translate NoKeyCeremonies}" />
</CollectionView.EmptyView>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:Election">
<DataTemplate x:DataType="model:KeyCeremonyRecord">
<Frame Style="{StaticResource ButtonishFrame}">
<Label Style="{StaticResource ButtonishLabel}" Text="{Binding Name}" />
</Frame>
Expand Down

0 comments on commit 6c5f003

Please sign in to comment.