Skip to content

Commit

Permalink
Merge pull request #8 from Soloplan/master
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
skowront authored Jun 25, 2020
2 parents b60fe57 + aecb43c commit 7843cbd
Show file tree
Hide file tree
Showing 42 changed files with 1,184 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,33 @@
</ToolTip>

<DataTemplate DataType="{x:Type local:CruiseControlProjectViewModel}">
<DockPanel Width="Auto" ContextMenu="{DynamicResource BuildServerProjectContextMenu}">
<buildServer:BuildInformationIconControl DataContext="{Binding CurrentStatus}"
<DockPanel Width="Auto" ContextMenu="{DynamicResource BuildServerProjectContextMenu}">
<buildServer:BuildInformationIconControl DataContext="{Binding CurrentStatus}"
DockPanel.Dock="Left"
ToolTip="{StaticResource CruiseControlBuildInfoToolTip}" />
<buildServer:BuildNumberControl Margin="5,0,0,0"
<buildServer:BuildNumberControl Margin="5,0,0,0"
VerticalAlignment="Center"
BuildNumber="{Binding DataContext.CurrentStatus.BuildNumber, RelativeSource={RelativeSource AncestorType=DockPanel}}" />
<TextBlock MinWidth="150"
<TextBlock MinWidth="150"
MaxWidth="250"
Margin="5,0,0,0"
FontSize="{Binding DataContext.FontSize, Mode=OneWay, RelativeSource={RelativeSource AncestorType=connectorTreeView:ConnectorsTreeView}}"
FontWeight="Normal"
Text="{Binding Name}"
TextTrimming="CharacterEllipsis" />
<buildServer:HistoryBuildList DataContext="{Binding ConnectorSnapshots, Mode=OneWay}" DockPanel.Dock="Right" />
<TextBlock Margin="5,0,10,0"
TextTrimming="CharacterEllipsis">
</TextBlock>
<buildServer:HistoryBuildList DataContext="{Binding ConnectorSnapshots, Mode=OneWay}" DockPanel.Dock="Right" />
<TextBlock Margin="5,0,10,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
DockPanel.Dock="Right"
FontSize="{Binding DataContext.FontSizeSmall, Mode=OneWay, RelativeSource={RelativeSource AncestorType=connectorTreeView:ConnectorsTreeView}}"
FontWeight="Normal"
Text="{Binding CurrentStatus.FinishTime, Converter={StaticResource TimeToApproximateTimeConverter}}"
Visibility="{Binding CurrentStatus.FinishTime, Converter={StaticResource NullOrDefaultVisibilityConverter}}" />
</DockPanel>
</DataTemplate>
<DockPanel.ToolTip>
<TextBlock Text="{Binding Description}"></TextBlock>
</DockPanel.ToolTip>
</DockPanel>
</DataTemplate>
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CruiseControlProjectViewModel : ConnectorViewModel
public CruiseControlProjectViewModel(CruiseControlConnector connector)
: base(connector)
{
this.Url = CruiseControlServer.UrlHelper.GetReportUrl(connector.Address, connector.Project);
this.Url = CruiseControlServer.UrlHelper.GetReportUrl(connector.directAddress, connector.Project);
}

protected override BuildStatusViewModel GetStatusViewModel()
Expand Down
8 changes: 5 additions & 3 deletions src/Soloplan.WhatsON.CruiseControl/CruiseControlConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ namespace Soloplan.WhatsON.CruiseControl
using Soloplan.WhatsON.CruiseControl.Model;
using Soloplan.WhatsON.Model;

[ConnectorType(ConnectorName, Description = "Retrieve the current status of a Cruise Control project.")]
[ConnectorType(ConnectorName, ConnectorDisplayName, Description = "Retrieve the current status of a Cruise Control project.")]
[NotificationConfigurationItem(NotificationsVisbility, typeof(ConnectorNotificationConfiguration), SupportsUnstableNotify = false, Priority = 1600000000)]
public class CruiseControlConnector : Connector
{
public const string ConnectorName = "CruiseControl";

public const string ConnectorDisplayName = "Cruise Control.Net";

private static readonly Logger log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType?.ToString());

private TimeSpan estimatedDuration = default;
Expand All @@ -35,7 +37,7 @@ public CruiseControlConnector(ConnectorConfiguration configuration)

protected override async Task<Status> GetCurrentStatus(CancellationToken cancellationToken)
{
var server = CruiseControlManager.GetServer(this.Address);
var server = CruiseControlManager.GetServer(this.directAddress);
var projectData = await server.GetProjectStatus(cancellationToken, this.Project, 5);
if (projectData == null)
{
Expand All @@ -48,7 +50,7 @@ protected override async Task<Status> GetCurrentStatus(CancellationToken cancell

protected override async Task<List<Status>> GetHistory(CancellationToken cancellationToken)
{
var server = CruiseControlManager.GetServer(this.Address);
var server = CruiseControlManager.GetServer(this.directAddress);
var history = new List<Status>();

var builds = await server.GetBuilds(this.Project);
Expand Down
5 changes: 4 additions & 1 deletion src/Soloplan.WhatsON.CruiseControl/CruiseControlManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public static CruiseControlServer GetServer(string address, bool addToCache = tr
server = new CruiseControlServer(uri.AbsoluteUri);
if (addToCache)
{
servers[uri] = server;
if(server!=null)
{
servers[uri] = server;
}
}

return server;
Expand Down
9 changes: 5 additions & 4 deletions src/Soloplan.WhatsON.CruiseControl/CruiseControlPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override async Task<IList<Project>> GetProjects(string address)
var serverProjects = new List<Project>();
foreach (var project in allProjects.CruiseControlProject)
{
var serverProjectTreeItem = new Project(address, project.Name);
var serverProjectTreeItem = new Project(address, project.Name, address + "server/" + project.ServerName + "/project/" + project.Name + "/ViewProjectReport.aspx"); ;
if (string.IsNullOrWhiteSpace(project.ServerName))
{
result.Add(serverProjectTreeItem);
Expand All @@ -51,7 +51,7 @@ public override async Task<IList<Project>> GetProjects(string address)
var serverProject = serverProjects.FirstOrDefault(s => s.Name == project.ServerName);
if (serverProject == null)
{
serverProject = new Project(null, project.ServerName);
serverProject = new Project(null, project.ServerName, address+"server/"+project.ServerName+"/viewServerReport.aspx", project.Name, address + "server/" + project.ServerName + "/project/" + project.Name);
serverProjects.Add(serverProject);
result.Add(serverProject);
}
Expand All @@ -70,10 +70,11 @@ public override async Task<IList<Project>> GetProjects(string address)
/// <param name="project">The server project.</param>
/// <param name="configurationItemsSupport">The configuration items provider.</param>
/// <param name="serverAddress">The server address.</param>
public override void Configure(Project project, IConfigurationItemProvider configurationItemsSupport, string serverAddress)
public override void Configure(Project project, IConfigurationItemProvider configurationItemsSupport, string serverAddress=null)
{
configurationItemsSupport.GetConfigurationByKey(Connector.ProjectName).Value = project.Name;
configurationItemsSupport.GetConfigurationByKey(Connector.ServerAddress).Value = serverAddress;
configurationItemsSupport.GetConfigurationByKey(Connector.ServerAddress).Value = project.Address;
configurationItemsSupport.GetConfigurationByKey(Connector.DirectAddress).Value = project.DirectAddress;
}
}
}
4 changes: 2 additions & 2 deletions src/Soloplan.WhatsON.CruiseControl/CruiseControlServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ private async Task<TModel> GetStatusAsync<TModel>(CancellationToken cancellation

public static class UrlHelper
{
public static string GetReportUrl(string baseUrl, string project)
public static string GetReportUrl(string baseUrl, string project=null)
{
return $"{SanitizeBaseUri(baseUrl)}/project/{Uri.EscapeDataString(project)}/ViewProjectReport.aspx";
return $"{SanitizeBaseUri(baseUrl)}"+(project!=null?$"/project/{Uri.EscapeDataString(project)}/ViewProjectReport.aspx":string.Empty);
}

public static string GetXmlReportUrl(string baseUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="TagOutline" />
<TextBlock Padding="10,0,0,0" Text="Copy latest build label" />
<TextBlock Padding="10,0,0,0" Text="Copy latest build label" IsEnabled="{Binding RenameCommand.canExecuteState}"/>
</StackPanel>
</MenuItem.Header>
</MenuItem>
<MenuItem Command="{Binding RenameCommand}">
<MenuItem Command="{Binding RenameCommand}" IsEnabled="{Binding RenameCommand.canExecuteState}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Rename" />
<TextBlock Padding="10,0,0,0" Text="Rename" />
</StackPanel>
</MenuItem.Header>
</MenuItem>
<MenuItem Command="{Binding EditCommand}">
<MenuItem Command="{Binding EditCommand}" IsEnabled="{Binding EditCommand.canExecuteState}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Edit" />
Expand All @@ -44,7 +44,7 @@
</StackPanel>
</MenuItem.Header>
</MenuItem>
<MenuItem Command="{Binding ExportCommand}">
<MenuItem Command="{Binding ExportCommand}" IsEnabled="{Binding ExportCommand.canExecuteState}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Export" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,6 @@ private async void DeleteConnector(object sender, DeleteTreeItemEventArgs e)
if (e.DeleteItem is ConnectorViewModel model)
{
this.OnDeleteItem(this, e);
var canceled = await e.CheckCanceled();
if (!canceled && this.ConnectorViewModels.Remove(model))
{
this.OnConfigurationChanged(this, EventArgs.Empty);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace Soloplan.WhatsON.GUI.Common.ConnectorTreeView
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using GongSolutions.Wpf.DragDrop;
using NLog;
Expand All @@ -33,6 +35,11 @@ public class ConnectorTreeViewModel : NotifyPropertyChanged, IHandleDoubleClick,
/// </summary>
private ObservableCollection<ConnectorGroupViewModel> connectorGroups;

/// <summary>
/// Copy of currently selected connectors in case of multiple actions on viewmodel/>.
/// </summary>
private Collection<ConnectorViewModel> selectedConnectors;

/// <summary>
/// Flag indicating that <see cref="ConfigurationChanged"/> event is triggered - used to ignore updates of model.
/// </summary>
Expand All @@ -48,6 +55,11 @@ public class ConnectorTreeViewModel : NotifyPropertyChanged, IHandleDoubleClick,
/// </summary>
private bool prevOneGroupValue;

/// <summary>
/// Previous value of relative instert position.
/// </summary>
private Collection<ConnectorViewModel> connectorsToDrop = new Collection<ConnectorViewModel>();

private int fontSize;

private int fontSizeSmall;
Expand Down Expand Up @@ -185,6 +197,7 @@ public void DragOver(IDropInfo dropInfo)
/// <param name="dropInfo">Information about the drop.</param>
public void Drop(IDropInfo dropInfo)
{

if (dropInfo.Effects != DragDropEffects.Move)
{
log.Warn("Unexpected drop operation. {data}", new { Effect = dropInfo.Effects, dropInfo.Data, Target = dropInfo.TargetItem });
Expand All @@ -198,7 +211,36 @@ public void Drop(IDropInfo dropInfo)
}
else if (dropInfo.Data is ConnectorViewModel draggedConnector)
{
changesExist = this.DropConnector(dropInfo, draggedConnector);
if (this.connectorsToDrop.Count != 0)
{
if (dropInfo.InsertPosition == GongSolutions.Wpf.DragDrop.RelativeInsertPosition.BeforeTargetItem)
{
var targetGroup = this.GetConnectorGroup((ConnectorViewModel)dropInfo.TargetItem);
foreach (var element in this.connectorsToDrop.Reverse())
{
var sourceGroup = this.GetConnectorGroup(element);
MoveObject(sourceGroup, targetGroup, dropInfo.InsertPosition);
targetGroup = this.GetConnectorGroup(element);
}
}
else
{
var targetGroup = this.GetConnectorGroup((ConnectorViewModel)dropInfo.TargetItem);
foreach (var element in this.connectorsToDrop)
{
var sourceGroup = this.GetConnectorGroup(element);
MoveObject(sourceGroup, targetGroup, dropInfo.InsertPosition);
targetGroup = this.GetConnectorGroup(element);
}
}

this.connectorsToDrop = new Collection<ConnectorViewModel>();
this.OnConfigurationChanged(this, EventArgs.Empty);
}
else
{
changesExist = this.DropConnector(dropInfo, draggedConnector);
}
}

if (changesExist)
Expand Down Expand Up @@ -401,6 +443,13 @@ protected void OnConfigurationChanged(object sender, EventArgs args)
}
}

public bool UpdateConnectorsToDrop(Collection<ConnectorViewModel> list)
{
this.connectorsToDrop = list;
return true;
}


/// <summary>
/// Moves object given by <paramref name="source"/> to <paramref name="target"/>.
/// </summary>
Expand Down Expand Up @@ -556,8 +605,77 @@ private void ExportHandler(object sender, ValueEventArgs<TreeItemViewModel> e)
this.ExportItem?.Invoke(sender, e);
}

private async void DeleteGroup(object sender, DeleteTreeItemEventArgs e)
/// <summary>
/// Removes any empty rpesent groups.
/// </summary>
private void ClearEmptyGroups()
{
foreach (var group in this.connectorGroups.ToList())
{
if (group.ConnectorViewModels.Count == 0)
{
this.connectorGroups.Remove(group);
}
}
}

/// <summary>
/// Performs a deletion of all selected connectors.
/// </summary>
private void DeleteSelectedConnectors()
{
bool madeChanges = false;
foreach (var connectorGroup in this.connectorGroups.ToList())
{
foreach (var connector in connectorGroup.ConnectorViewModels.ToList())
{
for (int i = 0; i < this.selectedConnectors.Count;)
{
if (this.selectedConnectors[i].Identifier == connector.Identifier)
{
connectorGroup.ConnectorViewModels.Remove(this.selectedConnectors[i]);
this.selectedConnectors.RemoveAt(i);
madeChanges = true;
i--;
}

i++;
}
}
}

this.ClearEmptyGroups();

if (madeChanges)
{
this.OnConfigurationChanged(this, EventArgs.Empty);
this.FireOneGroupChanged();
}
}

public async void DeleteGroup(object sender, DeleteTreeItemEventArgs e)
{
if (e.DeleteItem is ConnectorViewModel clickedConnector)
{
if (this.selectedConnectors.Count > 1)
{
e.NoOtherSelections = false;
}
else
{
e.NoOtherSelections = true;
}

this.DeleteItem?.Invoke(sender, e);
var canceled = await e.CheckCanceled();
if (!canceled)
{
this.DeleteSelectedConnectors();
}

return;
}

this.DeleteItem?.Invoke(sender, e);
if (e.DeleteItem is ConnectorGroupViewModel group)
{
Expand Down Expand Up @@ -591,10 +709,18 @@ private void SetConnectionModifiedInTree(bool value)
}
}

/// <summary>
/// Updates the currently selected items form view
/// </summary>
public void UpdateSelectedConnectors(Collection<ConnectorViewModel> selectedConnectors)
{
this.selectedConnectors = selectedConnectors;
}

/// <summary>
/// Helper class with information about where the moved object is or should be in <see cref="List"/>.
/// </summary>
private class MovedObjectLocation
public class MovedObjectLocation
{
public MovedObjectLocation(IList list, int index)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ protected virtual BuildStatusViewModel GetStatusViewModel()
protected override CustomCommand CreateEditCommand()
{
var command = base.CreateEditCommand();
command.CanExecuteExternal += (s, e) => e.Cancel = this.ConfigurationModifiedInTree;
command.CanExecuteExternal += (s, e) => { e.Cancel = this.ConfigurationModifiedInTree || !this.isOnlyOneSelected; };
return command;
}
}
Expand Down
Loading

0 comments on commit 7843cbd

Please sign in to comment.