Changeset 16185 for trunk/HeuristicLab.Clients.Hive.Administrator/3.3/Views
- Timestamp:
- 09/25/18 13:55:11 (6 years ago)
- Location:
- trunk/HeuristicLab.Clients.Hive.Administrator/3.3/Views
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectView.cs
r16117 r16185 134 134 135 135 if (Content != null) { 136 var parentProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).LastOrDefault(); 137 if (parentProject == null || parentProject.EndDate.HasValue) { 136 //var parentProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).LastOrDefault(); 137 var parentProject = HiveAdminClient.Instance.Projects.FirstOrDefault(x => x.Id == Content.ParentProjectId); 138 if ((!IsAdmin() && (parentProject == null || parentProject.EndDate.HasValue)) 139 || (IsAdmin() && parentProject != null && parentProject.EndDate.HasValue)) { 138 140 indefiniteCheckBox.Enabled = false; 139 141 } -
trunk/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs
r16117 r16185 106 106 BuildProjectTree(Content); 107 107 } 108 SetEnabledStateOfControls(); 108 109 } 109 110 110 111 protected override void SetEnabledStateOfControls() { 111 base.SetEnabledStateOfControls(); 112 bool selectedProjectExists = selectedProject != null && selectedProject.Id != Guid.Empty && Content.Contains(selectedProject); 113 bool projectIsNew = selectedProject != null && selectedProject.Id == Guid.Empty; 114 bool locked = Content == null || selectedProject == null || Locked || ReadOnly; 115 bool parentOwner = HiveAdminClient.Instance.CheckOwnershipOfParentProject(selectedProject, UserInformation.Instance.User.Id); 116 bool saveLocked = locked || (!IsAdmin() && selectedProject.OwnerUserId != UserInformation.Instance.User.Id && !parentOwner); 117 bool addLocked = saveLocked || projectIsNew || selectedProject.Id == Guid.Empty; 118 bool deleteLocked = locked || (!IsAdmin() && !parentOwner) || Content.Where(x => x.ParentProjectId == selectedProject.Id).Any(); 119 120 var now = DateTime.Now; 121 if (!addLocked && (now < selectedProject.StartDate || now > selectedProject.EndDate)) addLocked = true; 112 base.SetEnabledStateOfControls(); 113 114 bool locked = Content == null || Locked || ReadOnly; 115 bool parentOwner = selectedProject != null && HiveAdminClient.Instance.CheckOwnershipOfParentProject(selectedProject, UserInformation.Instance.User.Id); 116 bool selectedProjectDisabled = selectedProject == null 117 || selectedProject != null && selectedProject.Id == Guid.Empty; 118 119 bool selectedProjectHasJobs = 120 !selectedProjectDisabled && HiveAdminClient.Instance.Jobs.ContainsKey(selectedProject.Id) 121 && HiveAdminClient.Instance.Jobs[selectedProject.Id] != null 122 && HiveAdminClient.Instance.Jobs[selectedProject.Id].Any(); 123 124 bool addLocked = locked 125 || (selectedProject == null && !IsAdmin()) 126 || (selectedProject != null && selectedProject.Id == Guid.Empty) 127 || (selectedProject != null && !IsAdmin() && !parentOwner && selectedProject.OwnerUserId != UserInformation.Instance.User.Id) 128 || (selectedProject != null && (DateTime.Now < selectedProject.StartDate || DateTime.Now > selectedProject.EndDate)); 129 130 bool deleteLocked = locked 131 || !Content.Any() 132 || selectedProject == null 133 || Content.Any(x => x.ParentProjectId == selectedProject.Id) 134 || selectedProjectHasJobs 135 || (!IsAdmin() && !parentOwner); 136 137 bool saveLocked = locked 138 || !Content.Any() 139 || selectedProject == null 140 || (!IsAdmin() && !parentOwner && selectedProject.OwnerUserId != UserInformation.Instance.User.Id); 141 122 142 123 143 addButton.Enabled = !addLocked; 124 144 removeButton.Enabled = !deleteLocked; 125 145 saveProjectButton.Enabled = !saveLocked; 146 126 147 projectView.Enabled = !locked; 127 projectPermissionsView.Enabled = !locked ;128 projectResourcesView.Enabled = !locked ;129 projectJobsView.Enabled = !locked ;148 projectPermissionsView.Enabled = !locked && !selectedProjectDisabled; 149 projectResourcesView.Enabled = !locked && !selectedProjectDisabled; 150 projectJobsView.Enabled = !locked && !selectedProjectDisabled; 130 151 131 152 projectView.Locked = locked; 132 projectPermissionsView.Locked = locked ;133 projectResourcesView.Locked = locked ;134 projectJobsView.Locked = locked ;153 projectPermissionsView.Locked = locked || selectedProjectDisabled; 154 projectResourcesView.Locked = locked || selectedProjectDisabled; 155 projectJobsView.Locked = locked || selectedProjectDisabled; 135 156 } 136 157 #endregion … … 254 275 } 255 276 256 // double check of ChangeSelectedProject(..):257 // if the user is no admin nor owner of a parent project258 if (!IsAdmin() && !HiveAdminClient.Instance.CheckOwnershipOfParentProject(selectedProject, UserInformation.Instance.User.Id)) {259 MessageBox.Show(260 "Only admins and owners of parent projects are allowed to delete this project.",261 "HeuristicLab Hive Administrator",262 MessageBoxButtons.OK,263 MessageBoxIcon.Error);264 return;265 }266 267 268 if (Content.Any(x => x.ParentProjectId == selectedProject.Id)269 || HiveAdminClient.Instance.ProjectDescendants[selectedProject.Id].Any()) {270 MessageBox.Show(271 "Only empty projects can be deleted.",272 "HeuristicLab Hive Administrator",273 MessageBoxButtons.OK,274 MessageBoxIcon.Error);275 return;276 }277 278 if (HiveAdminClient.Instance.Jobs.ContainsKey(selectedProject.Id)279 && HiveAdminClient.Instance.Jobs[selectedProject.Id] != null280 && HiveAdminClient.Instance.Jobs[selectedProject.Id].Any()) {281 MessageBox.Show(282 "There are " + HiveAdminClient.Instance.Jobs[selectedProject.Id].Count + " job(s) using this project and/or child-projects. It is necessary to delete them before the project.",283 "HeuristicLab Hive Administrator",284 MessageBoxButtons.OK,285 MessageBoxIcon.Error);286 return;287 }288 289 277 var result = MessageBox.Show( 290 278 "Do you really want to delete " + selectedProject.Name + "?", … … 297 285 action: () => { 298 286 RemoveProject(selectedProject); 299 },300 finallyCallback: () => {301 removeButton.Enabled = true;302 287 }); 303 } else { 304 removeButton.Enabled = true; 305 } 288 } 289 SetEnabledStateOfControls(); 306 290 } 307 291 … … 540 524 try { 541 525 if (project.Id != Guid.Empty) { 542 var projectsToSave = Content.Where(x => x.Id == Guid.Empty || x.Modified);543 foreach (var p in projectsToSave)544 p.Store();545 546 526 SelectedProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(project.Id).LastOrDefault(); 547 527 HiveAdminClient.Delete(project); 548 528 UpdateProjects(); 549 } else { 529 } else { 530 SelectedProject = Content.FirstOrDefault(x => x.Id == project.ParentProjectId); 550 531 Content.Remove(project); 551 532 } -
trunk/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.Designer.cs
r16117 r16185 164 164 this.treeView.DragOver += new System.Windows.Forms.DragEventHandler(this.treeSlaveGroup_DragEnterOver); 165 165 this.treeView.BeforeCheck += new System.Windows.Forms.TreeViewCancelEventHandler(this.treeSlaveGroup_BeforeCheck); 166 this.treeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeSlaveGroup_AfterCheck); 166 167 // 167 168 // tabSlaveGroup -
trunk/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
r16122 r16185 125 125 126 126 HashSet<Guid> descendantResources = null; 127 bool selectedRDeleteLocked = selectedResource == null 128 || (selectedResource.Id != Guid.Empty && (!HiveAdminClient.Instance.ResourceDescendants.TryGetValue(selectedResource.Id, out descendantResources) || descendantResources.Any())); 129 130 var nodes = GetCheckedNodes(treeView.Nodes).ToList(); 131 var checkedResources = nodes.Select(x => x.Tag).OfType<Resource>().ToList(); 132 bool checkedRDeleteLocked = false; 133 for (int i = 0; !checkedRDeleteLocked && i < checkedResources.Count; i++) { 134 if (checkedResources[i].Id != Guid.Empty && 135 (!HiveAdminClient.Instance.ResourceDescendants.TryGetValue(checkedResources[i].Id, out descendantResources) || 136 descendantResources.Any())) 137 checkedRDeleteLocked = true; 138 } 127 139 128 140 bool deleteLocked = locked 129 || !IsAdmin()130 || !Content.Any()131 || selectedResource == null132 || (selectedResource.Id != Guid.Empty && (!HiveAdminClient.Instance.ResourceDescendants.TryGetValue(selectedResource.Id, out descendantResources) || descendantResources.Any()));141 || !IsAdmin() 142 || !Content.Any() 143 || checkedResources.Any() && checkedRDeleteLocked 144 || !checkedResources.Any() && selectedRDeleteLocked; 133 145 134 146 bool saveLocked = locked … … 235 247 } 236 248 237 private async void btnRemoveGroup_Click(object sender, EventArgs e) { 238 if (selectedResource == null) return; 249 private async void btnRemoveGroup_Click(object sender, EventArgs e) { 250 var nodes = GetCheckedNodes(treeView.Nodes).ToList(); 251 var checkedResources = nodes.Select(x => x.Tag).OfType<Resource>().ToList(); 252 if (selectedResource == null && !checkedResources.Any()) return; 239 253 240 254 lock (locker) { … … 243 257 } 244 258 245 var result = MessageBox.Show( 246 "Do you really want to delete " + selectedResource.Name + "?", 247 "HeuristicLab Hive Administrator", 248 MessageBoxButtons.YesNo, 249 MessageBoxIcon.Question); 250 if (result == DialogResult.Yes) { 251 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 252 action: () => { 253 RemoveResource(selectedResource); 254 }); 255 256 OnContentChanged(); 257 SetEnabledStateOfControls(); 258 } 259 if (checkedResources.Count > 0) { 260 var result = MessageBox.Show( 261 "Do you really want to delete all " + checkedResources.Count + " checked resources?", 262 "HeuristicLab Hive Administrator", 263 MessageBoxButtons.YesNo, 264 MessageBoxIcon.Question); 265 if (result == DialogResult.Yes) { 266 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 267 action: () => { 268 RemoveResource(checkedResources); 269 }); 270 } 271 } else { 272 var res = checkedResources.Any() ? checkedResources.First() : selectedResource; 273 var result = MessageBox.Show( 274 "Do you really want to delete the selected resource " + res.Name + "?", 275 "HeuristicLab Hive Administrator", 276 MessageBoxButtons.YesNo, 277 MessageBoxIcon.Question); 278 if (result == DialogResult.Yes) { 279 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 280 action: () => { 281 RemoveResource(res); 282 }); 283 } 284 } 285 286 OnContentChanged(); 287 SetEnabledStateOfControls(); 259 288 } 260 289 … … 297 326 } 298 327 } 328 } 329 330 private void treeSlaveGroup_AfterCheck(object sender, TreeViewEventArgs e) { 331 SetEnabledStateOfControls(); 299 332 } 300 333 … … 535 568 if (resource.Id != Guid.Empty) { 536 569 SelectedResource = HiveAdminClient.Instance.GetAvailableResourceAncestors(resource.Id).LastOrDefault(); 537 HiveAdminClient.Delete(resource); 570 571 // deal with all new, but not yet saved resources 572 var newResources = Content.Where(x => x.ParentResourceId == resource.Id).ToList(); 573 if (newResources.Any(x => x.Id != Guid.Empty)) return; 574 foreach (var nr in newResources) Content.Remove(nr); 575 576 HiveAdminClient.Delete(resource); 538 577 UpdateResources(); 539 578 } else { 540 SelectedResource = null;579 SelectedResource = Content.FirstOrDefault(x => x.Id == resource.ParentResourceId); 541 580 Content.Remove(resource); 542 581 } 582 } catch (AnonymousUserException) { 583 ShowHiveInformationDialog(); 584 } 585 } 586 587 private void RemoveResource(IEnumerable<Resource> resources) { 588 if (resources == null || !resources.Any()) return; 589 590 var ids = resources.Select(x => x.Id).ToList(); 591 try { 592 bool update = false; 593 foreach (var r in resources) { 594 if (r.Id != Guid.Empty) { 595 if(r.Id == SelectedResource.Id) 596 SelectedResource = HiveAdminClient.Instance.GetAvailableResourceAncestors(r.Id).LastOrDefault(); 597 598 // deal with all new, but not yet saved resources 599 var newResources = Content.Where(x => x.ParentResourceId == r.Id).ToList(); 600 if (newResources.Any(x => x.Id != Guid.Empty)) return; 601 foreach (var nr in newResources) Content.Remove(nr); 602 603 HiveAdminClient.Delete(r); 604 update = true; 605 } else { 606 if (r.Id == SelectedResource.Id) 607 SelectedResource = Content.FirstOrDefault(x => x.Id == r.ParentResourceId); 608 Content.Remove(r); 609 } 610 } 611 if (update) UpdateResources(); 543 612 } catch (AnonymousUserException) { 544 613 ShowHiveInformationDialog(); … … 678 747 private Dictionary<Guid, HashSet<Resource>> GetResourceDescendants() { 679 748 var resourceDescendants = new Dictionary<Guid, HashSet<Resource>>(); 749 //var resources = Content.Where(x => x.Id != Guid.Empty).Union(HiveAdminClient.Instance.DisabledParentResources).ToList(); 680 750 var resources = Content.Union(HiveAdminClient.Instance.DisabledParentResources).ToList(); 681 751 682 foreach (var r in resources) resourceDescendants.Add(r.Id, new HashSet<Resource>()); 752 foreach (var r in resources) { 753 if(!resourceDescendants.ContainsKey(r.Id)) 754 resourceDescendants.Add(r.Id, new HashSet<Resource>()); 755 } 683 756 foreach (var r in resources) { 684 757 var parentResourceId = r.ParentResourceId;
Note: See TracChangeset
for help on using the changeset viewer.