Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Any label color #61

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ obj/
_ReSharper*/
[Tt]est[Rr]esult*
*.nupkg
packages/
packages/
TrelloNet.sln.ide
6 changes: 5 additions & 1 deletion TrelloNet.Tests/BoardTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private static ExpectedObject CreateExpectedWelcomeBoard()
Name = "Welcome Board",
Desc = "A test description",
IdOrganization = Constants.TestOrganizationId,
Pinned = true,
Pinned = false,
Url = "https://trello.com/b/J9JUdoYV/welcome-board",
Id = Constants.WelcomeBoardId,
Prefs = new BoardPreferences
Expand All @@ -395,6 +395,10 @@ private static Dictionary<Color, string> CreateExpectedWelcomeBoardLabels()
{ Color.Orange, "" },
{ Color.Green, "label name" },
{ Color.Blue, "" },
{ Color.Pink, "" },
{ Color.Sky, "" },
{ Color.Lime, "" },
{ Color.Black, "" },
};
}
}
Expand Down
10 changes: 7 additions & 3 deletions TrelloNet.Tests/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Search_WithTestQuery_ReturnsCorrectBoard()
Name = "Welcome Board",
Desc = "A test description",
IdOrganization = Constants.TestOrganizationId,
Pinned = true,
Pinned = false,
Url = "https://trello.com/b/J9JUdoYV/welcome-board",
Id = Constants.WelcomeBoardId,
Prefs = new BoardPreferences
Expand All @@ -62,12 +62,16 @@ public void Search_WithTestQuery_ReturnsCorrectBoard()
},
LabelNames = new Dictionary<Color, string>
{
{ Color.Green, "label name" },
{ Color.Yellow, "" },
{ Color.Orange, "" },
{ Color.Red, "" },
{ Color.Purple, "" },
{ Color.Orange, "" },
{ Color.Green, "label name" },
{ Color.Blue, "" },
{ Color.Pink, "" },
{ Color.Sky, "" },
{ Color.Lime, "" },
{ Color.Black, "" },
}
}.ToExpectedObject();

Expand Down
4 changes: 3 additions & 1 deletion TrelloNet/Boards/Internal/BoardsChangeLabelNameRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ internal class BoardsChangeLabelNameRequest : BoardsRequest
public BoardsChangeLabelNameRequest(IBoardId board, Color color, string name)
: base(board, "labelNames/{color}", Method.PUT)
{
AddParameter("color", color.ToTrelloString(), ParameterType.UrlSegment);
Guard.NotNull(color, "color");

AddParameter("color", color.ColorName, ParameterType.UrlSegment);
this.AddValue(name ?? "");
}
}
Expand Down
33 changes: 33 additions & 0 deletions TrelloNet/Boards/Internal/ColorConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.ComponentModel;
using System.Globalization;

namespace TrelloNet.Internal
{
internal class ColorConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof (string);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
// color can be null in uncolored label attached to a card.
if (value == null) return null;

var colorName = value as string;
if (colorName != null)
{
return new Color(colorName);
}
else
{
throw new NotSupportedException(
string.Format(
"Conversion from {0} to Color is not supported",
value.GetType().Name));
}
}
}
}
2 changes: 1 addition & 1 deletion TrelloNet/Cards/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Card : ICardId, IUpdatableCard
public double Pos { get; set; }
public DateTime DateLastActivity { get; set; }
public List<string> IdMembers { get; set; }
public IEnumerable<Color> LabelColors { get { return Labels == null ? Enumerable.Empty<Color>() : Labels.Select(l => l.Color); } }
public IEnumerable<Color> LabelColors { get { return Labels == null ? Enumerable.Empty<Color>() : Labels.Where(l => l.Color != null).Select(l => l.Color); } }

public string GetCardId()
{
Expand Down
66 changes: 59 additions & 7 deletions TrelloNet/Cards/Color.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,64 @@
using System;
using System.ComponentModel;
using TrelloNet.Internal;

namespace TrelloNet
{
public enum Color
[TypeConverter(typeof(ColorConverter))]
public class Color
{
Green,
Yellow,
Orange,
Red,
Purple,
Blue
// Known colors:
public static readonly Color Green = new Color("green");
public static readonly Color Yellow = new Color("yellow");
public static readonly Color Orange = new Color("orange");
public static readonly Color Red = new Color("red");
public static readonly Color Purple = new Color("purple");
public static readonly Color Blue = new Color("blue");
public static readonly Color Pink = new Color("pink");
public static readonly Color Sky = new Color("sky");
public static readonly Color Lime = new Color("lime");
public static readonly Color Black = new Color("black");

public string ColorName { get; private set; }

public Color(string colorName)
{
if (colorName == null) throw new ArgumentNullException("colorName");

ColorName = colorName.ToLower();
}

public override string ToString()
{
return ColorName;
}

protected bool Equals(Color other)
{
return string.Equals(ColorName, other.ColorName);
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((Color)obj);
}

public override int GetHashCode()
{
return (ColorName != null ? ColorName.GetHashCode() : 0);
}

public static bool operator ==(Color left, Color right)
{
return Equals(left, right);
}

public static bool operator !=(Color left, Color right)
{
return !Equals(left, right);
}
}
}
4 changes: 3 additions & 1 deletion TrelloNet/Cards/Internal/CardsAddLabelRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ internal class CardsAddLabelRequest : CardsRequest
public CardsAddLabelRequest(ICardId card, Color color)
: base(card, "labels", Method.POST)
{
this.AddValue(color.ToTrelloString());
Guard.NotNull(color, "color");

this.AddValue(color.ColorName);
}
}
}
4 changes: 3 additions & 1 deletion TrelloNet/Cards/Internal/CardsRemoveLabelRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ internal class CardsRemoveLabelRequest : CardsRequest
public CardsRemoveLabelRequest(ICardId card, Color color)
: base(card, "labels/{color}", Method.DELETE)
{
AddParameter("color", color.ToTrelloString(), ParameterType.UrlSegment);
Guard.NotNull(color, "color");

AddParameter("color", color.ColorName, ParameterType.UrlSegment);
}
}
}
2 changes: 1 addition & 1 deletion TrelloNet/Cards/Internal/CardsUpdateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CardsUpdateRequest(IUpdatableCard card)
AddParameter("closed", card.Closed.ToTrelloString());
AddParameter("idList", card.IdList);
AddParameter("due", card.Due == null ? null : new DateTimeOffset(card.Due.Value).ToString(CultureInfo.InvariantCulture));
AddParameter("labels", string.Join(",", card.LabelColors.Select(c => c.ToTrelloString())));
AddParameter("labels", string.Join(",", card.LabelColors.Select(c => c.ColorName)));
}
}
}
1 change: 1 addition & 0 deletions TrelloNet/TrelloNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<Compile Include="Boards\Internal\BoardsRemoveMemberRequest.cs" />
<Compile Include="Boards\Internal\BoardsUpdateRequest.cs" />
<Compile Include="Boards\Internal\BoardsWithIdRequest.cs" />
<Compile Include="Boards\Internal\ColorConverter.cs" />
<Compile Include="Boards\IUpdatableBoard.cs" />
<Compile Include="Cards\BoardCardFilter.cs" />
<Compile Include="CardName.cs" />
Expand Down