From 9da20e18942139b0673034dcba2b9256b62563f6 Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Sun, 26 Jan 2014 19:53:54 +0100 Subject: [PATCH 1/6] Formatage du nombre de non lus --- p/scripts/main.js | 82 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 24 deletions(-) diff --git a/p/scripts/main.js b/p/scripts/main.js index d775b3a20..be5f4f3e4 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -25,28 +25,43 @@ function incLabel(p, inc) { return i > 0 ? ' (' + i + ')' : ''; } +function numberFormat(nStr) { + // Thx to http://www.mredkj.com/javascript/numberFormat.html + nStr += ''; + var x = nStr.split('.'); + var x1 = x[0]; + var x2 = x.length > 1 ? '.' + x[1] : ''; + var rgx = /(\d+)(\d{3})/; + while (rgx.test(x1)) { + x1 = x1.replace(rgx, '$1' + " " + '$2'); + } + return x1 + x2; +} + function incUnreadsFeed(article, feed_id, nb) { + //Update unread: feed var elem = $('#' + feed_id + '>.feed').get(0), - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0, + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0, feed_priority = elem ? (parseInt(elem.getAttribute('data-priority'), 10) || 0) : 0; if (elem) { - elem.setAttribute('data-unread', Math.max(0, feed_unreads + nb)); + elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); } //Update unread: category elem = $('#' + feed_id).parent().prevAll('.category').children(':first').get(0); - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; if (elem) { - elem.setAttribute('data-unread', Math.max(0, feed_unreads + nb)); + elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); } //Update unread: all if (feed_priority > 0) { elem = $('#aside_flux .all').children(':first').get(0); if (elem) { - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; - elem.setAttribute('data-unread', Math.max(0, feed_unreads + nb)); + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; + alert(elem.getAttribute('data-unread') + "\n" + feed_unreads); + elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); } } @@ -54,8 +69,8 @@ function incUnreadsFeed(article, feed_id, nb) { if (article && article.closest('div').hasClass('favorite')) { elem = $('#aside_flux .favorites').children(':first').get(0); if (elem) { - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; - elem.setAttribute('data-unread', Math.max(0, feed_unreads + nb)); + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; + elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); } } @@ -140,9 +155,9 @@ function mark_favorite(active) { if (active.closest('div').hasClass('not_read')) { var elem = $('#aside_flux .favorites').children(':first').get(0), - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; if (elem) { - elem.setAttribute('data-unread', Math.max(0, feed_unreads + inc)); + elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + inc))); } } }); @@ -527,7 +542,7 @@ function refreshUnreads() { $.each(data, function(feed_id, nbUnreads) { feed_id = 'f_' + feed_id; var elem = $('#' + feed_id + '>.feed').get(0), - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; if ((incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) || isAll) && //Update of current view? (nbUnreads - feed_unreads > 0)) { $('#new-article').show(); @@ -626,18 +641,14 @@ function init_loginForm() { if (data.salt1 == '' || data.nonce == '') { alert('Invalid user!'); } else { - try { - var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), - s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), - c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); - $('#challenge').val(c); - if (s == '' || c == '') { - alert('Crypto error!'); - } else { - success = true; - } - } catch (e) { - alert('Crypto exception! ' + e); + var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), + s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), + c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); + $('#challenge').val(c); + if (s == '' || c == '') { + alert('Crypto error!'); + } else { + success = true; } } }).fail(function() { @@ -738,6 +749,29 @@ function init_print_action() { }); } +function init_number_format_unreads() { + // Init global counter + var elem = $('#aside_flux .categories li .all a'); + elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); + + // Init favorites counter + elem = $('#aside_flux .categories li .favorites a'); + elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); + + // Init feeds counters + $('#aside_flux .categories li .stick').each(function() { + // Category-level counter + elem = $(this).find('a'); + elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); + + // Feeds counters + $(this).parent().find('ul.feeds li.item').each(function() { + elem = $(this).find('a.feed'); // There are two links here. a.feed is the title. + elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); + }); + }); +} + function init_all() { if (!(window.$ && window.url_freshrss && ((!full_lazyload) || $.fn.lazyload))) { if (window.console) { @@ -768,7 +802,7 @@ function init_all() { init_print_action(); window.setInterval(refreshUnreads, 120000); } - + init_number_format_unreads(); if (window.console) { console.log('FreshRSS init done.'); } From ec720c4f69759fb08bf07ef322eb2ecac187909f Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Sun, 26 Jan 2014 20:31:38 +0100 Subject: [PATCH 2/6] Formatage du nombre de favoris --- p/scripts/main.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/p/scripts/main.js b/p/scripts/main.js index be5f4f3e4..87df5b551 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -20,11 +20,6 @@ function redirect(url, new_tab) { } } -function incLabel(p, inc) { - var i = (parseInt(p.replace(/\D/g, ''), 10) || 0) + inc; - return i > 0 ? ' (' + i + ')' : ''; -} - function numberFormat(nStr) { // Thx to http://www.mredkj.com/javascript/numberFormat.html nStr += ''; @@ -38,6 +33,11 @@ function numberFormat(nStr) { return x1 + x2; } +function incLabel(p, inc) { + var i = (parseInt(p.replace(/\D/g, ''), 10) || 0) + inc; + return i > 0 ? ' (' + numberFormat(i) + ')' : ''; +} + function incUnreadsFeed(article, feed_id, nb) { //Update unread: feed @@ -148,7 +148,10 @@ function mark_favorite(active) { var favourites = $('.favorites>a').contents().last().get(0); if (favourites && favourites.textContent) { - favourites.textContent = favourites.textContent.replace(/((?: \(\d+\))?\s*)$/, function (m, p1) { + // Without javascript, the text displayed is « Favorites (1544) » where 1544 is the number unformatted. + // With Javascript, we replace this with « Favorites (1 544) ». To update this, the text is converted + // to the non-javascript format before. + favourites.textContent = favourites.textContent.replace(/ /g, '').replace('(', ' (').replace(/((?: \(\d+\))?\s*)$/, function (m, p1) { return incLabel(p1, inc); }); } @@ -749,15 +752,20 @@ function init_print_action() { }); } -function init_number_format_unreads() { +function init_number_formats() { // Init global counter var elem = $('#aside_flux .categories li .all a'); elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); - // Init favorites counter + // Init favorites counters elem = $('#aside_flux .categories li .favorites a'); elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); + var numFavorites = elem.text().replace(/((?: \(\d+\))?\s*)$/, function (m, p1) { + return numberFormat(p1) + }); + elem.text(numFavorites); + // Init feeds counters $('#aside_flux .categories li .stick').each(function() { // Category-level counter @@ -802,7 +810,7 @@ function init_all() { init_print_action(); window.setInterval(refreshUnreads, 120000); } - init_number_format_unreads(); + init_number_formats(); if (window.console) { console.log('FreshRSS init done.'); } From 0a1a7816093f0593dd140e664cbd09e79c0833c3 Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Sun, 26 Jan 2014 21:26:46 +0100 Subject: [PATCH 3/6] =?UTF-8?q?Suppression=20d'un=20message=20de=20d=C3=A9?= =?UTF-8?q?bogage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- p/scripts/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/p/scripts/main.js b/p/scripts/main.js index 87df5b551..bd9321202 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -60,7 +60,6 @@ function incUnreadsFeed(article, feed_id, nb) { elem = $('#aside_flux .all').children(':first').get(0); if (elem) { feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; - alert(elem.getAttribute('data-unread') + "\n" + feed_unreads); elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); } } From 19eefd434c45791ff48c0b5a9ecc642da72b71da Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Sun, 26 Jan 2014 21:36:42 +0100 Subject: [PATCH 4/6] Correction d'un conflit de PR Conflit avec le commit https://github.com/marienfressinaud/FreshRSS/commit/7a510af73a0ef04ce09fb7eedd98c844e7bff51c --- p/scripts/main.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/p/scripts/main.js b/p/scripts/main.js index bd9321202..ed3cf3779 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -643,15 +643,19 @@ function init_loginForm() { if (data.salt1 == '' || data.nonce == '') { alert('Invalid user!'); } else { - var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), - s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), - c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); - $('#challenge').val(c); - if (s == '' || c == '') { - alert('Crypto error!'); - } else { - success = true; - } + try { + var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), + s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), + c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); + $('#challenge').val(c); + if (s == '' || c == '') { + alert('Crypto error!'); + } else { + success = true; + } + } catch (e) { + alert('Crypto exception! ' + e); + } } }).fail(function() { alert('Communication error!'); From d56f51d5fc375ef808433d9f32455dab28d71c84 Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Sun, 26 Jan 2014 21:39:21 +0100 Subject: [PATCH 5/6] Style de code --- p/scripts/main.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/p/scripts/main.js b/p/scripts/main.js index ed3cf3779..ddfa0aec8 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -644,18 +644,18 @@ function init_loginForm() { alert('Invalid user!'); } else { try { - var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), - s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), - c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); - $('#challenge').val(c); - if (s == '' || c == '') { - alert('Crypto error!'); - } else { - success = true; - } - } catch (e) { - alert('Crypto exception! ' + e); - } + var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), + s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), + c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); + $('#challenge').val(c); + if (s == '' || c == '') { + alert('Crypto error!'); + } else { + success = true; + } + } catch (e) { + alert('Crypto exception! ' + e); + } } }).fail(function() { alert('Communication error!'); From 16e1c842b29cdce14b596a6e24c84dd5b9446cd7 Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Mon, 27 Jan 2014 19:22:17 +0100 Subject: [PATCH 6/6] Formatage des nombres sur la page de stats --- app/views/index/stats.phtml | 58 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/app/views/index/stats.phtml b/app/views/index/stats.phtml index ae9db172b..b5c18813d 100644 --- a/app/views/index/stats.phtml +++ b/app/views/index/stats.phtml @@ -4,73 +4,73 @@

-

+

- - + + - - - + + + - - - + + + - - - + + + - - - + + +
 
repartition['main_stream']['total']?>repartition['all_feeds']['total']?>repartition['main_stream']['total']); ?>repartition['all_feeds']['total']); ?>
repartition['main_stream']['read']?>repartition['all_feeds']['read']?>repartition['main_stream']['read']); ?>repartition['all_feeds']['read']); ?>
repartition['main_stream']['unread']?>repartition['all_feeds']['unread']?>repartition['main_stream']['unread']); ?>repartition['all_feeds']['unread']); ?>
repartition['main_stream']['favorite']?>repartition['all_feeds']['favorite']?>repartition['main_stream']['favorite']); ?>repartition['all_feeds']['favorite']); ?>
-

+

-

+

-

+

-

+

- - - + + + - topFeed as $feed):?> + topFeed as $feed): ?> - - - + + + @@ -96,7 +96,7 @@ function initStats() { bars: {horizontal: false, show: true}, xaxis: {noTicks: 6, showLabels: false, tickDecimals: 0}, yaxis: {min: 0}, - mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return obj.y;}} + mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return numberFormat(obj.y);}} }); // Feed per category Flotr.draw(document.getElementById('statsFeedPerCategory'), @@ -106,7 +106,7 @@ function initStats() { pie: {explode: 10, show: true, labelFormatter: function(){return '';}}, xaxis: {showLabels: false}, yaxis: {showLabels: false}, - mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return obj.series.label + ' - '+ obj.y + ' ('+ (obj.fraction * 100).toFixed(1) + '%)';}}, + mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return obj.series.label + ' - '+ numberFormat(obj.y) + ' ('+ (obj.fraction * 100).toFixed(1) + '%)';}}, legend: {container: document.getElementById('statsFeedPerCategoryLegend'), noColumns: 3} }); // Entry per category @@ -117,7 +117,7 @@ function initStats() { pie: {explode: 10, show: true, labelFormatter: function(){return '';}}, xaxis: {showLabels: false}, yaxis: {showLabels: false}, - mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return obj.series.label + ' - '+ obj.y + ' ('+ (obj.fraction * 100).toFixed(1) + '%)';}}, + mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return obj.series.label + ' - '+ numberFormat(obj.y) + ' ('+ (obj.fraction * 100).toFixed(1) + '%)';}}, legend: {container: document.getElementById('statsEntryPerCategoryLegend'), noColumns: 3} }); }