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

Add "members" field to card #30

Open
wants to merge 1 commit 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
207 changes: 104 additions & 103 deletions TrelloNet/Cards/Card.cs
Original file line number Diff line number Diff line change
@@ -1,104 +1,105 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace TrelloNet
{
public class Card : ICardId, IUpdatableCard
{
public string Id { get; set; }
public string Name { get; set; }
public string Desc { get; set; }
public bool Closed { get; set; }
public string IdList { get; set; }
public string IdBoard { get; set; }
public DateTime? Due { get; set; }
public List<Label> Labels { get; set; }
public int IdShort { get; set; }
public CardBadges Badges { get; set; }
public List<Checklist> Checklists { get; set; }
public List<Attachment> Attachments { get; set; }
public string Url { get; set; }
public double Pos { get; set; }

public string GetCardId()
{
return Id;
}

public override string ToString()
{
return Name;
}

public class Label
{
public Color Color { get; set; }
public string Name { get; set; }
}

public class CardBadges
{
public int Votes { get; set; }
public DateTime? Due { get; set; }
public bool Description { get; set; }
public int Attachments { get; set; }
public int Comments { get; set; }
public int CheckItemsChecked { get; set; }
public int CheckItems { get; set; }
public string FogBugz { get; set; }
}

public class Attachment : IAttachmentId
{
public string Id { get; set; }
public string IdMember { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public DateTime Date { get; set; }

public string GetAttachmentId()
{
return Id;
}
}

// Handling of check item state :(
// -------------------------------
// A Card has a list of Checklists and a Checklist has a list of CheckItems, but a CheckItem does not include the state (checked/unchecked).
// A Card also has a list of CheckItemState with the ID of it's CheckItem and the state (which always seems to be "complete").
// After we have deserialized go through each CheckItemState and set Checked to true on the corresponding CheckItem.
public class CheckItem : TrelloNet.CheckItem
{
public bool Checked { get; set; }
}

public class Checklist : Checklist<CheckItem>
{
}

private class CheckItemState
{
public string IdCheckItem { get; set; }
public string State { get; set; }
}

[JsonProperty]
private List<CheckItemState> CheckItemStates { get; set; }

[OnDeserialized]
private void AfterDeserialization(StreamingContext context)
{
var checkItems = from cl in Checklists ?? Enumerable.Empty<Checklist>()
from ci in cl.CheckItems
join cis in CheckItemStates on ci.Id equals cis.IdCheckItem
where cis.State == "complete"
select ci;

foreach (var checkItem in checkItems)
checkItem.Checked = true;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace TrelloNet
{
public class Card : ICardId, IUpdatableCard
{
public string Id { get; set; }
public string Name { get; set; }
public string Desc { get; set; }
public bool Closed { get; set; }
public string IdList { get; set; }
public string IdBoard { get; set; }
public DateTime? Due { get; set; }
public List<Label> Labels { get; set; }
public int IdShort { get; set; }
public CardBadges Badges { get; set; }
public List<Checklist> Checklists { get; set; }
public List<Attachment> Attachments { get; set; }
public string Url { get; set; }
public double Pos { get; set; }
public List<Member> Members { get; set; }

public string GetCardId()
{
return Id;
}

public override string ToString()
{
return Name;
}

public class Label
{
public Color Color { get; set; }
public string Name { get; set; }
}

public class CardBadges
{
public int Votes { get; set; }
public DateTime? Due { get; set; }
public bool Description { get; set; }
public int Attachments { get; set; }
public int Comments { get; set; }
public int CheckItemsChecked { get; set; }
public int CheckItems { get; set; }
public string FogBugz { get; set; }
}

public class Attachment : IAttachmentId
{
public string Id { get; set; }
public string IdMember { get; set; }
public string Name { get; set; }
public string Url { get; set; }
public DateTime Date { get; set; }

public string GetAttachmentId()
{
return Id;
}
}

// Handling of check item state :(
// -------------------------------
// A Card has a list of Checklists and a Checklist has a list of CheckItems, but a CheckItem does not include the state (checked/unchecked).
// A Card also has a list of CheckItemState with the ID of it's CheckItem and the state (which always seems to be "complete").
// After we have deserialized go through each CheckItemState and set Checked to true on the corresponding CheckItem.
public class CheckItem : TrelloNet.CheckItem
{
public bool Checked { get; set; }
}

public class Checklist : Checklist<CheckItem>
{
}

private class CheckItemState
{
public string IdCheckItem { get; set; }
public string State { get; set; }
}

[JsonProperty]
private List<CheckItemState> CheckItemStates { get; set; }

[OnDeserialized]
private void AfterDeserialization(StreamingContext context)
{
var checkItems = from cl in Checklists ?? Enumerable.Empty<Checklist>()
from ci in cl.CheckItems
join cis in CheckItemStates on ci.Id equals cis.IdCheckItem
where cis.State == "complete"
select ci;

foreach (var checkItem in checkItems)
checkItem.Checked = true;
}
}
}
125 changes: 63 additions & 62 deletions TrelloNet/Internal/RestRequestExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,63 +1,64 @@
using System;
using System.Collections.Generic;
using RestSharp;
using System.Linq;

namespace TrelloNet.Internal
{
internal static class RestRequestExtensions
{
public static void AddFilter(this RestRequest request, Enum filter, string parameterName = "filter")
{
request.AddParameter(parameterName, filter.ToTrelloString(), ParameterType.GetOrPost);
}

public static void AddPaging(this RestRequest request, Paging paging)
{
if (paging == null)
return;

request.AddParameter("limit", paging.Limit, ParameterType.GetOrPost);
request.AddParameter("page", paging.Page, ParameterType.GetOrPost);
}

public static void AddValue(this RestRequest request, object value)
{
request.AddParameter("value", value);
}

public static void AddCommonCardParameters(this RestRequest request)
{
request.AddParameter("labels", "true");
request.AddParameter("badges", "true");
request.AddParameter("checkItemStates", "true");
request.AddParameter("attachments", "true");
request.AddParameter("checklists", "all");
}

public static void AddRequiredMemberFields(this RestRequest request)
{
request.AddParameter("fields", "fullName,username,bio,url,avatarHash,initials,status");
}

public static void AddSince(this RestRequest request, ISince since)
{
if (since == null)
return;

if (since.LastView)
request.AddParameter("since", "lastView");
if (since.Date > DateTime.MinValue)
request.AddParameter("since", since.Date);
}

public static void AddTypeFilter(this RestRequest request, IEnumerable<ActionType> filters)
{
if (filters == null || !filters.Any())
return;

var filterString = string.Join(",", filters.Select(f => f.ToTrelloString()));
request.AddParameter("filter", filterString, ParameterType.GetOrPost);
}
}
using System;
using System.Collections.Generic;
using RestSharp;
using System.Linq;

namespace TrelloNet.Internal
{
internal static class RestRequestExtensions
{
public static void AddFilter(this RestRequest request, Enum filter, string parameterName = "filter")
{
request.AddParameter(parameterName, filter.ToTrelloString(), ParameterType.GetOrPost);
}

public static void AddPaging(this RestRequest request, Paging paging)
{
if (paging == null)
return;

request.AddParameter("limit", paging.Limit, ParameterType.GetOrPost);
request.AddParameter("page", paging.Page, ParameterType.GetOrPost);
}

public static void AddValue(this RestRequest request, object value)
{
request.AddParameter("value", value);
}

public static void AddCommonCardParameters(this RestRequest request)
{
request.AddParameter("labels", "true");
request.AddParameter("badges", "true");
request.AddParameter("checkItemStates", "true");
request.AddParameter("attachments", "true");
request.AddParameter("checklists", "all");
request.AddParameter("members", "true");
}

public static void AddRequiredMemberFields(this RestRequest request)
{
request.AddParameter("fields", "fullName,username,bio,url,avatarHash,initials,status");
}

public static void AddSince(this RestRequest request, ISince since)
{
if (since == null)
return;

if (since.LastView)
request.AddParameter("since", "lastView");
if (since.Date > DateTime.MinValue)
request.AddParameter("since", since.Date);
}

public static void AddTypeFilter(this RestRequest request, IEnumerable<ActionType> filters)
{
if (filters == null || !filters.Any())
return;

var filterString = string.Join(",", filters.Select(f => f.ToTrelloString()));
request.AddParameter("filter", filterString, ParameterType.GetOrPost);
}
}
}