Changeset View
Changeset View
Standalone View
Standalone View
swh/web/assets/src/bundles/webapp/badges.js
/** | /** | ||||
* Copyright (C) 2019-2020 The Software Heritage developers | * Copyright (C) 2019-2020 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 | ||||
*/ | */ | ||||
export function showBadgeInfoModal(objectType, objectPid) { | export function showBadgeInfoModal(objectType, objectPid) { | ||||
let badgeImageUrl; | let badgeImageUrl; | ||||
let badgeLinkUrl; | let badgeLinkUrl; | ||||
if (objectType === 'origin') { | if (objectType === 'origin') { | ||||
badgeImageUrl = Urls.swh_badge(objectType, objectPid); | badgeImageUrl = Urls.swh_badge(objectType, objectPid); | ||||
badgeLinkUrl = `${Urls.browse_origin()}?origin_url=${objectPid}`; | badgeLinkUrl = `${Urls.browse_origin()}?origin_url=${objectPid}`; | ||||
} else { | } else { | ||||
const pos = objectPid.indexOf(';'); | |||||
if (pos !== -1) { | |||||
badgeImageUrl = Urls.swh_badge_pid(objectPid.slice(0, pos)); | |||||
} else { | |||||
badgeImageUrl = Urls.swh_badge_pid(objectPid); | badgeImageUrl = Urls.swh_badge_pid(objectPid); | ||||
} | |||||
badgeLinkUrl = Urls.browse_swh_id(objectPid); | badgeLinkUrl = Urls.browse_swh_id(objectPid); | ||||
} | } | ||||
let urlPrefix = `${window.location.protocol}//${window.location.hostname}`; | let urlPrefix = `${window.location.protocol}//${window.location.hostname}`; | ||||
if (window.location.port) { | if (window.location.port) { | ||||
urlPrefix += `:${window.location.port}`; | urlPrefix += `:${window.location.port}`; | ||||
} | } | ||||
const absoluteBadgeImageUrl = `${urlPrefix}${badgeImageUrl}`; | const absoluteBadgeImageUrl = `${urlPrefix}${badgeImageUrl}`; | ||||
const absoluteBadgeLinkUrl = `${urlPrefix}${badgeLinkUrl}`; | const absoluteBadgeLinkUrl = `${urlPrefix}${badgeLinkUrl}`; | ||||
Show All 21 Lines |