Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/03/18 13:50:29 (6 years ago)
Author:
jzenisek
Message:

#2839: adapted handling of project start/end boundaries for non-admins

Location:
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectView.Designer.cs

    r15953 r16043  
    153153      this.startDateTimePicker.Size = new System.Drawing.Size(200, 20);
    154154      this.startDateTimePicker.TabIndex = 9;
    155       this.startDateTimePicker.ValueChanged += new System.EventHandler(this.startDateTimePicker_ValueChanged);
     155      this.startDateTimePicker.ValueChanged += new System.EventHandler(this.startDateTimePicker_ValueChanged);     
    156156      //
    157157      // startLabel
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectView.cs

    r16040 r16043  
    6767    }
    6868
     69    protected void RegisterControlEvents() {
     70      nameTextBox.TextChanged += nameTextBox_TextChanged;
     71      nameTextBox.Validating += nameTextBox_Validating;
     72      descriptionTextBox.TextChanged += descriptionTextBox_TextChanged;
     73      ownerComboBox.SelectedIndexChanged += ownerComboBox_SelectedIndexChanged;
     74      startDateTimePicker.ValueChanged += startDateTimePicker_ValueChanged;
     75      endDateTimePicker.ValueChanged += endDateTimePicker_ValueChanged;
     76      indefiniteCheckBox.CheckedChanged += indefiniteCheckBox_CheckedChanged;
     77    }
     78
     79    protected void DeregisterControlEvents() {
     80      nameTextBox.TextChanged -= nameTextBox_TextChanged;
     81      nameTextBox.Validating -= nameTextBox_Validating;
     82      descriptionTextBox.TextChanged -= descriptionTextBox_TextChanged;
     83      ownerComboBox.SelectedIndexChanged -= ownerComboBox_SelectedIndexChanged;
     84      startDateTimePicker.ValueChanged -= startDateTimePicker_ValueChanged;
     85      endDateTimePicker.ValueChanged -= endDateTimePicker_ValueChanged;
     86      indefiniteCheckBox.CheckedChanged -= indefiniteCheckBox_CheckedChanged;
     87    }
     88
    6989    protected override void OnContentChanged() {
    7090      base.OnContentChanged();
     91      DeregisterControlEvents();
    7192      if (Content == null) {
    7293        idTextBox.Clear();
     
    98119        endDateTimePicker.Enabled = !indefiniteCheckBox.Checked;
    99120      }
     121      RegisterControlEvents();
    100122    }
    101123
     
    112134      indefiniteCheckBox.Enabled = enabled;
    113135
    114       if (!IsAdmin() && !HiveAdminClient.Instance.CheckOwnershipOfParentProject(Content, UserInformation.Instance.User.Id)) {
    115         ownerComboBox.Enabled = false;
    116         startDateTimePicker.Enabled = false;
    117         endDateTimePicker.Enabled = false;
    118         indefiniteCheckBox.Enabled = false;
    119       }
     136      if(Content != null) {
     137        var parentProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).LastOrDefault();
     138        if (parentProject == null || parentProject.EndDate.HasValue) {
     139          indefiniteCheckBox.Enabled = false;
     140        }
     141
     142        if (!IsAdmin() && !HiveAdminClient.Instance.CheckOwnershipOfParentProject(Content, UserInformation.Instance.User.Id)) {
     143          ownerComboBox.Enabled = false;
     144          startDateTimePicker.Enabled = false;
     145          endDateTimePicker.Enabled = false;
     146          indefiniteCheckBox.Enabled = false;
     147        }
     148      }
    120149    }
    121150    #endregion
     
    187216
    188217    private void nameTextBox_TextChanged(object sender, EventArgs e) {
    189       if (Content != null && Content.Name != nameTextBox.Text)
     218      if (Content != null && Content.Name != nameTextBox.Text) {
     219        DeregisterContentEvents();
    190220        Content.Name = nameTextBox.Text;
     221        RegisterContentEvents();
     222      }       
    191223    }
    192224
    193225    private void descriptionTextBox_TextChanged(object sender, EventArgs e) {
    194       if (Content != null && Content.Description != descriptionTextBox.Text)
     226      if (Content != null && Content.Description != descriptionTextBox.Text) {
     227        DeregisterContentEvents();
    195228        Content.Description = descriptionTextBox.Text;
     229        RegisterContentEvents();
     230      }       
    196231    }
    197232
     
    199234      var selectedItem = (LightweightUser)ownerComboBox.SelectedItem;
    200235      var selectedOwnerUserId = selectedItem != null ? selectedItem.Id : Guid.Empty;
    201       if (Content != null && Content.OwnerUserId != selectedOwnerUserId)
     236      if (Content != null && Content.OwnerUserId != selectedOwnerUserId) {
     237        DeregisterContentEvents();
    202238        Content.OwnerUserId = selectedOwnerUserId;
     239        RegisterContentEvents();
     240      }       
    203241    }
    204242
    205243    private void startDateTimePicker_ValueChanged(object sender, EventArgs e) {
    206244      if (Content == null) return;
    207  
     245      startDateTimePicker.ValueChanged -= startDateTimePicker_ValueChanged;
     246
     247      if (!IsAdmin()) {
     248        var parentProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).LastOrDefault();
     249        if (parentProject != null) {
     250          if(startDateTimePicker.Value < parentProject.StartDate)
     251            startDateTimePicker.Value = parentProject.StartDate;
     252        } else {
     253          startDateTimePicker.Value = Content.StartDate;
     254        }
     255      }
     256
    208257      if (!Content.EndDate.HasValue || startDateTimePicker.Value > Content.EndDate)
    209258        endDateTimePicker.Value = startDateTimePicker.Value;
    210       if (Content.StartDate != startDateTimePicker.Value)
     259      if (Content.StartDate != startDateTimePicker.Value) {
     260        DeregisterContentEvents();
    211261        Content.StartDate = startDateTimePicker.Value;
     262        RegisterContentEvents();
     263      }       
     264
     265      startDateTimePicker.ValueChanged += startDateTimePicker_ValueChanged;
    212266    }
    213267
    214268    private void endDateTimePicker_ValueChanged(object sender, EventArgs e) {
    215269      if (Content == null) return;
     270      endDateTimePicker.ValueChanged -= endDateTimePicker_ValueChanged;
     271
     272      if (!IsAdmin()) {
     273        var parentProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).LastOrDefault();
     274        if (parentProject != null) {
     275          if (parentProject.EndDate.HasValue && endDateTimePicker.Value > parentProject.EndDate.Value) {
     276            endDateTimePicker.Value = parentProject.EndDate.Value;
     277          }
     278        } else if(Content.EndDate.HasValue) {
     279          endDateTimePicker.Value = Content.EndDate.Value;
     280        }
     281      }
    216282
    217283      if (endDateTimePicker.Value < startDateTimePicker.Value)
    218284        endDateTimePicker.Value = startDateTimePicker.Value;
    219       if (Content.EndDate != endDateTimePicker.Value)
     285      if (Content.EndDate != endDateTimePicker.Value) {
     286        DeregisterContentEvents();
    220287        Content.EndDate = endDateTimePicker.Value;
     288        RegisterContentEvents();
     289      }       
     290
     291      endDateTimePicker.ValueChanged += endDateTimePicker_ValueChanged;
    221292    }
    222293
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs

    r16040 r16043  
    197197    }
    198198
    199     private void addButton_Click(object sender, EventArgs e) {
    200       Guid? parentProjectId = null;
    201 
    202       if(selectedProject == null && !IsAdmin()) {
     199    private void addButton_Click(object sender, EventArgs e) {     
     200
     201      if (selectedProject == null && !IsAdmin()) {
    203202        MessageBox.Show(
    204203          "You are not allowed to add a root project - please select a parent project.",
     
    218217      }
    219218
    220       if (selectedProject != null) parentProjectId = selectedProject.Id;
    221219      var project = new Project {
    222220        Name = "New Project",
    223         OwnerUserId = UserInformation.Instance.User.Id,
    224         ParentProjectId = parentProjectId
     221        OwnerUserId = UserInformation.Instance.User.Id,       
    225222      };
     223      if(selectedProject != null) {
     224        project.ParentProjectId = selectedProject.Id;
     225        project.EndDate = selectedProject.EndDate;
     226      }
    226227
    227228      SelectedProject = project;
     
    508509
    509510      bool addEnabled = !locked;
    510       if (!IsAdmin() && project == null) addEnabled = false;
     511      if(addEnabled) {
     512        var now = DateTime.Now;
     513        if (now < project.StartDate || now > project.EndDate) addEnabled = false;
     514      }
    511515
    512516      bool saveEnabled = project != null;
Note: See TracChangeset for help on using the changeset viewer.