Skip to content
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

OLMIS-7909-inventory-items-export #8

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/cce-inventory-item/cce-inventory-item.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
get: get,
query: query,
save: save,
transfer: transfer
transfer: transfer,
getDownloadURL: getDownloadURL
};

/**
Expand Down Expand Up @@ -130,6 +131,21 @@
return resource.save({}, inventoryItem).$promise;
}

/**
* @ngdoc method
* @methodOf cce-inventory-item.inventoryItemService
* @name getDownloadURL
*
* @description
* Returns the download url for the provided parameters
*
* @return {String} the download url
*/
function getDownloadURL(params) {
return cceUrlFactory('/api/inventoryItems/download?format=csv&programId='
+ params.programId + '&facilityId=' + params.facilityId);
}

function transformGetResponse(data, headers, status) {
return transformResponse(data, status, transformInventoryItem);
}
Expand All @@ -155,4 +171,4 @@
return data;
}
}
})();
})();
23 changes: 20 additions & 3 deletions src/cce-inventory-list/cce-inventory-list.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

CceInventoryListController.$inject = [
'inventoryItems', '$state', '$stateParams', 'FUNCTIONAL_STATUS', 'CCE_RIGHTS', 'messageService',
'REASON_FOR_NOT_WORKING', 'cceAlerts', 'canEdit', 'canTransfer'
'REASON_FOR_NOT_WORKING', 'cceAlerts', 'canEdit', 'canTransfer', 'inventoryItemService'
];

function CceInventoryListController(inventoryItems, $state, $stateParams, FUNCTIONAL_STATUS,
CCE_RIGHTS, messageService, REASON_FOR_NOT_WORKING, cceAlerts, canEdit,
canTransfer) {
canTransfer, inventoryItemService) {

var vm = this;

Expand All @@ -45,6 +45,7 @@
vm.getReasonLabel = getReasonLabel;
vm.search = search;
vm.getFunctionalStatusClass = FUNCTIONAL_STATUS.getClass;
vm.getDownloadURL = getDownloadURL;

/**
* @ngdoc property
Expand Down Expand Up @@ -237,6 +238,22 @@
reload: true
});
}
}

/**
* @ngdoc method
* @methodOf cce-inventory-list.controller:CceInventoryListController
* @name getDownloadURL
*
* @description
* Downloads the facility Inventory data as a csv.
*
* @return {String} url
*/
function getDownloadURL() {
return inventoryItemService.getDownloadURL({
facilityId: vm.facility.id,
programId: vm.program.id
});
}
}
})();
1 change: 1 addition & 0 deletions src/cce-inventory-list/cce-inventory-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ <h2>{{'cceInventoryList.cceInventory' | message}}</h2>
<input type="submit" value="{{'cceInventoryList.search' | message}}"/>
</form>
<section class="openlmis-table-container">
<input openlmis-download="{{vm.getDownloadURL()}}" type="button" value="{{'cceInventoryList.exportCSV' | message}}"/>
<button id="add-inventory-item" class="add" ui-sref="openlmis.cce.inventory.add"
ng-show="vm.userHasRightToEdit">
{{'cceInventoryList.addEquipment' | message}}
Expand Down
3 changes: 2 additions & 1 deletion src/cce-inventory-list/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"cceInventoryList.actions": "Actions",
"cceInventoryList.view": "View",
"cceInventoryList.noInventoryItems": "No inventory items found.",
"cceInventoryList.search": "Search"
"cceInventoryList.search": "Search",
"cceInventoryList.exportCSV": "Export CSV"
}
Loading