Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Added links to inventory items from reports
Browse files Browse the repository at this point in the history
Resolves #74
  • Loading branch information
jkleinsc committed Apr 7, 2015
1 parent 8062d10 commit 628a7ea
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 13 deletions.
60 changes: 55 additions & 5 deletions app/controllers/abstract-report-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import NumberFormat from 'hospitalrun/mixins/number-format';
import PouchDbMixin from 'hospitalrun/mixins/pouchdb';
import ProgressDialog from "hospitalrun/mixins/progress-dialog";
export default Ember.ArrayController.extend(DateFormat, NumberFormat, PouchDbMixin, ProgressDialog, {
offset: 0,
limit: 25,
progressMessage: 'Please wait while your report is generated.',
progressTitle: 'Generating Report',
reportColumns: null,
Expand All @@ -20,8 +22,9 @@ export default Ember.ArrayController.extend(DateFormat, NumberFormat, PouchDbMix
* @param reportColumns {Object} the columns to display on the report;
* optional, if not set, the property reportColumns on the controller
* will be used.
* @param reportAction {Object} action to fire on row when row is clicked.
*/
_addReportRow: function(row, skipNumberFormatting, reportColumns) {
_addReportRow: function(row, skipNumberFormatting, reportColumns, rowAction) {
var columnValue,
reportRows = this.get('reportRows'),
reportRow = [];
Expand All @@ -46,7 +49,14 @@ export default Ember.ArrayController.extend(DateFormat, NumberFormat, PouchDbMix
}
}
}
reportRows.addObject(reportRow);
if (rowAction) {
reportRows.addObject({
rowAction: rowAction,
row: reportRow
});
} else {
reportRows.addObject(reportRow);
}
},

/**
Expand All @@ -57,6 +67,7 @@ export default Ember.ArrayController.extend(DateFormat, NumberFormat, PouchDbMix
*/
_finishReport: function(reportColumns) {
this.set('showReportResults', true);
this.set('offset', 0);
this._setReportHeaders(reportColumns);
this._setReportTitle();
this._generateExport();
Expand All @@ -68,8 +79,12 @@ export default Ember.ArrayController.extend(DateFormat, NumberFormat, PouchDbMix
reportHeaders = this.get('reportHeaders'),
dataArray = [reportHeaders];
dataArray.addObjects(this.get('reportRows'));
dataArray.forEach(function(row) {
csvRows.push('"'+row.join('","')+'"');
dataArray.forEach(function(reportRow) {
if (reportRow.row) {
csvRows.push('"'+reportRow.row.join('","')+'"');
} else {
csvRows.push('"'+reportRow.join('","')+'"');
}
});
var csvString = csvRows.join('\r\n');
var uriContent = "data:application/csv;charset=utf-8," + encodeURIComponent(csvString);
Expand Down Expand Up @@ -108,6 +123,41 @@ export default Ember.ArrayController.extend(DateFormat, NumberFormat, PouchDbMix
this.set('reportTitle', '%@ Report %@ - %@'.fmt(reportDesc.name, formattedStartDate, formattedEndDate));
}
},


actions: {
nextPage: function() {
var limit = this.get('limit');
this.incrementProperty('offset', limit);
},

previousPage: function() {
var limit = this.get('limit');
this.decrementProperty('offset', limit);
}
},

currentReportRows: function() {
var limit = this.get('limit'),
offset = this.get('offset'),
reportRows = this.get('reportRows');
return reportRows.slice(offset, offset+limit);
}.property('reportRows.@each', 'offset', 'limit'),

disablePreviousPage: function() {
return (this.get('offset') === 0);
}.property('offset'),

disableNextPage: function() {
var limit = this.get('limit'),
length = this.get('reportRows.length'),
offset = this.get('offset');
return ((offset+limit) >= length);
}.property('offset','limit','reportRows.length'),

showPagination: function() {
var length = this.get('reportRows.length'),
limit = this.get('limit');
return (length > limit);
}.property('reportRows.length')

});
3 changes: 2 additions & 1 deletion app/inventory/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import AbstractEditController from 'hospitalrun/controllers/abstract-edit-contro
import Ember from "ember";
import InventoryLocations from "hospitalrun/mixins/inventory-locations";
import InventoryTypeList from 'hospitalrun/mixins/inventory-type-list';
import ReturnTo from 'hospitalrun/mixins/return-to';
import UnitTypes from "hospitalrun/mixins/unit-types";
import UserSession from "hospitalrun/mixins/user-session";

export default AbstractEditController.extend(InventoryLocations, InventoryTypeList, UnitTypes, UserSession, {
export default AbstractEditController.extend(InventoryLocations, InventoryTypeList, ReturnTo, UnitTypes, UserSession, {
needs: ['inventory','pouchdb'],

canAddPurchase: function() {
Expand Down
17 changes: 17 additions & 0 deletions app/inventory/reports/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ export default AbstractReportController.extend(LocationName, ModalHelper, Number
}
},

_addReportRow: function(row, skipNumberFormatting, reportColumns, rowAction) {
if (Ember.isEmpty(rowAction) && !Ember.isEmpty(row.inventoryItem)) {
rowAction = {
action: 'viewInventory',
model: row.inventoryItem._id.substr(10)
};
}
this._super(row, skipNumberFormatting, reportColumns, rowAction);
},

_addTotalsRow: function(label, summaryCost, summaryQuantity) {
if (summaryQuantity > 0) {
this._addReportRow({
Expand Down Expand Up @@ -759,6 +769,13 @@ export default AbstractReportController.extend(LocationName, ModalHelper, Number
break;
}
}
},

viewInventory: function(id) {
this.store.find('inventory', id).then(function(item) {
item.set('returnTo', 'inventory.reports');
this.transitionToRoute('inventory.edit', item);
}.bind(this));
}
}
});
22 changes: 15 additions & 7 deletions app/inventory/reports/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
{{#if showReportResults}}
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">{{reportTitle}}</h3>
<h3 class="panel-title">{{reportTitle}}{{partial 'paging'}}</h3>
</div>
<div class="panel-body">
<table class="table">
Expand All @@ -77,12 +77,20 @@
</th>
{{/each}}
</tr>
{{#each reportRows}}
<tr>
{{#each this}}
<td>{{array-display content=this}}</td>
{{/each}}
</tr>
{{#each currentReportRows}}
{{#if rowAction}}
<tr {{action rowAction.action rowAction.model}}>
{{#each row}}
<td>{{array-display content=this }}</td>
{{/each}}
</tr>
{{else}}
<tr>
{{#each this}}
<td>{{array-display content=this }}</td>
{{/each}}
</tr>
{{/if}}
{{/each}}
</table>
</div>
Expand Down

0 comments on commit 628a7ea

Please sign in to comment.