Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use escaped label as id for querygrid, because id are not unique #3622

Merged
merged 2 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions contribs/gmf/src/directives/displayquerygrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ gmf.DisplayquerygridController = function($injector, $scope, ngeoQueryResult, ng

/**
* @type {!gmfx.GridMergeTabs}
* @export
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: this fixes #3508

*/
this.mergeTabs = {};

Expand Down Expand Up @@ -346,7 +347,7 @@ gmf.DisplayquerygridController.prototype.updateData_ = function() {
if (source.tooManyResults) {
this.makeGrid_(null, source);
} else {
source.id = this.escapeValue_(source.id);
source.id = this.escapeValue(source.id);
const features = source.features;
if (features.length > 0) {
this.collectData_(source);
Expand Down Expand Up @@ -381,12 +382,12 @@ gmf.DisplayquerygridController.prototype.hasOneWithTooManyResults_ = function()
};

/**
* Returns an escaped value.
* Returns the value with all symbols and spaces replaced by an underscore.
* @param {string|number} value A value to escape.
* @returns {string|number} value An escaped value.
* @private
* @export
*/
gmf.DisplayquerygridController.prototype.escapeValue_ = function(value) {
gmf.DisplayquerygridController.prototype.escapeValue = function(value) {
// Work-around for Number.isInteger() when not always getting a number ...
if (Number.isInteger(/** @type {number} */ (value))) {
return value;
Expand Down Expand Up @@ -703,21 +704,21 @@ gmf.DisplayquerygridController.prototype.selectTab = function(gridSource) {
}
this.updateFeatures_(gridSource);

this.reflowGrid_(source.id);
this.reflowGrid_();
};


/**
* @private
* @param {string|number} sourceId Id of the source that should be refreshed.
*/
gmf.DisplayquerygridController.prototype.reflowGrid_ = function(sourceId) {
gmf.DisplayquerygridController.prototype.reflowGrid_ = function() {
// This is a "work-around" to make sure that the grid is rendered correctly.
// When a pane is activated by setting `this.selectedTab`, the class `active`
// is not yet set on the pane. That's why the class is set manually, and
// after the pane is shown (in the next digest loop), the grid table can
// be refreshed.
const activePane = this.$element_.find(`div.tab-pane#${sourceId}`);
const id = this.escapeValue(this.selectedTab || '');
const activePane = this.$element_.find(`div.tab-pane#${id}`);
activePane.removeClass('active').addClass('active');
this.$timeout_(() => {
activePane.find('div.ngeo-grid-table-container table')['trigger']('reflow');
Expand Down
8 changes: 4 additions & 4 deletions contribs/gmf/src/directives/partials/displayquerygrid.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
ng-click="ctrl.selectTab(gridSource)">

<a
href="#{{gridSource.source.id}}"
data-target="#{{gridSource.source.id}}"
aria-controls="{{gridSource.source.id}}"
href="#{{ctrl.escapeValue(gridSource.source.label)}}"
data-target="#{{ctrl.escapeValue(gridSource.source.label)}}"
aria-controls="{{ctrl.escapeValue(gridSource.source.label)}}"
role="tab"
data-toggle="tab">

Expand All @@ -38,7 +38,7 @@
role="tabpanel"
class="tab-pane"
ng-class="{'active' : ctrl.isSelected(gridSource)}"
id="{{gridSource.source.id}}">
id="{{ctrl.escapeValue(gridSource.source.label)}}">

<ngeo-grid
ngeo-grid-configuration="gridSource.configuration"
Expand Down