- Timestamp:
- 06/21/18 15:27:56 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectJobsView.cs
r15966 r15969 30 30 using HeuristicLab.Data.Views; 31 31 using HeuristicLab.Data; 32 using HeuristicLab.Clients.Hive.Views; 32 33 33 34 namespace HeuristicLab.Clients.Hive.Administrator.Views { … … 38 39 private const string JOB_NAME = "Name"; 39 40 private const string JOB_OWNER = "Owner"; 41 private const string JOB_OWNERID = "Owner Id"; 40 42 private const string JOB_DATECREATED = "Date Created"; 41 43 private const string JOB_STATE = "State"; 42 44 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 43 55 44 56 public new Project Content { … … 47 59 } 48 60 49 public ProjectJobsView() /*: base()*/{61 public ProjectJobsView() { 50 62 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; 51 77 } 52 78 … … 54 80 protected override void OnContentChanged() { 55 81 base.OnContentChanged(); 82 removeButton.Enabled = false; 56 83 UpdateJobs(); 57 84 } … … 61 88 62 89 refreshButton.Enabled = enabled; 63 removeButton.Enabled = enabled;90 removeButton.Enabled = false; 64 91 matrixView.Enabled = enabled; 65 92 } … … 72 99 73 100 private void refreshButton_Click(object sender, EventArgs e) { 74 HiveAdminClient.Instance.Refresh(); 75 // Update list/matrix 101 RefreshJobs(); 76 102 } 77 103 78 104 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 } 80 135 } 81 136 … … 83 138 84 139 #region Helpers 140 private void RefreshJobs() { 141 HiveAdminClient.Instance.RefreshJobs(); 142 UpdateJobs(); 143 } 144 85 145 private StringMatrix CreateValueMatrix() { 86 146 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]; 88 149 89 150 for(int i = 0; i < jobs.Count; i++) { 90 151 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 100 165 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 }; 102 167 matrix.SortableView = true; 103 168 return matrix; 104 169 } 105 170 106 171 private void UpdateJobs() { 107 172 if (InvokeRequired) Invoke((Action)UpdateJobs); … … 115 180 } 116 181 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 117 194 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 } 121 214 } 122 215 }
Note: See TracChangeset
for help on using the changeset viewer.