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

#2839:

  • updated enabled state of controls for projects
  • updated enabled state of controls for resources
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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        }
Note: See TracChangeset for help on using the changeset viewer.