diff --git a/cypress/integration/home.spec.js b/cypress/integration/home.spec.js --- a/cypress/integration/home.spec.js +++ b/cypress/integration/home.spec.js @@ -1,5 +1,5 @@ /** - * Copyright (C) 2019 The Software Heritage developers + * Copyright (C) 2019-2020 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 @@ -22,7 +22,7 @@ cy.visit(url) .wait('@getStatCounters') .wait(500) - .get('.swh-counter') + .get('.swh-counter:visible') .then((counters) => { for (let counter of counters) { let innerText = $(counter).text(); @@ -32,7 +32,7 @@ }); }); - it('should display null counters when storage is empty', function() { + it('should display null counters and hide history graphs when storage is empty', function() { cy.server(); @@ -48,13 +48,47 @@ cy.visit(url) .wait('@getStatCounters') .wait(500) - .get('.swh-counter') + .get('.swh-counter:visible') .then((counters) => { for (let counter of counters) { const value = parseInt($(counter).text()); assert.equal(value, 0); } }); + + cy.get('.swh-counter-history') + .should('not.be.visible'); + }); + + it('should hide counters when data is missing', function() { + + cy.server(); + + cy.route({ + method: 'GET', + url: this.Urls.stat_counters(), + response: { + 'stat_counters': { + 'content': 150, + 'directory': 45, + 'revision': 78 + }, + 'stat_counters_history': {} + } + }).as('getStatCounters'); + + cy.visit(url) + .wait('@getStatCounters') + .wait(500); + + cy.get('#swh-content-count, #swh-directory-count, #swh-revision-count') + .should('be.visible'); + + cy.get('#swh-release-count, #swh-person-count, #swh-origin-count') + .should('not.be.visible'); + + cy.get('.swh-counter-history') + .should('not.be.visible'); }); it('should redirect to search page when submitting search form', function() { diff --git a/swh/web/assets/src/bundles/webapp/webapp-utils.js b/swh/web/assets/src/bundles/webapp/webapp-utils.js --- a/swh/web/assets/src/bundles/webapp/webapp-utils.js +++ b/swh/web/assets/src/bundles/webapp/webapp-utils.js @@ -201,22 +201,30 @@ fetch(Urls.stat_counters()) .then(response => response.json()) .then(data => { - if (data.stat_counters.content) { - $('#swh-contents-count').html(data.stat_counters.content.toLocaleString()); - $('#swh-revisions-count').html(data.stat_counters.revision.toLocaleString()); - $('#swh-origins-count').html(data.stat_counters.origin.toLocaleString()); - $('#swh-directories-count').html(data.stat_counters.directory.toLocaleString()); - $('#swh-persons-count').html(data.stat_counters.person.toLocaleString()); - $('#swh-releases-count').html(data.stat_counters.release.toLocaleString()); + if (data.stat_counters && !$.isEmptyObject(data.stat_counters)) { + for (let objectType of ['content', 'revision', 'origin', 'directory', 'person', 'release']) { + const count = data.stat_counters[objectType]; + if (count !== undefined) { + $(`#swh-${objectType}-count`).html(count.toLocaleString()); + } else { + $(`#swh-${objectType}-count`).closest('.swh-counter-container').hide(); + } + } + } else { + $('.swh-counter').html('0'); } - if (data.stat_counters_history.content) { - swh.webapp.drawHistoryCounterGraph('#swh-contents-count-history', data.stat_counters_history.content); - swh.webapp.drawHistoryCounterGraph('#swh-revisions-count-history', data.stat_counters_history.revision); - swh.webapp.drawHistoryCounterGraph('#swh-origins-count-history', data.stat_counters_history.origin); + if (data.stat_counters_history && !$.isEmptyObject(data.stat_counters_history)) { + for (let objectType of ['content', 'revision', 'origin']) { + const history = data.stat_counters_history[objectType]; + if (history) { + swh.webapp.drawHistoryCounterGraph(`#swh-${objectType}-count-history`, history); + } else { + $(`#swh-${objectType}-count-history`).hide(); + } + + } } else { - $('#swh-contents-count-history').hide(); - $('#swh-revisions-count-history').hide(); - $('#swh-origins-count-history').hide(); + $('.swh-counter-history').hide(); } }); }); diff --git a/swh/web/templates/homepage.html b/swh/web/templates/homepage.html --- a/swh/web/templates/homepage.html +++ b/swh/web/templates/homepage.html @@ -1,7 +1,7 @@ {% extends "layout.html" %} {% comment %} -Copyright (C) 2017-2019 The Software Heritage developers +Copyright (C) 2017-2020 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 @@ -70,35 +70,35 @@ of objects:
-
+
Source files
- 0 -
+ 0 +
-
+
Commits
- 0 -
+ 0 +
-
+
Projects
- 0 -
+ 0 +
-
+
Directories
- 0 + 0
-
+
Authors
- 0 + 0
-
+
Releases
- 0 + 0