Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,8 @@ pulls.compare_changes_desc = Select the branch to merge into and the branch to p
pulls.has_viewed_file = Viewed
pulls.has_changed_since_last_review = Changed since your last review
pulls.viewed_files_label = %[1]d / %[2]d files viewed
pulls.expand_files = Expand all files
pulls.collapse_files = Collapse all files
pulls.compare_base = merge into
pulls.compare_compare = pull from
pulls.switch_comparison_type = Switch comparison type
Expand Down
6 changes: 6 additions & 0 deletions templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
<label for="viewed-files-summary" id="viewed-files-summary-label" class="gt-mr-3 gt-f1" data-text-changed-template="{{.locale.Tr "repo.pulls.viewed_files_label"}}">
{{.locale.Tr "repo.pulls.viewed_files_label" .Diff.NumViewedFiles .Diff.NumFiles}}
</label>
<button id="expand-files-btn" class="ui button tiny tooltip basic" data-content="{{.locale.Tr "repo.pulls.expand_files"}}">
{{svg "octicon-fold-down"}}
</button>
<button id="collapse-files-btn" class="ui button tiny tooltip basic" data-content="{{.locale.Tr "repo.pulls.collapse_files"}}">
{{svg "octicon-fold-up"}}
</button>
{{end}}
{{template "repo/diff/whitespace_dropdown" .}}
{{template "repo/diff/options_dropdown" .}}
Expand Down
18 changes: 18 additions & 0 deletions web_src/js/features/pull-view-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const {csrfToken, pageData} = window.config;
const prReview = pageData.prReview || {};
const viewedStyleClass = 'viewed-file-checked-form';
const viewedCheckboxSelector = '.viewed-file-form'; // Selector under which all "Viewed" checkbox forms can be found
const expandFilesBtnSelector = '#expand-files-btn';
const collapseFilesBtnSelector = '#collapse-files-btn';


// Refreshes the summary of viewed files if present
Expand Down Expand Up @@ -69,3 +71,19 @@ export function initViewedCheckboxListenerFor() {
});
}
}

export function initExpandAndCollapseFilesButton() {
// expand btn
document.querySelector(expandFilesBtnSelector)?.addEventListener('click', () => {
for (const box of document.querySelectorAll('.file-content[data-folded="true"]')) {
setFileFolding(box, box.querySelector('.fold-file'), false);
}
});
// collapse btn, need to exclude the div of “show more”
document.querySelector(collapseFilesBtnSelector)?.addEventListener('click', () => {
for (const box of document.querySelectorAll('.file-content:not([data-folded="true"])')) {
if (box.getAttribute('id') === 'diff-incomplete') continue;
setFileFolding(box, box.querySelector('.fold-file'), true);
}
});
}
3 changes: 2 additions & 1 deletion web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import {
initRepoSettingsCollaboration,
initRepoSettingSearchTeamBox,
} from './features/repo-settings.js';
import {initViewedCheckboxListenerFor} from './features/pull-view-file.js';
import {initViewedCheckboxListenerFor, initExpandAndCollapseFilesButton} from './features/pull-view-file.js';
import {initOrgTeamSearchRepoBox, initOrgTeamSettings} from './features/org-team.js';
import {initUserAuthWebAuthn, initUserAuthWebAuthnRegister} from './features/user-auth-webauthn.js';
import {initRepoRelease, initRepoReleaseNew} from './features/repo-release.js';
Expand Down Expand Up @@ -201,4 +201,5 @@ $(document).ready(() => {
initUserAuthWebAuthnRegister();
initUserSettings();
initViewedCheckboxListenerFor();
initExpandAndCollapseFilesButton();
});