Changeset View
Changeset View
Standalone View
Standalone View
assets/src/bundles/webapp/webapp-utils.js
/** | /** | ||||
* Copyright (C) 2018-2020 The Software Heritage developers | * Copyright (C) 2018-2021 The Software Heritage developers | ||||
* See the AUTHORS file at the top-level directory of this distribution | * See the AUTHORS file at the top-level directory of this distribution | ||||
* License: GNU Affero General Public License version 3, or any later version | * License: GNU Affero General Public License version 3, or any later version | ||||
* See top-level LICENSE file for more information | * See top-level LICENSE file for more information | ||||
*/ | */ | ||||
import objectFitImages from 'object-fit-images'; | import objectFitImages from 'object-fit-images'; | ||||
import {selectText} from 'utils/functions'; | import {selectText} from 'utils/functions'; | ||||
import {BREAKPOINT_MD} from 'utils/constants'; | import {BREAKPOINT_MD} from 'utils/constants'; | ||||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | $(window).scroll(() => { | ||||
} else { | } else { | ||||
$('#back-to-top').css('display', 'none'); | $('#back-to-top').css('display', 'none'); | ||||
} | } | ||||
}); | }); | ||||
// navbar search form submission callback | // navbar search form submission callback | ||||
$('#swh-origins-search-top').submit(event => { | $('#swh-origins-search-top').submit(event => { | ||||
event.preventDefault(); | event.preventDefault(); | ||||
if (event.target.checkValidity()) { | |||||
$(event.target).removeClass('was-validated'); | |||||
let searchQueryText = $('#swh-origins-search-top-input').val().trim(); | let searchQueryText = $('#swh-origins-search-top-input').val().trim(); | ||||
let queryParameters = new URLSearchParams(); | let queryParameters = new URLSearchParams(); | ||||
queryParameters.append('q', searchQueryText); | queryParameters.append('q', searchQueryText); | ||||
queryParameters.append('with_visit', true); | queryParameters.append('with_visit', true); | ||||
queryParameters.append('with_content', true); | queryParameters.append('with_content', true); | ||||
window.location = `${Urls.browse_search()}?${queryParameters.toString()}`; | window.location = `${Urls.browse_search()}?${queryParameters.toString()}`; | ||||
} else { | |||||
$(event.target).addClass('was-validated'); | |||||
} | |||||
}); | }); | ||||
vlorentz: could you document the motivation? (you can copy-paste the example in T3234) | |||||
Done Inline ActionsI will add the URL of the task in the comment. anlambert: I will add the URL of the task in the comment. | |||||
}); | }); | ||||
export function initPage(page) { | export function initPage(page) { | ||||
$(document).ready(() => { | $(document).ready(() => { | ||||
// set relevant sidebar link to page active | // set relevant sidebar link to page active | ||||
$(`.swh-${page}-item`).addClass('active'); | $(`.swh-${page}-item`).addClass('active'); | ||||
$(`.swh-${page}-link`).addClass('active'); | $(`.swh-${page}-link`).addClass('active'); | ||||
// triggered when unloading the current page | // triggered when unloading the current page | ||||
$(window).on('unload', () => { | $(window).on('unload', () => { | ||||
// backup current browse page | // backup current browse page | ||||
Not Done Inline ActionsDoesn't work if there is = in the value vlorentz: Doesn't work if there is `=` in the value | |||||
Done Inline ActionsBased on qualifiers parsing code in swh-model, having a = character in qualifier value will raise a ValidationError. I guess I can check the size of the split and abort if is not equal to 2. anlambert: Based on [[ https://forge.softwareheritage.org/source/swh… | |||||
Not Done Inline Actionsthen it's a bug in swh-model. From the SWHID spec: <context_qualifier> ::= <origin_ctxt> | <visit_ctxt> | <anchor_ctxt> | <path_ctxt> ; <origin_ctxt> ::= "origin" "=" <url_escaped> ; <path_ctxt> ::= "path" "=" <path_absolute_escaped> ; where <url_escaped> is a RFC 3987 IRI in either case all occurrences of ; (and %, as required by the RFC) have been percent-encoded (as %3B and %25 respectively). Other characters can be percent-encoded, e.g., to improve readability and/or embeddability of SWHID in other contexts. and from said RFC: ipath-absolute = "/" [ isegment-nz *( "/" isegment ) ] isegment = *ipchar ipchar = iunreserved / pct-encoded / sub-delims / ":" / "@" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" vlorentz: then it's a bug in swh-model. From the SWHID spec:
```
<context_qualifier> ::=… | |||||
Not Done Inline Actionsforgot this line: <path_absolute_escaped> is an <ipath-absolute> from RFC 3987, and vlorentz: forgot this line:
```
<path_absolute_escaped> is an <ipath-absolute> from RFC 3987, and
``` | |||||
Done Inline ActionsDoes it mean that we should split the qualifier at the first = character or percent encode it in qualifier value ? anlambert: Does it mean that we should split the qualifier at the first `=` character or percent encode it… | |||||
Not Done Inline Actionsthe former vlorentz: the former | |||||
Done Inline ActionsAck, will fix the issue in swh-model first and update that diff afterwards. anlambert: Ack, will fix the issue in `swh-model` first and update that diff afterwards. | |||||
Done Inline Actionsanlambert: D5487 | |||||
if (page === 'browse') { | if (page === 'browse') { | ||||
sessionStorage.setItem('last-browse-page', window.location); | sessionStorage.setItem('last-browse-page', window.location); | ||||
} | } | ||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
export function initHomePage() { | export function initHomePage() { | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
export function setContainerFullWidth() { | export function setContainerFullWidth() { | ||||
let previousFullWidthState = JSON.parse(localStorage.getItem('swh-web-full-width')); | let previousFullWidthState = JSON.parse(localStorage.getItem('swh-web-full-width')); | ||||
if (previousFullWidthState !== null) { | if (previousFullWidthState !== null) { | ||||
setFullWidth(previousFullWidthState); | setFullWidth(previousFullWidthState); | ||||
} | } | ||||
} | } | ||||
export async function validateSWHIDInput(swhidInputElt) { | |||||
const swhidInput = swhidInputElt.value.trim(); | |||||
let customValidity = ''; | |||||
if (swhidInput.startsWith('swh:')) { | |||||
const resolveSWHIDUrl = Urls.api_1_resolve_swhid(swhidInput); | |||||
const response = await fetch(resolveSWHIDUrl); | |||||
const responseData = await response.json(); | |||||
if (responseData.hasOwnProperty('exception')) { | |||||
customValidity = responseData.reason; | |||||
} | |||||
} | |||||
swhidInputElt.setCustomValidity(customValidity); | |||||
$(swhidInputElt).siblings('.invalid-feedback').text(customValidity); | |||||
} |
could you document the motivation? (you can copy-paste the example in T3234)