-
Notifications
You must be signed in to change notification settings - Fork 105
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
Journal export csv with custom options #1554
Changes from all commits
9a0e98b
b50308f
e287caf
a2b948c
aedf2c1
fddcb14
96686b2
3ec8486
60704b2
49003e8
5b3830a
4d663fd
a4fb28c
9c4be51
5a0eba3
8081ae8
54341ac
9b18d21
63c1383
a025765
e21c788
07d7e3b
31f4662
0301dcc
d2bec39
06a81eb
3d79a76
45cb46f
6d47968
b3f050e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ var bhima = angular.module('bhima', [ | |
'tmh.dynamicLocale', 'ngFileUpload', 'ui.grid', | ||
'ui.grid.selection', 'ui.grid.autoResize', 'ui.grid.resizeColumns', | ||
'ui.grid.edit', 'ui.grid.grouping', 'ui.grid.treeView', 'ui.grid.cellNav', | ||
'ui.grid.pagination', 'ui.grid.moveColumns', 'angularMoment', 'ngMessages', | ||
'ui.grid.pagination', 'ui.grid.moveColumns', 'ui.grid.exporter', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... is this possible to do without the exporter service? I don't see where it is used and I hate to introduce another dependency for something we can almost already do... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes but with a lot of supplementary request to the server, also if we don't use the exporter service we cannot share the client service for exporting with custom name to other modules. The first reason of using Also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your analysis is correct - for the trial balance, it is more work to export a CSV from the server side. My biggest worry with this change is that, as a developer, I do not know when to use the server-side CSV rather than the client-side CSV. It creates another question to ask during development and something else to test.... |
||
'angularMoment', 'ngMessages', | ||
'growlNotifications', 'ngAnimate', 'ngSanitize', 'ui.select', 'ngTouch', | ||
'ui.router.state.events', | ||
]); | ||
|
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; | ||
} |
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> |
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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For simplicity, I propose we always render all rows in the grid. That's how our PDFs work and it makes sense that the filters chosen will be the ones applied to the dataset. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current state of the |
||
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); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍