Hi Kyriakos,
Thanks for sharing the solution. I believe this is the correct way to
download documents.
In the existing implementation of downloading documents, it has a manually
constructed URL which is opened in a new tab without headers; effectively
breaking the security modes of oauth and two factor as they rely on
multiple headers.
@Alex,
Please do a codebase search for manually constructed URLs used for document
downloads and move it to this implementation in your open pull request.
Places you might need to fix :-
- viewclient.html - {{docUrl}
- ViewClientController
- Check loan documents tab as well for this pattern.
- Generate one simple pentaho report and try downloading it to check if
the pattern exists there as well.
@Gaurav,
Let us know your views on it. Please add to the above list if I missed any
location where it should be fixed.
Regards,
Avik.
On Sun, Aug 27, 2017 at 5:30 AM, Kyriakos Patsias <[email protected]>
wrote:
> 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 <[email protected]>
> 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: </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>
>