Skip to content

Commit

Permalink
OLMIS-7909-inventory-items-export (#8)
Browse files Browse the repository at this point in the history
* OLMIS-7909-inventory-items-export

* OLMIS-7909-inventory-items-export

* OLMIS-7909-inventory-items-export

* OLMIS-7909-inventory-items-export
  • Loading branch information
Asquarep authored Apr 10, 2024
1 parent 343075f commit c9fc7c9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
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"
}

0 comments on commit c9fc7c9

Please sign in to comment.