-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grids): export to csv with custom options (#1554)
This commit uses the `ui-grid-exporter` plugin to provide the ability to export to CSV on the client from any grid. These changes are prototyped on the Trial Balance modal.
- Loading branch information
1 parent
cb96f6c
commit 869599d
Showing
12 changed files
with
216 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
angular.module('bhima.services') | ||
.service('GridExportService', GridExportService); | ||
|
||
GridExportService.$inject = ['$uibModal', 'util']; | ||
|
||
function GridExportService(Modal, util) { | ||
|
||
/** | ||
* @constructor | ||
*/ | ||
function GridExport(gridOptions, defaultRowKey, defaultColKey) { | ||
|
||
this.gridOptions = gridOptions; | ||
this.ROWS = defaultRowKey; | ||
this.COLS = defaultColKey; | ||
|
||
util.after(gridOptions, 'onRegisterApi', function onRegisterApi(api) { | ||
this.api = api; | ||
}.bind(this)); | ||
} | ||
|
||
/** | ||
* @method run | ||
* @description run the export tool | ||
*/ | ||
GridExport.prototype.run = function run() { | ||
var gridApi = this.api; | ||
var gridOptions = this.gridOptions; | ||
var rows = this.ROWS; | ||
var cols = this.COLS; | ||
|
||
var request = { | ||
api: gridApi, | ||
options: gridOptions, | ||
rows: rows, | ||
cols: cols, | ||
}; | ||
|
||
var params = { | ||
templateUrl : 'modules/templates/modals/export.modal.html', | ||
controller : 'ExportGridModalController', | ||
controllerAs : '$ctrl', | ||
size : 'md', | ||
backdrop : 'static', | ||
animation : false, | ||
resolve : { | ||
data : function dataProvider() { return request; }, | ||
}, | ||
}; | ||
|
||
var instance = Modal.open(params); | ||
return instance.result; | ||
} | ||
|
||
return GridExport; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<div class="modal-header"> | ||
<ol class="headercrumb"> | ||
<li class="title"> | ||
<i class="fa fa-file-excel-o text-success"></i> <span translate>FORM.BUTTONS.EXPORT</span> | ||
</li> | ||
</ol> | ||
</div> | ||
|
||
<div class="modal-body"> | ||
|
||
<div class="form-group"> | ||
<label translate>FORM.LABELS.FILE_NAME</label> | ||
|
||
<input type="text" class="form-control" ng-model="$ctrl.filename" required> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label translate>FORM.LABELS.RECORDS</label> | ||
<select class="form-control" ng-model="$ctrl.exportRowType"</select> | ||
<option value='all' translate>FORM.LABELS.ROWS_ALL</option> | ||
<option value='visible' translate>FORM.LABELS.ROWS_VISIBLE</option> | ||
<option value='selected' translate>FORM.LABELS.ROWS_SELECTED</option> | ||
</select> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label translate>FORM.LABELS.COLUMNS</label> | ||
<select class="form-control" ng-model="$ctrl.exportColType"</select> | ||
<option value='all' translate>FORM.LABELS.COLS_ALL</option> | ||
<option value='visible' translate>FORM.LABELS.COLS_VISIBLE</option> | ||
</select> | ||
</div> | ||
|
||
<span class="ui-grid-exporter-csv-link"> </span> | ||
</div> | ||
|
||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-default" ng-click="$ctrl.dismiss()" data-method="cancel"> | ||
<span translate>FORM.BUTTONS.CANCEL</span> | ||
</button> | ||
|
||
<button type="button" class="btn btn-success" ng-click="$ctrl.exportGrid()" data-method="export"> | ||
<span translate>FORM.BUTTONS.EXPORT</span> | ||
</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
angular.module('bhima.controllers') | ||
.controller('ExportGridModalController', ExportGridModalController); | ||
|
||
ExportGridModalController.$inject = [ | ||
'$uibModalInstance', 'uiGridConstants', '$filter', | ||
'moment', 'bhConstants', 'data', | ||
]; | ||
|
||
function ExportGridModalController(Instance, uiGridConstants, $filter, | ||
moment, bhConstants, Data) { | ||
var vm = this; | ||
|
||
var gridOptions = Data.options || {}; | ||
var gridApi = Data.api || {}; | ||
var filename = Data.filename || 'Export ' + moment().format('YYYY-MM-DD'); | ||
var ROWS = Data.rows || 'visible'; | ||
var COLS = Data.cols || 'visible'; | ||
|
||
// bind with view | ||
vm.exportColType = COLS; | ||
vm.exportRowType = ROWS; | ||
|
||
// expose to the view | ||
vm.exportGrid = exportGrid; | ||
vm.dismiss = Instance.dismiss; | ||
|
||
/** | ||
* Export to csv | ||
*/ | ||
function exportGrid() { | ||
var myElement = angular.element(document.querySelectorAll('.ui-grid-exporter-csv-link')); | ||
filename = vm.filename || filename; | ||
gridOptions.exporterCsvFilename = filename.concat('.csv'); | ||
gridOptions.exporterHeaderFilter = exporterHeaderFilter; | ||
gridOptions.exporterOlderExcelCompatibility = true; | ||
gridApi.exporter.csvExport(vm.exportRowType, vm.exportColType, myElement); | ||
Instance.close(true); | ||
} | ||
|
||
/** | ||
* Exporter apply header filter | ||
*/ | ||
function exporterHeaderFilter(displayName) { | ||
return $filter('translate')(displayName); | ||
} | ||
} |