diff --git a/cypress/integration/vault.spec.js b/cypress/integration/vault.spec.js --- a/cypress/integration/vault.spec.js +++ b/cypress/integration/vault.spec.js @@ -23,6 +23,8 @@ cy.contains('.dropdown-item', objectType) .click(); + cy.wait('@checkVaultCookingTask'); + cy.get('.modal-dialog') .contains('button:visible', 'Ok') .click(); @@ -113,21 +115,28 @@ // Stub responses when requesting the vault API to simulate // a task has been created + + cy.route({ + method: 'GET', + url: this.vaultDirectoryUrl, + response: {'exception': 'NotFoundExc'} + }).as('checkVaultCookingTask'); + cy.route({ method: 'POST', url: this.vaultDirectoryUrl, response: this.genVaultDirCookingResponse('new') }).as('createVaultCookingTask'); + // Create a vault cooking task through the GUI + createVaultCookingTask('as tarball'); + cy.route({ method: 'GET', url: this.vaultDirectoryUrl, response: this.genVaultDirCookingResponse('new') }).as('checkVaultCookingTask'); - // Create a vault cooking task through the GUI - createVaultCookingTask('Directory'); - cy.wait('@createVaultCookingTask'); // Check that a redirection to the vault UI has been performed @@ -185,21 +194,28 @@ // Stub responses when requesting the vault API to simulate // a task has been created + + cy.route({ + method: 'GET', + url: this.vaultRevisionUrl, + response: {'exception': 'NotFoundExc'} + }).as('checkVaultCookingTask'); + cy.route({ method: 'POST', url: this.vaultRevisionUrl, response: this.genVaultRevCookingResponse('new') }).as('createVaultCookingTask'); + // Create a vault cooking task through the GUI + createVaultCookingTask('as git'); + cy.route({ method: 'GET', url: this.vaultRevisionUrl, response: this.genVaultRevCookingResponse('new') }).as('checkVaultCookingTask'); - // Create a vault cooking task through the GUI - createVaultCookingTask('Revision'); - cy.wait('@createVaultCookingTask'); // Check that a redirection to the vault UI has been performed 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 @@ + +