fineract-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kyriakos Patsias <kpats...@gmail.com>
Subject Re: MifosX Excel download
Date Sun, 27 Aug 2017 00:00:03 GMT
After a lot of digging, and trial and error, I finally found out what I was
doing wrong.

Had to add
transformResponse: function(data, headersGetter) { return { data : data }}

in the controller.

clientBulkImportResource: defineResource(apiVer +
"/clients/bulkimporttemplate", {}, {
    get: {method: 'GET', responseType: 'arraybuffer',
transformResponse: function(data, headersGetter) { return { data :
data }}, params: {}}
}),


Regards,
Kyriakos

On Sun, Aug 20, 2017 at 9:38 AM, Kyriakos Patsias <kpatsias@gmail.com>
wrote:

> Hi community,
>
> This is more of a Community App question, but sending here as well in case
> anyone can help.
>
> I am working on an excel download, as part of the data import project, and
> I can't seem to get it to work.
>
> Here's what I did:
>
> In ResourceFactoryProvider.js added (the endpoint is new and was added as
> part of a GSOG project not yet released. Verified that it is working and
> returns a file with data):
>
> clientBulkImportResource: defineResource(apiVer + "/clients/bulkimporttemplate", {},
{
>     get: {method: 'GET', responseType: 'arraybuffer', params: {}}
> }),
>
>
> Created a new controller BulkImportClientsController.js
>
> (function (module) {
>     mifosX.controllers = _.extend(module, {
>         BulkImportClientsController: function (scope, resourceFactory, location) {
>
>             scope.getTemplate = function () {
>                 resourceFactory.clientBulkImportResource.get(function (data) {
>                 console.log(JSON.stringify(data));
>                                var blob = new Blob([data], {type: 'application/vnd.ms-excel'});
>                                var url = (window.URL || window.webkitURL).createObjectURL(blob);
>                                var a = document.createElement('a');
>                                a.href = url;
>                                a.download = 'client-template';
>                                a.target = '_blank';
>                                a.click();
>                 });
>             };
>         }
>     });
>     mifosX.ng.application.controller('BulkImportClientsController', ['$scope','ResourceFactory',
'$location', 'dateFilter', mifosX.controllers.BulkImportClientsController]).run(function ($log)
{
>         $log.info("BulkImportClientsController initialized");
>     });
> }(mifosX.controllers || {}));
>
>
> And a new view, bulkimportclients.html, containing this to trigger the
> download:
>
> <div class="panel-body">
>     <div class="form-group">
>         <form name="bulkImportClients" class="form-inline ng-dirty ng-invalid ng-invalid-required"
role="form" rc-submit="submitTemplate()">
>             <label>Client Type:&nbsp;</label>
>             <div class="form-group">
>                 <select name="clientType" class="form-control ng-pristine ng-valid
ng-valid-required" ng-model="formData.clientType" value required>
>                     <option>Individual</option>
>                     <option>Corporate</option>
>                 </select>
>             </div>
>             <button style="margin-left:20px;" type="button" class="form-control btn
btn-primary" ng-click="getTemplate()">{{'label.button.bulkimporttemplate'
>                 | translate }}</button>
>         </form>
>     </div>
>
>
> The download is triggered, and I get an excel file, but it is empty.
>
> Did I miss something?
>
> Thank you,
>
> --
> Kyriakos <https://www.linkedin.com/in/kyriakospatsias>
>



-- 
Kyriakos <https://www.linkedin.com/in/kyriakospatsias>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message