Changeset 16122 for trunk/HeuristicLab.Clients.Hive.Administrator
- Timestamp:
- 09/04/18 11:16:36 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
r16117 r16122 112 112 BuildResourceTree(Content); 113 113 } 114 SetEnabledStateOfControls(); 114 115 } 115 116 … … 117 118 base.SetEnabledStateOfControls(); 118 119 119 bool locked = Content == null || selectedResource == null || Locked || ReadOnly; 120 bool adminLocked = locked || !IsAdmin(); 121 bool addLocked = adminLocked || selectedResource.Id == Guid.Empty || selectedResource is Slave; 122 bool deleteLocked = adminLocked || HiveAdminClient.Instance.ResourceDescendants[selectedResource.Id].Any(); 120 bool locked = Content == null || Locked || ReadOnly; 121 bool addLocked = locked 122 || !IsAdmin() 123 || (selectedResource is Slave && selectedResource.ParentResourceId != null) 124 || (selectedResource != null && selectedResource.Id == Guid.Empty); 125 126 HashSet<Guid> descendantResources = null; 127 128 bool deleteLocked = locked 129 || !IsAdmin() 130 || !Content.Any() 131 || selectedResource == null 132 || (selectedResource.Id != Guid.Empty && (!HiveAdminClient.Instance.ResourceDescendants.TryGetValue(selectedResource.Id, out descendantResources) || descendantResources.Any())); 133 134 bool saveLocked = locked 135 || !IsAdmin() 136 || !Content.Any() 137 || selectedResource == null; 123 138 124 139 btnAddGroup.Enabled = !addLocked; 125 140 btnRemoveGroup.Enabled = !deleteLocked; 126 btnSave.Enabled = !locked; 127 scheduleView.Locked = adminLocked; 141 btnSave.Enabled = !saveLocked; 142 viewHost.Locked = locked || !IsAdmin(); 143 scheduleView.Locked = locked || !IsAdmin(); 128 144 } 129 145 #endregion … … 207 223 208 224 private void btnAddGroup_Click(object sender, EventArgs e) { 209 Guid? parentResourceId = null; 210 if (!IsAdmin()) { 211 MessageBox.Show( 212 "You have no permission to add a resource group.", 213 "HeuristicLab Hive Administrator", 214 MessageBoxButtons.OK, 215 MessageBoxIcon.Information); 216 return; 217 } else if (selectedResource != null && selectedResource.Id == Guid.Empty) { 218 MessageBox.Show( 219 "You cannot add a resource group to a not yet stored group.", 220 "HeuristicLab Hive Administrator", 221 MessageBoxButtons.OK, 222 MessageBoxIcon.Information); 223 return; 224 } 225 226 if (selectedResource != null && selectedResource is SlaveGroup) { 227 parentResourceId = selectedResource.Id; 228 } else { 229 MessageBox.Show( 230 "You cannot add a resource group to a slave.", 231 "HeuristicLab Hive Administrator", 232 MessageBoxButtons.OK, 233 MessageBoxIcon.Information); 234 return; 235 } 225 var parentResourceId = selectedResource is SlaveGroup ? selectedResource.Id : (Guid?)null; 236 226 237 227 var group = new SlaveGroup { … … 241 231 }; 242 232 243 //HiveAdminClient.Instance.UpdateResourceGenealogy(Content);244 233 SelectedResource = group; 245 234 Content.Add(group); … … 252 241 if (!btnRemoveGroup.Enabled) return; 253 242 btnRemoveGroup.Enabled = false; 254 }255 256 if (!IsAdmin()) {257 MessageBox.Show(258 "You have no permission to delete resource groups.",259 "HeuristicLab Hive Administrator",260 MessageBoxButtons.OK,261 MessageBoxIcon.Information);262 return;263 }264 265 if (Content.Any(x => x.ParentResourceId == selectedResource.Id)) {266 MessageBox.Show(267 "Only empty resource groups can be deleted.",268 "HeuristicLab Hive Administrator",269 MessageBoxButtons.OK,270 MessageBoxIcon.Error);271 return;272 243 } 273 244 … … 281 252 action: () => { 282 253 RemoveResource(selectedResource); 283 },284 finallyCallback: () => {285 btnRemoveGroup.Enabled = true;286 254 }); 287 } else { 288 btnRemoveGroup.Enabled = true; 255 256 OnContentChanged(); 257 SetEnabledStateOfControls(); 289 258 } 290 259 } … … 302 271 resource.Store(); 303 272 UpdateResources(); 304 }, 305 finallyCallback: () => btnSave.Enabled = true); 273 }); 306 274 307 275 OnContentChanged(); 276 SetEnabledStateOfControls(); 308 277 } 309 278 … … 483 452 ungroupedGroupNode = new TreeNode(UNGROUPED_GROUP_NAME) { 484 453 ForeColor = SystemColors.GrayText, 454 ImageIndex = slaveGroupImageIndex, 485 455 Tag = new SlaveGroup() { 486 456 Name = UNGROUPED_GROUP_NAME, … … 508 478 ungroupedGroupNode.Text += " [" + ungroupedGroupNode.Nodes.Count.ToString() + "]"; 509 479 ungroupedGroupNode.Expand(); 510 }511 treeView.Nodes.Add(ungroupedGroupNode);480 treeView.Nodes.Add(ungroupedGroupNode); 481 } 512 482 } 513 483 … … 564 534 try { 565 535 if (resource.Id != Guid.Empty) { 566 var resourcesToSave = Content.Where(x => x.Id == Guid.Empty || x.Modified);567 foreach (var r in resourcesToSave)568 r.Store();569 570 536 SelectedResource = HiveAdminClient.Instance.GetAvailableResourceAncestors(resource.Id).LastOrDefault(); 571 537 HiveAdminClient.Delete(resource); 572 538 UpdateResources(); 573 539 } else { 574 Content.Remove(selectedResource); 540 SelectedResource = null; 541 Content.Remove(resource); 575 542 } 576 543 } catch (AnonymousUserException) {
Note: See TracChangeset
for help on using the changeset viewer.