From f5ef4c55bccd1d9ee5655a23172707c2a76cac32 Mon Sep 17 00:00:00 2001 From: Danil Kislov Date: Mon, 18 Mar 2019 19:10:20 +0300 Subject: [PATCH] ok --- JiraTimeBotForm/Configuration/Settings.cs | 1 + JiraTimeBotForm/JiraIntegration/JiraApi.cs | 23 +++++++++++++-- JiraTimeBotForm/UI/frmSettings.Designer.cs | 33 ++++++++++++++++++---- JiraTimeBotForm/UI/frmSettings.cs | 10 ++++++- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/JiraTimeBotForm/Configuration/Settings.cs b/JiraTimeBotForm/Configuration/Settings.cs index f4dc0ed..56edd42 100644 --- a/JiraTimeBotForm/Configuration/Settings.cs +++ b/JiraTimeBotForm/Configuration/Settings.cs @@ -21,6 +21,7 @@ namespace JiraTimeBotForm.Configuration public TimeSpan ActivationTime { get; set; } public bool AddCommentsToWorklog { get; set; } public WorkType WorkType { get; set; } + public string JiraQuery { get; set; } public static Settings LoadAndCheck(Action settingsSource, Action errorMessageReporter) { diff --git a/JiraTimeBotForm/JiraIntegration/JiraApi.cs b/JiraTimeBotForm/JiraIntegration/JiraApi.cs index d88c3a4..107966c 100644 --- a/JiraTimeBotForm/JiraIntegration/JiraApi.cs +++ b/JiraTimeBotForm/JiraIntegration/JiraApi.cs @@ -41,9 +41,26 @@ namespace JiraTimeBotForm.JiraIntegration var userName = settings.JiraUserName; - var jql = $"status changed by '{userName}' during (\"{date.Value:yyyy-MM-dd}\",\"{date.Value:yyyy-MM-dd}\")"; - var affectedIssues = jira.Issues.GetIssuesFromJqlAsync(jql, 50, 0, cancellationToken).Result.ToList(); - return affectedIssues; + var jql = settings.JiraQuery; + if (string.IsNullOrEmpty(jql)) + { + jql = $"status changed by '%USER%' during (\"%DATE%\",\"%DATE%\")"; + } + + jql = jql.Replace("%USER%", userName); + jql = jql.Replace("%DATE%", $"{date.Value:yyyy-MM-dd}"); + + try + { + List affectedIssues = + jira.Issues.GetIssuesFromJqlAsync(jql, 50, 0, cancellationToken).Result.ToList(); + return affectedIssues; + } + catch (Exception ex) + { + _log.Error($"Ошибка получения информации из JIRA: {ex.InnerException?.Message}"); + return new List(); + } } public void SetTodayWorklog(List taskTimeItems, Settings settings, DateTime? date = null, bool dummy = false, bool addCommentsToWorklog = false) diff --git a/JiraTimeBotForm/UI/frmSettings.Designer.cs b/JiraTimeBotForm/UI/frmSettings.Designer.cs index 4addc97..33238c0 100644 --- a/JiraTimeBotForm/UI/frmSettings.Designer.cs +++ b/JiraTimeBotForm/UI/frmSettings.Designer.cs @@ -44,6 +44,8 @@ this.btnSave = new System.Windows.Forms.Button(); this.cboWorkType = new System.Windows.Forms.ComboBox(); this.label6 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.txtJQL = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // label5 @@ -131,7 +133,7 @@ // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(16, 180); + this.label3.Location = new System.Drawing.Point(16, 206); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(91, 13); this.label3.TabIndex = 30; @@ -140,7 +142,7 @@ // actTime // this.actTime.Format = System.Windows.Forms.DateTimePickerFormat.Time; - this.actTime.Location = new System.Drawing.Point(109, 176); + this.actTime.Location = new System.Drawing.Point(109, 202); this.actTime.Name = "actTime"; this.actTime.Size = new System.Drawing.Size(100, 20); this.actTime.TabIndex = 29; @@ -148,7 +150,7 @@ // chkAddComments // this.chkAddComments.AutoSize = true; - this.chkAddComments.Location = new System.Drawing.Point(39, 202); + this.chkAddComments.Location = new System.Drawing.Point(46, 242); this.chkAddComments.Name = "chkAddComments"; this.chkAddComments.Size = new System.Drawing.Size(133, 17); this.chkAddComments.TabIndex = 31; @@ -157,7 +159,7 @@ // // btnSave // - this.btnSave.Location = new System.Drawing.Point(61, 236); + this.btnSave.Location = new System.Drawing.Point(61, 276); this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(75, 23); this.btnSave.TabIndex = 32; @@ -176,6 +178,7 @@ this.cboWorkType.Name = "cboWorkType"; this.cboWorkType.Size = new System.Drawing.Size(99, 21); this.cboWorkType.TabIndex = 34; + this.cboWorkType.SelectedIndexChanged += new System.EventHandler(this.cboWorkType_SelectedIndexChanged); // // label6 // @@ -186,11 +189,29 @@ this.label6.TabIndex = 35; this.label6.Text = "Режим работы:"; // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(74, 179); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(29, 13); + this.label7.TabIndex = 37; + this.label7.Text = "JQL:"; + // + // txtJQL + // + this.txtJQL.Location = new System.Drawing.Point(109, 176); + this.txtJQL.Name = "txtJQL"; + this.txtJQL.Size = new System.Drawing.Size(99, 20); + this.txtJQL.TabIndex = 36; + // // frmSettings // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(220, 268); + this.ClientSize = new System.Drawing.Size(220, 311); + this.Controls.Add(this.label7); + this.Controls.Add(this.txtJQL); this.Controls.Add(this.label6); this.Controls.Add(this.cboWorkType); this.Controls.Add(this.btnSave); @@ -236,5 +257,7 @@ private System.Windows.Forms.Button btnSave; private System.Windows.Forms.ComboBox cboWorkType; private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.TextBox txtJQL; } } \ No newline at end of file diff --git a/JiraTimeBotForm/UI/frmSettings.cs b/JiraTimeBotForm/UI/frmSettings.cs index 4da7a0d..0833cd6 100644 --- a/JiraTimeBotForm/UI/frmSettings.cs +++ b/JiraTimeBotForm/UI/frmSettings.cs @@ -31,6 +31,8 @@ namespace JiraTimeBotForm.UI chkAddComments.Checked = settings.AddCommentsToWorklog; txtRoundTo.Text = settings.RountToMinutes.ToString(); cboWorkType.SelectedIndex = (int) settings.WorkType; + txtJQL.Text = settings.JiraQuery; + txtJQL.Enabled = settings.WorkType == WorkType.JiraLogs; } public Settings ReadSettingsAndLock() @@ -50,7 +52,8 @@ namespace JiraTimeBotForm.UI //DummyMode = txtDummyMode.Checked, AddCommentsToWorklog = chkAddComments.Checked, RountToMinutes = roundTo, - WorkType = (WorkType) cboWorkType.SelectedIndex + WorkType = (WorkType) cboWorkType.SelectedIndex, + JiraQuery = txtJQL.Text, }; //LockUnlock(false); @@ -73,5 +76,10 @@ namespace JiraTimeBotForm.UI { e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar); } + + private void cboWorkType_SelectedIndexChanged(object sender, EventArgs e) + { + txtJQL.Enabled = (cboWorkType.SelectedIndex == 1); + } } }