- Timestamp:
- 02/27/18 23:20:14 (7 years ago)
- Location:
- branches/2839_HiveProjectManagement
- Files:
-
- 6 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 -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs
r15813 r15819 65 65 } 66 66 67 private IItemList<AssignedProjectResource> projectResourceAssignments; 68 public IItemList<AssignedProjectResource> ProjectResourceAssignments { 69 get { return projectResourceAssignments; } 70 } 71 67 72 private Dictionary<Guid, HashSet<Project>> projectAncestors; 68 73 public Dictionary<Guid, HashSet<Project>> ProjectAncestors { … … 110 115 resources = new ItemList<Resource>(); 111 116 projects = new ItemList<Project>(); 117 projectResourceAssignments = new ItemList<AssignedProjectResource>(); 112 118 113 119 projectAncestors = new Dictionary<Guid, HashSet<Project>>(); … … 120 126 service.GetSlavesForAdministration().ForEach(s => resources.Add(s)); 121 127 service.GetProjectsForAdministration().ForEach(p => projects.Add(p)); 128 var projectIds = projects.Select(p => p.Id).ToList(); 129 if(projectIds.Any()) 130 service.GetAssignedResourcesForProjectsAdministration(projectIds) 131 .ForEach(a => projectResourceAssignments.Add(a)); 122 132 }); 123 133 -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/ServiceClients/HiveServiceClient.cs
r15658 r15819 2452 2452 void SaveProjectPermissions(System.Guid projectId, System.Collections.Generic.List<System.Guid> grantedUserIds, bool reassign, bool cascading, bool reassignCascading); 2453 2453 2454 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GrantProjectPermissions", ReplyAction="http://tempuri.org/IHiveService/GrantProjectPermissionsResponse")]2455 void GrantProjectPermissions(System.Guid projectId, System.Collections.Generic.List<System.Guid> grantedUserIds, bool cascading);2456 2457 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/RevokeProjectPermissions", ReplyAction="http://tempuri.org/IHiveService/RevokeProjectPermissionsResponse")]2458 void RevokeProjectPermissions(System.Guid projectId, System.Collections.Generic.List<System.Guid> grantedUserIds, bool cascading);2459 2460 2454 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetProjectPermissions", ReplyAction="http://tempuri.org/IHiveService/GetProjectPermissionsResponse")] 2461 2455 System.Collections.Generic.List<HeuristicLab.Clients.Hive.ProjectPermission> GetProjectPermissions(System.Guid projectId); … … 2463 2457 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/SaveProjectResourceAssignments", ReplyAction="http://tempuri.org/IHiveService/SaveProjectResourceAssignmentsResponse")] 2464 2458 void SaveProjectResourceAssignments(System.Guid projectId, System.Collections.Generic.List<System.Guid> resourceIds, bool reassign, bool cascading, bool reassignCascading); 2465 2466 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/AssignProjectResources", ReplyAction="http://tempuri.org/IHiveService/AssignProjectResourcesResponse")]2467 void AssignProjectResources(System.Guid projectId, System.Collections.Generic.List<System.Guid> resourceIds, bool cascading);2468 2469 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/UnassignProjectResources", ReplyAction="http://tempuri.org/IHiveService/UnassignProjectResourcesResponse")]2470 void UnassignProjectResources(System.Guid projectId, System.Collections.Generic.List<System.Guid> resourceIds, bool cascading);2471 2459 2472 2460 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetAssignedResourcesForProject", ReplyAction="http://tempuri.org/IHiveService/GetAssignedResourcesForProjectResponse")] … … 2477 2465 System.Collections.Generic.List<HeuristicLab.Clients.Hive.AssignedProjectResource> GetAssignedResourcesForProjectAdministration(System.Guid projectId); 2478 2466 2467 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetAssignedResourcesForProjectsAdministration", ReplyAction="http://tempuri.org/IHiveService/GetAssignedResourcesForProjectsAdministrationResp" + 2468 "onse")] 2469 System.Collections.Generic.List<HeuristicLab.Clients.Hive.AssignedProjectResource> GetAssignedResourcesForProjectsAdministration(System.Collections.Generic.List<System.Guid> projectIds); 2470 2479 2471 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/AddSlave", ReplyAction="http://tempuri.org/IHiveService/AddSlaveResponse")] 2480 2472 System.Guid AddSlave(HeuristicLab.Clients.Hive.Slave slave); … … 2767 2759 } 2768 2760 2769 public void GrantProjectPermissions(System.Guid projectId, System.Collections.Generic.List<System.Guid> grantedUserIds, bool cascading)2770 {2771 base.Channel.GrantProjectPermissions(projectId, grantedUserIds, cascading);2772 }2773 2774 public void RevokeProjectPermissions(System.Guid projectId, System.Collections.Generic.List<System.Guid> grantedUserIds, bool cascading)2775 {2776 base.Channel.RevokeProjectPermissions(projectId, grantedUserIds, cascading);2777 }2778 2779 2761 public System.Collections.Generic.List<HeuristicLab.Clients.Hive.ProjectPermission> GetProjectPermissions(System.Guid projectId) 2780 2762 { … … 2787 2769 } 2788 2770 2789 public void AssignProjectResources(System.Guid projectId, System.Collections.Generic.List<System.Guid> resourceIds, bool cascading)2790 {2791 base.Channel.AssignProjectResources(projectId, resourceIds, cascading);2792 }2793 2794 public void UnassignProjectResources(System.Guid projectId, System.Collections.Generic.List<System.Guid> resourceIds, bool cascading)2795 {2796 base.Channel.UnassignProjectResources(projectId, resourceIds, cascading);2797 }2798 2799 2771 public System.Collections.Generic.List<HeuristicLab.Clients.Hive.AssignedProjectResource> GetAssignedResourcesForProject(System.Guid projectId) 2800 2772 { … … 2807 2779 } 2808 2780 2781 public System.Collections.Generic.List<HeuristicLab.Clients.Hive.AssignedProjectResource> GetAssignedResourcesForProjectsAdministration(System.Collections.Generic.List<System.Guid> projectIds) 2782 { 2783 return base.Channel.GetAssignedResourcesForProjectsAdministration(projectIds); 2784 } 2785 2809 2786 public System.Guid AddSlave(HeuristicLab.Clients.Hive.Slave slave) 2810 2787 { -
branches/2839_HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs
r15760 r15819 1053 1053 } 1054 1054 1055 public IEnumerable<DT.AssignedProjectResource> GetAssignedResourcesForProjectsAdministration(IEnumerable<Guid> projectIds) { 1056 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 1057 foreach(var id in projectIds) 1058 AuthorizationManager.AuthorizeForProjectAdministration(id, false); 1059 1060 var pm = PersistenceManager; 1061 using (new PerformanceLogger("GetAssignedResourcesForProject")) { 1062 var assignedProjectResourceDao = pm.AssignedProjectResourceDao; 1063 var assignments = new List<DT.AssignedProjectResource>(); 1064 pm.UseTransaction(() => { 1065 foreach (var id in projectIds) { 1066 assignments.AddRange(assignedProjectResourceDao.GetByProjectId(id) 1067 .Select(x => x.ToDto())); 1068 } 1069 }); 1070 return assignments.Distinct(); 1071 } 1072 } 1073 1055 1074 #endregion 1056 1075 -
branches/2839_HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs
r15715 r15819 185 185 [OperationContract] 186 186 IEnumerable<AssignedProjectResource> GetAssignedResourcesForProjectAdministration(Guid projectId); 187 188 [OperationContract] 189 IEnumerable<AssignedProjectResource> GetAssignedResourcesForProjectsAdministration(IEnumerable<Guid> projectIds); 187 190 #endregion 188 191
Note: See TracChangeset
for help on using the changeset viewer.