Skip to content

Commit

Permalink
Remove JS globals related to timetracking and due date
Browse files Browse the repository at this point in the history
Refactor to avoid these globals. Should work exactly as before.
  • Loading branch information
silverwind committed Dec 9, 2020
1 parent c85bb62 commit 120c8e7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 37 deletions.
8 changes: 4 additions & 4 deletions integrations/timetracking_test.go
Expand Up @@ -40,8 +40,8 @@ func testViewTimetrackingControls(t *testing.T, session *TestSession, user, repo

htmlDoc := NewHTMLParser(t, resp.Body)

htmlDoc.AssertElement(t, ".timetrack .start-add .start", canTrackTime)
htmlDoc.AssertElement(t, ".timetrack .start-add .add-time", canTrackTime)
htmlDoc.AssertElement(t, ".timetrack .issue-start-time", canTrackTime)
htmlDoc.AssertElement(t, ".timetrack .issue-add-time", canTrackTime)

req = NewRequestWithValues(t, "POST", path.Join(user, repo, "issues", issue, "times", "stopwatch", "toggle"), map[string]string{
"_csrf": htmlDoc.GetCSRF(),
Expand All @@ -56,8 +56,8 @@ func testViewTimetrackingControls(t *testing.T, session *TestSession, user, repo
events := htmlDoc.doc.Find(".event > span.text")
assert.Contains(t, events.Last().Text(), "started working")

htmlDoc.AssertElement(t, ".timetrack .stop-cancel .stop", true)
htmlDoc.AssertElement(t, ".timetrack .stop-cancel .cancel", true)
htmlDoc.AssertElement(t, ".timetrack .issue-stop-time", true)
htmlDoc.AssertElement(t, ".timetrack .issue-cancel-time", true)

// Sleep for 1 second to not get wrong order for stopping timer
time.Sleep(time.Second)
Expand Down
18 changes: 9 additions & 9 deletions templates/repo/issue/view_content/sidebar.tmpl
Expand Up @@ -336,18 +336,18 @@
{{$.CsrfTokenHtml}}
</form>
{{if $.IsStopwatchRunning}}
<div class="ui buttons fluid stop-cancel">
<button onclick="this.disabled=true;window.toggleStopwatch()" class="ui button stop">{{.i18n.Tr "repo.issues.stop_tracking"}}</button>
<button onclick="this.disabled=true;window.cancelStopwatch()" class="ui negative button cancel">{{.i18n.Tr "repo.issues.cancel_tracking"}}</button>
<div class="ui buttons fluid">
<button class="ui button issue-stop-time">{{.i18n.Tr "repo.issues.stop_tracking"}}</button>
<button class="ui negative button issue-cancel-time">{{.i18n.Tr "repo.issues.cancel_tracking"}}</button>
</div>
{{else}}
{{if .HasUserStopwatch}}
<div class="ui warning message">
{{.i18n.Tr "repo.issues.tracking_already_started" .OtherStopwatchURL | Safe}}
</div>
{{end}}
<div class="ui buttons two fluid start-add">
<button onclick="this.disabled=true;window.toggleStopwatch()" class="ui button poping up start" data-content='{{.i18n.Tr "repo.issues.start_tracking"}}' data-position="top center" data-variation="small inverted">{{.i18n.Tr "repo.issues.start_tracking_short"}}</button>
<div class="ui buttons two fluid">
<button class="ui button poping up issue-start-time" data-content='{{.i18n.Tr "repo.issues.start_tracking"}}' data-position="top center" data-variation="small inverted">{{.i18n.Tr "repo.issues.start_tracking_short"}}</button>
<div class="ui mini modal">
<div class="header">{{.i18n.Tr "repo.issues.add_time"}}</div>
<div class="content">
Expand All @@ -362,7 +362,7 @@
<div class="ui red cancel button">{{.i18n.Tr "repo.issues.add_time_cancel"}}</div>
</div>
</div>
<button onclick="window.timeAddManual()" class="ui button green poping up add-time" data-content='{{.i18n.Tr "repo.issues.add_time"}}' data-position="top center" data-variation="small inverted">{{.i18n.Tr "repo.issues.add_time_short"}}</button>
<button class="ui button green poping up issue-add-time" data-content='{{.i18n.Tr "repo.issues.add_time"}}' data-position="top center" data-variation="small inverted">{{.i18n.Tr "repo.issues.add_time_short"}}</button>
</div>
{{end}}
</div>
Expand Down Expand Up @@ -407,8 +407,8 @@
{{end}}
{{if and .HasIssuesOrPullsWritePermission (not .Repository.IsArchived)}}
<br/>
<a style="cursor:pointer;" onclick="window.toggleDeadlineForm();"><i class="edit icon"></i>{{$.i18n.Tr "repo.issues.due_date_form_edit"}}</a> -
<a style="cursor:pointer;" onclick="window.updateDeadline('');"><i class="remove icon"></i>{{$.i18n.Tr "repo.issues.due_date_form_remove"}}</a>
<a class="issue-due-edit"><i class="edit icon"></i>{{$.i18n.Tr "repo.issues.due_date_form_edit"}}</a> -
<a class="issue-due-remove"><i class="remove icon"></i>{{$.i18n.Tr "repo.issues.due_date_form_remove"}}</a>
{{end}}
</p>
{{else}}
Expand All @@ -417,7 +417,7 @@

{{if and .HasIssuesOrPullsWritePermission (not .Repository.IsArchived)}}
<div {{if ne .Issue.DeadlineUnix 0}} style="display: none;"{{end}} id="deadlineForm">
<form class="ui fluid action input" action="{{AppSubUrl}}/api/v1/repos/{{.Repository.Owner.Name}}/{{.Repository.Name}}/issues/{{.Issue.Index}}" method="post" id="update-issue-deadline-form" onsubmit="window.setDeadline();return false;">
<form class="ui fluid action input issue-due-form" action="{{AppSubUrl}}/api/v1/repos/{{.Repository.Owner.Name}}/{{.Repository.Name}}/issues/{{.Issue.Index}}" method="post" id="update-issue-deadline-form">
{{$.CsrfTokenHtml}}
<input required placeholder="{{.i18n.Tr "repo.issues.due_date_form"}}" {{if gt .Issue.DeadlineUnix 0}}value="{{.Issue.DeadlineUnix.Format "2006-01-02"}}"{{end}} type="date" name="deadlineDate" id="deadlineDate">
<button class="ui green icon button">
Expand Down
53 changes: 29 additions & 24 deletions web_src/js/index.js
@@ -1,5 +1,4 @@
/* exported timeAddManual, toggleStopwatch, cancelStopwatch */
/* exported toggleDeadlineForm, setDeadline, updateDeadline, deleteDependencyModal, cancelCodeComment, onOAuthLoginClick */
/* exported deleteDependencyModal, cancelCodeComment, onOAuthLoginClick */

import './publicpath.js';

Expand Down Expand Up @@ -2519,6 +2518,8 @@ $(document).ready(async () => {
initU2FAuth();
initU2FRegister();
initIssueList();
initIssueTimetracking();
initIssueDue();
initWipTitle();
initPullRequestReview();
initRepoStatusChecker();
Expand Down Expand Up @@ -3098,22 +3099,22 @@ function initVueApp() {
});
}

window.timeAddManual = function () {
$('.mini.modal')
.modal({
function initIssueTimetracking() {
$(document).on('click', '.issue-add-time', () => {
$('.mini.modal').modal({
duration: 200,
onApprove() {
$('#add_time_manual_form').trigger('submit');
}
}).modal('show');
};

window.toggleStopwatch = function () {
$('#toggle_stopwatch_form').trigger('submit');
};
window.cancelStopwatch = function () {
$('#cancel_stopwatch_form').trigger('submit');
};
});
$(document).on('click', '.issue-start-time, .issue-stop-time', () => {
$('#toggle_stopwatch_form').trigger('submit');
});
$(document).on('click', '.issue-cancel-time', () => {
$('#cancel_stopwatch_form').trigger('submit');
});
}

function initFilterBranchTagDropdown(selector) {
$(selector).each(function () {
Expand Down Expand Up @@ -3469,16 +3470,7 @@ function initTopicbar() {
});
}

window.toggleDeadlineForm = function () {
$('#deadlineForm').fadeToggle(150);
};

window.setDeadline = function () {
const deadline = $('#deadlineDate').val();
window.updateDeadline(deadline);
};

window.updateDeadline = function (deadlineString) {
function updateDeadline(deadlineString) {
$('#deadline-err-invalid-date').hide();
$('#deadline-loader').addClass('loading');

Expand Down Expand Up @@ -3512,7 +3504,20 @@ window.updateDeadline = function (deadlineString) {
$('#deadline-err-invalid-date').show();
}
});
};
}

function initIssueDue() {
$(document).on('click', '.issue-due-edit', () => {
$('#deadlineForm').fadeToggle(150);
});
$(document).on('click', '.issue-due-remove', () => {
updateDeadline('');
});
$(document).on('submit', '.issue-due-form', () => {
updateDeadline($('#deadlineDate').val());
return false;
});
}

window.deleteDependencyModal = function (id, type) {
$('.remove-dependency')
Expand Down

0 comments on commit 120c8e7

Please sign in to comment.