Skip to content

Commit

Permalink
HDX-9462 - Issue changing resource for Quick chart
Browse files Browse the repository at this point in the history
  • Loading branch information
aalecs committed Jul 17, 2024
1 parent 11e1b3a commit 531e697
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,15 @@
var selectOptions = $('#field_dataset_preview_value').prop('options');
selectOptions[0] = new Option('Default (first resource with preview)', 'first_resource');
var i = 'first_resource';
$.each(newOptions, function (index, value) {
var resName = value.get('name') ? value.get('name') : 'Resource ' + (index + 1);
if (value.get('dataset_preview_enabled') === true) {
selectOptions[selectOptions.length] = new Option(resName, index + '', true, true);
i = index + '';
} else {
selectOptions[selectOptions.length] = new Option(resName, index + '');
}
});
$.each(newOptions, function (index, value) {
var resName = value.get('name') ? value.get('name') : 'Resource ' + (index + 1);
if (value.get('dataset_preview_enabled') === true) {
selectOptions[selectOptions.length] = new Option(resName, index + '', true, true);
i = index + '';
} else {
selectOptions[selectOptions.length] = new Option(resName, index + '');
}
});
$("#field_dataset_preview_value").val(i).trigger('change');

},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ $(function(){

hashResource: function() {
var newUpload = this.get('upload') ? 'true' : 'false';
var dpe = this.get('dataset_preview_enabled') === '1' || this.get('dataset_preview_enabled') === 'True' ? 'True' : 'False';
var dpe = this.get('dataset_preview_enabled') ? 'true' : 'false';
var microdata = this.get('microdata') ? 'true' : 'false';
var properties = [
this.get('name'), this.get('format'), this.get('url'),
Expand Down Expand Up @@ -121,16 +121,11 @@ $(function(){

sandbox.subscribe('hdx-resource-information', function (message) {
if (message.type == 'dataset_preview_resource_change' && message.newValue!=null) {
var resIdx = Number(message.newValue);
var modelsList = this.models;
for(var i=0; i<modelsList.length; i++){
// modelsList[i].attributes['dataset_preview_enabled'] = '0';
modelsList[i].set('dataset_preview_enabled', '0');
}
if(!isNaN(resIdx)){
modelsList[resIdx].set('dataset_preview_enabled', '1');
}

let resIdx = Number(message.newValue);
this.models.forEach((model, idx) => {
const value = !isNaN(resIdx) && idx === resIdx; //true for selected resource
model.set({ 'dataset_preview_enabled': value });
});
}
}.bind(this));
},
Expand Down

0 comments on commit 531e697

Please sign in to comment.