From bdc99b8736adc52d677d2c8929fc74053cdef206 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Fri, 1 May 2015 21:17:17 +0200 Subject: [PATCH] LocalOrg works for display, perhaps - assignment is next --- Common/Generics/Tree.cs | 3 +- Logic/Financial/FinancialAccount.cs | 9 ++++++ Logic/Swarm/Positions.cs | 29 ++++++++++++------- Site5/App_GlobalResources/Pages.Swarm.resx | 8 ++++- Site5/Automation/Json-PositionsTree.aspx.cs | 20 +++++++------ .../Pages/v5/Swarm/LocalOrganization.aspx.cs | 10 ++++++- 6 files changed, 56 insertions(+), 23 deletions(-) diff --git a/Common/Generics/Tree.cs b/Common/Generics/Tree.cs index a43ed845..ec51b7a6 100644 --- a/Common/Generics/Tree.cs +++ b/Common/Generics/Tree.cs @@ -84,13 +84,14 @@ namespace Swarmops.Common.Generics Data = data; } - public void AddChild (TNode newChild) + public TreeNode AddChild (TNode newChild) { TreeNode newNode = new TreeNode(newChild); newNode.Parent = this; newNode.Children = new List>(); // should not be necessary Children.Add (newNode); + return newNode; } public TNode Data; diff --git a/Logic/Financial/FinancialAccount.cs b/Logic/Financial/FinancialAccount.cs index da0e35e4..8dbf78c1 100644 --- a/Logic/Financial/FinancialAccount.cs +++ b/Logic/Financial/FinancialAccount.cs @@ -1,6 +1,7 @@ using System; using Swarmops.Basic.Types.Financial; using Swarmops.Common.Enums; +using Swarmops.Common.Generics; using Swarmops.Database; using Swarmops.Logic.Structure; using Swarmops.Logic.Support; @@ -89,6 +90,14 @@ namespace Swarmops.Logic.Financial } } + public Tree Tree + { + get + { + FinancialAccounts accounts = this.ThisAndBelow(); + return Tree.FromCollection (accounts); + } + } diff --git a/Logic/Swarm/Positions.cs b/Logic/Swarm/Positions.cs index 7a099014..2d549c35 100644 --- a/Logic/Swarm/Positions.cs +++ b/Logic/Swarm/Positions.cs @@ -55,25 +55,32 @@ namespace Swarmops.Logic.Swarm localizedLeaderTitle = geographyLeaderTemplate.Localized(); } - // Add leader positions of the geographies immediately below (in X generations?). + // Add leader positions of the geographies immediately below (in two generations). Tree treeResult = result.Tree; - Geographies children = geography.Children; + Tree geoTree = geography.Tree; - foreach (Geography childGeo in children) - { - // Create copies of the leader position and use as templates for the children - - Position childPosition = Position.FromBasic (geographyLeaderTemplate); - childPosition.AssignGeography (childGeo); - - treeResult.RootNodes[0].AddChild (childPosition); - } + ForOrganizationGeographyRecurse (geoTree.RootNodes[0], treeResult.RootNodes[0], geographyLeaderTemplate, 2); return treeResult; } + private static void ForOrganizationGeographyRecurse (TreeNode geoNode, TreeNode positionNode, Position positionTemplate, int generation) + { + if (generation <= 0) + { + return; + } + + foreach (TreeNode geographyChildNode in geoNode.Children) + { + positionTemplate.AssignGeography (geographyChildNode.Data); + TreeNode newPositionNode = positionNode.AddChild (Position.FromBasic(positionTemplate)); // "FromBasic" creates a deep copy + ForOrganizationGeographyRecurse (geographyChildNode, newPositionNode, positionTemplate, generation - 1); + } + } + public Positions AtLevel (PositionLevel level) { return FromArray (this.Where (position => position.PositionLevel == level).ToArray()); diff --git a/Site5/App_GlobalResources/Pages.Swarm.resx b/Site5/App_GlobalResources/Pages.Swarm.resx index a7dc41de..ec1eaf44 100644 --- a/Site5/App_GlobalResources/Pages.Swarm.resx +++ b/Site5/App_GlobalResources/Pages.Swarm.resx @@ -176,11 +176,17 @@ The result set contains over a thousand people (display limited to a thousand). Please refine your search? + + Local Organization ({0}) + + + The Global Organization + These are your local contacts. (If you have administrative privileges, you may also assign people to these positions.) - My Local Organization ({0}) + My Local Organization The {0} is the geography name. diff --git a/Site5/Automation/Json-PositionsTree.aspx.cs b/Site5/Automation/Json-PositionsTree.aspx.cs index c424be43..b9674c0f 100644 --- a/Site5/Automation/Json-PositionsTree.aspx.cs +++ b/Site5/Automation/Json-PositionsTree.aspx.cs @@ -121,10 +121,12 @@ namespace Swarmops.Frontend.Automation Position position = positionNode.Data; string localizedPositionName = position.Localized (positionNode.Data.MaxCount != 1); PositionAssignments assignments = position.Assignments; + string nodeState = "open"; if (position.GeographyId != _geographyId) { - localizedPositionName += " (" + position.Geography.Name + ")"; + localizedPositionName += " " + position.Geography.Name; + nodeState = "closed"; } string expires = string.Empty; @@ -135,10 +137,10 @@ namespace Swarmops.Frontend.Automation { assignedName = string.Format ( - "{2} {0}", + "{2} {0}", Resources.Controls.Swarm.Positions_Vacant, _customCookieClass, Resources.Controls.Swarm.Positions_AssignFirstPerson, position.Identity, - JavascriptEscape (position.Localized())); + JavascriptEscape(position.Localized()), position.GeographyId); } if (localizedPositionName == null) @@ -164,11 +166,11 @@ namespace Swarmops.Frontend.Automation } } - string element = string.Format("\"id\":\"{0}-1\",\"positionTitle\":\"{1}\",\"assignedName\":\"{2}\",\"expires\":\"{3}\",\"minMax\":\"{4} / {5}\",\"iconType\":\"{6}\",\"actions\":\"{7}\"", + string element = string.Format("\"id\":\"{0}-1-{8}\",\"positionTitle\":\"{1}\",\"assignedName\":\"{2}\",\"expires\":\"{3}\",\"minMax\":\"{4} / {5}\",\"iconType\":\"{6}\",\"actions\":\"{7}\"", position.Identity, JsonSanitize (localizedPositionName), JsonSanitize (assignedName), JsonSanitize (expires), position.MinCount, position.MaxCount == 0? @"∞" : position.MaxCount.ToString(CultureInfo.InvariantCulture), position.MaxCount == 1? "Person" : "Group", - action); + action, position.GeographyId); // TODO: Add all assignments after the first one right here @@ -226,9 +228,9 @@ namespace Swarmops.Frontend.Automation elements.Add ("{" + element + "}"); string addPerson = string.Format ( - "{0}", + "{0}", overEngineeredAssignmentPrompts[count], position.Identity, - JavascriptEscape (position.Localized()), _customCookieClass); + JavascriptEscape (position.Localized()), _customCookieClass, position.GeographyId); element = String.Format( @@ -237,9 +239,9 @@ namespace Swarmops.Frontend.Automation } - if (position.Children.Count > 0) // This should only trigger when position.MaxCount is also 1, or a very weird UI will result + if (positionNode.Children.Count > 0) // This should only trigger when position.MaxCount is also 1, or a very weird UI will result { - element += ",\"state\":\"open\",\"children\":" + RecursePositionTree(positionNode.Children); + element += ",\"state\":\"" + nodeState + "\",\"children\":" + RecursePositionTree(positionNode.Children); } elements.Add("{" + element + "}"); diff --git a/Site5/Pages/v5/Swarm/LocalOrganization.aspx.cs b/Site5/Pages/v5/Swarm/LocalOrganization.aspx.cs index c21fd511..2d88de03 100644 --- a/Site5/Pages/v5/Swarm/LocalOrganization.aspx.cs +++ b/Site5/Pages/v5/Swarm/LocalOrganization.aspx.cs @@ -50,6 +50,15 @@ namespace Swarmops.Frontend.Pages.v5.Swarm } } + if (displayGeography.Identity == Geography.RootIdentity) + { + this.LabelHeaderLocal.Text = Resources.Pages.Swarm.LocalOrganization_HeaderGlobal; + } + else + { + this.LabelHeaderLocal.Text = String.Format(Resources.Pages.Swarm.LocalOrganization_Header, displayGeography.Name); + } + this.TreePositions.GeographyId = displayGeography.Identity; } @@ -59,7 +68,6 @@ namespace Swarmops.Frontend.Pages.v5.Swarm private void Localize() { - this.LabelHeaderLocal.Text = Resources.Pages.Swarm.LocalOrganization_PageTitle; }