Changeset 15559
- Timestamp:
- 12/22/17 11:30:52 (7 years ago)
- 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 40 40 41 41 private readonly HashSet<Resource> assignedResources = new HashSet<Resource>(); 42 private readonly HashSet<Resource> newAssignedResources = new HashSet<Resource>(); 42 43 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); 44 50 45 51 public new Project Content { … … 60 66 if (Content == null) { 61 67 assignedResources.Clear(); 68 newAssignedResources.Clear(); 62 69 inheritedResources.Clear(); 70 resourceAncestors.Clear(); 63 71 treeView.Nodes.Clear(); 64 72 detailsViewHost.Content = null; 65 73 } else { 66 74 UpdateAssignedResources(); 67 Update InheritedResources();75 UpdateResourceGenealogy(); 68 76 var top = BuildResourceTree(HiveAdminClient.Instance.Resources); 69 77 detailsViewHost.Content = top; 70 78 } 71 79 } 80 72 81 #endregion 73 82 … … 79 88 private void refreshButton_Click(object sender, EventArgs e) { 80 89 UpdateAssignedResources(); 81 Update InheritedResources();90 UpdateResourceGenealogy(); 82 91 var top = BuildResourceTree(HiveAdminClient.Instance.Resources); 83 92 detailsViewHost.Content = top; … … 85 94 86 95 private void inheritButton_Click(object sender, EventArgs e) { 96 return; 87 97 SetAssignedProjectResources(Content.Id, Enumerable.Empty<Guid>()); 88 98 UpdateAssignedResources(); 89 Update InheritedResources();99 UpdateResourceGenealogy(); 90 100 var top = BuildResourceTree(HiveAdminClient.Instance.Resources); 91 101 detailsViewHost.Content = top; … … 94 104 private async void saveButton_Click(object sender, EventArgs e) { 95 105 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(); 97 110 } 98 111 … … 104 117 private void treeView_BeforeCheck(object sender, TreeViewCancelEventArgs e) { 105 118 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; 107 120 } 108 121 109 122 private void treeView_AfterCheck(object sender, TreeViewEventArgs e) { 110 123 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; 115 134 } 116 135 #endregion 117 136 118 137 #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 119 152 private static IEnumerable<Resource> GetAssignedResourcesForProject(Guid projectId) { 120 153 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) { 126 158 HiveServiceLocator.Instance.CallHiveService(s => { 127 159 var currentlyAssignedResources = s.GetAssignedResourcesForProject(projectId); … … 131 163 } 132 164 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 133 173 private void UpdateAssignedResources() { 134 174 assignedResources.Clear(); 135 foreach (var r in GetAssignedResourcesForProject(Content.Id)) 175 newAssignedResources.Clear(); 176 foreach (var r in GetAssignedResourcesForProject(Content.Id)) { 136 177 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 140 217 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 //} 147 234 } 148 235 … … 154 241 treeView.AfterCheck -= treeView_AfterCheck; 155 242 156 var slaveGroups = new HashSet<SlaveGroup>(resources.OfType<SlaveGroup>());157 var s laves = 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)); 160 247 var top = stack.Peek(); 161 248 162 249 TreeNode currentNode = null; 163 250 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); 164 256 165 257 while (stack.Any()) { … … 167 259 var newNode = new TreeNode(newResource.Name) { Tag = newResource }; 168 260 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) 169 264 while (currentNode != null && newResource.ParentResourceId != currentResource.Id) { 170 265 currentNode = currentNode.Parent; … … 178 273 } 179 274 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 180 292 if (newResource is Slave) { 181 293 newNode.ImageIndex = slaveImageIndex; … … 183 295 newNode.ImageIndex = slaveGroupImageIndex; 184 296 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); 208 302 } 209 303 currentNode = newNode; … … 211 305 } 212 306 } 213 214 307 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; 223 310 } 224 311 … … 231 318 }; 232 319 233 foreach (var slave in s laves.OrderBy(x => x.Name)) {320 foreach (var slave in subResources.OfType<Slave>().OrderBy(x => x.Name)) { 234 321 var slaveNode = new TreeNode(slave.Name) { Tag = slave }; 235 322 ungroupedNode.Nodes.Add(slaveNode); … … 243 330 return top; 244 331 } 332 245 333 #endregion 246 334 } -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs
r15422 r15559 40 40 private const int greenFlagImageIndex = 0; 41 41 private const int redFlagImageIndex = 1; 42 private readonly Color changedColor = Color.FromArgb(255, Color.LightGreen); 43 private readonly Color selectedColor = Color.SkyBlue; 42 44 43 45 private readonly object locker = new object(); … … 246 248 private void projectsTreeView_AfterSelect(object sender, TreeViewEventArgs e) { 247 249 var selectedProject = (Project)e.Node.Tag; 250 ReColorTreeNodes(projectsTreeView.Nodes, selectedColor, Color.Transparent); 251 e.Node.BackColor = selectedColor; 252 248 253 249 254 if (projectView.Content != null) … … 317 322 318 323 #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 319 335 private Project BuildProjectTree(IEnumerable<Project> projects) { 320 336 projectsTreeView.Nodes.Clear(); … … 326 342 var stack = new Stack<Project>(mainProjects.OrderByDescending(x => x.Name)); 327 343 var top = stack.Peek(); 344 bool first = true; 328 345 329 346 TreeNode currentNode = null; 330 347 Project currentProject = null; 331 348 332 349 while (stack.Any()) { 333 350 var newProject = stack.Pop(); 334 351 var newNode = new TreeNode(newProject.Name) { Tag = newProject }; 352 if (first) { 353 newNode.BackColor = selectedColor; 354 first = false; 355 } 335 356 336 357 while (currentNode != null && newProject.ParentProjectId != currentProject.Id) {
Note: See TracChangeset
for help on using the changeset viewer.