Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123614
D7427.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D7427.diff
View Options
diff --git a/assets/src/bundles/save/index.js b/assets/src/bundles/save/index.js
--- a/assets/src/bundles/save/index.js
+++ b/assets/src/bundles/save/index.js
@@ -9,6 +9,7 @@
getCanonicalOriginURL, getHumanReadableDate} from 'utils/functions';
import {swhSpinnerSrc} from 'utils/constants';
import artifactFormRowTemplate from './artifact-form-row.ejs';
+import userRequestsFilterCheckboxFn from 'utils/requests-filter-checkbox.ejs';
let saveRequestsTable;
@@ -103,15 +104,11 @@
$(event.target).closest('.swh-save-origin-artifact-form').remove();
}
-const userRequestsFilterCheckbox = `
-<div class="custom-control custom-checkbox swhid-option">
- <input class="custom-control-input" value="option-user-requests-filter" type="checkbox"
- id="swh-save-requests-user-filter">
- <label class="custom-control-label font-weight-normal" for="swh-save-requests-user-filter">
- show only your own requests
- </label>
-</div>
-`;
+const saveRequestCheckboxId = 'swh-save-requests-user-filter';
+const userRequestsFilterCheckbox = userRequestsFilterCheckboxFn({
+ 'inputId': saveRequestCheckboxId,
+ 'checked': false // no filtering by default on that view
+});
export function initOriginSave() {
@@ -136,7 +133,7 @@
ajax: {
url: Urls.origin_save_requests_list('all'),
data: (d) => {
- if (swh.webapp.isUserLoggedIn() && $('#swh-save-requests-user-filter').prop('checked')) {
+ if (swh.webapp.isUserLoggedIn() && $(`#${saveRequestCheckboxId}`).prop('checked')) {
d.user_requests_only = '1';
}
}
@@ -151,7 +148,7 @@
fnInitComplete: function() {
if (swh.webapp.isUserLoggedIn()) {
$('div.user-requests-filter').html(userRequestsFilterCheckbox);
- $('#swh-save-requests-user-filter').on('change', () => {
+ $(`#${saveRequestCheckboxId}`).on('change', () => {
saveRequestsTable.draw();
});
}
diff --git a/assets/src/utils/requests-filter-checkbox.ejs b/assets/src/utils/requests-filter-checkbox.ejs
new file mode 100644
--- /dev/null
+++ b/assets/src/utils/requests-filter-checkbox.ejs
@@ -0,0 +1,17 @@
+<%#
+ Copyright (C) 2022 The Software Heritage developers
+ See the AUTHORS file at the top-level directory of this distribution
+ License: GNU Affero General Public License version 3, or any later version
+ See top-level LICENSE file for more information
+%>
+<div class="custom-control custom-checkbox swhid-option">
+ <input class="custom-control-input" value="option-user-requests-filter"
+ type="checkbox"
+ <% if (checked) { %>
+ checked="checked"
+ <% } %>
+ id="<%= inputId %>">
+ <label class="custom-control-label font-weight-normal" for="<%= inputId %>">
+ show only your own requests
+ </label>
+</div>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 2:02 PM (20 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3216818
Attached To
D7427: save-code-now: Extract the checkbox filtering into a js template
Event Timeline
Log In to Comment