forked from google/github-issue-mover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgim_ui.dart
246 lines (207 loc) · 8.1 KB
/
gim_ui.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// Copyright 2014 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License
/// Contains all the UI related actions.
part of githubissuemover;
/// Displays the details of the given [issue] in the "IssueOverview" div.
displayIssueDetails(Issue issue) {
issueOverviewTitle.text = "${issue.title} #${issue.number}";
issueOverviewTitle.href = issue.htmlUrl;
issueOverviewUserName.text = issue.user.login;
issueOverviewUserName.href = issue.user.htmlUrl;
issueOverviewUserAvatar.src = issue.user.avatarUrl;
issueOverviewBody.innerHtml = issue.body != ""
? markdownToHtml(issue.body) : "No description provided.";
issueOverviewComment.text = issue.commentsCount != 1
? "${issue.commentsCount} Comments" : "1 Comment";
issueError.style.display = "none";
issueOverview.style.display = "block";
}
/// Displays the details of the given [repo] in the "RepoOverview" div.
displayRepoDetails(Repository repo) {
repoOverviewName.text = repo.fullName;
repoOverviewName.href = repo.htmlUrl;
repoOverviewDescription.text =
repo.description != "" ? repo.description : "No description provided.";
repoError.style.display = "none";
repoOverview.style.display = "block";
}
/// Displays an error about the issue input.
displayIssueError(String errorMessage) {
issueError.style.display = "block";
issueError.text = errorMessage;
issueOverview.style.display = "none";
}
/// Clears the Issue details section.
clearIssue() {
issueError.style.display = "none";
issueOverview.style.display = "none";
}
/// Displays an Error about the Repo Input.
displayRepoError(String errorMessage) {
repoError.style.display = "block";
repoError.text = errorMessage;
repoOverview.style.display = "none";
}
/// Displays an error that happened during the issue moving process.
displayMoveError(String errorMessage) {
moveError.style.display = "block";
moveError.text = errorMessage;
closeMoveWidgetButton.attributes.remove("disabled");
closeMoveWidgetButton.focus();
}
/// Clears the Repo details section.
clearRepo() {
repoError.style.display = "none";
repoOverview.style.display = "none";
}
/// Hide the "Authorize" button block and show the move issues form.
displayMoveIssueForm() {
authorizeContainer.style.display = "none";
moveIssueForm.style.display = "table";
issueInput.focus();
}
/// Enables or Disables the "Move" button depending on whether or not we have
/// both an issue to move and a destination repo.
enableDisableMoveButton() {
// We disable the "Move" button if we don't have a destinationRepo or Issue.
if (destinationRepo == null || issueToMove == null) {
moveIssueButton.attributes["disabled"] = "disabled";
if (destinationRepo != null) {
displayRepoDetails(destinationRepo);
}
return;
}
GitHubUrl destinationRepoUrl = GitHubUrl.parse(destinationRepo.htmlUrl);
GitHubUrl issueToMoveUrl = GitHubUrl.parse(issueToMove.htmlUrl);
if (destinationRepoUrl.ownerName == issueToMoveUrl.ownerName
&& destinationRepoUrl.repoName == issueToMoveUrl.repoName) {
displayRepoError("You can't move an issue to its current repo.");
moveIssueButton.attributes["disabled"] = "disabled";
} else {
moveIssueButton.attributes.remove("disabled");
if (destinationRepo != null) {
displayRepoDetails(destinationRepo);
}
}
}
/// Displays information about the currently authorized GitHub [User].
displayAuthorizedUser() {
signedInUserLogin.text = currentGitHubUser.login;
signedInUserLogin.href = currentGitHubUser.htmlUrl;
signedInUserAvatar.src = currentGitHubUser.avatarUrl;
signedInUserContainer.style.display = "block";
}
/// Hides information about the currently authorized GitHub [User].
hideAuthorizedUser() => signedInUserContainer.style.display = "none";
/// Close the move details container and re-initializes it for next use.
closeMoveResultContainer() {
// Re-initializes all the elements in the move widget.
checkMarks.forEach((element) => element.style.visibility = "hidden");
newIssueLink.href = "";
newIssueLink.text = "";
oldIssueLink.href = "";
oldIssueLink.text = "";
numCommentsMoved.text = "";
closeMoveWidgetButton.attributes["disabled"] = "disabled";
// Re-enables all elements in the main form section.
moveIssueButton.attributes.remove("disabled");
repoInput.attributes.remove("disabled");
issueInput.attributes.remove("disabled");
// Hide potential Error.
moveError.style.display = "none";
// Hides the move widget.
moveResultContainer.style.display = "none";
}
/// Displays and initializes the move details container.
initMoveContainer() {
// Disable all elements in the main form section.
moveIssueButton.attributes["disabled"] = "disabled";
repoInput.attributes["disabled"] = "disabled";
issueInput.attributes["disabled"] = "disabled";
// Populate Old Issue Link part of the move widget.
GitHubUrl issueToMoveUrl = GitHubUrl.parse(issueToMove.htmlUrl);
oldIssueLink.href = issueToMoveUrl.fullUrl;
oldIssueLink.text = issueToMoveUrl.simplifiedUrl;
// Display the move details container.
moveResultContainer.style.display = "block";
}
/// Marks the Original Issue closing task as completed.
markOriginalIssueClosedCompleted() =>
closeIssueCheckMark.style.visibility = "visible";
/// Enables and moves the focus to the Close Move Widget button.
moveFocusToCloseButton() {
closeMoveWidgetButton.attributes.remove("disabled");
closeMoveWidgetButton.focus();
}
/// Marks the Comments copy task as completed.
markCommentsCopyCompleted() =>
copyCommentsCheckMark.style.visibility = "visible";
/// Marks the closing comment creation task as completed.
markClosingCommentCreationCompleted() =>
referenceCommentCheckMark.style.visibility = "visible";
/// Updates the number of Comments that have been copied.
updateNumCommentsCopied(int num, int total) =>
numCommentsMoved.text = "$num/$total";
/// Initializes the Comments copy counter.
initCommentsCounter(int commentsListLength) =>
numCommentsMoved.text = "0/${commentsListLength}";
/// Marks the Creation of the copied Issue completed.
markCopiedIssueCreationCompleted() =>
copyIssueCheckMark.style.visibility = "visible";
/// Display the link to the new issue.
displayNewIssueLink(Issue newIssue) {
GitHubUrl newIssueUrl = GitHubUrl.parse(newIssue.htmlUrl);
newIssueLink.href = newIssueUrl.fullUrl;
newIssueLink.text = newIssueUrl.simplifiedUrl;
}
/// Simplifies the URL entered in the Issue Input field.
GitHubUrl simplifyIssueInput() {
GitHubUrl issueUrl;
try {
issueUrl = GitHubUrl.parse(issueInput.value);
} catch (exception) {
return null;
}
issueInput.value = issueUrl.simplifiedUrl;
return issueUrl;
}
/// Simplifies the URL entered in the Repo Input field.
GitHubUrl simplifyRepoInput() {
GitHubUrl repoUrl;
try {
repoUrl = GitHubUrl.parse(repoInput.value);
} catch (exception) {
return null;
}
repoInput.value = "${repoUrl.ownerName}/${repoUrl.repoName}";
return repoUrl;
}
/// Initialize the Repo field if empty and move focus to it.
initRepoInput(GitHubUrl issueUrl) {
InputElement repo = repoInput;
if (repo.value.isEmpty) {
repo.value = "${issueUrl.ownerName}/";
}
repoInput.focus();
}
/// Disable the Issue Input Field.
disableIssueInputField() => issueInput.attributes["disabled"] = "disabled";
/// Enables the Issue Input Field.
enableIssueInputField() => issueInput.attributes.remove("disabled");
/// Disable the Repo Input Field.
disableRepoInputField() => repoInput.attributes["disabled"] = "disabled";
/// Enables the Repo Input Field.
enableRepoInputField() => repoInput.attributes.remove("disabled");
/// Move focus to the Move button.
focusMoveButton() => moveIssueButton.focus();