diff --git a/pages/statistics/statistics.css b/pages/statistics/statistics.css index 02aa99c6..df4b326e 100644 --- a/pages/statistics/statistics.css +++ b/pages/statistics/statistics.css @@ -4,15 +4,13 @@ body { } table { - margin-left: auto; - margin-right: auto; border-spacing: 0; - padding-bottom: 30px; + padding-top: 30px; + width: 100%; } td:first-child { text-align: left; - min-width: 300px; } td { @@ -24,6 +22,43 @@ th:first-child { text-align: left; } -#all-injections, #tbl-statistics-cdns, #tbl-statistics-frameworks { +#statistics-overview, #tbl-statistics-cdns, #tbl-statistics-frameworks { display: none; } + +#statistics-overview { + text-align: left; +} + +.container { + width: 300px; + margin-left: auto; + margin-right: auto; +} + +.overview { + display: flex; + justify-content: space-between; + margin-top: 10px; +} + +.button { + -moz-user-select: none; + background-color: #f5f5f5; + border-radius: 2px; + border: 1px solid #b2b2b2; + color: #5f5f5f; + cursor: pointer; + float: right; + font-size: 12px; + outline: 0; + padding: 5px 22px; + text-decoration: none; + user-select: none; + text-align: center; + background: none; +} + +.button:hover { + background-color: #e6e6e6; +} diff --git a/pages/statistics/statistics.html b/pages/statistics/statistics.html index a82789c7..cde8ce7a 100644 --- a/pages/statistics/statistics.html +++ b/pages/statistics/statistics.html @@ -12,43 +12,41 @@ -

Statistic

-
- - - - - -

-
-
- - - - - - -
DescriptionQuantity
-
-
- - - - - - - -
CDNQuantity
no data-
-
-
- - - - - - - -
FrameworkQuantity
no data-
+

Statistics

+
+
+ +
Delete
+
+
+
Average (injections/day)-
+
Injected frameworks-
+
+
+ + + + + + + +
CDNsQuantity
--
+
+
+ + + + + + + +
FrameworksQuantity
--
+
diff --git a/pages/statistics/statistics.js b/pages/statistics/statistics.js index 4f3decd7..4ae01a61 100644 --- a/pages/statistics/statistics.js +++ b/pages/statistics/statistics.js @@ -23,6 +23,13 @@ var statistics = {}; * Private Methods */ statistics._onDocumentLoaded = function () { + helpers.insertI18nContentIntoDocument(document); + helpers.insertI18nTitlesIntoDocument(document); + + // Default view is 'today' + statistics._dateRange = [new Date().toISOString().slice(0, 10)]; + document.getElementById('date-range').value = 'day'; + statistics._registerListener(); statistics._getStatistics().then(statistics._renderContents); }; @@ -38,7 +45,7 @@ statistics._renderContents = function () { statistics._showData(true); statistics._clearTables(); - statistics._generateTable(statistics._dataOverview, 'overview'); + statistics._determineInjections(); statistics._generateTable(statistics._dataSortedCDNs, 'cdns'); statistics._generateTable(statistics._dataSortedFrameworks, 'frameworks'); }; @@ -127,11 +134,10 @@ statistics._determineInjections = function () { } }); avg = sum / days > 0 ? sum / days : 0; + avg = Math.round((avg + Number.EPSILON) * 100) / 100; - // Preparation for generateTable() - let avgInjections = ['Average (injections/days)', avg]; - let injectedFrameworks = ['Injected frameworks', sum]; - statistics._dataOverview.push(avgInjections, injectedFrameworks); + document.getElementById('avg-quantity').textContent = isNaN(avg) ? '-' : avg; + document.getElementById('quantity-injected-frameworks').textContent = isNaN(sum) ? '-' : sum; }; statistics._getStatistics = function () { @@ -172,12 +178,12 @@ statistics._displayNameOfFramework = function (str, type) { return str; }; -statistics._handlerButton = function ({ target }) { - let btnType = target.getAttribute('data-option'); - if (btnType === 'day' || btnType === 'week' || btnType === 'month' || btnType === 'year') { - statistics._dateUnit = btnType; +statistics._handlerDateRange = function ({ target }) { + let type = target.value; + if (type === 'day' || type === 'week' || type === 'month' || type === 'year') { + statistics._dateUnit = type; statistics._getStatistics().then(statistics._setDateRange); - } else if (btnType === 'delete') { + } else if (type === 'delete') { statistics._deleteStatistic(); statistics._showData(false); } @@ -194,18 +200,17 @@ statistics._deleteStatistic = function () { statistics._showData = function (type) { let attr = type === true ? 'block' : 'none'; - document.getElementById('tbl-statistics-overview').style.display = attr; + document.getElementById('statistics-overview').style.display = attr; document.getElementById('tbl-statistics-cdns').style.display = attr; document.getElementById('tbl-statistics-frameworks').style.display = attr; document.getElementById('btn-delete').disabled = !type; }; statistics._registerListener = function () { - document.getElementById('btn-day').addEventListener('click', statistics._handlerButton); - document.getElementById('btn-week').addEventListener('click', statistics._handlerButton); - document.getElementById('btn-month').addEventListener('click', statistics._handlerButton); - document.getElementById('btn-year').addEventListener('click', statistics._handlerButton); - document.getElementById('btn-delete').addEventListener('click', statistics._handlerButton); + document.getElementById('date-range').addEventListener('change', statistics._handlerDateRange); + document.getElementById('btn-delete').addEventListener('click', function () { + statistics._handlerDateRange({ target: { value: 'delete' } }); + }); }; /**