Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/22/17 11:30:52 (7 years ago)
Author:
jzenisek
Message:

#2839 worked views for Projects and ProjectResources

Location:
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectResourcesView.cs

    r15422 r15559  
    4040
    4141    private readonly HashSet<Resource> assignedResources = new HashSet<Resource>();
     42    private readonly HashSet<Resource> newAssignedResources = new HashSet<Resource>();
    4243    private readonly HashSet<Resource> inheritedResources = new HashSet<Resource>();
    43     private readonly Color ownedResourceColor = Color.LightGreen;
     44    private readonly HashSet<Resource> newInheritedResources = new HashSet<Resource>();
     45    private readonly Dictionary<Guid, HashSet<Resource>> resourceAncestors = new Dictionary<Guid, HashSet<Resource>>();
     46    private readonly Dictionary<Guid, HashSet<Resource>> resourceDescendants = new Dictionary<Guid, HashSet<Resource>>();
     47    //private readonly Color ownedResourceColor = Color.LightGreen;
     48    private readonly Color changedAssignmentColor = Color.FromArgb(255, Color.LightGreen);
     49    private readonly Color changedInheritanceColor = Color.FromArgb(255, Color.LightGray);
    4450
    4551    public new Project Content {
     
    6066      if (Content == null) {
    6167        assignedResources.Clear();
     68        newAssignedResources.Clear();
    6269        inheritedResources.Clear();
     70        resourceAncestors.Clear();
    6371        treeView.Nodes.Clear();
    6472        detailsViewHost.Content = null;
    6573      } else {
    6674        UpdateAssignedResources();
    67         UpdateInheritedResources();
     75        UpdateResourceGenealogy();
    6876        var top = BuildResourceTree(HiveAdminClient.Instance.Resources);
    6977        detailsViewHost.Content = top;
    7078      }
    7179    }
     80
    7281    #endregion
    7382
     
    7988    private void refreshButton_Click(object sender, EventArgs e) {
    8089      UpdateAssignedResources();
    81       UpdateInheritedResources();
     90      UpdateResourceGenealogy();
    8291      var top = BuildResourceTree(HiveAdminClient.Instance.Resources);
    8392      detailsViewHost.Content = top;
     
    8594
    8695    private void inheritButton_Click(object sender, EventArgs e) {
     96      return;
    8797      SetAssignedProjectResources(Content.Id, Enumerable.Empty<Guid>());
    8898      UpdateAssignedResources();
    89       UpdateInheritedResources();
     99      UpdateResourceGenealogy();
    90100      var top = BuildResourceTree(HiveAdminClient.Instance.Resources);
    91101      detailsViewHost.Content = top;
     
    94104    private async void saveButton_Click(object sender, EventArgs e) {
    95105      await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
    96         action: () => SetAssignedProjectResources(Content.Id, assignedResources.Select(x => x.Id)));
     106        action: () => {
     107          SetAssignedProjectResources(Content.Id, newAssignedResources.Select(x => x.Id));
     108        });
     109      UpdateResourceTree();
    97110    }
    98111
     
    104117    private void treeView_BeforeCheck(object sender, TreeViewCancelEventArgs e) {
    105118      var checkedResource = (Resource)e.Node.Tag;
    106       if (inheritedResources.Contains(checkedResource) || checkedResource.Id == Guid.Empty) e.Cancel = true;
     119      if (newInheritedResources.Contains(checkedResource) || checkedResource.Id == Guid.Empty) e.Cancel = true;
    107120    }
    108121
    109122    private void treeView_AfterCheck(object sender, TreeViewEventArgs e) {
    110123      var checkedResource = (Resource)e.Node.Tag;
    111       if (e.Node.Checked)
    112         assignedResources.Add(checkedResource);
    113       else
    114         assignedResources.Remove(checkedResource);
     124      if (e.Node.Checked) {
     125        newAssignedResources.Add(checkedResource);
     126      } else {
     127        newAssignedResources.Remove(checkedResource);
     128      }
     129
     130      UpdateNewAssignedResources();
     131      UpdateNewInheritedResources();
     132      var top = BuildResourceTree(HiveAdminClient.Instance.Resources);
     133      detailsViewHost.Content = top;
    115134    }
    116135    #endregion
    117136
    118137    #region Helpers
     138
     139    //private void DisableResourceTree(TreeNode node) {
     140    //  foreach(var n in node.Nodes) {
     141
     142    //  }
     143    //}
     144
     145    private void UpdateResourceTree() {
     146      UpdateAssignedResources();
     147      UpdateResourceGenealogy();
     148      var top = BuildResourceTree(HiveAdminClient.Instance.Resources);
     149      detailsViewHost.Content = top;
     150    }
     151
    119152    private static IEnumerable<Resource> GetAssignedResourcesForProject(Guid projectId) {
    120153      var assignedProjectResources = HiveServiceLocator.Instance.CallHiveService(s => s.GetAssignedResourcesForProject(projectId));
    121       var resourceIds = new HashSet<Guid>(assignedProjectResources.Select(x => x.ResourceId));
    122       return HiveAdminClient.Instance.Resources.Where(x => resourceIds.Contains(x.Id));
    123     }
    124 
    125     private static void SetAssignedProjectResources(Guid projectId, IEnumerable<Guid> resourceIds) {
     154      return HiveAdminClient.Instance.Resources.Where(x => assignedProjectResources.Select(y => y.ResourceId).Contains(x.Id));
     155    }
     156
     157    private void SetAssignedProjectResources(Guid projectId, IEnumerable<Guid> resourceIds) {
    126158      HiveServiceLocator.Instance.CallHiveService(s => {
    127159        var currentlyAssignedResources = s.GetAssignedResourcesForProject(projectId);
     
    131163    }
    132164
     165    private void UpdateNewAssignedResources() {
     166      for(int i = newAssignedResources.Count -1; i >= 0; i--) {
     167        if(newAssignedResources.Intersect(resourceAncestors[newAssignedResources.ElementAt(i).Id]).Any()) {
     168          newAssignedResources.Remove(newAssignedResources.ElementAt(i));
     169        }
     170      }
     171    }
     172
    133173    private void UpdateAssignedResources() {
    134174      assignedResources.Clear();
    135       foreach (var r in GetAssignedResourcesForProject(Content.Id))
     175      newAssignedResources.Clear();
     176      foreach (var r in GetAssignedResourcesForProject(Content.Id)) {
    136177        assignedResources.Add(r);
    137     }
    138 
    139     private void UpdateInheritedResources() {
     178        newAssignedResources.Add(r);
     179      }
     180    }
     181
     182    private void UpdateNewInheritedResources() {
     183      newInheritedResources.Clear();
     184      foreach (var a in newAssignedResources) {
     185        if (resourceDescendants.ContainsKey(a.Id)) {
     186          foreach (var r in resourceDescendants[a.Id]) {
     187            newInheritedResources.Add(r);
     188          }
     189        }
     190      }
     191    }
     192
     193    private void UpdateResourceGenealogy() {
     194      resourceAncestors.Clear();
     195      resourceDescendants.Clear();
     196      var resources = HiveAdminClient.Instance.Resources;
     197
     198      foreach(var r in resources) {
     199        resourceAncestors.Add(r.Id, new HashSet<Resource>());
     200        resourceDescendants.Add(r.Id, new HashSet<Resource>());
     201      }
     202
     203      foreach(var r in resources) {
     204        var parentResourceId = r.ParentResourceId;
     205        while(parentResourceId != null) {
     206          var parent = resources.SingleOrDefault(x => x.Id == parentResourceId);
     207          if(parent != null) {
     208            resourceAncestors[r.Id].Add(parent);
     209            resourceDescendants[parent.Id].Add(r);
     210            parentResourceId = parent.ParentResourceId;
     211          } else {
     212            parentResourceId = null;
     213          }
     214        }
     215      }
     216
    140217      inheritedResources.Clear();
    141       var parentProject = HiveAdminClient.Instance.Projects.SingleOrDefault(x => x.Id == Content.ParentProjectId);
    142       while (parentProject != null) {
    143         foreach (var r in GetAssignedResourcesForProject(parentProject.Id))
    144           inheritedResources.Add(r);
    145         parentProject = HiveAdminClient.Instance.Projects.SingleOrDefault(x => x.Id == parentProject.ParentProjectId);
    146       }
     218      newInheritedResources.Clear();
     219      foreach(var a in assignedResources) {
     220        if (resourceDescendants.ContainsKey(a.Id)) {
     221          foreach(var r in resourceDescendants[a.Id]) {
     222            inheritedResources.Add(r);
     223            newInheritedResources.Add(r);
     224          }
     225        }
     226      }
     227
     228      //foreach(var r in resources) {
     229      //  if (resourceAncestors.ContainsKey(r.Id)
     230      //    && resourceAncestors[r.Id].Intersect(assignedResources.Select(x => x.Id)).Any()) {
     231      //    inheritedResources.Add(r);
     232      //  }
     233      //}
    147234    }
    148235
     
    154241      treeView.AfterCheck -= treeView_AfterCheck;
    155242
    156       var slaveGroups = new HashSet<SlaveGroup>(resources.OfType<SlaveGroup>());
    157       var slaves = new HashSet<Slave>(resources.OfType<Slave>());
    158 
    159       var stack = new Stack<Resource>(slaveGroups.OrderByDescending(x => x.Name));
     243      var mainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>().Where(x => x.ParentResourceId == null));
     244      var subResources = new HashSet<Resource>(resources.Except(mainResources));
     245
     246      var stack = new Stack<Resource>(mainResources.OrderByDescending(x => x.Name));
    160247      var top = stack.Peek();
    161248
    162249      TreeNode currentNode = null;
    163250      Resource currentResource = null;
     251
     252      var assignmentDiff = new HashSet<Resource>(newAssignedResources);
     253      assignmentDiff.SymmetricExceptWith(assignedResources);
     254      var inheritanceDiff = new HashSet<Resource>(newInheritedResources);
     255      inheritanceDiff.SymmetricExceptWith(inheritedResources);
    164256
    165257      while (stack.Any()) {
     
    167259        var newNode = new TreeNode(newResource.Name) { Tag = newResource };
    168260
     261        // search for parent node of newNode and save in currentNode
     262        // necessary since newNodes (stack top items) might be siblings
     263        // or grand..grandparents of previous node (currentNode)
    169264        while (currentNode != null && newResource.ParentResourceId != currentResource.Id) {
    170265          currentNode = currentNode.Parent;
     
    178273        }
    179274
     275
     276        if (newAssignedResources.Contains(newResource)) {
     277          newNode.Checked = true;
     278        } else if (newInheritedResources.Contains(newResource)) {
     279          newNode.Checked = true;
     280          newNode.Text += " (Inherited)";
     281          newNode.ForeColor = SystemColors.GrayText;
     282        }
     283
     284        if (assignmentDiff.Contains(newResource)) {
     285          newNode.BackColor = changedAssignmentColor;
     286          newNode.Text += " [changed]";
     287        } else if(inheritanceDiff.Contains(newResource)) {
     288          newNode.BackColor = changedInheritanceColor;
     289          newNode.Text += " [changed]";
     290        }
     291
    180292        if (newResource is Slave) {
    181293          newNode.ImageIndex = slaveImageIndex;
     
    183295          newNode.ImageIndex = slaveGroupImageIndex;
    184296
    185           var childSlaves = slaves.Where(x => x.ParentResourceId == newResource.Id);
    186           foreach (var slave in childSlaves.OrderBy(x => x.Name)) {
    187             slaves.Remove(slave);
    188             var slaveNode = new TreeNode(slave.Name) { Tag = slave };
    189 
    190             slaveNode.SelectedImageIndex = slaveNode.ImageIndex = slaveImageIndex;
    191             if (slave.OwnerUserId == UserInformation.Instance.User.Id)
    192               slaveNode.BackColor = ownedResourceColor;
    193             if (inheritedResources.Contains(slave)) {
    194               slaveNode.Checked = true;
    195               slaveNode.Text += " (Inherited)";
    196               slaveNode.ForeColor = SystemColors.GrayText;
    197             } else if (assignedResources.Contains(slave))
    198               slaveNode.Checked = true;
    199 
    200             newNode.Nodes.Add(slaveNode);
    201           }
    202 
    203           var childSlaveGroups = slaveGroups.Where(x => x.ParentResourceId == newResource.Id);
    204           if (childSlaveGroups.Any()) {
    205             foreach (var slaveGroup in childSlaveGroups.OrderByDescending(x => x.Name)) {
    206               slaveGroups.Remove(slaveGroup);
    207               stack.Push(slaveGroup);
     297          var childResources = subResources.Where(x => x.ParentResourceId == newResource.Id);
     298          if (childResources.Any()) {
     299            foreach (var resource in childResources.OrderByDescending(x => x.Name)) {
     300              subResources.Remove(resource);
     301              stack.Push(resource);
    208302            }
    209303            currentNode = newNode;
     
    211305          }
    212306        }
    213 
    214307        newNode.SelectedImageIndex = newNode.ImageIndex;
    215         if (newResource.OwnerUserId == UserInformation.Instance.User.Id)
    216           newNode.BackColor = ownedResourceColor;
    217         if (inheritedResources.Contains(newResource)) {
    218           newNode.Checked = true;
    219           newNode.Text += " (Inherited)";
    220           newNode.ForeColor = SystemColors.GrayText;
    221         } else if (assignedResources.Contains(newResource))
    222           newNode.Checked = true;
     308        //if (newResource.OwnerUserId == UserInformation.Instance.User.Id)
     309        //  newNode.BackColor = ownedResourceColor;
    223310      }
    224311
     
    231318      };
    232319
    233       foreach (var slave in slaves.OrderBy(x => x.Name)) {
     320      foreach (var slave in subResources.OfType<Slave>().OrderBy(x => x.Name)) {
    234321        var slaveNode = new TreeNode(slave.Name) { Tag = slave };
    235322        ungroupedNode.Nodes.Add(slaveNode);
     
    243330      return top;
    244331    }
     332
    245333    #endregion
    246334  }
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs

    r15422 r15559  
    4040    private const int greenFlagImageIndex = 0;
    4141    private const int redFlagImageIndex = 1;
     42    private readonly Color changedColor = Color.FromArgb(255, Color.LightGreen);
     43    private readonly Color selectedColor = Color.SkyBlue;
    4244
    4345    private readonly object locker = new object();
     
    246248    private void projectsTreeView_AfterSelect(object sender, TreeViewEventArgs e) {
    247249      var selectedProject = (Project)e.Node.Tag;
     250      ReColorTreeNodes(projectsTreeView.Nodes, selectedColor, Color.Transparent);
     251      e.Node.BackColor = selectedColor;
     252     
    248253
    249254      if (projectView.Content != null)
     
    317322
    318323    #region Helpers
     324    private void ReColorTreeNodes(TreeNodeCollection nodes, Color c1, Color c2) {
     325      foreach(TreeNode n in nodes) {
     326        if(n.BackColor.Equals(c1)) {
     327          n.BackColor = c2;
     328        }
     329        if (n.Nodes.Count > 0) {
     330          ReColorTreeNodes(n.Nodes, c1, c2);
     331        }
     332      }
     333    }
     334
    319335    private Project BuildProjectTree(IEnumerable<Project> projects) {
    320336      projectsTreeView.Nodes.Clear();
     
    326342      var stack = new Stack<Project>(mainProjects.OrderByDescending(x => x.Name));
    327343      var top = stack.Peek();
     344      bool first = true;
    328345
    329346      TreeNode currentNode = null;
    330347      Project currentProject = null;
    331 
     348     
    332349      while (stack.Any()) {
    333350        var newProject = stack.Pop();
    334351        var newNode = new TreeNode(newProject.Name) { Tag = newProject };
     352        if (first) {
     353          newNode.BackColor = selectedColor;
     354          first = false;
     355        }
    335356
    336357        while (currentNode != null && newProject.ParentProjectId != currentProject.Id) {
Note: See TracChangeset for help on using the changeset viewer.