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

ALS-6416: Add ability to download data as PFB #327

Merged
merged 2 commits into from
Aug 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ div#package-datatable-table{
<i class="fa fa-download" id="package-download-icon" aria-hidden="true"></i>
<span id='package-download-label'>Download</span>
</a>
<button id="package-package-button" class="btn btn-primary package-button" tabindex="1099998">Package Data</button>
<button id="package-package-button-csv" class="btn btn-primary package-button" tabindex="1099998">Package Data as CSV</button>
<button id="package-package-button-pfb" class="btn btn-primary package-button" tabindex="1099998">Package Data as PFB</button>
</div>
<div class="package-query-container">
<label id="query-id-label" for="package-query-id">Dataset Id:</label><div id="package-query-id">xxx</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,15 @@ define([
var viewObj = this;
if(exportStatus === 'Ready'){
statusMessage = 'Status: Ready to package. \nClick "Package Data" to proceed.';
$('#package-package-button').attr('disabled', false);
$('#package-package-button', this.$el).click(function(){
viewObj.initiatePackage();
$('#package-package-button-csv').attr('disabled', false);
$('#package-package-button-pbf').attr('disabled', false);
$('#package-package-button-csv', this.$el).click(function(){
viewObj.initiatePackage('DATAFRAME');
}.bind(viewObj));
$('#package-package-button').css('background-color', 'var(--catalyst-blue)');
$('#package-package-button-pfb', this.$el).click(function(){
viewObj.initiatePackage('DATAFRAME_PFB');
}.bind(viewObj));
$('#package-package-button-csv, #package-package-button-pfb').css('background-color', 'var(--catalyst-blue)');
$('.package-query-container').hide();
$('#package-download-button').hide();
$('#package-copy-query-button').hide();
Expand All @@ -167,9 +171,9 @@ define([
else if (exportStatus === 'Overload') {
fontColor = 'Red';
statusMessage = 'Status: NUMBER OF DATA POINTS EXCEEDED\nRemove data selections';
$('#package-package-button').attr('disabled', true);
$('#package-package-button', this.$el).off('click');
$('#package-package-button').css('background-color', 'lightgrey');
$('#package-package-button-csv, #package-package-button-pfb').attr('disabled', true);
$('#package-package-button-csv, #package-package-button-pfb', this.$el).off('click');
$('#package-package-button-csv, #package-package-button-pfb').css('background-color', 'lightgrey');
$('.package-query-container').hide();
$('#package-copy-query-button').hide();
$('#save-named-dataset-btn').hide();
Expand All @@ -179,9 +183,9 @@ define([
}
else if (exportStatus === 'Progress') {
statusMessage = 'Status: In Progress';
$('#package-package-button').attr('disabled', true);
$('#package-package-button', this.$el).off('click');
$('#package-package-button').css('background-color', 'lightgrey');
$('#package-package-button-csv, #package-package-button-pfb').attr('disabled', true);
$('#package-package-button-csv, #package-package-button-pfb', this.$el).off('click');
$('#package-package-button-csv, #package-package-button-pfb').css('background-color', 'lightgrey');
$('.package-query-container').hide();
$('#package-copy-query-button').hide();
$('#save-named-dataset-btn').hide();
Expand All @@ -191,11 +195,14 @@ define([
}
else if (exportStatus === 'Done') {
statusMessage = 'Status: Available';
$('#package-package-button').attr('disabled', false);
$('#package-package-button', this.$el).click(function(){
viewObj.initiatePackage();
$('#package-package-button-csv, #package-package-button-pfb').attr('disabled', false);
$('#package-package-button-csv', this.$el).click(function(){
viewObj.initiatePackage('DATAFRAME');
}.bind(viewObj));
$('#package-package-button-pfb', this.$el).click(function(){
viewObj.initiatePackage('DATAFRAME_PFB');
}.bind(viewObj));
$('#package-package-button').css('background-color', 'var(--catalyst-blue)');
$('#package-package-button-csv, #package-package-button-pfb').css('background-color', 'var(--catalyst-blue)');
$('.package-query-container').show();
$('#seven-bridges-export').show();
$('#terra-export').show();
Expand All @@ -214,11 +221,14 @@ define([
else {
statusMessage = 'Error-please try again';
fontColor = 'Red';
$('#package-package-button').prop('disabled', false);
$('#package-package-button', this.$el).click(function(){
viewObj.initiatePackage();
$('#package-package-button-csv, #package-package-button-pfb').prop('disabled', false);
$('#package-package-button-csv', this.$el).click(function(){
viewObj.initiatePackage('DATAFRAME');
}.bind(viewObj));
$('#package-package-button').css('background-color', '#337ab7');
$('#package-package-button-pfb', this.$el).click(function(){
viewObj.initiatePackage('DATAFRAME_PFB');
}.bind(viewObj));
$('#package-package-button-csv, #package-package-button-pfb').css('background-color', '#337ab7');
}

// $('#package-download-button', this.$el).removeAttr("href");
Expand All @@ -228,14 +238,19 @@ define([
$('#package-status').html(statusMessage);
$('#package-status').css('color', fontColor);
},
initiatePackage: function() {
initiatePackage: function(expectedResultType) {
this.model.set('exportStatus', 'Progress');
this.model.set("datasetName", undefined);
if (expectedResultType === 'DATAFRAME_PFB') {
this.model.set('fileExtension', 'avro');
} else {
this.model.set('fileExtension', 'csv');
}
$("#save-named-dataset-btn").html("Save Dataset ID");
this.updateHeader();
var query = queryBuilder.createQueryNew(filterModel.get("activeFilters").toJSON(), filterModel.get("exportFields").toJSON(), settings.picSureResourceId);
query = JSON.parse(JSON.stringify(query));
query.query.expectedResultType="DATAFRAME";
query.query.expectedResultType=expectedResultType;
queryBuilder.updateConsentFilters(query, settings);
var deferredQueryId = $.Deferred();
var viewObj = this;
Expand Down Expand Up @@ -339,7 +354,8 @@ define([
success: function(response){
responseDataUrl = URL.createObjectURL(new Blob([response], {type: "octet/stream"}));
const link = document.createElement('a');
link.download = 'data.csv';
let fileExtension = viewObj.model.get('fileExtension');
link.download = 'data.' + fileExtension;
link.href = responseDataUrl;
link.click();
link.remove();
Expand Down
Loading