Skip to content

Commit 581fab7

Browse files
Global header and translations implemented for native reports
1 parent 780f56b commit 581fab7

4 files changed

Lines changed: 51 additions & 5 deletions

File tree

src/order-view/order-view.controller.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232
controller.$inject = [
3333
'supplyingFacilities', 'requestingFacilities', 'programs', 'requestingFacilityFactory',
3434
'loadingModalService', 'notificationService', 'fulfillmentUrlFactory', 'orders',
35-
'orderService', 'orderStatusFactory', 'canRetryTransfer', '$stateParams', '$filter', '$state', '$scope'
35+
'orderService', 'orderStatusFactory', 'canRetryTransfer', '$stateParams', '$filter',
36+
'$state', '$scope', 'localStorageService'
3637
];
3738

3839
function controller(supplyingFacilities, requestingFacilities, programs, requestingFacilityFactory,
3940
loadingModalService, notificationService, fulfillmentUrlFactory, orders, orderService,
40-
orderStatusFactory, canRetryTransfer, $stateParams, $filter, $state, $scope) {
41+
orderStatusFactory, canRetryTransfer, $stateParams, $filter, $state, $scope,
42+
localStorageService) {
4143

4244
var vm = this;
4345

@@ -238,7 +240,13 @@
238240
* @return {String} the prepared URL
239241
*/
240242
function getPrintUrl(order) {
241-
return fulfillmentUrlFactory('/api/orders/' + order.id + '/print?format=pdf');
243+
var locale = localStorageService.get('current_locale');
244+
var localeParam = '';
245+
if (locale) {
246+
localeParam = '&lang=' + locale;
247+
}
248+
return fulfillmentUrlFactory('/api/orders/' + order.id + '/print?format=pdf' +
249+
localeParam);
242250
}
243251

244252
/**

src/order-view/order-view.controller.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,16 @@ describe('OrderViewController', function() {
324324

325325
describe('getPrintUrl', function() {
326326

327+
var localStorageServiceMock;
328+
327329
beforeEach(function() {
328330
this.fulfillmentUrlFactoryMock = jasmine.createSpy();
329331
this.fulfillmentUrlFactoryMock.andCallFake(function(url) {
330332
return 'http://some.url' + url;
331333
});
334+
localStorageServiceMock = {
335+
get: jasmine.createSpy('get').andReturn(undefined)
336+
};
332337

333338
this.vm = this.$controller('OrderViewController', {
334339
supplyingFacilities: this.supplyingFacilities,
@@ -338,6 +343,7 @@ describe('OrderViewController', function() {
338343
canRetryTransfer: this.canRetryTransfer,
339344
fulfillmentUrlFactory: this.fulfillmentUrlFactoryMock,
340345
orderStatusFactory: this.orderStatusFactory,
346+
localStorageService: localStorageServiceMock,
341347
$scope: this.scope
342348
});
343349
});

src/proof-of-delivery/proof-of-delivery-printer.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,34 @@
2828
.module('proof-of-delivery')
2929
.factory('ProofOfDeliveryPrinter', ProofOfDeliveryPrinter);
3030

31-
ProofOfDeliveryPrinter.$inject = ['classExtender', 'OpenlmisPrinter'];
31+
ProofOfDeliveryPrinter.$inject = ['classExtender', 'OpenlmisPrinter', 'localStorageService',
32+
'$window', 'openlmisUrlFactory', 'accessTokenFactory'];
3233

33-
function ProofOfDeliveryPrinter(classExtender, OpenlmisPrinter) {
34+
function ProofOfDeliveryPrinter(classExtender, OpenlmisPrinter, localStorageService, $window,
35+
openlmisUrlFactory, accessTokenFactory) {
3436

3537
classExtender.extend(ProofOfDeliveryPrinter, OpenlmisPrinter);
3638

39+
ProofOfDeliveryPrinter.prototype.getUri = getUri;
40+
ProofOfDeliveryPrinter.prototype.print = print;
41+
3742
return ProofOfDeliveryPrinter;
3843

44+
function getUri() {
45+
var uri = this.resourceUri + '/' + this.id + '/print?format=pdf';
46+
var locale = localStorageService.get('current_locale');
47+
if (locale) {
48+
uri += '&lang=' + locale;
49+
}
50+
return uri;
51+
}
52+
53+
function print() {
54+
var url = openlmisUrlFactory(this.getUri());
55+
url = accessTokenFactory.addAccessToken(url);
56+
this.tab.location.href = url;
57+
}
58+
3959
function ProofOfDeliveryPrinter(proofOfDeliveryId) {
4060
this.super({
4161
resourceUri: '/api/proofsOfDelivery/',

src/proof-of-delivery/proof-of-delivery-printer.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,16 @@ describe('ProofOfDeliveryPrinter', function() {
4040
id: 'some-id'
4141
});
4242
});
43+
44+
it('should have getUri method', function() {
45+
var printer = new ProofOfDeliveryPrinter('some-id');
46+
47+
expect(typeof printer.getUri).toEqual('function');
48+
});
49+
50+
it('should have print method', function() {
51+
var printer = new ProofOfDeliveryPrinter('some-id');
52+
53+
expect(typeof printer.print).toEqual('function');
54+
});
4355
});

0 commit comments

Comments
 (0)