diff --git a/assets/src/bundles/add_forge/index.js b/assets/src/bundles/add_forge/index.js --- a/assets/src/bundles/add_forge/index.js +++ b/assets/src/bundles/add_forge/index.js @@ -9,3 +9,4 @@ export * from './create-request'; export * from './moderation-dashboard'; +export * from './request-dashboard'; 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 @@ -28,7 +28,10 @@ { data: 'id', name: 'id', - render: $.fn.dataTable.render.text() + render: function(data, type, row, meta) { + const dashboardUrl = Urls.add_forge_now_request_dashboard(data); + return `${data}`; + } }, { data: 'submission_date', diff --git a/assets/src/bundles/add_forge/request-dashboard.js b/assets/src/bundles/add_forge/request-dashboard.js new file mode 100644 --- /dev/null +++ b/assets/src/bundles/add_forge/request-dashboard.js @@ -0,0 +1,162 @@ +/** + * 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 + */ + +import {handleFetchError, csrfPost} from 'utils/functions'; + +var emailTempate = `Dear forge administrator, + +The mission of Software Heritage is to collect, preserve and share all the publicly available source code (see https://www.softwareheritage.org for more information). + +We just received a request to add the forge hosted at [URL] to the list of software origins that are archived, and it is our understanding that you are the contact person for this forge. + +In order to archive the forge contents, we will have to periodically pull the public repositories it contains and clone them into the Software Heritage archive. + +Would you be so kind to reply to this message to acknowledge the reception of this email and let us know if there are any special steps we should take in order to properly archive the public repositories hosted on your infrastructure? + +Thank you in advance for your help. + +Kind regards, +The Software Heritage team`; + +export function onRequestDashboardLoad(requestId) { + $(document).ready(() => { + populateRequestDetails(requestId); + + $('#contactForgeAdmin').click((event) => { + contactForgeAdmin(event); + }); + + $('#updateRequestForm').submit(async function(event) { + event.preventDefault(); + try { + const response = await csrfPost($(this).attr('action'), + {'Content-Type': 'application/x-www-form-urlencoded'}, + $(this).serialize()); + handleFetchError(response); + $('#userMessage').text('The request status has been updated '); + $('#userMessage').removeClass('badge-danger'); + $('#userMessage').addClass('badge-success'); + populateRequestDetails(requestId); + } catch (response) { + $('#userMessage').text('Sorry; Updating the request failed'); + $('#userMessage').removeClass('badge-success'); + $('#userMessage').addClass('badge-danger'); + } + }); + }); +} + +async function populateRequestDetails(requestId) { + try { + const response = await fetch(Urls.api_1_add_forge_request_get(requestId)); + handleFetchError(response); + const data = await response.json(); + $('#requestStatus').text(data.request.status); + $('#requestType').text(data.request.forge_type); + $('#requestURL').text(data.request.forge_url); + $('#requestEmail').text(data.request.forge_contact_email); + $('#submitterMessage').text(data.request.forge_contact_comment); + $('#updateComment').val(''); + + // Setting data for the email, now adding static data + $('#swh-input-forge-admin-email').val(emailTempate); + $('#contactForgeAdmin').attr('emailTo', data.request.forge_contact_email); + $('#contactForgeAdmin').attr('emailSubject', `[swh-add_forge_now] Request ${data.request.id}`); + populateRequestHistory(data.history); + populateDecisionSelectOption(data.request.status); + } catch (response) { + // The error message + $('#fetchError').removeClass('d-none'); + $('#requestDetails').addClass('d-none'); + } +} + +function populateRequestHistory(history) { + $('#requestHistory').children().remove(); + + history.forEach((event, i) => { + let historyEvent = `
${event.text}
`; + if (event.new_status !== null) { + historyEvent += `New status: ${event.new_status}
`; + } + historyEvent += '