- Timestamp:
- 02/27/18 23:20:14 (7 years ago)
- Location:
- branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectResourcesView.cs
r15813 r15819 37 37 private const int slaveImageIndex = 0; 38 38 private const int slaveGroupImageIndex = 1; 39 public const string ungroupedGroupName = "UNGROUPED"; 40 public const string ungroupedGroupDescription = "Contains slaves that are not assigned to any group."; 39 public const string UNGROUPED_GROUP_NAME = "UNGROUPED"; 40 public const string UNGROUPED_GROUP_DESCRIPTION = "Contains slaves that are not assigned to any group."; 41 public const string IMMUTABLE_TAG = " [assigned, immutable]"; 42 public const string INCLUDED_TAG = " [included]"; 43 public const string ADDED_ASSIGNMENT_TAG = " [added assignment]"; 44 public const string REMOVED_ASSIGNMENT_TAG = " [removed assignment]"; 45 public const string ADDED_INCLUDE_TAG = " [added include]"; 46 public const string REMOVED_INCLUDE_TAG = " [removed include]"; 41 47 42 48 private readonly HashSet<Resource> assignedResources = new HashSet<Resource>(); 43 49 private readonly HashSet<Resource> newAssignedResources = new HashSet<Resource>(); 44 private readonly HashSet<Resource> in heritedResources = new HashSet<Resource>();45 private readonly HashSet<Resource> newIn heritedResources = new HashSet<Resource>();50 private readonly HashSet<Resource> includedResources = new HashSet<Resource>(); 51 private readonly HashSet<Resource> newIncludedResources = new HashSet<Resource>(); 46 52 47 53 private readonly Dictionary<Guid, HashSet<Project>> projectAncestors = new Dictionary<Guid, HashSet<Project>>(); … … 54 60 private readonly Color addedIncludeColor = Color.FromArgb(25, 169, 221, 221); // #a9dddd 55 61 private readonly Color removedIncludeColor = Color.FromArgb(25, 249, 210, 145); // #f9d291 62 63 private HashSet<Resource> projectExclusiveResources = new HashSet<Resource>(); 64 private TreeNode ungroupedGroupNode; 56 65 57 66 public new Project Content { … … 73 82 assignedResources.Clear(); 74 83 newAssignedResources.Clear(); 75 in heritedResources.Clear();84 includedResources.Clear(); 76 85 resourceAncestors.Clear(); 77 86 treeView.Nodes.Clear(); … … 132 141 private void treeView_BeforeCheck(object sender, TreeViewCancelEventArgs e) { 133 142 var checkedResource = (Resource)e.Node.Tag; 134 if (newIn heritedResources.Contains(checkedResource) || checkedResource.Id == Guid.Empty) {143 if (newIncludedResources.Contains(checkedResource) || checkedResource.Id == Guid.Empty || e.Node == ungroupedGroupNode) { 135 144 e.Cancel = true; 136 145 } else if (!HiveRoles.CheckAdminUserPermissions()) { 137 if (!projectAncestors[Content.Id].Any() ) {146 if (!projectAncestors[Content.Id].Any() || projectExclusiveResources.Contains(checkedResource)) { 138 147 e.Cancel = true; 139 148 } … … 164 173 private void UpdateNewResourceTree() { 165 174 UpdateNewAssignedResources(); 166 UpdateNewIn heritedResources();175 UpdateNewIncludedResources(); 167 176 var top = BuildResourceTree(HiveAdminClient.Instance.Resources); 168 177 detailsViewHost.Content = top; 169 178 } 170 179 171 private static IEnumerable<Resource> GetAssignedResourcesForProject(Guid projectId) { 180 private IEnumerable<Resource> GetAvailableResourcesForProjectAdministration(Guid projectId) { 181 projectExclusiveResources.Clear(); 172 182 if (projectId == Guid.Empty) return Enumerable.Empty<Resource>(); 173 var assignedProjectResources = HiveServiceLocator.Instance.CallHiveService(s => s.GetAssignedResourcesForProjectAdministration(projectId)); 174 return HiveAdminClient.Instance.Resources.Where(x => assignedProjectResources.Select(y => y.ResourceId).Contains(x.Id)); 183 var resources = HiveAdminClient.Instance.Resources.Where(x => x.Id != Guid.Empty); 184 if (!resources.Any()) return resources; 185 if (IsAdmin()) return resources; 186 187 // get project specific assigned resources 188 var projectResources = resources.Where(x => 189 HiveAdminClient.Instance.ProjectResourceAssignments 190 .Where(a => a.ProjectId == projectId) 191 .Select(a => a.ResourceId) 192 .Contains(x.Id)); 193 194 // look up for assignments of ancestor projects 195 var projectIds = new HashSet<Guid>(); 196 if(projectAncestors.ContainsKey(projectId)) { 197 projectAncestors[projectId].ToList().ForEach(x => projectIds.Add(x.Id)); 198 } 199 var ancestorProjectResources = resources.Where(x => 200 HiveAdminClient.Instance.ProjectResourceAssignments 201 .Where(a => projectIds.Contains(a.ProjectId)) 202 .Select(a => a.ResourceId) 203 .Contains(x.Id)); 204 205 // look down for included resources of ancestor projects 206 HashSet<Resource> availableResources = new HashSet<Resource>(ancestorProjectResources); 207 foreach (var r in ancestorProjectResources) { 208 if(resourceDescendants.ContainsKey(r.Id)) { 209 foreach(var d in resourceDescendants[r.Id]) { 210 availableResources.Add(d); 211 } 212 } 213 } 214 215 // determine resources, which are exclusively assigned to the currently selected project 216 projectResources 217 .Except(availableResources) 218 .ToList() 219 .ForEach(x => projectExclusiveResources.Add(x)); 220 221 // look down for included resources of currently selected project 222 if (projectExclusiveResources.Any()) { 223 foreach (var r in projectExclusiveResources.ToArray()) { 224 if (resourceDescendants.ContainsKey(r.Id)) { 225 foreach (var d in resourceDescendants[r.Id]) { 226 projectExclusiveResources.Add(d); 227 } 228 } 229 } 230 } 231 232 return availableResources.Union(projectExclusiveResources); 233 } 234 235 private IEnumerable<Resource> GetAssignedResourcesForProject(Guid projectId) { 236 if (projectId == Guid.Empty) return Enumerable.Empty<Resource>(); 237 return HiveAdminClient.Instance.Resources.Where(x => 238 HiveAdminClient.Instance.ProjectResourceAssignments 239 .Where(a => a.ProjectId == projectId) 240 .Select(a => a.ResourceId) 241 .Contains(x.Id)); 175 242 } 176 243 … … 199 266 } 200 267 201 private void UpdateNewIn heritedResources() {202 newIn heritedResources.Clear();268 private void UpdateNewIncludedResources() { 269 newIncludedResources.Clear(); 203 270 foreach (var a in newAssignedResources) { 204 271 if (resourceDescendants.ContainsKey(a.Id)) { 205 272 foreach (var r in resourceDescendants[a.Id]) { 206 newInheritedResources.Add(r); 207 } 208 } 209 } 210 } 211 212 private void UpdateResourceGenealogy() { 213 resourceAncestors.Clear(); 214 resourceDescendants.Clear(); 215 var resources = HiveAdminClient.Instance.Resources; 216 217 foreach(var r in resources.Where(x => x.Id != Guid.Empty)) { 218 resourceAncestors.Add(r.Id, new HashSet<Resource>()); 219 resourceDescendants.Add(r.Id, new HashSet<Resource>()); 220 } 221 222 foreach(var r in resources.Where(x => x.Id != Guid.Empty)) { 223 var parentResourceId = r.ParentResourceId; 224 while(parentResourceId != null) { 225 var parent = resources.SingleOrDefault(x => x.Id == parentResourceId); 226 if(parent != null) { 227 resourceAncestors[r.Id].Add(parent); 228 resourceDescendants[parent.Id].Add(r); 229 parentResourceId = parent.ParentResourceId; 230 } else { 231 parentResourceId = null; 232 } 233 } 234 } 235 236 inheritedResources.Clear(); 237 newInheritedResources.Clear(); 238 foreach(var a in assignedResources) { 239 if (resourceDescendants.ContainsKey(a.Id)) { 240 foreach(var r in resourceDescendants[a.Id]) { 241 inheritedResources.Add(r); 242 newInheritedResources.Add(r); 243 } 244 } 245 } 246 247 //foreach(var r in resources) { 248 // if (resourceAncestors.ContainsKey(r.Id) 249 // && resourceAncestors[r.Id].Intersect(assignedResources.Select(x => x.Id)).Any()) { 250 // inheritedResources.Add(r); 251 // } 252 //} 273 newIncludedResources.Add(r); 274 } 275 } 276 } 253 277 } 254 278 … … 260 284 treeView.AfterCheck -= treeView_AfterCheck; 261 285 262 resources = resources.Where(x => x.Id != Guid.Empty); 286 resources = GetAvailableResourcesForProjectAdministration(Content.Id); 287 263 288 var mainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>().Where(x => x.ParentResourceId == null)); 264 289 var parentedMainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>() … … 273 298 Resource currentResource = null; 274 299 275 276 300 var addedAssignments = newAssignedResources.Except(assignedResources); 277 301 var removedAssignments = assignedResources.Except(newAssignedResources); 278 var addedIncludes = newInheritedResources.Except(inheritedResources); 279 var removedIncludes = inheritedResources.Except(newInheritedResources); 280 281 //var assignmentDiff = new HashSet<Resource>(newAssignedResources); 282 //assignmentDiff.SymmetricExceptWith(assignedResources); 283 //var inheritanceDiff = new HashSet<Resource>(newInheritedResources); 284 //inheritanceDiff.SymmetricExceptWith(inheritedResources); 302 var addedIncludes = newIncludedResources.Except(includedResources); 303 var removedIncludes = includedResources.Except(newIncludedResources); 285 304 286 305 while (stack.Any()) { … … 306 325 newNode.Checked = true; 307 326 if(!HiveRoles.CheckAdminUserPermissions()) { 308 if(!projectAncestors[Content.Id].Any() ) {327 if(!projectAncestors[Content.Id].Any() || projectExclusiveResources.Contains(newResource)) { 309 328 newNode.ForeColor = SystemColors.GrayText; 310 newNode.Text += " [immutable]";329 newNode.Text += IMMUTABLE_TAG; 311 330 } 312 331 } 313 332 314 } else if (newIn heritedResources.Contains(newResource)) {333 } else if (newIncludedResources.Contains(newResource)) { 315 334 newNode.Checked = true; 316 335 newNode.ForeColor = SystemColors.GrayText; 317 336 } 318 337 319 if (in heritedResources.Contains(newResource) && newInheritedResources.Contains(newResource)) {320 newNode.Text += " [included]";338 if (includedResources.Contains(newResource) && newIncludedResources.Contains(newResource)) { 339 newNode.Text += INCLUDED_TAG; 321 340 } else if (addedIncludes.Contains(newResource)) { 322 341 newNode.BackColor = addedIncludeColor; 323 342 newNode.ForeColor = SystemColors.GrayText; 324 newNode.Text += " [added include]";343 newNode.Text += ADDED_INCLUDE_TAG; 325 344 } else if (removedIncludes.Contains(newResource)) { 326 345 newNode.BackColor = removedIncludeColor; 327 newNode.Text += " [removed include]";346 newNode.Text += REMOVED_INCLUDE_TAG; 328 347 } 329 348 … … 331 350 newNode.BackColor = addedAssignmentColor; 332 351 newNode.ForeColor = SystemColors.ControlText; 333 newNode.Text += " [added assignment]";352 newNode.Text += ADDED_ASSIGNMENT_TAG; 334 353 } else if (removedAssignments.Contains(newResource)) { 335 354 newNode.BackColor = removedAssignmentColor; 336 355 newNode.ForeColor = SystemColors.ControlText; 337 newNode.Text += " [removed assignment]";356 newNode.Text += REMOVED_ASSIGNMENT_TAG; 338 357 } 339 358 … … 354 373 } 355 374 newNode.SelectedImageIndex = newNode.ImageIndex; 356 //if (newResource.OwnerUserId == UserInformation.Instance.User.Id)357 // newNode.BackColor = ownedResourceColor;358 375 } 359 376 360 377 var ungroupedSlaves = subResources.OfType<Slave>().OrderBy(x => x.Name); 361 378 if(ungroupedSlaves.Any()) { 362 var ungroupedNode = new TreeNode(ungroupedGroupName) {379 ungroupedGroupNode = new TreeNode(UNGROUPED_GROUP_NAME) { 363 380 ForeColor = SystemColors.GrayText, 364 381 Tag = new SlaveGroup() { 365 Name = ungroupedGroupName,366 Description = ungroupedGroupDescription382 Name = UNGROUPED_GROUP_NAME, 383 Description = UNGROUPED_GROUP_DESCRIPTION 367 384 } 368 385 }; … … 370 387 foreach (var slave in ungroupedSlaves) { 371 388 var slaveNode = new TreeNode(slave.Name) { Tag = slave }; 372 ungroupedNode.Nodes.Add(slaveNode); 373 } 374 treeView.Nodes.Add(ungroupedNode); 389 ungroupedGroupNode.Nodes.Add(slaveNode); 390 } 391 treeView.Nodes.Add(ungroupedGroupNode); 392 } else { 393 ungroupedGroupNode?.Nodes.Clear(); 375 394 } 376 395 … … 407 426 } 408 427 428 private void UpdateResourceGenealogy() { 429 resourceAncestors.Clear(); 430 resourceDescendants.Clear(); 431 var resources = HiveAdminClient.Instance.Resources; 432 433 foreach (var r in resources.Where(x => x.Id != Guid.Empty)) { 434 resourceAncestors.Add(r.Id, new HashSet<Resource>()); 435 resourceDescendants.Add(r.Id, new HashSet<Resource>()); 436 } 437 438 foreach (var r in resources.Where(x => x.Id != Guid.Empty)) { 439 var parentResourceId = r.ParentResourceId; 440 while (parentResourceId != null) { 441 var parent = resources.SingleOrDefault(x => x.Id == parentResourceId); 442 if (parent != null) { 443 resourceAncestors[r.Id].Add(parent); 444 resourceDescendants[parent.Id].Add(r); 445 parentResourceId = parent.ParentResourceId; 446 } else { 447 parentResourceId = null; 448 } 449 } 450 } 451 452 includedResources.Clear(); 453 newIncludedResources.Clear(); 454 foreach (var a in assignedResources) { 455 if (resourceDescendants.ContainsKey(a.Id)) { 456 foreach (var r in resourceDescendants[a.Id]) { 457 includedResources.Add(r); 458 newIncludedResources.Add(r); 459 } 460 } 461 } 462 } 463 464 private bool IsAdmin() { 465 return HiveRoles.CheckAdminUserPermissions(); 466 } 467 409 468 #endregion 410 469 } -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
r15813 r15819 298 298 private void treeSlaveGroup_MouseDown(object sender, MouseEventArgs e) { 299 299 var node = treeView.GetNodeAt(e.Location); 300 if(node != null && node != ungroupedGroupNode /*!node.Text.StartsWith(UNGROUPED_GROUP_NAME)*/) ChangeSelectedResourceNode(node);300 if(node != null && node != ungroupedGroupNode) ChangeSelectedResourceNode(node); 301 301 } 302 302
Note: See TracChangeset
for help on using the changeset viewer.