diff --git a/swh/web/assets/src/bundles/vault/vault-create-tasks.js b/swh/web/assets/src/bundles/vault/vault-create-tasks.js --- a/swh/web/assets/src/bundles/vault/vault-create-tasks.js +++ b/swh/web/assets/src/bundles/vault/vault-create-tasks.js @@ -7,6 +7,27 @@ import {handleFetchError, csrfPost} from 'utils/functions'; +export function vaultRequest(objectType, objectId) { + let vaultUrl; + if (objectType === 'directory') { + vaultUrl = Urls.api_1_vault_cook_directory(objectId); + } else { + vaultUrl = Urls.api_1_vault_cook_revision_gitfast(objectId); + } + // check if object has already been cooked + fetch(vaultUrl) + .then(response => response.json()) + .then(data => { + // object needs to be cooked + if (data.exception === 'NotFoundExc') { + $(`#vault-cook-${objectType}-modal`).modal('show'); + // object has been cooked and is in the vault cache + } else if (data.status === 'done') { + $(`#vault-fetch-${objectType}-modal`).modal('show'); + } + }); +} + function addVaultCookingTask(cookingTask) { let vaultCookingTasks = JSON.parse(localStorage.getItem('swh-vault-cooking-tasks')); if (!vaultCookingTasks) { @@ -64,6 +85,16 @@ } } +export function fetchDirectoryArchive(directoryId) { + $('#vault-fetch-directory-modal').modal('hide'); + const vaultUrl = Urls.api_1_vault_cook_directory(directoryId); + fetch(vaultUrl) + .then(response => response.json()) + .then(data => { + swh.vault.fetchCookedObject(data.fetch_url); + }); +} + export function cookRevisionArchive(revisionId) { let email = $('#swh-vault-revision-email').val().trim(); if (!email || validateEmail(email)) { @@ -78,3 +109,13 @@ $('#invalid-email-modal').modal('show'); } } + +export function fetchRevisionArchive(revisionId) { + $('#vault-fetch-directory-modal').modal('hide'); + const vaultUrl = Urls.api_1_vault_cook_revision_gitfast(revisionId); + fetch(vaultUrl) + .then(response => response.json()) + .then(data => { + swh.vault.fetchCookedObject(data.fetch_url); + }); +} diff --git a/swh/web/templates/browse/vault-ui.html b/swh/web/templates/browse/vault-ui.html --- a/swh/web/templates/browse/vault-ui.html +++ b/swh/web/templates/browse/vault-ui.html @@ -1,7 +1,7 @@ {% extends "./layout.html" %} {% comment %} -Copyright (C) 2017-2018 The Software Heritage developers +Copyright (C) 2017-2019 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 @@ -37,31 +37,7 @@ - - +{% include "includes/vault-common.html" %} -{% endblock %} + \ No newline at end of file diff --git a/swh/web/templates/includes/vault-create-tasks.html b/swh/web/templates/includes/vault-create-tasks.html --- a/swh/web/templates/includes/vault-create-tasks.html +++ b/swh/web/templates/includes/vault-create-tasks.html @@ -16,13 +16,13 @@ @@ -42,8 +42,12 @@ + +