Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/21/18 15:27:56 (7 years ago)
Author:
jzenisek
Message:

#2839: finalized ProjectJobsView

File:
1 edited

Legend:

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

    r15966 r15969  
    3030using HeuristicLab.Data.Views;
    3131using HeuristicLab.Data;
     32using HeuristicLab.Clients.Hive.Views;
    3233
    3334namespace HeuristicLab.Clients.Hive.Administrator.Views {
     
    3839    private const string JOB_NAME = "Name";
    3940    private const string JOB_OWNER = "Owner";
     41    private const string JOB_OWNERID = "Owner Id";
    4042    private const string JOB_DATECREATED = "Date Created";
    4143    private const string JOB_STATE = "State";
    4244    private const string JOB_DESCRIPTION = "Description";
     45    private const string JOB_TASKCOUNT = "Tasks";
     46    private const string JOB_CALCULATINGTASKCOUNT = "Calculating";
     47    private const string JOB_FINISHEDTASKCOUNT = "Finished";
     48
     49
     50    private readonly Color onlineStatusColor = Color.FromArgb(255, 189, 249, 143); // #bdf98f
     51    private readonly Color onlineStatusColor2 = Color.FromArgb(255, 157, 249, 143); // #9df98f
     52    private readonly Color statisticsPendingStatusColor = Color.FromArgb(255, 249, 210, 145); // #f9d291
     53    private readonly Color deletionPendingStatusColor = Color.FromArgb(255, 249, 172, 144); // #f9ac90
     54    private readonly Color deletionPendingStatusColor2 = Color.FromArgb(255, 249, 149, 143); // #f9958f
    4355
    4456    public new Project Content {
     
    4759    }
    4860
    49     public ProjectJobsView() /*: base()*/ {
     61    public ProjectJobsView() {
    5062      InitializeComponent();
     63
     64      removeButton.Enabled = false;
     65      matrixView.DataGridView.SelectionChanged += DataGridView_SelectionChanged;
     66    }
     67
     68    private void DataGridView_SelectionChanged(object sender, EventArgs e) {
     69      if (matrixView.DataGridView.SelectedRows == null || matrixView.DataGridView.SelectedRows.Count == 0) return;
     70
     71      bool anyDeletable = false;
     72      foreach (DataGridViewRow r in matrixView.DataGridView.SelectedRows) {
     73        if (((string)r.Cells[0].Value) == JobState.Online.ToString()) anyDeletable = true;
     74      }
     75
     76      removeButton.Enabled = anyDeletable;
    5177    }
    5278
     
    5480    protected override void OnContentChanged() {
    5581      base.OnContentChanged();
     82      removeButton.Enabled = false;
    5683      UpdateJobs();
    5784    }
     
    6188
    6289      refreshButton.Enabled = enabled;
    63       removeButton.Enabled = enabled;
     90      removeButton.Enabled = false;
    6491      matrixView.Enabled = enabled;
    6592    }
     
    7299
    73100    private void refreshButton_Click(object sender, EventArgs e) {
    74       HiveAdminClient.Instance.Refresh();
    75       // Update list/matrix
     101      RefreshJobs();
    76102    }
    77103
    78104    private async void removeButton_Click(object sender, EventArgs e) {
    79       // remove selected job(s)
     105      if (matrixView.DataGridView.SelectedRows == null || matrixView.DataGridView.SelectedRows.Count == 0) return;
     106
     107      var jobNamesToDelete = new List<string>();
     108      var jobIdsToDelete = new List<Guid>();
     109      foreach (DataGridViewRow r in matrixView.DataGridView.SelectedRows) {
     110        if(((string)r.Cells[0].Value) == JobState.Online.ToString()) {
     111          jobNamesToDelete.Add(" - " + ((string)r.Cells[3].Value));
     112          jobIdsToDelete.Add(Guid.Parse((string)r.Cells[8].Value));
     113        }
     114      }
     115
     116      if(jobIdsToDelete.Any()) {
     117        var result = MessageBox.Show("Do you really want to remove following job(s):\n\n"
     118          + String.Join("\n", jobNamesToDelete),
     119          "HeuristicLab Hive Administrator",
     120          MessageBoxButtons.YesNo,
     121          MessageBoxIcon.Question);
     122
     123        if (result == DialogResult.Yes) {
     124          await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
     125            action: () => {
     126              DeleteJobs(jobIdsToDelete);
     127            },
     128            finallyCallback: () => {
     129              matrixView.DataGridView.ClearSelection();
     130              removeButton.Enabled = false;
     131              RefreshJobs();
     132            });
     133        }
     134      }
    80135    }
    81136
     
    83138
    84139    #region Helpers
     140    private void RefreshJobs() {
     141      HiveAdminClient.Instance.RefreshJobs();
     142      UpdateJobs();
     143    }
     144
    85145    private StringMatrix CreateValueMatrix() {
    86146      var jobs = HiveAdminClient.Instance.Jobs[Content.Id];
    87       string[,] values = new string[jobs.Count, 7];
     147      var resources = HiveAdminClient.Instance.Resources;
     148      string[,] values = new string[jobs.Count, 10];
    88149
    89150      for(int i = 0; i < jobs.Count; i++) {
    90151        var job = jobs.ElementAt(i);
    91         values[i, 0] = job.Id.ToString();
    92         values[i, 1] = job.Name;
    93         values[i, 2] = job.OwnerUserId.ToString();
    94         values[i, 3] = job.OwnerUsername;
    95         values[i, 4] = job.DateCreated.ToString();
    96         values[i, 5] = job.State.ToString();
    97         values[i, 6] = job.Description;
    98       }
    99 
     152       
     153        values[i, 0] = job.State.ToString();
     154        values[i, 1] = job.DateCreated.ToString();
     155        values[i, 2] = job.OwnerUsername;
     156        values[i, 3] = job.Name;
     157        values[i, 4] = job.JobCount.ToString();
     158        values[i, 5] = job.CalculatingCount.ToString();
     159        values[i, 6] = job.FinishedCount.ToString();
     160        values[i, 7] = job.Description;       
     161        values[i, 8] = job.Id.ToString();
     162        values[i, 9] = job.OwnerUserId.ToString();
     163      }
     164     
    100165      var matrix = new StringMatrix(values);
    101       matrix.ColumnNames = new string[] { JOB_ID, JOB_NAME, JOB_OWNER, JOB_OWNER, JOB_DATECREATED, JOB_STATE, JOB_DESCRIPTION };
     166      matrix.ColumnNames = new string[] { JOB_STATE, JOB_DATECREATED, JOB_OWNER, JOB_NAME, JOB_TASKCOUNT, JOB_CALCULATINGTASKCOUNT, JOB_FINISHEDTASKCOUNT, JOB_DESCRIPTION, JOB_ID, JOB_OWNERID };
    102167      matrix.SortableView = true;
    103168      return matrix;
    104169    }
    105 
     170   
    106171    private void UpdateJobs() {
    107172      if (InvokeRequired) Invoke((Action)UpdateJobs);
     
    115180        }
    116181        matrixView.Content = matrix;
     182       
     183        foreach(DataGridViewRow row in matrixView.DataGridView.Rows) {
     184          string val = ((string)row.Cells[0].Value);
     185          if (val == JobState.Online.ToString()) {
     186            row.DefaultCellStyle.BackColor = onlineStatusColor;
     187          } else if(val == JobState.StatisticsPending.ToString()) {
     188            row.DefaultCellStyle.BackColor = statisticsPendingStatusColor;
     189          } else if(val == JobState.DeletionPending.ToString()) {
     190            row.DefaultCellStyle.BackColor = deletionPendingStatusColor;
     191          }
     192        }
     193
    117194        matrixView.DataGridView.AutoResizeColumns();
    118         //foreach(DataGridViewColumn col in matrixView.DataGridView.Columns) {
    119         //  col.Width = -2;
    120         //}
     195        matrixView.DataGridView.Columns[0].MinimumWidth = 90;
     196        matrixView.DataGridView.Columns[1].MinimumWidth = 108;
     197      }
     198    }
     199
     200    private void DeleteJobs(List<Guid> jobIds) {
     201      try {
     202        HiveAdminClient.DeleteJobs(jobIds);
     203      } catch (AnonymousUserException) {
     204        ShowHiveInformationDialog();
     205      }
     206    }
     207
     208    private void ShowHiveInformationDialog() {
     209      if (InvokeRequired) Invoke((Action)ShowHiveInformationDialog);
     210      else {
     211        using (HiveInformationDialog dialog = new HiveInformationDialog()) {
     212          dialog.ShowDialog(this);
     213        }
    121214      }
    122215    }
Note: See TracChangeset for help on using the changeset viewer.