Skip to content

Commit

Permalink
Change progress bar to circular one. Moved percentage information and…
Browse files Browse the repository at this point in the history
… taking longer then to tooltip.
  • Loading branch information
dominikgolda committed Apr 16, 2019
1 parent 7b7cf38 commit bd243ff
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 81 deletions.
120 changes: 54 additions & 66 deletions src/Soloplan.WhatsON.Jenkins.GUI/JenkinsProjectDataTemplate.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,64 @@
Fill="{Binding CurrentStatus.State, Mode=OneWay, Converter={StaticResource StatusToColorConverter}}"
Stretch="Fill"
Visibility="{Binding CurrentStatus.Unknown, Converter={StaticResource BoolToVisibility}}" />
<Path Data="M17.65,6.35C16.2,4.9 14.21,4 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20C15.73,20 18.84,17.45 19.73,14H17.65C16.83,16.33 14.61,18 12,18A6,6 0 0,1 6,12A6,6 0 0,1 12,6C13.66,6 15.14,6.69 16.22,7.78L13,11H20V4L17.65,6.35Z"
Fill="{Binding CurrentStatus.State, Mode=OneWay, Converter={StaticResource StatusToColorConverter}}"
Stretch="Fill"
Visibility="{Binding CurrentStatus.Building, Converter={StaticResource BoolToVisibility}}" />
<Path Data="M13,13H11V7H13M13,17H11V15H13M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z"
Fill="{Binding CurrentStatus.State, Mode=OneWay, Converter={StaticResource StatusToColorConverter}}"
Stretch="Fill"
Visibility="{Binding CurrentStatus.Failure, Converter={StaticResource BoolToVisibility}}" />
<StackPanel Orientation="Horizontal">
<ProgressBar IsIndeterminate="True"
Style="{StaticResource MaterialDesignCircularProgressBar}"
Visibility="{Binding CurrentStatus.Building, Converter={StaticResource BoolToVisibility}}"
Value="{Binding CurrentStatus.Progres, Mode=OneWay}">
<ProgressBar.ToolTip>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Vertical" Visibility="{Binding CurrentStatus.BuildingNoLongerThenExpected, Converter={StaticResource BoolToVisibility}}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Completion: " />
<TextBlock Text="{Binding CurrentStatus.Progres}" />
<TextBlock Text="% " />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:00}:{1:00}:{2:00}">
<Binding Path="CurrentStatus.EstimatedRemaining.Hours" />
<Binding Path="CurrentStatus.EstimatedRemaining.Minutes" />
<Binding Path="CurrentStatus.EstimatedRemaining.Seconds" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Text=" estimated remaining" />
</StackPanel>
</StackPanel>
<StackPanel Visibility="{Binding CurrentStatus.BuildingLongerThenExpected, Converter={StaticResource BoolToVisibility}}">
<TextBlock FontSize="10" Text=" Taking " />
<TextBlock FontSize="10">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:00}:{1:00}:{2:00}">
<Binding Path="CurrentStatus.BuildTimeExcedingEstimation.Hours" />
<Binding Path="CurrentStatus.BuildTimeExcedingEstimation.Minutes" />
<Binding Path="CurrentStatus.BuildTimeExcedingEstimation.Seconds" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock FontSize="10" Text=" longer then estimated." />
</StackPanel>
<TextBlock Text="---------------------------" />
<TextBlock Text="Changes by:" />
<ItemsControl ItemsSource="{Binding CurrentStatus.Culprits}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding FullName}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ProgressBar.ToolTip>
</ProgressBar>
</StackPanel>
<TextBlock Text=" " />
<TextBlock FontWeight="Black" Text="{Binding Name}" />
<TextBlock Text=" #" />
Expand Down Expand Up @@ -131,68 +181,6 @@
</ListView>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding CurrentStatus.BuildingNoLongerThenExpected, Converter={StaticResource BoolToVisibility}}">
<StackPanel.ToolTip>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:00}:{1:00}:{2:00}">
<Binding Path="CurrentStatus.EstimatedRemaining.Hours" />
<Binding Path="CurrentStatus.EstimatedRemaining.Minutes" />
<Binding Path="CurrentStatus.EstimatedRemaining.Seconds" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Text=" estimated remaining" />
</StackPanel>
<TextBlock Text="---------------------------" />
<TextBlock Text="Changes by:" />
<ItemsControl ItemsSource="{Binding CurrentStatus.Culprits}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding FullName}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</StackPanel.ToolTip>
<TextBlock FontSize="10" Text=" Completion: " />
<TextBlock FontSize="10" Text="{Binding CurrentStatus.Progres}" />
<TextBlock FontSize="10" Text="% " />
<ProgressBar Width="100"
materialDesign:TransitionAssist.DisableTransitions="True"
Value="{Binding CurrentStatus.Progres, Mode=OneWay}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding CurrentStatus.BuildingLongerThenExpected, Converter={StaticResource BoolToVisibility}}">
<StackPanel.ToolTip>
<StackPanel>
<TextBlock Text="Changes by:" />
<ItemsControl ItemsSource="{Binding CurrentStatus.Culprits}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding FullName}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</StackPanel.ToolTip>
<TextBlock FontSize="10" Text=" Taking " />
<TextBlock FontSize="10">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0:00}:{1:00}:{2:00}">
<Binding Path="CurrentStatus.BuildTimeExcedingEstimation.Hours" />
<Binding Path="CurrentStatus.BuildTimeExcedingEstimation.Minutes" />
<Binding Path="CurrentStatus.BuildTimeExcedingEstimation.Seconds" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock FontSize="10" Text=" longer then estimated." />
</StackPanel>
</StackPanel>
</DataTemplate>
</ResourceDictionary>
76 changes: 61 additions & 15 deletions src/Soloplan.WhatsON.Jenkins.GUI/JenkinsStatusViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class JenkinsStatusViewModel : StatusViewModel

private bool unstable;

private int rawProgres;

public JenkinsStatusViewModel(JenkinsProjectViewModel model)
: base(model)
{
Expand Down Expand Up @@ -90,7 +92,6 @@ protected set
{
this.building = value;
this.OnPropertyChanged();
this.UpdateEstimatedRemaining();
}
}
}
Expand All @@ -100,8 +101,8 @@ public bool Failure
get => this.failure;
set
{
this.failure = value;
this.OnPropertyChanged();
this.failure = value;
this.OnPropertyChanged();
}
}

Expand All @@ -110,8 +111,8 @@ public bool Unknown
get => this.unknown;
set
{
this.unknown = value;
this.OnPropertyChanged();
this.unknown = value;
this.OnPropertyChanged();
}
}

Expand All @@ -120,8 +121,8 @@ public bool Succees
get => this.succees;
set
{
this.succees = value;
this.OnPropertyChanged();
this.succees = value;
this.OnPropertyChanged();
}
}

Expand All @@ -130,8 +131,8 @@ public bool Unstable
get => this.unstable;
set
{
this.unstable = value;
this.OnPropertyChanged();
this.unstable = value;
this.OnPropertyChanged();
}
}

Expand All @@ -148,7 +149,6 @@ protected set
{
this.duration = value;
this.OnPropertyChanged();
this.UpdateEstimatedRemaining();
}
}
}
Expand All @@ -166,7 +166,6 @@ protected set
{
this.estimatedDuration = value;
this.OnPropertyChanged();
this.UpdateEstimatedRemaining();
}
}
}
Expand Down Expand Up @@ -197,24 +196,45 @@ public TimeSpan BuildTimeExcedingEstimation
}
}

/// <summary>
/// Gets or sets progress shown in progress bar and displayed in GUI.
/// The value is processed:
/// <list type="">
/// <item>0 is changed to 1 to prevent progress bar showing unknown value.</item>
/// <item>Changed to 0 if build is taking longer then expected to show unknown value.</item>
/// <item>Otherwise the value from build server is shown.</item>
/// </list>
/// </summary>
public int Progres
{
get
{
return this.progres;
}

protected set
private set
{
if (this.progres != value)
{
this.progres = value;
this.OnPropertyChanged();
this.UpdateEstimatedRemaining();
}
}
}

/// <summary>
/// Gets or sets the true value of progress. Can get above 100% if the build takes longer then expected.
/// </summary>
public int RawProgres
{
get => this.rawProgres;
private set
{
this.rawProgres = value;
this.OnPropertyChanged();
}
}

public bool BuildingNoLongerThenExpected
{
get => this.buildingNoLongerThenExpected;
Expand Down Expand Up @@ -261,12 +281,12 @@ public override void Update(Status newStatus)
if (this.State == ObservationState.Running)
{
var elapsedSinceStart = (DateTime.Now - this.Time).TotalSeconds;
this.Progres = (int)((100 * elapsedSinceStart) / this.EstimatedDuration.TotalSeconds);
this.RawProgres = (int)((100 * elapsedSinceStart) / this.EstimatedDuration.TotalSeconds);
this.Duration = DateTime.Now - this.Time;
}
else
{
this.Progres = 100;
this.RawProgres = 0;
}

this.Culprits.Clear();
Expand All @@ -278,6 +298,8 @@ public override void Update(Status newStatus)
}

this.UpdateStateFlags();
this.UpdateEstimatedRemaining();
this.UpdateProgres();
}

public void SetJobAddress(OpenWebPageCommandData parentData)
Expand Down Expand Up @@ -342,5 +364,29 @@ private void UpdateStateFlags()
}
}
}

/// <summary>
/// Updates <see cref="Progres"/> based on other parameters.
/// </summary>
/// <remarks>
/// Must be called when <see cref="BuildingNoLongerThenExpected"/>, <see cref="BuildingLongerThenExpected"/> and <see cref="RawProgres"/> are calculated
/// and won't change. It is important not to change values when <see cref="BuildingLongerThenExpected"/> because it resets the indeterminate progress bar
/// and the animation looks bad.
/// </remarks>
private void UpdateProgres()
{
if (this.BuildingNoLongerThenExpected && this.RawProgres == 0)
{
this.Progres = 1;
}
else if (this.BuildingLongerThenExpected)
{
this.Progres = 0;
}
else
{
this.Progres = this.RawProgres;
}
}
}
}

0 comments on commit bd243ff

Please sign in to comment.