-
-
Notifications
You must be signed in to change notification settings - Fork 730
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
Uk/1316 ui grid reports #1547
Uk/1316 ui grid reports #1547
Changes from all commits
9ca5341
ad76528
009bf0b
8c44add
d33df30
74f644b
2c287b8
1f552d2
206715e
c704925
cd5c4b7
9dbc135
346a8f3
fa911f3
fd584bb
d566086
a92071c
b1d69be
444ee92
a89a08f
8d12518
1328431
da10c01
457cbfd
9247066
c35a165
1e7406a
689afd0
12e67db
cceba09
40b5ce1
3fd7a98
8ebda59
4d136f7
535ec98
9b216ee
ba9383f
d4a6eca
37ecd52
8473978
bb43600
097636e
a5a1146
c0022c6
1b7fafe
605bf12
2627c7a
37cb961
0e99a8e
73580a0
56ae5dc
74370b3
b3ead35
9d84988
c46a09f
b1f5035
7b8221c
c5a9913
20b5aca
c60182c
954530b
fdb1c59
9546123
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -749,4 +749,4 @@ RUBY VERSION | |
ruby 2.1.5p273 | ||
|
||
BUNDLED WITH | ||
1.14.3 | ||
1.14.6 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
angular.module("admin.reports").controller "bulkCoopCtrl", ($scope, $controller, $location, $http, BulkCoopReport, Enterprises, LineItems, Orders, Products, Variants, distributors, reportType) -> | ||
angular.extend this, $controller('ReportsCtrl', {$scope: $scope, $location: $location}) | ||
|
||
if $location.search().report_type | ||
reportType = $location.search().report_type | ||
$scope.q = {report_type: reportType} | ||
$scope.reportType = reportType | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit confused about what is happening with |
||
|
||
$scope.distributors = distributors | ||
$scope.columnOptions = BulkCoopReport.columnOptions() | ||
$scope.gridOptions = BulkCoopReport.gridOptions(reportType) | ||
$scope.gridOptions.onRegisterApi = (gridApi) -> $scope.gridApi = gridApi | ||
|
||
$scope.load = -> | ||
$scope.loading = true | ||
$scope.loadAttempted = false | ||
$scope.gridOptions.data = [] | ||
params = {} | ||
params["q[#{param}]"] = value for param, value of $scope.q | ||
$http.get('/admin/reports/bulk_coop.json', params: params) | ||
.success (data) -> | ||
LineItems.load data.line_items | ||
Orders.load data.orders | ||
Variants.load data.variants | ||
Products.load data.products | ||
Enterprises.load data.distributors | ||
LineItems.linkToOrders() | ||
LineItems.linkToVariants() | ||
LineItems.linkToProducts() | ||
$scope.gridOptions.data = LineItems.all | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realise that this is work in progress, but we will need to at least have a generic "Loading data failed" message render if data can't be loaded. |
||
.finally -> | ||
$scope.loading = false | ||
$scope.loadAttempted = true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
angular.module("admin.reports").controller "ordersAndDistributorsCtrl", ($scope, $controller, $http, OrdersAndDistributorsReport, Enterprises, LineItems, Orders, Products, Variants) -> | ||
angular.extend this, $controller('ReportsCtrl', {$scope: $scope}) | ||
|
||
$scope.gridOptions = OrdersAndDistributorsReport.gridOptions() | ||
$scope.gridOptions.onRegisterApi = (gridApi) -> $scope.gridApi = gridApi | ||
|
||
$scope.load = -> | ||
$scope.loading = true | ||
$scope.loadAttempted = false | ||
$scope.gridOptions.data = [] | ||
params = {} | ||
params["q[#{param}]"] = value for param, value of $scope.q | ||
$http.get('/admin/reports/orders_and_distributors.json', params: params) | ||
.success (data) -> | ||
LineItems.load data.line_items | ||
Orders.load data.orders | ||
Variants.load data.variants | ||
Products.load data.products | ||
Enterprises.load data.distributors | ||
|
||
Orders.linkToDistributors() | ||
LineItems.linkToOrders() | ||
LineItems.linkToVariants() | ||
$scope.gridOptions.data = LineItems.all | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto with error message |
||
.finally -> | ||
$scope.loading = false | ||
$scope.loadAttempted = true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
angular.module("admin.reports").controller "ordersAndFulfillmentsCtrl", ($scope, $controller, $http, $location, OrdersAndFulfillmentsReport, Enterprises, OrderCycles, LineItems, Orders, Products, Variants, shops, producers, reportType) -> | ||
angular.extend this, $controller('ReportsCtrl', {$scope: $scope, $location: $location}) | ||
|
||
$scope.shops = shops | ||
$scope.producers = producers | ||
$scope.orderCycles = OrderCycles.all | ||
$scope.columnOptions = OrdersAndFulfillmentsReport.columnOptions() | ||
|
||
if $location.search().report_type | ||
reportType = $location.search().report_type | ||
$scope.q = {report_type: reportType} | ||
$scope.reportType = reportType | ||
|
||
$scope.gridOptions = OrdersAndFulfillmentsReport.gridOptions(reportType) | ||
$scope.gridOptions.onRegisterApi = (gridApi) -> $scope.gridApi = gridApi | ||
|
||
$scope.load = -> | ||
$scope.loading = true | ||
$scope.loadAttempted = false | ||
$scope.gridOptions.data = [] | ||
params = {} | ||
params["q[#{param}]"] = value for param, value of $scope.q | ||
$http.get('/admin/reports/orders_and_fulfillment.json', params: params) | ||
.success (data) -> | ||
LineItems.load data.line_items | ||
Orders.load data.orders | ||
Products.load data.products | ||
Variants.load data.variants | ||
LineItems.linkToOrders() | ||
LineItems.linkToProducts() | ||
$scope.gridOptions.data = LineItems.all | ||
.finally -> | ||
$scope.loading = false | ||
$scope.loadAttempted = true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
angular.module("admin.reports").controller 'ReportsCtrl', ($scope, $location) -> | ||
$scope.loading = false | ||
$scope.loadAttempted = false | ||
|
||
$scope.download = ($event, type, visibility = 'all') -> | ||
$event.stopPropagation() | ||
$event.preventDefault() | ||
if type == 'csv' | ||
$scope.gridApi.exporter.csvExport(visibility, visibility) | ||
else | ||
$scope.gridApi.exporter.pdfExport(visibility, visibility) | ||
|
||
$scope.reload = -> | ||
$scope.loading = false | ||
$scope.loadAttempted = false | ||
$scope.reportType = $scope.q.report_type | ||
$scope.gridOptions.columnDefs = $scope.$eval('columnOptions.' + $scope.reportType) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need |
||
$location.search('report_type', $scope.reportType) | ||
$scope.gridOptions.data = new Array() | ||
$scope.gridApi.grid.refresh() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
angular.module("admin.reports").filter "customCurrency", ($filter, currencyConfig) -> | ||
return (value) -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could rename this as |
||
value = 0 if !value | ||
if currencyConfig && currencyConfig.currency | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By requesting |
||
return currencyConfig.symbol + parseFloat(value).toFixed(2) | ||
else | ||
return parseFloat(value).toFixed(2) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
angular.module("admin.reports", ['admin.indexUtils', 'ui.grid', 'ui.grid.resizeColumns', 'ui.grid.moveColumns', 'ui.grid.grouping', 'ui.grid.exporter', 'admin.resources']) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
angular.module("admin.reports").factory 'BulkCoopReport', (uiGridGroupingConstants, UIGridReport) -> | ||
new class BulkCoopReport extends UIGridReport | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This bit is awesome 👍 |
||
|
||
columnOptions: -> | ||
{supplier_report: [ | ||
{ field: 'id', displayName: 'Line Item ID', width: '5%', visible: false, groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'product.producer.name', displayName: 'Supplier', width: '15%', sort: { priority: 0, direction: 'asc' }, grouping: { groupPriority: 1 }, groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'product.name', displayName: 'Product', width: '15%', sort: { priority: 1, direction: 'asc' }, grouping: { groupPriority: 10 }, groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'product.group_buy_unit_size', displayName: 'Bulk Unit size', width: '8%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false, treeAggregationType: uiGridGroupingConstants.aggregation.SUM, customTreeAggregationFinalizerFn: @basicFinalizer } | ||
{ field: 'full_name', displayName: 'Variant', width: '10%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'variant.value', displayName: 'Variant value', width: '10%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'variant.unit', displayName: 'Variant unit', width: '10%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'variant.weight_from_unit_value', displayName: 'Weight', width: '8%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'scaled_final_weight_volume', displayName: 'Sum Total', width: '8%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false, treeAggregationType: uiGridGroupingConstants.aggregation.SUM, customTreeAggregationFinalizerFn: @basicFinalizer } | ||
{ field: 'units_required', displayName: 'Units required', width: '8%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false, treeAggregationType: uiGridGroupingConstants.aggregation.SUM, customTreeAggregationFinalizerFn: @basicFinalizer } | ||
{ field: 'remainder', displayName: 'Unallocated', width: '8%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false, treeAggregationType: uiGridGroupingConstants.aggregation.SUM, customTreeAggregationFinalizerFn: @basicFinalizer } | ||
{ field: 'max_quantity_excess', displayName: 'Max quantity excess', width: '8%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false, treeAggregationType: uiGridGroupingConstants.aggregation.SUM, customTreeAggregationFinalizerFn: @basicFinalizer } | ||
], | ||
allocation: [ | ||
{ field: 'id', displayName: 'Line Item ID', width: '5%', visible: false, groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'order.customer', displayName: 'Customer', width: '15%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'product.name', displayName: 'Product', width: '15%', sort: { priority: 0, direction: 'asc' }, grouping: { groupPriority: 0 }, groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'product.group_buy_unit_size', displayName: 'Bulk Unit size', width: '8%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'full_name', displayName: 'Variant', width: '10%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'variant.value', displayName: 'Variant value', width: '10%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'variant.unit', displayName: 'Variant unit', width: '10%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'variant.weight_from_unit_value', displayName: 'Weight', width: '8%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'scaled_final_weight_volume', displayName: 'Sum Total', width: '8%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false, treeAggregationType: uiGridGroupingConstants.aggregation.SUM, customTreeAggregationFinalizerFn: @basicFinalizer } | ||
{ field: 'total_available', displayName: 'Total available', width: '8%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false, treeAggregationType: uiGridGroupingConstants.aggregation.SUM, customTreeAggregationFinalizerFn: @basicFinalizer } | ||
{ field: 'remainder', displayName: 'Unallocated', width: '8%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'max_quantity_excess', displayName: 'Max quantity excess', width: '8%', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false, treeAggregationType: uiGridGroupingConstants.aggregation.SUM, customTreeAggregationFinalizerFn: @basicFinalizer } | ||
], | ||
packing_sheets: [ | ||
{ field: 'id', displayName: 'Line Item ID', width: '*', visible: false, groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'order.customer', displayName: 'Customer', width: '*', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'product.name', displayName: 'Product', width: '*', sort: { priority: 0, direction: 'asc' }, groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'full_name', displayName: 'Variant', width: '*', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'quantity', displayName: 'Sum total', width: '*', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
], | ||
customer_payments: [ | ||
{ field: 'order.id', displayName: 'Order ID', width: '*', visible: false, grouping: { groupPriority: 0 }, groupingShowAggregationMenu: false, groupingShowGroupingMenu: false } | ||
{ field: 'order.customer', displayName: 'Customer', width: '*', groupingShowAggregationMenu: false, groupingShowGroupingMenu: false, treeAggregationType: uiGridGroupingConstants.aggregation.CUSTOM, customTreeAggregationFn: @orderAggregator, customTreeAggregationFinalizerFn: @customerFinalizer } | ||
{ field: 'order.completed_at', displayName: 'Date of order', width: '*', sort: { priority: 0, direction: 'asc' }, groupingShowAggregationMenu: false, groupingShowGroupingMenu: false, treeAggregationType: uiGridGroupingConstants.aggregation.CUSTOM, customTreeAggregationFn: @orderAggregator, customTreeAggregationFinalizerFn: @orderDateFinalizer } | ||
{ field: 'order.total', displayName: 'Total cost', width: '*', cellFilter: "customCurrency", groupingShowAggregationMenu: false, groupingShowGroupingMenu: false, treeAggregationType: uiGridGroupingConstants.aggregation.CUSTOM, customTreeAggregationFn: @orderAggregator, customTreeAggregationFinalizerFn: @orderTotalFinalizer } | ||
{ field: 'order.outstanding_balance', displayName: 'Amount owing', width: '*', cellFilter: "customCurrency", groupingShowAggregationMenu: false, groupingShowGroupingMenu: false, treeAggregationType: uiGridGroupingConstants.aggregation.CUSTOM, customTreeAggregationFn: @orderAggregator, customTreeAggregationFinalizerFn: @orderOutstandingBalanceFinalizer } | ||
{ field: 'order.payment_total', displayName: 'Amount paid', width: '*', cellFilter: "customCurrency", groupingShowAggregationMenu: false, groupingShowGroupingMenu: false, treeAggregationType: uiGridGroupingConstants.aggregation.CUSTOM, customTreeAggregationFn: @orderAggregator, customTreeAggregationFinalizerFn: @orderPaymentTotalFinalizer } | ||
] | ||
} | ||
|
||
gridOptions: (reportType = 'supplier_report') -> | ||
enableSorting: true | ||
enableFiltering: true | ||
enableGridMenu: true | ||
exporterMenuAllData: false | ||
exporterMenuVisibleData: false | ||
exporterPdfDefaultStyle: {fontSize: 6 } | ||
exporterPdfTableHeaderStyle: { fontSize: 5, bold: true } | ||
exporterPdfTableStyle: { width: 'auto'} | ||
exporterPdfMaxGridWidth: 600 | ||
columnDefs: eval('this.columnOptions().' + reportType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really what this directive is for. If you need to change the datepicker elements to rails form elements rather than pure angular elements, I would suggest removing the
ng-model
directive altogether (it is doing nothing) and using our customwatch-value-as
directive instead.That said, my preference (instead of c35a165) would be to inject the search data as a service, and have everything be pure angular from there on. I don't like hacking rails form elements to make them 'work' with angular. Too many pitfalls, and too hard to work out what is going wrong when you have multiple custom directives all trying to manipulate the value of the form element directly.