Skip to content
This repository was archived by the owner on Jul 27, 2022. It is now read-only.

Commit 39a26e1

Browse files
author
Nicolas Teichtweier
committed
added userlist and fixed minor bugs
1 parent 087949b commit 39a26e1

File tree

7 files changed

+140
-21
lines changed

7 files changed

+140
-21
lines changed

JiraTimeTracker/CConsole.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,28 @@ namespace JiraTimeTracker
1010
class CConsole
1111
{
1212
private TextBox outputBox;
13-
public CConsole(TextBox outputTextBox)
13+
private TextBox userOutputTextBox;
14+
15+
public CConsole(TextBox outputTextBox, TextBox userOutputTextBox)
1416
{
1517
outputBox = outputTextBox;
18+
this.userOutputTextBox = userOutputTextBox;
1619
}
1720

18-
public void Write(string text)
21+
public void WriteOutput(string text)
1922
{
2023
if(text != null)
2124
{
2225
outputBox.Text += "\r\n" + text;
2326
}
2427
}
28+
29+
public void WriteUserList(string text)
30+
{
31+
if (text != null)
32+
{
33+
userOutputTextBox.Text = text;
34+
}
35+
}
2536
}
2637
}

JiraTimeTracker/ConnectionHandler.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ private string PrepareUrl(string url)
7676
}
7777
}
7878

79-
private string PrepareQuery(string username, string projectKey)
79+
private string PrepareUserQuery(string username, string projectKey)
8080
{
8181
query = url + "/rest/api/2/search?jql=project=" + projectKey + "&assignee=" + username + "&maxResults=1000";
8282

8383
return query;
8484
}
8585

86+
87+
8688
private string BuildAuthHeader()
8789
{
8890
var builtstring = login + ":" + password;
@@ -92,7 +94,7 @@ private string BuildAuthHeader()
9294

9395
public string GetAssignedIssuesForUser(string username, string projectKey)
9496
{
95-
PrepareQuery(username, projectKey);
97+
PrepareUserQuery(username, projectKey);
9698
try
9799
{
98100
var response = httpClient.GetAsync(query).Result;
@@ -105,7 +107,27 @@ public string GetAssignedIssuesForUser(string username, string projectKey)
105107
}
106108
catch (Exception e)
107109
{
108-
cConsole.Write(e.Message + " | Please check your URL for typos");
110+
cConsole.WriteOutput(e.Message + " | Please check your URL for typos");
111+
return null;
112+
}
113+
}
114+
115+
public string GetAllStudentUsers()
116+
{
117+
var query = url + "/rest/api/2/group?groupname=Student&expand=users";
118+
try
119+
{
120+
var response = httpClient.GetAsync(query).Result;
121+
if (response.IsSuccessStatusCode)
122+
{
123+
string result = response.Content.ReadAsStringAsync().Result;
124+
return result;
125+
}
126+
return null;
127+
}
128+
catch (Exception e)
129+
{
130+
cConsole.WriteOutput(e.Message + " | Please check your URL for typos");
109131
return null;
110132
}
111133
}
@@ -124,7 +146,7 @@ public bool TestConnection()
124146
}
125147
catch(Exception e)
126148
{
127-
cConsole.Write(e.Message + " | Please check your URL for typos");
149+
cConsole.WriteOutput(e.Message + " | Please check your URL for typos");
128150
return false;
129151
}
130152
}

JiraTimeTracker/JTT.Designer.cs

Lines changed: 31 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JiraTimeTracker/JTT.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public JTT()
2424
private void JTT_Load(object sender, EventArgs e)
2525
{
2626
SetActiveForm();
27+
form.FormBorderStyle = FormBorderStyle.FixedSingle;
28+
form.MinimizeBox = false;
29+
form.MaximizeBox = false;
2730
InitializeOutput();
2831
}
2932

@@ -40,7 +43,7 @@ private JTT SetActiveForm()
4043

4144
private void InitializeOutput()
4245
{
43-
cConsole = new CConsole(form.OutputTextBox);
46+
cConsole = new CConsole(form.OutputTextBox, form.UserTextBox);
4447
}
4548

4649
private ConnectionHandler GetConnectionHandler()
@@ -58,7 +61,7 @@ private void TestButton_Click(object sender, EventArgs e)
5861
{
5962
if (GetConnectionHandler().TestConnection())
6063
{
61-
cConsole.Write("Test Successfull");
64+
cConsole.WriteOutput("Test Successfull");
6265
}
6366
}
6467

@@ -73,11 +76,11 @@ private void GetTimeForUser()
7376
var result = GetWorkingTime();
7477
if(result != null)
7578
{
76-
cConsole.Write("Working hours for user " + UsernameTextBox.Text + " : " + result);
79+
cConsole.WriteOutput("Working hours for user " + UsernameTextBox.Text + " : " + result);
7780
}
7881
else
7982
{
80-
cConsole.Write("An error occured. Is there a typo in the provided username?");
83+
cConsole.WriteOutput("An error occured. Is there a typo in the provided username?");
8184
}
8285
}
8386

@@ -87,8 +90,9 @@ private string GetWorkingTime()
8790
if(queryresult != null)
8891
{
8992
JsonConv conv = new JsonConv();
90-
RootObject decoderesult = conv.DecodeJsonToRootObject(queryresult);
93+
IssuesRoot decoderesult = conv.DecodeJsonToIssuesRoot(queryresult);
9194
int timeinseconds = CalculateWorkingTimeInSeconds(decoderesult);
95+
conv = null;
9296
return TimeSpan.FromSeconds(timeinseconds).TotalHours.ToString();
9397
}
9498
else
@@ -97,7 +101,7 @@ private string GetWorkingTime()
97101
}
98102
}
99103

100-
private int CalculateWorkingTimeInSeconds(RootObject root)
104+
private int CalculateWorkingTimeInSeconds(IssuesRoot root)
101105
{
102106
int result = 0;
103107
for(int i = 0; i < root.issues.Count; i++)
@@ -113,5 +117,32 @@ private int CalculateWorkingTimeInSeconds(RootObject root)
113117
}
114118
return result;
115119
}
120+
121+
private void GetUsersButton_Click(object sender, EventArgs e)
122+
{
123+
GetConnectionHandler();
124+
GetAllUsers();
125+
}
126+
127+
private void GetAllUsers()
128+
{
129+
var queryresult = connectionHandler.GetAllStudentUsers();
130+
if (queryresult != null)
131+
{
132+
JsonConv conv = new JsonConv();
133+
UserRoot decoderesult = conv.DecodeJsonToUserRoot(queryresult);
134+
string outputText = " ";
135+
for(int i = 0; i < decoderesult.users.items.Count; i++)
136+
{
137+
if(decoderesult.users.items[i] != null)
138+
{
139+
outputText += decoderesult.users.items[i].displayName + " aka. " + decoderesult.users.items[i].name + "\r\n";
140+
cConsole.WriteUserList(outputText);
141+
}
142+
}
143+
conv = null;
144+
}
145+
}
146+
116147
}
117148
}

JiraTimeTracker/JsonConv.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class Issue
2828
public Fields fields { get; set; }
2929
}
3030

31-
public class RootObject
31+
public class IssuesRoot
3232
{
3333
public string expand { get; set; }
3434
public int startAt { get; set; }
@@ -37,11 +37,40 @@ public class RootObject
3737
public List<Issue> issues { get; set; }
3838
}
3939

40-
class JsonConv
40+
public class Item
4141
{
42-
public RootObject DecodeJsonToRootObject(string jsonstr)
42+
public string self { get; set; }
43+
public string name { get; set; }
44+
public string key { get; set; }
45+
public string emailAddress { get; set; }
46+
public string displayName { get; set; }
47+
public bool active { get; set; }
48+
}
49+
50+
public class Users
51+
{
52+
public int size { get; set; }
53+
public List<Item> items { get; set; }
54+
}
55+
56+
public class UserRoot
57+
{
58+
public string name { get; set; }
59+
public string self { get; set; }
60+
public Users users { get; set; }
61+
public string expand { get; set; }
62+
}
63+
64+
class JsonConv
65+
{
66+
public IssuesRoot DecodeJsonToIssuesRoot(string jsonstr)
67+
{
68+
return JsonConvert.DeserializeObject<IssuesRoot>(jsonstr);
69+
}
70+
71+
public UserRoot DecodeJsonToUserRoot(string jsonstr)
4372
{
44-
return JsonConvert.DeserializeObject<RootObject>(jsonstr);
73+
return JsonConvert.DeserializeObject<UserRoot>(jsonstr);
4574
}
4675
}
4776
}
3 KB
Binary file not shown.
8 KB
Binary file not shown.

0 commit comments

Comments
 (0)