Skip to content

Commit

Permalink
Advertise most-viewed pages of the year
Browse files Browse the repository at this point in the history
  • Loading branch information
MusikAnimal committed Jan 13, 2020
1 parent 560d3ec commit 7561b37
Show file tree
Hide file tree
Showing 24 changed files with 91 additions and 58 deletions.
2 changes: 1 addition & 1 deletion bin/import_topviews_yearly.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const [sourceFile, year] = process.argv.slice(2);

const source = fs.readFile(sourceFile, 'utf8', function (err, tsv) {
fs.readFile(sourceFile, 'utf8', function(err, tsv) {
const lines = tsv.split('\n');
const headers = lines.slice(0, 1)[0].split('\t');

Expand Down
35 changes: 33 additions & 2 deletions javascripts/shared/pv.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,37 @@ class Pv extends PvConfig {
return;
}

this.loadTranslations();
this.loadTranslations().then(() => {
// Advertise most-viewed pages for the year.

// Don't show when viewing the yearly results in Topviews.
if ('topviews' === this.app && this.isYearly()) {
return;
}

// Don't show if seen over 3 times.
const cacheKey = 'pageviews-yearly-topviews-add';
const seenCount = parseInt(this.getFromLocalStorage(cacheKey), 10) || 0;
if (seenCount > 3) {
return;
}
this.setLocalStorage(cacheKey, seenCount + 1);

let project = this.project;

// Grab the first project in the list if viewing Siteviews.
if ('siteviews' === this.app) {
if (this.isAllProjects()) {
return;
}
project = ($(this.config.select2Input).select2('val') || [])[0].replace(/\.org$/, '');
}

const year = 2019;
this.toastInfo(
`<a href="/topviews?project=${project}.org&date=${year}"><strong>${$.i18n('notice-year-stats', year)}</strong></a>`
);
});

// extensions
$.extend($.i18n.parser.emitter, {
Expand Down Expand Up @@ -132,6 +162,7 @@ class Pv extends PvConfig {
* Load translations then initialize the app.
* Each app has it's own initialize method.
* Make sure we load 'en.json' as a fallback.
* @returns {jQuery.Promise}
*/
loadTranslations() {
let messagesToLoad = {
Expand All @@ -146,7 +177,7 @@ class Pv extends PvConfig {

messagesToLoad.en = `${appPath}/${currentApp}/messages/en.json`;
}
$.i18n({
return $.i18n({
locale: i18nLang
}).load(messagesToLoad).then(this.initialize.bind(this));
}
Expand Down
1 change: 1 addition & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
"no-autocompletion": "No autocompletion",
"none": "None",
"note": "Note",
"notice-year-stats": "The most-viewed pages of $1 is now available!",
"november": "November",
"num-bytes": "$1 {{PLURAL:$2|byte|bytes}}",
"num-days-span": "$1-day span",
Expand Down
1 change: 1 addition & 0 deletions messages/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
"no-autocompletion": "Label for option to disable autocompletion when searching",
"none": "The word 'none', used for general purpose.\n{{Identical|None}}",
"note": "The word that goes before a general notice, such as a temporarily limited feature.\n{{Identical|Note}}",
"notice-year-stats": "Message advertizing that the most-viewed pages of the past year are now available. $1 is the year.",
"november": "{{doc-months|11}}\n{{Identical|November}}",
"num-bytes": "Text indicating a number of bytes. $1 is the formatted number, $2 is the same number but unformatted so that it can be used with PLURAL.\n{{Identical|Byte}}",
"num-days-span": "Indicates the number of days across which a user was active in creating articles. Shown above the 'date created' column in the Userviews tool. $1 is the number of days as a formatted number, $2 is the same number but unformatted so that it can be used with PLURAL.",
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/langviews/rev-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"application.css": "application-54ee1e4194.css",
"application.js": "application-490aa0d933.js"
"application.js": "application-eda25bf0ec.js"
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/massviews/rev-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"application.css": "application-ba7ac06e9c.css",
"application.js": "application-78d305b7a7.js"
"application.js": "application-7caf956a80.js"
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/mediaviews/rev-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"application.css": "application-b39b0a67c5.css",
"application.js": "application-6aeb1b733d.js"
"application.js": "application-5dc5fca7f2.js"
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/metaviews/rev-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"application.css": "application-4c15a89e60.css",
"application.js": "application-c6fb26a53c.js"
"application.js": "application-f8adacff79.js"
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/pageviews/rev-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"application.css": "application-b39b0a67c5.css",
"application.js": "application-c60f270f58.js"
"application.js": "application-ba078e5f80.js"
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/redirectviews/rev-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"application.css": "application-f11ffb7dfb.css",
"application.js": "application-0f7a3de57c.js"
"application.js": "application-88fcf75525.js"
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/siteviews/rev-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"application.css": "application-ccef5b85f4.css",
"application.js": "application-67a013f5bc.js"
"application.js": "application-fd2f1da7a8.js"
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public_html/topviews/rev-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"application.css": "application-cef11c1cce.css",
"application.js": "application-94287e02cf.js"
"application.css": "application-6857a33d26.css",
"application.js": "application-fe1ccab48e.js"
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/userviews/rev-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"application.css": "application-69c14a164e.css",
"application.js": "application-7bec9575ee.js"
"application.js": "application-a210a1a64f.js"
}
2 changes: 1 addition & 1 deletion stylesheets/topviews/topviews.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$gray: #ccc;

.chart-container {
overflow-x: scroll;
overflow-x: auto;
padding: 0;
}

Expand Down

0 comments on commit 7561b37

Please sign in to comment.