Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9313221
D8178.id29560.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
D8178.id29560.diff
View Options
diff --git a/assets/src/bundles/add_forge/create-request.js b/assets/src/bundles/add_forge/create-request.js
--- a/assets/src/bundles/add_forge/create-request.js
+++ b/assets/src/bundles/add_forge/create-request.js
@@ -6,7 +6,7 @@
*/
import {handleFetchError, errorMessageFromResponse, csrfPost,
- getHumanReadableDate} from 'utils/functions';
+ getHumanReadableDate, genLink} from 'utils/functions';
import userRequestsFilterCheckboxFn from 'utils/requests-filter-checkbox.ejs';
import {swhSpinnerSrc} from 'utils/constants';
@@ -107,16 +107,9 @@
{
data: 'forge_url',
name: 'forge_url',
- render: function(data, type, row) {
- if (type === 'display') {
- let html = '';
- const sanitizedURL = $.fn.dataTable.render.text().display(data);
- html += sanitizedURL;
- html += ` <a href="${sanitizedURL}" target="_blank" rel="noopener noreferrer">` +
- '<i class="mdi mdi-open-in-new" aria-hidden="true"></i></a>';
- return html;
- }
- return data;
+ render: (data, type, row) => {
+ const sanitizedURL = $.fn.dataTable.render.text().display(data);
+ return genLink(sanitizedURL, type, true);
}
},
{
diff --git a/assets/src/bundles/add_forge/moderation-dashboard.js b/assets/src/bundles/add_forge/moderation-dashboard.js
--- a/assets/src/bundles/add_forge/moderation-dashboard.js
+++ b/assets/src/bundles/add_forge/moderation-dashboard.js
@@ -5,7 +5,7 @@
* See top-level LICENSE file for more information
*/
-import {getHumanReadableDate} from 'utils/functions';
+import {getHumanReadableDate, genLink} from 'utils/functions';
export function onModerationPageLoad() {
populateModerationList();
@@ -48,7 +48,10 @@
{
data: 'forge_url',
name: 'forge_url',
- render: $.fn.dataTable.render.text()
+ render: (data, type, row) => {
+ const sanitizedURL = $.fn.dataTable.render.text().display(data);
+ return genLink(sanitizedURL, type, true);
+ }
},
{
data: 'last_moderator',
diff --git a/assets/src/bundles/admin/deposit.js b/assets/src/bundles/admin/deposit.js
--- a/assets/src/bundles/admin/deposit.js
+++ b/assets/src/bundles/admin/deposit.js
@@ -5,7 +5,7 @@
* See top-level LICENSE file for more information
*/
-import {getHumanReadableDate} from 'utils/functions';
+import {getHumanReadableDate, genLink} from 'utils/functions';
function genSwhLink(data, type, linkText = '') {
if (type === 'display' && data && data.startsWith('swh')) {
@@ -19,21 +19,6 @@
return data;
}
-function genLink(data, type, openInNewTab = false, linkText = '') {
- if (type === 'display' && data) {
- const sData = encodeURI(data);
- if (!linkText) {
- linkText = sData;
- }
- let attrs = '';
- if (openInNewTab) {
- attrs = 'target="_blank" rel="noopener noreferrer"';
- }
- return `<a href="${sData}" ${attrs}>${linkText}</a>`;
- }
- return data;
-}
-
export function initDepositAdmin(username, isStaff) {
let depositsTable;
$(document).ready(() => {
diff --git a/assets/src/utils/functions.js b/assets/src/utils/functions.js
--- a/assets/src/utils/functions.js
+++ b/assets/src/utils/functions.js
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2018-2020 The Software Heritage developers
+ * Copyright (C) 2018-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
@@ -166,3 +166,19 @@
const date = new Date(data);
return date.toLocaleString();
}
+
+export function genLink(sanitizedUrl, type, openInNewTab = false, linkText = '') {
+ // Display link. It's up to the caller to sanitize sanitizedUrl first.
+ if (type === 'display' && sanitizedUrl) {
+ const encodedSanitizedUrl = encodeURI(sanitizedUrl);
+ if (!linkText) {
+ linkText = encodedSanitizedUrl;
+ }
+ let attrs = '';
+ if (openInNewTab) {
+ attrs = 'target="_blank" rel="noopener noreferrer"';
+ }
+ return `<a href="${encodedSanitizedUrl}" ${attrs}>${linkText}</a>`;
+ }
+ return sanitizedUrl;
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jul 2, 11:28 AM (1 w, 8 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3228949
Attached To
D8178: add-forge-now: Display forge url as link in moderation view
Event Timeline
Log In to Comment