Code Cleanup: Assemblies
This commit is contained in:
+133
-139
@@ -7,174 +7,168 @@ using Swarmops.Logic.Swarm;
|
||||
|
||||
namespace Swarmops.Interface.Objects
|
||||
{
|
||||
public class ExpensePayout: IHasIdentity
|
||||
{
|
||||
internal ExpensePayout(Person person, ExpenseClaims expenseClaims)
|
||||
{
|
||||
this.person = person;
|
||||
this.expenseClaims = expenseClaims;
|
||||
public class ExpensePayout : IHasIdentity
|
||||
{
|
||||
private readonly decimal amount;
|
||||
private readonly ExpenseClaims expenseClaims;
|
||||
private readonly Person person;
|
||||
|
||||
decimal total = 0.0m;
|
||||
internal ExpensePayout(Person person, ExpenseClaims expenseClaims)
|
||||
{
|
||||
this.person = person;
|
||||
this.expenseClaims = expenseClaims;
|
||||
|
||||
foreach (ExpenseClaim expense in expenseClaims)
|
||||
{
|
||||
total += expense.Amount;
|
||||
}
|
||||
decimal total = 0.0m;
|
||||
|
||||
this.amount = total;
|
||||
}
|
||||
foreach (ExpenseClaim expense in expenseClaims)
|
||||
{
|
||||
total += expense.Amount;
|
||||
}
|
||||
|
||||
private readonly Person person;
|
||||
this.amount = total;
|
||||
}
|
||||
|
||||
public Person Person
|
||||
{
|
||||
get { return person; }
|
||||
}
|
||||
public Person Person
|
||||
{
|
||||
get { return this.person; }
|
||||
}
|
||||
|
||||
private readonly decimal amount;
|
||||
public decimal Amount
|
||||
{
|
||||
get { return this.amount; }
|
||||
}
|
||||
|
||||
public decimal Amount
|
||||
{
|
||||
get { return amount; }
|
||||
}
|
||||
|
||||
private readonly ExpenseClaims expenseClaims;
|
||||
|
||||
public ExpenseClaims ExpenseClaims
|
||||
{
|
||||
get { return expenseClaims; }
|
||||
}
|
||||
|
||||
public static ExpensePayout FromOrganizationAndPerson (int organizationId, int personId)
|
||||
{
|
||||
ExpenseClaims allExpenseClaims = ExpenseClaims.FromOrganization(Organization.FromIdentity(organizationId));
|
||||
ExpenseClaims expenseClaims = new ExpenseClaims();
|
||||
|
||||
// Aggregate per person
|
||||
|
||||
foreach (ExpenseClaim expense in allExpenseClaims)
|
||||
{
|
||||
if (expense.ClaimingPersonId == personId)
|
||||
{
|
||||
if (expense.Approved && expense.Open)
|
||||
{
|
||||
// Ready for payout
|
||||
|
||||
expenseClaims.Add(expense);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create ExpensePayout object
|
||||
|
||||
return new ExpensePayout(Person.FromIdentity(personId), expenseClaims);
|
||||
}
|
||||
public ExpenseClaims ExpenseClaims
|
||||
{
|
||||
get { return this.expenseClaims; }
|
||||
}
|
||||
|
||||
|
||||
public string ReceiptIdentitiesString // this could be calculated on construction
|
||||
{
|
||||
get
|
||||
{
|
||||
List<string> identities = new List<string>();
|
||||
public string ReceiptIdentitiesString // this could be calculated on construction
|
||||
{
|
||||
get
|
||||
{
|
||||
List<string> identities = new List<string>();
|
||||
|
||||
foreach (ExpenseClaim expense in expenseClaims)
|
||||
{
|
||||
identities.Add(expense.Identity.ToString());
|
||||
}
|
||||
foreach (ExpenseClaim expense in this.expenseClaims)
|
||||
{
|
||||
identities.Add(expense.Identity.ToString());
|
||||
}
|
||||
|
||||
return String.Join(",", identities.ToArray());
|
||||
}
|
||||
}
|
||||
return String.Join(",", identities.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
public string ReceiptList // this could be calculated on construction
|
||||
{
|
||||
get
|
||||
{
|
||||
List<string> spans = new List<string>();
|
||||
List<int> expenseIdList = new List<int>();
|
||||
public string ReceiptList // this could be calculated on construction
|
||||
{
|
||||
get
|
||||
{
|
||||
List<string> spans = new List<string>();
|
||||
List<int> expenseIdList = new List<int>();
|
||||
|
||||
foreach (ExpenseClaim expense in expenseClaims)
|
||||
{
|
||||
expenseIdList.Add(expense.Identity);
|
||||
}
|
||||
foreach (ExpenseClaim expense in this.expenseClaims)
|
||||
{
|
||||
expenseIdList.Add(expense.Identity);
|
||||
}
|
||||
|
||||
int[] expenseIds = expenseIdList.ToArray();
|
||||
Array.Sort(expenseIds);
|
||||
int[] expenseIds = expenseIdList.ToArray();
|
||||
Array.Sort(expenseIds);
|
||||
|
||||
// iterate over the sorted array: group spans of ids together
|
||||
// iterate over the sorted array: group spans of ids together
|
||||
|
||||
int spanStart = expenseIds[0];
|
||||
int spanLength = 0;
|
||||
int currentIndex = 1;
|
||||
int spanStart = expenseIds[0];
|
||||
int spanLength = 0;
|
||||
int currentIndex = 1;
|
||||
|
||||
while (currentIndex < expenseIds.Length)
|
||||
{
|
||||
if (spanStart + spanLength + 1 == expenseIds[currentIndex])
|
||||
{
|
||||
// the span continues
|
||||
while (currentIndex < expenseIds.Length)
|
||||
{
|
||||
if (spanStart + spanLength + 1 == expenseIds[currentIndex])
|
||||
{
|
||||
// the span continues
|
||||
|
||||
spanLength++;
|
||||
currentIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// the span does NOT continue: add
|
||||
spanLength++;
|
||||
currentIndex++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// the span does NOT continue: add
|
||||
|
||||
if (spanLength == 0)
|
||||
{
|
||||
spans.Add(spanStart.ToString());
|
||||
}
|
||||
else if (spanLength == 1) // really means 2, is zero based
|
||||
{
|
||||
spans.Add(spanStart.ToString());
|
||||
spans.Add((spanStart + 1).ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
spans.Add (String.Format ("{0}-{1}", spanStart, spanStart + spanLength));
|
||||
}
|
||||
if (spanLength == 0)
|
||||
{
|
||||
spans.Add(spanStart.ToString());
|
||||
}
|
||||
else if (spanLength == 1) // really means 2, is zero based
|
||||
{
|
||||
spans.Add(spanStart.ToString());
|
||||
spans.Add((spanStart + 1).ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
spans.Add(String.Format("{0}-{1}", spanStart, spanStart + spanLength));
|
||||
}
|
||||
|
||||
spanStart = expenseIds[currentIndex];
|
||||
spanLength = 0;
|
||||
spanStart = expenseIds[currentIndex];
|
||||
spanLength = 0;
|
||||
|
||||
currentIndex++;
|
||||
currentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// Add the last span
|
||||
|
||||
// Add the last span
|
||||
if (spanLength == 0)
|
||||
{
|
||||
spans.Add(spanStart.ToString());
|
||||
}
|
||||
else if (spanLength == 1) // really means 2, is zero based
|
||||
{
|
||||
spans.Add(spanStart.ToString());
|
||||
spans.Add((spanStart + 1).ToString());
|
||||
}
|
||||
else if (spanLength > 1)
|
||||
{
|
||||
spans.Add(String.Format("{0}-{1}", spanStart, spanStart + spanLength));
|
||||
}
|
||||
|
||||
if (spanLength == 0)
|
||||
{
|
||||
spans.Add(spanStart.ToString());
|
||||
}
|
||||
else if (spanLength == 1) // really means 2, is zero based
|
||||
{
|
||||
spans.Add(spanStart.ToString());
|
||||
spans.Add((spanStart + 1).ToString());
|
||||
}
|
||||
else if (spanLength > 1)
|
||||
{
|
||||
spans.Add (String.Format ("{0}-{1}", spanStart, spanStart + spanLength));
|
||||
}
|
||||
// Join spans together with ", " between them
|
||||
|
||||
// Join spans together with ", " between them
|
||||
return String.Join(", ", spans.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
return String.Join (", ", spans.ToArray());
|
||||
#region IHasIdentity Members
|
||||
|
||||
}
|
||||
}
|
||||
public int Identity
|
||||
{
|
||||
// We're borrowing the person's identity, as that is what we iterate across.
|
||||
get { return this.person.Identity; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IHasIdentity Members
|
||||
public static ExpensePayout FromOrganizationAndPerson(int organizationId, int personId)
|
||||
{
|
||||
ExpenseClaims allExpenseClaims = ExpenseClaims.FromOrganization(Organization.FromIdentity(organizationId));
|
||||
ExpenseClaims expenseClaims = new ExpenseClaims();
|
||||
|
||||
public int Identity
|
||||
{
|
||||
// We're borrowing the person's identity, as that is what we iterate across.
|
||||
// Aggregate per person
|
||||
|
||||
get { return person.Identity; }
|
||||
}
|
||||
foreach (ExpenseClaim expense in allExpenseClaims)
|
||||
{
|
||||
if (expense.ClaimingPersonId == personId)
|
||||
{
|
||||
if (expense.Approved && expense.Open)
|
||||
{
|
||||
// Ready for payout
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
expenseClaims.Add(expense);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create ExpensePayout object
|
||||
|
||||
return new ExpensePayout(Person.FromIdentity(personId), expenseClaims);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using System.Xml.Serialization;
|
||||
namespace Swarmops.Interface.Objects
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for MainMenuItem
|
||||
/// Summary description for MainMenuItem
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class MainMenuItem
|
||||
@@ -26,10 +26,21 @@ namespace Swarmops.Interface.Objects
|
||||
}
|
||||
}
|
||||
|
||||
public string ResourceKey { get; set; }
|
||||
public int UserLevel { get; set; }
|
||||
public string Permissions { get; set; }
|
||||
public string ImageUrl { get; set; }
|
||||
public string NavigateUrl { get; set; }
|
||||
public MenuItemType Type { get; set; }
|
||||
|
||||
// TODO: INSERTION POINT (for plugins)
|
||||
|
||||
public MainMenuItem[] Children { get; set; }
|
||||
|
||||
public static MainMenuItem Link(string image, string navUrl, string resourceKey, int userLevel,
|
||||
string permissions)
|
||||
{
|
||||
MainMenuItem result = new MainMenuItem()
|
||||
MainMenuItem result = new MainMenuItem
|
||||
{
|
||||
ImageUrl = image,
|
||||
NavigateUrl = navUrl,
|
||||
@@ -44,7 +55,7 @@ namespace Swarmops.Interface.Objects
|
||||
|
||||
public static MainMenuItem Submenu(string resourceKey, int userLevel, string permissions)
|
||||
{
|
||||
MainMenuItem result = new MainMenuItem()
|
||||
MainMenuItem result = new MainMenuItem
|
||||
{
|
||||
Permissions = permissions,
|
||||
ResourceKey = resourceKey,
|
||||
@@ -57,7 +68,7 @@ namespace Swarmops.Interface.Objects
|
||||
|
||||
public static MainMenuItem Disabled(string image, string resourceKey, int userLevel, string permissions)
|
||||
{
|
||||
MainMenuItem result = new MainMenuItem()
|
||||
MainMenuItem result = new MainMenuItem
|
||||
{
|
||||
ImageUrl = image,
|
||||
Permissions = permissions,
|
||||
@@ -82,40 +93,26 @@ namespace Swarmops.Interface.Objects
|
||||
|
||||
public static void PrimeNewMenuFile()
|
||||
{
|
||||
MainMenuItem todoItem = MainMenuItem.Disabled(string.Empty, "Placeholder_Todo", 1, string.Empty);
|
||||
MainMenuItem[] todoItemArray = new MainMenuItem[] {todoItem};
|
||||
MainMenuItem todoItem = Disabled(string.Empty, "Placeholder_Todo", 1, string.Empty);
|
||||
MainMenuItem[] todoItemArray = {todoItem};
|
||||
|
||||
MainMenuItem peopleItem = MainMenuItem.Submenu("People", 1, string.Empty);
|
||||
MainMenuItem peopleItem = Submenu("People", 1, string.Empty);
|
||||
peopleItem.Children = todoItemArray;
|
||||
|
||||
MainMenuItem commsItem = MainMenuItem.Submenu("Communications", 1, string.Empty);
|
||||
MainMenuItem commsItem = Submenu("Communications", 1, string.Empty);
|
||||
peopleItem.Children = todoItemArray;
|
||||
|
||||
MainMenuItem claimRefundItem = MainMenuItem.Link("iconshock-moneyback",
|
||||
MainMenuItem claimRefundItem = Link("iconshock-moneyback",
|
||||
"/Pages/v5/Financial/FileExpenseClaim.aspx", "Financial_ClaimExpense", 2, String.Empty);
|
||||
MainMenuItem separatorItem = MainMenuItem.Separator;
|
||||
MainMenuItem separatorItem = Separator;
|
||||
|
||||
MainMenuItem[] financialChildren = new[] {claimRefundItem, separatorItem};
|
||||
MainMenuItem financialItem = MainMenuItem.Submenu("Financial", 2, string.Empty);
|
||||
MainMenuItem[] financialChildren = {claimRefundItem, separatorItem};
|
||||
MainMenuItem financialItem = Submenu("Financial", 2, string.Empty);
|
||||
financialItem.Children = financialChildren;
|
||||
|
||||
MainMenuItem[] protoMenu = new[] {peopleItem, commsItem, financialItem};
|
||||
MainMenuItem[] protoMenu = {peopleItem, commsItem, financialItem};
|
||||
PrimeXml(protoMenu);
|
||||
|
||||
}
|
||||
|
||||
public string ResourceKey { get; set; }
|
||||
public int UserLevel { get; set; }
|
||||
public string Permissions { get; set; }
|
||||
public string ImageUrl { get; set; }
|
||||
public string NavigateUrl { get; set; }
|
||||
public MenuItemType Type { get; set; }
|
||||
|
||||
// TODO: INSERTION POINT (for plugins)
|
||||
|
||||
public MainMenuItem[] Children { get; set; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
public enum MenuItemType
|
||||
@@ -123,37 +120,37 @@ namespace Swarmops.Interface.Objects
|
||||
Unknown = 0,
|
||||
|
||||
/// <summary>
|
||||
/// A normal link
|
||||
/// A normal link
|
||||
/// </summary>
|
||||
Link,
|
||||
|
||||
/// <summary>
|
||||
/// Something that looks like a menu item but is disabled
|
||||
/// Something that looks like a menu item but is disabled
|
||||
/// </summary>
|
||||
Disabled,
|
||||
|
||||
/// <summary>
|
||||
/// A header (with or without image) that leads to more options as sub
|
||||
/// A header (with or without image) that leads to more options as sub
|
||||
/// </summary>
|
||||
Submenu,
|
||||
|
||||
/// <summary>
|
||||
/// A thin line separating menu items
|
||||
/// A thin line separating menu items
|
||||
/// </summary>
|
||||
Separator,
|
||||
|
||||
/// <summary>
|
||||
/// A major header (non-link) introducing new menu section
|
||||
/// A major header (non-link) introducing new menu section
|
||||
/// </summary>
|
||||
Header,
|
||||
|
||||
/// <summary>
|
||||
/// Build number indicator
|
||||
/// Build number indicator
|
||||
/// </summary>
|
||||
BuildNumber,
|
||||
|
||||
/// <summary>
|
||||
/// SPECIAL CASE: Close Books menu item
|
||||
/// SPECIAL CASE: Close Books menu item
|
||||
/// </summary>
|
||||
SpecialCloseBooks
|
||||
}
|
||||
|
||||
@@ -6,19 +6,39 @@ namespace Swarmops.Interface.Objects
|
||||
{
|
||||
public class OrganizationMetadata
|
||||
{
|
||||
public OrganizationMetadata (int organizationId, bool recursive, Color color)
|
||||
private readonly Color color;
|
||||
private readonly int organizationId;
|
||||
private readonly bool recursive;
|
||||
|
||||
public OrganizationMetadata(int organizationId, bool recursive, Color color)
|
||||
{
|
||||
this.organizationId = organizationId;
|
||||
this.recursive = recursive;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
|
||||
public int OrganizationId
|
||||
{
|
||||
get { return this.organizationId; }
|
||||
}
|
||||
|
||||
public bool Recursive
|
||||
{
|
||||
get { return this.recursive; }
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get { return this.color; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines the organization accessed from the URL, like *.piratpartiet.se => orgid 1.
|
||||
/// Determines the organization accessed from the URL, like *.piratpartiet.se => orgid 1.
|
||||
/// </summary>
|
||||
/// <param name="url">The url of the webpage in question, like data.piratpartiet.se/something.</param>
|
||||
/// <returns>A new OrganizationMetadata instance.</returns>
|
||||
static public OrganizationMetadata FromUrl (string url)
|
||||
public static OrganizationMetadata FromUrl(string url)
|
||||
{
|
||||
// We could do this using regexps, but it would be messy and error-prone. So instead, I'm going to do it
|
||||
// the old fashioned readable way.
|
||||
@@ -63,7 +83,7 @@ namespace Swarmops.Interface.Objects
|
||||
|
||||
if (url.EndsWith("localhost"))
|
||||
{
|
||||
return new OrganizationMetadata(1, false, Color.FromArgb(0x66, 0, 0x87)); // debug purposes
|
||||
return new OrganizationMetadata(1, false, Color.FromArgb(0x66, 0, 0x87)); // debug purposes
|
||||
}
|
||||
|
||||
//HACK:
|
||||
@@ -79,29 +99,7 @@ namespace Swarmops.Interface.Objects
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
throw new ArgumentException("Unsupported organization" );
|
||||
throw new ArgumentException("Unsupported organization");
|
||||
}
|
||||
|
||||
|
||||
public int OrganizationId
|
||||
{
|
||||
get { return this.organizationId; }
|
||||
}
|
||||
|
||||
public bool Recursive
|
||||
{
|
||||
get { return this.recursive; }
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get { return this.color; }
|
||||
}
|
||||
|
||||
private int organizationId;
|
||||
private bool recursive;
|
||||
private Color color;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user