diff --git a/seed/static/seed/js/controllers/export_report_modal_controller.js b/seed/static/seed/js/controllers/export_report_modal_controller.js index 630a351621..dda327f45e 100644 --- a/seed/static/seed/js/controllers/export_report_modal_controller.js +++ b/seed/static/seed/js/controllers/export_report_modal_controller.js @@ -6,11 +6,10 @@ angular.module('BE.seed.controller.export_report_modal', []).controller('export_ '$scope', '$uibModalInstance', 'axes_data', - 'cycle_start', - 'cycle_end', + 'cycles', 'inventory_reports_service', // eslint-disable-next-line func-names - function ($scope, $uibModalInstance, axes_data, cycle_start, cycle_end, inventory_reports_service) { + function ($scope, $uibModalInstance, axes_data, cycles, inventory_reports_service) { $scope.export_name = ''; $scope.export_selected = () => { @@ -21,7 +20,7 @@ angular.module('BE.seed.controller.export_report_modal', []).controller('export_ const ext = '.xlsx'; if (!filename.endsWith(ext)) filename += ext; - inventory_reports_service.export_reports_data(axes_data, cycle_start, cycle_end).then((response) => { + inventory_reports_service.export_reports_data(axes_data, cycles).then((response) => { const blob_type = response.headers()['content-type']; const blob = new Blob([response.data], { type: blob_type }); diff --git a/seed/static/seed/js/controllers/inventory_reports_controller.js b/seed/static/seed/js/controllers/inventory_reports_controller.js index ebb6f1af07..744460a36c 100644 --- a/seed/static/seed/js/controllers/inventory_reports_controller.js +++ b/seed/static/seed/js/controllers/inventory_reports_controller.js @@ -54,10 +54,6 @@ angular.module('BE.seed.controller.inventory_reports', []).controller('inventory /* Setup models from "From" and "To" selectors */ $scope.cycles = cycles.cycles; - /* Model for pulldowns, initialized in init below */ - $scope.fromCycle = {}; - $scope.toCycle = {}; - const translateAxisLabel = (label, units) => { let str = ''; str += $translate.instant(label); @@ -123,15 +119,6 @@ angular.module('BE.seed.controller.inventory_reports', []).controller('inventory $scope.chart1Title = ''; $scope.chart2Title = ''; - // Datepickers - const initStartDate = new Date(); - initStartDate.setYear(initStartDate.getFullYear() - 1); - $scope.startDate = initStartDate; - $scope.startDatePickerOpen = false; - $scope.endDate = new Date(); - $scope.endDatePickerOpen = false; - $scope.invalidDates = false; // set this to true when startDate >= endDate; - // Series // the following variable keeps track of which // series will be sent to the graphs when data is updated @@ -252,34 +239,33 @@ angular.module('BE.seed.controller.inventory_reports', []).controller('inventory // specific styling for scatter chart $scope.scatterChart.options.scales.x.suggestedMin = 0; - /* END NEW CHART STUFF */ - - /* UI HANDLERS */ - /* ~~~~~~~~~~~ */ - - // Handle datepicker open/close events - $scope.openStartDatePicker = ($event) => { - $event.preventDefault(); - $event.stopPropagation(); - $scope.startDatePickerOpen = !$scope.startDatePickerOpen; + $scope.cycle_selection = ''; + $scope.selected_cycles = []; + $scope.available_cycles = () => $scope.cycles.filter(({ id }) => !$scope.selected_cycles.includes(id)); + $scope.select_cycle = () => { + const selection = $scope.cycle_selection; + $scope.cycle_selection = ''; + if (!$scope.selected_cycles) { + $scope.selected_cycles = []; + } + $scope.selected_cycles.push(selection); }; - $scope.openEndDatePicker = ($event) => { - $event.preventDefault(); - $event.stopPropagation(); - $scope.endDatePickerOpen = !$scope.endDatePickerOpen; + + $scope.get_cycle_display = (id) => { + const record = _.find($scope.cycles, { id }); + if (record) { + return record.name; + } }; - $scope.$watch('startDate', () => { - $scope.checkInvalidDate(); - }); + $scope.click_remove_cycle = (id) => { + $scope.selected_cycles = $scope.selected_cycles.filter((item) => item !== id); + }; - $scope.$watch('endDate', () => { - $scope.checkInvalidDate(); - }); + /* END NEW CHART STUFF */ - $scope.checkInvalidDate = () => { - $scope.invalidDates = $scope.endDate < $scope.startDate; - }; + /* UI HANDLERS */ + /* ~~~~~~~~~~~ */ /* Update data used by the chart. This will force the charts to re-render */ $scope.updateChartData = () => { @@ -374,8 +360,7 @@ angular.module('BE.seed.controller.inventory_reports', []).controller('inventory yVar: $scope.chartData.yAxisVarName, yLabel: $scope.chartData.yAxisTitle }), - cycle_start: () => $scope.fromCycle.selected_cycle.start, - cycle_end: () => $scope.toCycle.selected_cycle.end + cycles: () => $scope.selected_cycles, } }); }; @@ -398,7 +383,7 @@ angular.module('BE.seed.controller.inventory_reports', []).controller('inventory $scope.chartIsLoading = true; inventory_reports_service - .get_report_data(xVar, yVar, $scope.fromCycle.selected_cycle.start, $scope.toCycle.selected_cycle.end) + .get_report_data(xVar, yVar, $scope.selected_cycles) .then( (data) => { data = data.data; @@ -462,7 +447,7 @@ angular.module('BE.seed.controller.inventory_reports', []).controller('inventory const yVar = $scope.yAxisSelectedItem.varName; $scope.aggChartIsLoading = true; inventory_reports_service - .get_aggregated_report_data(xVar, yVar, $scope.fromCycle.selected_cycle.start, $scope.toCycle.selected_cycle.end) + .get_aggregated_report_data(xVar, yVar, $scope.selected_cycles) .then( (data) => { data = data.aggregated_data; @@ -506,9 +491,7 @@ angular.module('BE.seed.controller.inventory_reports', []).controller('inventory // Save axis and cycle selections localStorage.setItem(localStorageXAxisKey, JSON.stringify($scope.xAxisSelectedItem)); localStorage.setItem(localStorageYAxisKey, JSON.stringify($scope.yAxisSelectedItem)); - - localStorage.setItem(localStorageFromCycleKey, JSON.stringify($scope.fromCycle.selected_cycle)); - localStorage.setItem(localStorageToCycleKey, JSON.stringify($scope.toCycle.selected_cycle)); + localStorage.setItem(localStorageSelectedCycles, JSON.stringify($scope.selected_cycles)); } /* Generate an array of color objects to be used as part of chart configuration @@ -536,19 +519,13 @@ angular.module('BE.seed.controller.inventory_reports', []).controller('inventory return colorsArr; } - var localStorageFromCycleKey = `${base_storage_key}.fromcycle`; - var localStorageToCycleKey = `${base_storage_key}.tocycle`; + var localStorageSelectedCycles = `${base_storage_key}.SelectedCycles`; /* Call the update method so the page initializes with the values set in the scope */ function init() { // Initialize pulldowns - $scope.fromCycle = { - selected_cycle: JSON.parse(localStorage.getItem(localStorageFromCycleKey)) || _.head($scope.cycles) - }; - $scope.toCycle = { - selected_cycle: JSON.parse(localStorage.getItem(localStorageToCycleKey)) || _.last($scope.cycles) - }; + $scope.selected_cycles = JSON.parse(localStorage.getItem(localStorageSelectedCycles)) || [] // Attempt to load selections $scope.updateChartData(); diff --git a/seed/static/seed/js/services/inventory_reports_service.js b/seed/static/seed/js/services/inventory_reports_service.js index 242b597d7e..9f6d436f72 100644 --- a/seed/static/seed/js/services/inventory_reports_service.js +++ b/seed/static/seed/js/services/inventory_reports_service.js @@ -34,9 +34,9 @@ angular.module('BE.seed.service.inventory_reports', []).factory('inventory_repor ] } */ - const get_report_data = (xVar, yVar, start, end) => { + const get_report_data = (xVar, yVar, cycle_ids) => { // Error checks - if (_.some([xVar, yVar, start, end], _.isNil)) { + if (_.some([xVar, yVar, cycle_ids], _.isNil)) { $log.error('#inventory_reports_service.get_report_data(): null parameter'); throw new Error('Invalid Parameter'); } @@ -47,8 +47,7 @@ angular.module('BE.seed.service.inventory_reports', []).factory('inventory_repor params: { x_var: xVar, y_var: yVar, - start, - end + cycle_ids, } }) .then((response) => response.data) @@ -83,9 +82,9 @@ angular.module('BE.seed.service.inventory_reports', []).factory('inventory_repor } } */ - const get_aggregated_report_data = (xVar, yVar, start, end) => { + const get_aggregated_report_data = (xVar, yVar, cycle_ids) => { // Error checks - if (_.some([xVar, yVar, start, end], _.isNil)) { + if (_.some([xVar, yVar, cycle_ids], _.isNil)) { $log.error('#inventory_reports_service.get_aggregated_report_data(): null parameter'); throw new Error('Invalid Parameter'); } @@ -96,21 +95,20 @@ angular.module('BE.seed.service.inventory_reports', []).factory('inventory_repor params: { x_var: xVar, y_var: yVar, - start, - end + cycle_ids, } }) .then((response) => response.data) .catch(() => {}); }; - const export_reports_data = (axes_data, start, end) => { + const export_reports_data = (axes_data, cycle_ids) => { const { xVar } = axes_data; const { xLabel } = axes_data; const { yVar } = axes_data; const { yLabel } = axes_data; // Error checks - if (_.some([xVar, xLabel, yVar, yLabel, start, end], _.isNil)) { + if (_.some([xVar, xLabel, yVar, yLabel, cycle_ids], _.isNil)) { $log.error('#inventory_reports_service.get_aggregated_report_data(): null parameter'); throw new Error('Invalid Parameter'); } @@ -123,8 +121,7 @@ angular.module('BE.seed.service.inventory_reports', []).factory('inventory_repor x_label: xLabel, y_var: yVar, y_label: yLabel, - start, - end + cycle_ids, }, responseType: 'arraybuffer' }) diff --git a/seed/static/seed/partials/inventory_reports.html b/seed/static/seed/partials/inventory_reports.html index 30d09564ce..e140b5c2fa 100644 --- a/seed/static/seed/partials/inventory_reports.html +++ b/seed/static/seed/partials/inventory_reports.html @@ -19,42 +19,34 @@