Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16185 for trunk


Ignore:
Timestamp:
09/25/18 13:55:11 (6 years ago)
Author:
jzenisek
Message:

#2839:

  • updated enabled state of controls for projects
  • updated enabled state of controls for resources
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  
    134134
    135135      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)) {
    138140          indefiniteCheckBox.Enabled = false;
    139141        }
  • trunk/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs

    r16117 r16185  
    106106        BuildProjectTree(Content);
    107107      }
     108      SetEnabledStateOfControls();
    108109    }
    109110
    110111    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
    122142
    123143      addButton.Enabled = !addLocked;
    124144      removeButton.Enabled = !deleteLocked;
    125145      saveProjectButton.Enabled = !saveLocked;
     146
    126147      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;
    130151
    131152      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;
    135156    }
    136157    #endregion
     
    254275      }
    255276
    256       // double check of ChangeSelectedProject(..):
    257       // if the user is no admin nor owner of a parent project
    258       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] != null
    280         && 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 
    289277      var result = MessageBox.Show(
    290278        "Do you really want to delete " + selectedProject.Name + "?",
     
    297285          action: () => {
    298286            RemoveProject(selectedProject); 
    299           },
    300           finallyCallback: () => {
    301             removeButton.Enabled = true;
    302287          });
    303       } else {
    304         removeButton.Enabled = true;
    305       }
     288      }
     289      SetEnabledStateOfControls();
    306290    }
    307291
     
    540524      try {
    541525        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 
    546526          SelectedProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(project.Id).LastOrDefault();
    547527          HiveAdminClient.Delete(project);         
    548528          UpdateProjects();
    549         } else {
     529        } else {         
     530          SelectedProject = Content.FirstOrDefault(x => x.Id == project.ParentProjectId);
    550531          Content.Remove(project);
    551532        }
  • trunk/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.Designer.cs

    r16117 r16185  
    164164      this.treeView.DragOver += new System.Windows.Forms.DragEventHandler(this.treeSlaveGroup_DragEnterOver);
    165165      this.treeView.BeforeCheck += new System.Windows.Forms.TreeViewCancelEventHandler(this.treeSlaveGroup_BeforeCheck);
     166      this.treeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeSlaveGroup_AfterCheck);
    166167      //
    167168      // tabSlaveGroup
  • trunk/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs

    r16122 r16185  
    125125
    126126      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      }
    127139
    128140      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()));
     141                          || !IsAdmin()
     142                          || !Content.Any()
     143                          || checkedResources.Any() && checkedRDeleteLocked
     144                          || !checkedResources.Any() && selectedRDeleteLocked;
    133145
    134146      bool saveLocked = locked
     
    235247    }
    236248
    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;
    239253
    240254      lock (locker) {
     
    243257      }
    244258
    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();
    259288    }
    260289
     
    297326        }
    298327      }
     328    }
     329
     330    private void treeSlaveGroup_AfterCheck(object sender, TreeViewEventArgs e) {
     331      SetEnabledStateOfControls();
    299332    }
    300333
     
    535568        if (resource.Id != Guid.Empty) {
    536569          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);         
    538577          UpdateResources();
    539578        } else {
    540           SelectedResource = null;
     579          SelectedResource = Content.FirstOrDefault(x => x.Id == resource.ParentResourceId);
    541580          Content.Remove(resource);
    542581        }
     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();
    543612      } catch (AnonymousUserException) {
    544613        ShowHiveInformationDialog();
     
    678747    private Dictionary<Guid, HashSet<Resource>> GetResourceDescendants() {
    679748      var resourceDescendants = new Dictionary<Guid, HashSet<Resource>>();
     749      //var resources = Content.Where(x => x.Id != Guid.Empty).Union(HiveAdminClient.Instance.DisabledParentResources).ToList();     
    680750      var resources = Content.Union(HiveAdminClient.Instance.DisabledParentResources).ToList();
    681751
    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      }
    683756      foreach (var r in resources) {
    684757        var parentResourceId = r.ParentResourceId;
Note: See TracChangeset for help on using the changeset viewer.