Skip to content

Commit

Permalink
More fixes for normalizing pages names for list-based apps
Browse files Browse the repository at this point in the history
Always show Clear button unless there are no pages
  • Loading branch information
MusikAnimal committed Nov 17, 2016
1 parent 3564740 commit 5f32e12
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 49 deletions.
36 changes: 23 additions & 13 deletions javascripts/langviews/langviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,11 @@ class LangViews extends mix(Pv).with(ChartHelpers, ListHelpers) {
params.end = this.daterangepicker.endDate.format('YYYY-MM-DD');
}

/** only certain characters within the page name are escaped */
params.page = $(this.config.sourceInput).val().score().replace(/[&%]/g, escape);

if (!forCacheKey) {
if (forCacheKey) {
// Page name needed to make a unique cache key for the query.
// For other purposes (e.g. this.pushParams()), we want to do special escaping of the page name
params.page = $(this.config.sourceInput).val().score();
} else {
params.sort = this.sort;
params.direction = this.direction;
params.view = this.view;
Expand All @@ -285,9 +286,11 @@ class LangViews extends mix(Pv).with(ChartHelpers, ListHelpers) {
return history.replaceState(null, document.title, location.href.split('?')[0]);
}

window.history.replaceState({}, document.title, `?${$.param(this.getParams())}`);
const escapedPageName = $(this.config.sourceInput).val().score().replace(/[&%?]/g, escape);

window.history.replaceState({}, document.title, `?${$.param(this.getParams())}&page=${escapedPageName}`);

$('.permalink').prop('href', `/langviews?${$.param(this.getPermaLink())}`);
$('.permalink').prop('href', `/langviews?${$.param(this.getPermaLink())}&page=${escapedPageName}`);
}

/**
Expand Down Expand Up @@ -519,11 +522,6 @@ class LangViews extends mix(Pv).with(ChartHelpers, ListHelpers) {

this.patchUsage();

// fill in value for the page
if (params.page) {
$(this.config.sourceInput).val(decodeURIComponent(params.page).descore());
}

// If there are invalid params, remove page from params so we don't process the defaults.
// FIXME: we're checking for site messages because super.validateParams doesn't return a boolean
// or any indication the validations failed. This is hacky but necessary.
Expand All @@ -543,7 +541,19 @@ class LangViews extends mix(Pv).with(ChartHelpers, ListHelpers) {

/** start up processing if page name is present */
if (params.page) {
this.processInput();
this.getPageInfo([params.page]).done(data => {
// throw errors if page is missing
const normalizedPage = Object.keys(data)[0];
if (data[normalizedPage].missing) {
this.setState('initial');
return this.writeMessage(`${this.getPageLink(normalizedPage)}: ${$.i18n('api-error-no-data')}`);
}
// fill in value for the page
$(this.config.sourceInput).val(normalizedPage);
this.processInput();
}).fail(() => {
this.writeMessage($.i18n('api-error-unknown', 'Info'));
});
} else {
$(this.config.sourceInput).focus();
}
Expand Down Expand Up @@ -619,7 +629,7 @@ class LangViews extends mix(Pv).with(ChartHelpers, ListHelpers) {
this.getPageViewsData(interWikiData).done(pageViewsData => {
$('.progress-bar').css('width', '100%');
$('.progress-counter').text($.i18n('building-dataset'));
const pageLink = this.getPageLink(decodeURIComponent(page), this.project);
const pageLink = this.getPageLink(page, this.project);
setTimeout(() => {
this.buildMotherDataset(page, pageLink, pageViewsData);
readyForRendering();
Expand Down
1 change: 0 additions & 1 deletion javascripts/pageviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ class PageViews extends mix(Pv).with(ChartHelpers) {
this.updateTable();
});
$('.clear-pages').on('click', () => {
$('.clear-pages').hide();
this.resetView(true);
this.focusSelect2();
});
Expand Down
19 changes: 13 additions & 6 deletions javascripts/redirectviews/redirectviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,6 @@ class RedirectViews extends mix(Pv).with(ChartHelpers, ListHelpers) {

this.patchUsage();

// fill in value for the page
if (params.page) {
$(this.config.sourceInput).val(decodeURIComponent(params.page).descore());
}

// If there are invalid params, remove page from params so we don't process the defaults.
// FIXME: we're checking for site messages because super.validateParams doesn't return a boolean
// or any indication the validations failed. This is hacky but necessary.
Expand All @@ -514,7 +509,19 @@ class RedirectViews extends mix(Pv).with(ChartHelpers, ListHelpers) {

/** start up processing if page name is present */
if (params.page) {
this.processInput();
this.getPageInfo([params.page]).done(data => {
// throw errors if page is missing
const normalizedPage = Object.keys(data)[0];
if (data[normalizedPage].missing) {
this.setState('initial');
return this.writeMessage(`${this.getPageLink(normalizedPage)}: ${$.i18n('api-error-no-data')}`);
}
// fill in value for the page
$(this.config.sourceInput).val(normalizedPage);
this.processInput();
}).fail(() => {
this.writeMessage($.i18n('api-error-unknown', 'Info'));
});
} else {
$(this.config.sourceInput).focus();
}
Expand Down
2 changes: 0 additions & 2 deletions javascripts/shared/chart_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,8 @@ const ChartHelpers = superclass => class extends superclass {
return this.stopSpinny();
} else if (entityNames.length === 1) {
$('.multi-page-chart-node').hide();
$('.clear-pages').hide();
} else {
$('.multi-page-chart-node').show();
$('.clear-pages').show();
}

if (xhrData) {
Expand Down
1 change: 0 additions & 1 deletion javascripts/siteviews/siteviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ class SiteViews extends mix(Pv).with(ChartHelpers) {
this.updateTable();
});
$('.clear-pages').on('click', () => {
$('.clear-pages').hide();
this.resetView(true);
this.focusSelect2();
});
Expand Down
2 changes: 1 addition & 1 deletion public_html/application.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/application.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/langviews/application.css

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions public_html/langviews/application.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/massviews/application.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions public_html/massviews/application.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/meta/application.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions public_html/meta/application.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/redirectviews/application.css

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions public_html/redirectviews/application.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public_html/siteviews/application.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions public_html/siteviews/application.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions stylesheets/_chart_view.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ body.initial {
.table-view,
.summary-column,
.single-page-stats,
.single-page-ranking {
.single-page-ranking,
.clear-pages {
display: none !important;
}
}
Expand Down Expand Up @@ -98,7 +99,6 @@ body.initial {

.clear-pages {
cursor: pointer;
display: none;
}

.modal-chart-type {
Expand Down

0 comments on commit 5f32e12

Please sign in to comment.