Skip to content

Commit

Permalink
Merge pull request #3009 from SEED-platform/feat-2960/add-download-is…
Browse files Browse the repository at this point in the history
…sues-button

feature: added an export csv button for import issues
  • Loading branch information
Ryo committed Nov 15, 2021
2 parents 156ac0b + 0f00a32 commit 2898863
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
31 changes: 31 additions & 0 deletions seed/static/seed/js/controllers/data_upload_modal_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,14 @@ angular.module('BE.seed.controller.data_upload_modal', [])
var result = JSON.parse(progress_data.message);
$scope.buildingsync_valid = result.valid;
$scope.buildingsync_issues = result.issues;
for (file in $scope.buildingsync_issues) {
let schema_errors = [];
for (i in $scope.buildingsync_issues[file].schema_errors) {
let error = $scope.buildingsync_issues[file].schema_errors[i];
schema_errors.push([error.message, error.path].join(' - '));
}
$scope.buildingsync_issues[file].schema_errors = schema_errors;
}

// if validation failed, end the import flow here; otherwise continue
if ($scope.buildingsync_valid !== true) {
Expand Down Expand Up @@ -734,6 +742,29 @@ angular.module('BE.seed.controller.data_upload_modal', [])
});
};

$scope.export_issues = function (issues) {
let data = ['File Name,Severity,Message'];
let allowed_severities = {
'warnings': 'Warning',
'use_case_warnings': 'Use Case Warning',
'errors': 'Error',
'use_case_errors': 'Use Case Error',
'schema_errors': 'Schema Error'
}
for (i in issues) {
for (severity in allowed_severities) {
for (issue in issues[i][severity]) {
data.push([
'"' + issues[i].file + '"',
allowed_severities[severity],
'"' + issues[i][severity][issue].replace(/\r?\n|\r/gm, ' ') + '"'
].join(','));
}
}
}
saveAs(new Blob([data.join('\r\n')], {type: 'text/csv'}), 'import_issues.csv');
};

/**
* init: ran upon the controller load
*/
Expand Down
15 changes: 10 additions & 5 deletions seed/static/seed/partials/data_upload_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ <h4 class="modal-title" ng-switch-when="16" translate>PM_METER_IMPORT_RESULTS</h
<div class="alert alert-success"
translate="DATASET_FILENAME_UPLOADED_TO"
translate-values="{ dataset_name: dataset.name , dataset_filename: dataset.filename , cycle_name: selectedCycle.name }"></div>
<div class="alert alert-danger" ng-if="buildingsync_issues != null && buildingsync_issues.length > 0">
There were errors and/or warnings for the file(s) uploaded.
<div class="alert alert-danger" ng-if="buildingsync_issues != null && buildingsync_issues.length > 0" style="display:flex;align-items:baseline;">
<div style="flex-grow:1">There were errors and/or warnings for the file(s) uploaded.</div>
<button type="button" class="btn btn-primary" ng-click="export_issues(buildingsync_issues)"><i class="fa fa-download" aria-hidden="true"></i><span class="pad-left-5" translate>Export CSV<span></button>
</div>
</div>
<div class="row" ng-if="buildingsync_issues != null && buildingsync_issues.length > 0">
Expand Down Expand Up @@ -297,9 +298,10 @@ <h4 class="modal-title" ng-switch-when="16" translate>PM_METER_IMPORT_RESULTS</h
</div>
</ul>
</div>
<div class="alert alert-{$ step_10_style $}">
<div class="alert alert-{$ step_10_style $}" style="display:flex;align-items:baseline;">
<span ng-show="step_10_error_message">{$ step_10_error_message | translate $}</span>
<span ng-show="step_10_file_message">{$ step_10_file_message $}</span>
<span ng-show="step_10_file_message" style="flex-grow:1">{$ step_10_file_message $}</span>
<button ng-show="step_10_file_message" type="button" class="btn btn-primary" ng-click="export_issues(match_issues)"><i class="fa fa-download" aria-hidden="true"></i><span class="pad-left-5" translate>Export CSV<span></button>
<span ng-hide="step_10_error_message || step_10_file_message" translate="IMPORT_ANOTHER_QUESTION"></span>
</div>
<div class="col-sm-12">
Expand All @@ -322,7 +324,10 @@ <h4 class="modal-title" ng-switch-when="16" translate>PM_METER_IMPORT_RESULTS</h
<p ng-if="!step_12_buildingsync_validation_error" translate>An error occurred while processing the file. Please ensure that your file meets the required specifications.</p>
<pre class="text-wrap" ng-class="{'pre-scrollable': step_12_error_message.length >= 300}" ng-show="step_12_error_message && !step_12_buildingsync_validation_error">{$ step_12_error_message | json $}</pre>
<span ng-if="step_12_buildingsync_validation_error">
<div class="alert alert-danger">BuildingSync file(s) failed to validate. No files were imported. Please fix the errors and re-upload the corrected file(s).</div>
<div class="alert alert-danger" style="display:flex;align-items:center;">
<div style="flex-grow:1" class="pad-right-20">BuildingSync file(s) failed to validate. No files were imported. Please fix the errors and re-upload the corrected file(s).</div>
<button type="button" class="btn btn-primary" ng-click="export_issues(buildingsync_issues)"><i class="fa fa-download" aria-hidden="true"></i><span class="pad-left-5" translate>Export CSV<span></button>
</div>
<div ng-repeat="issues in buildingsync_issues">
<ng-include src="::urls.static_url + 'seed/partials/import_messages.html'"></ng-include>
</div>
Expand Down

0 comments on commit 2898863

Please sign in to comment.