Пример #1
0
 private void RemoveNode(GoalNode node, List <ulong> visible)
 {
     RefreshParents(node);
     UnloadNode(node, visible);
     RemoveFromMap(node.Goal);
     node.Remove();
 }
Пример #2
0
        private void RefreshParents(GoalNode node)
        {
            GoalNode parent = node.Parent as GoalNode;

            while (parent != null)
            {
                parent.RefreshProgress();

                parent = parent.Parent as GoalNode;
            }
        }
Пример #3
0
        private void GoalTree_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }

            GoalNode node = GoalTree.GetNodeAt(e.Location) as GoalNode;

            if (node == null)
            {
                return;
            }


            ContextMenuStripEx menu = new ContextMenuStripEx();


            bool owned = IsOwned(node);

            bool     root   = false;
            GoalNode parent = node.ParentNode() as GoalNode;

            if (parent == null && node.Goal.Person == Core.UserID && Head.Person == Core.UserID)
            {
                root = true;
            }

            if (owned)
            {
                menu.Items.Add(new GoalMenuItem("Edit", node.Goal, null, Goal_Edit));
                menu.Items.Add(new GoalMenuItem("View Schedule", node.Goal, PlanRes.Schedule.ToBitmap(), Goal_Schedule));
                menu.Items.Add("-");
            }

            if (root)
            {
                menu.Items.Add(new GoalMenuItem("Archive", node.Goal, PlanRes.archive, Goal_Archive));
            }

            if (owned)
            {
                menu.Items.Add(new GoalMenuItem("Delete", node.Goal, PlanRes.delete, Goal_Delete));
            }

            if (!owned)
            {
                menu.Items.Add(new GoalMenuItem("Details", node.Goal, PlanRes.details, Goal_View));
            }


            menu.Show(GoalTree, e.Location);
        }
Пример #4
0
        private GoalNode CreateNode(PlanGoal goal)
        {
            GoalNode node = new GoalNode(this, goal);

            if (!TreeMap.ContainsKey(goal.Person))
            {
                TreeMap[goal.Person] = new List <GoalNode>();
            }

            TreeMap[goal.Person].Add(node);

            return(node);
        }
Пример #5
0
        private void ExpandPath(GoalNode node, List <ulong> uplinks)
        {
            if (!uplinks.Contains(node.Goal.Person))
            {
                return;
            }

            // expand triggers even loading nodes two levels down, one level shown, the other hidden
            node.Expand();

            foreach (GoalNode sub in node.Nodes)
            {
                ExpandPath(sub, uplinks);
            }
        }
Пример #6
0
        private bool LowNode()
        {
            GoalNode above = Parent as GoalNode;

            while (above != null)
            {
                if (above.Goal.Person == Panel.View.UserID)
                {
                    return(true);
                }

                above = above.Parent as GoalNode;
            }

            return(false);
        }
Пример #7
0
        private bool IsOwned(GoalNode node)
        {
            GoalNode parent = node.ParentNode() as GoalNode;

            if (parent != null && parent.Goal.Person == Core.UserID)
            {
                return(true);
            }

            if (parent == null && node.Goal.Person == Core.UserID && Head.Person == Core.UserID)
            {
                return(true);
            }

            return(false);
        }
Пример #8
0
        void GoalTree_NodeExpanding(object sender, EventArgs e)
        {
            GoalNode node = sender as GoalNode;

            if (node == null)
            {
                return;
            }

            Debug.Assert(node.AddSubs);

            // search invisible children of expanded nodes so ready when expanded
            foreach (GoalNode child in node.Nodes)
            {
                LoadNode(child);
            }
        }
Пример #9
0
        private void ReloadGoals()
        {
            TreeMap.Clear();
            GoalTree.Nodes.Clear();

            List <ulong> uplinks = Trust.GetUplinkIDs(View.UserID, View.ProjectID);

            uplinks.Add(View.UserID);

            // show all branches
            if (!MineOnly.Checked)
            {
                GoalNode root = CreateNode(Head);
                LoadNode(root);
                GoalTree.Nodes.Add(root);

                ExpandPath(root, uplinks);
            }

            // show only our branch
            else if (Head != null)
            {
                foreach (ulong id in uplinks)
                {
                    OpPlan plan = Plans.GetPlan(id, true);

                    if (plan != null && plan.GoalMap.ContainsKey(Head.Ident))
                    {
                        foreach (PlanGoal goal in plan.GoalMap[Head.Ident])
                        {
                            if (goal.Person == View.UserID)
                            {
                                GoalNode root = CreateNode(goal);
                                LoadNode(root);
                                InsertSubNode(GoalTree.virtualParent, root);
                                root.Expand();
                            }
                        }
                    }
                }
            }

            Reselect();
        }
Пример #10
0
        public void InsertSubNode(TreeListNode parent, GoalNode node)
        {
            int index = 0;

            foreach (TreeListNode entry in parent.Nodes)
            {
                if (string.Compare(node.Text, entry.Text, true) < 0)
                {
                    parent.Nodes.Insert(index, node);
                    node.RefreshProgress();
                    return;
                }
                else
                {
                    index++;
                }
            }

            parent.Nodes.Insert(index, node);
            node.RefreshProgress();
        }
Пример #11
0
        private void GoalTree_SelectedItemChanged(object sender, EventArgs e)
        {
            if (GoalTree.SelectedNodes.Count == 0)
            {
                return;
            }

            GoalNode node = GoalTree.SelectedNodes[0] as GoalNode;

            if (node == null)
            {
                return;
            }

            Plans.Research(node.Goal.Person);
            Trust.Research(node.Goal.Person, View.ProjectID, false);

            UpdatePlanItems(node);

            View.SetDetails(node.Goal, null);
        }
Пример #12
0
        private void GoalTree_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            GoalNode node = GoalTree.GetNodeAt(e.Location) as GoalNode;

            if (node == null)
            {
                return;
            }

            bool         owned    = IsOwned(node);
            EditGoalMode editMode = owned ? EditGoalMode.Edit : EditGoalMode.View;

            EditGoal form = new EditGoal(editMode, View, node.Goal);

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                if (owned)
                {
                    View.ChangesMade();
                }
            }
        }
Пример #13
0
        private void LoadNode(GoalNode node)
        {
            // check if already loaded
            if (node.AddSubs)
            {
                return;
            }

            node.AddSubs = true;

            // load that person specified by the node
            OpPlan plan = Plans.GetPlan(node.Goal.Person, true);

            if (plan == null)
            {
                Plans.Research(node.Goal.Person);
                return;
            }

            if (!plan.GoalMap.ContainsKey(Head.Ident))
            {
                return;
            }

            // read the person's goals
            foreach (PlanGoal goal in plan.GoalMap[Head.Ident])
            {
                // if the upbranch matches the node's down branch, add
                if (goal.BranchDown == 0 || goal.BranchUp != node.Goal.BranchDown)
                {
                    continue;
                }

                if (CheckGoal(plan.UserID, goal))
                {
                    InsertSubNode(node, CreateNode(goal));
                }
            }
        }
Пример #14
0
        private void VisiblePath(GoalNode node, List <ulong> path)
        {
            bool found = false;

            foreach (GoalNode sub in node.Nodes)
            {
                if (path.Contains(sub.Goal.Person))
                {
                    found = true;
                }
            }

            if (found)
            {
                node.Expand();

                foreach (GoalNode sub in node.Nodes)
                {
                    VisiblePath(sub, path);
                }
            }
        }
Пример #15
0
        void GoalTree_NodeCollapsed(object sender, EventArgs e)
        {
            GoalNode node = sender as GoalNode;

            if (node == null)
            {
                return;
            }

            if (!node.AddSubs) // this node is already collapsed
            {
                return;
            }

            // remove nodes 2 levels down
            foreach (GoalNode child in node.Nodes)
            {
                UnloadNode(child, null);
            }

            Debug.Assert(node.AddSubs); // this is the top level, children hidden underneath
        }
Пример #16
0
        private void UnloadNode(GoalNode node, List <ulong> visible)
        {
            node.AddSubs = false;

            // for each child, call unload node, then clear
            foreach (GoalNode child in node.Nodes)
            {
                RemoveFromMap(child.Goal);


                if (visible != null && child.IsVisible())
                {
                    visible.Add(child.Goal.Person);
                }

                UnloadNode(child, visible);
            }


            node.Nodes.Clear();
            node.Collapse();
        }
Пример #17
0
        private void RefreshParents(GoalNode node)
        {
            GoalNode parent = node.Parent as GoalNode;

            while (parent != null)
            {
                parent.RefreshProgress();

                parent = parent.Parent as GoalNode;
            }
        }
Пример #18
0
        public void TrustUpdate(ulong key)
        {
            if (Head == null)
            {
                return;
            }


            List <ulong> visible = new List <ulong>();

            // remove key from all parent sub items
            // if link changed children confirmations, this takes care of that during the re-add

            if (MineOnly.Checked)
            {
                return;
            }

            if (key == Head.Person || MineOnly.Checked)
            {
                ReloadGoals();
                return;
            }

            else if (TreeMap.ContainsKey(key))
            {
                List <GoalNode> list = new List <GoalNode>(TreeMap[key]);

                foreach (GoalNode node in list)
                {
                    RemoveNode(node, visible);
                }
            }

            List <ulong> myUplinks   = Trust.GetUplinkIDs(View.UserID, View.ProjectID);
            List <ulong> linkUplinks = Trust.GetUplinkIDs(key, View.ProjectID);

            // each uplink from this key can assign goals, we need to see if a re-add is necessary
            foreach (ulong uplink in linkUplinks)
            {
                OpPlan plan = Plans.GetPlan(uplink, true);

                if (plan != null && TreeMap.ContainsKey(uplink))
                {
                    foreach (GoalNode treeNode in TreeMap[uplink])
                    {
                        // look through goals for assignments for this link
                        if (treeNode.AddSubs && plan.GoalMap.ContainsKey(Head.Ident))
                        {
                            foreach (PlanGoal goal in plan.GoalMap[Head.Ident])
                            {
                                if (goal.Person == key &&
                                    treeNode.Goal.BranchDown == goal.BranchUp &&
                                    CheckGoal(plan.UserID, goal))
                                {
                                    GoalNode node = CreateNode(goal);

                                    InsertSubNode(treeNode, node);
                                    RefreshParents(node);

                                    if (treeNode.IsExpanded)
                                    {
                                        LoadNode(node);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // make removed nodes that were visible, visible again
            foreach (ulong id in visible)
            {
                List <ulong> uplinks = Trust.GetUplinkIDs(id, View.ProjectID);

                foreach (GoalNode root in GoalTree.Nodes) // should only be one root
                {
                    VisiblePath(root, uplinks);
                }
            }

            Reselect();
        }
Пример #19
0
        private void UpdatePlanItems(GoalNode node)
        {
            PlanListItem ReselectPlanItem = null;
            if (PlanList.SelectedItems.Count > 0)
                ReselectPlanItem = PlanList.SelectedItems[0] as PlanListItem;

            PlanList.Items.Clear();

            if (node == null)
            {
                Selected = null;
                DelegateLink.Hide();
                PlanList.Columns[0].Text = "Plan";
                //splitContainer2.Panel1Collapsed = true;
                return;
            }

            Selected = node.Goal;

            // set delegate task vis
            if (Selected.Person == Core.UserID && Trust.HasSubs(Selected.Person, View.ProjectID ))
                DelegateLink.Show();
            else
                DelegateLink.Hide();

            if (Selected.Person == Core.UserID)
                AddItemLink.Show();
            else
                AddItemLink.Hide();

            // name's Plan for <goal>

            PlanList.Columns[0].Text = Core.GetName(node.Goal.Person) + "'s Plan for " + node.Goal.Title;

            // set plan items
            OpPlan plan = Plans.GetPlan(Selected.Person, true);

            if (plan == null) // re-searched at during selection
                return;

            if (plan.ItemMap.ContainsKey(Head.Ident))
                foreach (PlanItem item in plan.ItemMap[Head.Ident])
                    if (item.BranchUp == Selected.BranchDown)
                    {
                        PlanListItem row = new PlanListItem(item);

                        if (ReselectPlanItem != null && item == ReselectPlanItem.Item)
                            row.Selected = true;

                        PlanList.Items.Add(row);
                        FormatTime(row);
                    }

            PlanList.Invalidate();
        }
Пример #20
0
        private void UnloadNode(GoalNode node, List<ulong> visible)
        {
            node.AddSubs = false;

            // for each child, call unload node, then clear
              foreach (GoalNode child in node.Nodes)
              {
                  RemoveFromMap(child.Goal);

                  if (visible != null && child.IsVisible())
                      visible.Add(child.Goal.Person);

                  UnloadNode(child, visible);
              }

              node.Nodes.Clear();
              node.Collapse();
        }
Пример #21
0
        private GoalNode CreateNode(PlanGoal goal)
        {
            GoalNode node = new GoalNode(this, goal);

            if (!TreeMap.ContainsKey(goal.Person))
                TreeMap[goal.Person] = new List<GoalNode>();

            TreeMap[goal.Person].Add(node);

            return node;
        }
Пример #22
0
        private void LoadNode(GoalNode node)
        {
            // check if already loaded
            if (node.AddSubs)
                return;

            node.AddSubs = true;

            // load that person specified by the node
            OpPlan plan = Plans.GetPlan(node.Goal.Person, true);

            if (plan == null)
            {
                Plans.Research(node.Goal.Person);
                return;
            }

            if (!plan.GoalMap.ContainsKey(Head.Ident))
                return;

            // read the person's goals
            foreach (PlanGoal goal in plan.GoalMap[Head.Ident])
            {
                // if the upbranch matches the node's down branch, add
                if (goal.BranchDown == 0 || goal.BranchUp != node.Goal.BranchDown)
                    continue;

                if (CheckGoal(plan.UserID, goal))
                    InsertSubNode(node, CreateNode(goal));
            }
        }
Пример #23
0
        private void UpdatePlanItems(GoalNode node)
        {
            PlanListItem ReselectPlanItem = null;

            if (PlanList.SelectedItems.Count > 0)
            {
                ReselectPlanItem = PlanList.SelectedItems[0] as PlanListItem;
            }

            PlanList.Items.Clear();


            if (node == null)
            {
                Selected = null;
                DelegateLink.Hide();
                PlanList.Columns[0].Text = "Plan";
                //splitContainer2.Panel1Collapsed = true;
                return;
            }

            Selected = node.Goal;


            // set delegate task vis
            if (Selected.Person == Core.UserID && Trust.HasSubs(Selected.Person, View.ProjectID))
            {
                DelegateLink.Show();
            }
            else
            {
                DelegateLink.Hide();
            }

            if (Selected.Person == Core.UserID)
            {
                AddItemLink.Show();
            }
            else
            {
                AddItemLink.Hide();
            }

            // name's Plan for <goal>

            PlanList.Columns[0].Text = Core.GetName(node.Goal.Person) + "'s Plan for " + node.Goal.Title;

            // set plan items
            OpPlan plan = Plans.GetPlan(Selected.Person, true);

            if (plan == null) // re-searched at during selection
            {
                return;
            }


            if (plan.ItemMap.ContainsKey(Head.Ident))
            {
                foreach (PlanItem item in plan.ItemMap[Head.Ident])
                {
                    if (item.BranchUp == Selected.BranchDown)
                    {
                        PlanListItem row = new PlanListItem(item);

                        if (ReselectPlanItem != null && item == ReselectPlanItem.Item)
                        {
                            row.Selected = true;
                        }

                        PlanList.Items.Add(row);
                        FormatTime(row);
                    }
                }
            }

            PlanList.Invalidate();
        }
Пример #24
0
        private bool IsOwned(GoalNode node)
        {
            GoalNode parent = node.ParentNode() as GoalNode;

            if (parent != null && parent.Goal.Person == Core.UserID)
                return true;

            if (parent == null && node.Goal.Person == Core.UserID && Head.Person == Core.UserID)
                return true;

            return false;
        }
Пример #25
0
 private void RemoveNode(GoalNode node, List<ulong> visible)
 {
     RefreshParents(node);
     UnloadNode(node, visible);
     RemoveFromMap(node.Goal);
     node.Remove();
 }
Пример #26
0
        private void ExpandPath(GoalNode node, List<ulong> uplinks)
        {
            if (!uplinks.Contains(node.Goal.Person))
                return;

            // expand triggers even loading nodes two levels down, one level shown, the other hidden
            node.Expand();

            foreach (GoalNode sub in node.Nodes)
                ExpandPath(sub, uplinks);
        }
Пример #27
0
        public void InsertSubNode(TreeListNode parent, GoalNode node)
        {
            int index = 0;

            foreach (TreeListNode entry in parent.Nodes)
                if (string.Compare(node.Text, entry.Text, true) < 0)
                {
                    parent.Nodes.Insert(index, node);
                    node.RefreshProgress();
                    return;
                }
                else
                    index++;

            parent.Nodes.Insert(index, node);
            node.RefreshProgress();
        }
Пример #28
0
        public void PlanUpdate(OpPlan plan)
        {
            if (Head == null)
            {
                return;
            }


            if (!plan.Loaded)
            {
                Plans.LoadPlan(plan.UserID);
            }

            // update progress of high levels for updated plan not in tree map because it is hidden
            if (plan.GoalMap.ContainsKey(Head.Ident) || plan.ItemMap.ContainsKey(Head.Ident))
            {
                List <ulong> uplinks = Trust.GetUplinkIDs(plan.UserID, View.ProjectID);
                uplinks.Add(plan.UserID);

                if (uplinks.Contains(Head.Person))
                {
                    foreach (ulong id in uplinks)
                    {
                        if (TreeMap.ContainsKey(id))
                        {
                            foreach (GoalNode node in TreeMap[id])
                            {
                                node.RefreshProgress();
                            }
                        }
                    }
                }
            }

            if (!TreeMap.ContainsKey(plan.UserID))
            {
                return;
            }

            if (MineOnly.Checked)
            {
                List <ulong> myUplinks = Trust.GetUplinkIDs(View.UserID, View.ProjectID);
                myUplinks.Add(View.UserID);

                if (myUplinks.Contains(plan.UserID))
                {
                    ReloadGoals();
                    return;
                }
            }


            List <PlanGoal> updated = new List <PlanGoal>();

            if (plan.GoalMap.ContainsKey(Head.Ident))
            {
                updated = plan.GoalMap[Head.Ident];
            }


            List <ulong> visible = new List <ulong>();

            foreach (GoalNode oldNode in TreeMap[plan.UserID])
            {
                // if root
                if (oldNode.Goal.BranchDown == 0)
                {
                    foreach (PlanGoal updatedGoal in updated)
                    {
                        if (updatedGoal.BranchDown == 0)
                        {
                            oldNode.Update(updatedGoal);
                            RefreshParents(oldNode);
                            break;
                        }
                    }
                }


                // go through displayed goals, if doesn't exist in update, remove
                List <GoalNode> removeList = new List <GoalNode>();

                foreach (GoalNode original in oldNode.Nodes)
                {
                    bool remove = true;

                    foreach (PlanGoal updatedGoal in updated)
                    {
                        if (oldNode.Goal.BranchDown == updatedGoal.BranchUp &&
                            original.Goal.BranchDown == updatedGoal.BranchDown)
                        {
                            remove = false;
                            original.Update(updatedGoal);
                            RefreshParents(original);
                        }
                    }

                    if (remove)
                    {
                        removeList.Add(original);
                    }
                }

                foreach (GoalNode node in removeList)
                {
                    RemoveNode(node, visible);
                }

                // go through updated goals, if isn't shown in display, add
                foreach (PlanGoal updatedGoal in updated)
                {
                    bool add = true; // if not in subs, add

                    if (updatedGoal.BranchDown == 0)
                    {
                        continue;
                    }

                    if (oldNode.Goal.BranchDown != updatedGoal.BranchUp)
                    {
                        continue;
                    }

                    foreach (GoalNode original in oldNode.Nodes)
                    {
                        if (oldNode.Goal.BranchDown == updatedGoal.BranchUp &&
                            original.Goal.BranchDown == updatedGoal.BranchDown)
                        {
                            add = false;
                        }
                    }
                    //crit check this is hit

                    if (add && oldNode.AddSubs && CheckGoal(plan.UserID, updatedGoal))
                    {
                        GoalNode node = CreateNode(updatedGoal);

                        InsertSubNode(oldNode, node);
                        RefreshParents(node);

                        if (oldNode.IsExpanded)
                        {
                            LoadNode(node);
                        }
                    }
                }
            }


            Reselect();
        }
Пример #29
0
        private void VisiblePath(GoalNode node, List<ulong> path)
        {
            bool found = false;

            foreach (GoalNode sub in node.Nodes)
                if (path.Contains(sub.Goal.Person))
                    found = true;

            if (found)
            {
                node.Expand();

                foreach (GoalNode sub in node.Nodes)
                    VisiblePath(sub, path);
            }
        }