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

Fix HETS-1344 #2216

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 7 additions & 6 deletions Server/HetsApi/Controllers/DistrictEquipmentTypeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,19 @@ public virtual ActionResult<DistrictEquipmentTypeAgreementSummary> DistrictEquip
{
// get user's district
int? districtId = UserAccountHelper.GetUsersDistrictId(_context);

var summary = _context.HetRentalAgreements.AsNoTracking()
.Include(x => x.Equipment.DistrictEquipmentType)
.Where(x => x.DistrictId == districtId &&
!x.Number.StartsWith("BCBid"))
.ToList()
.GroupBy(x => x.Equipment.DistrictEquipmentType, (t, agreements) => new DistrictEquipmentTypeAgreementSummary
.Include(x => x.Equipment.DistrictEquipmentType)
.Where(x => x.DistrictId == districtId &&
!x.Number.StartsWith("BCBid"))
.ToList()
.OrderByDescending(x => x.DatedOn).GroupBy(x => x.Equipment.DistrictEquipmentTypeId).Select(x => x.FirstOrDefault()).ToList()
.GroupBy(x => x.Equipment.DistrictEquipmentType, (t, agreements) => new DistrictEquipmentTypeAgreementSummary
{
Id = t.DistrictEquipmentTypeId,
Name = t.DistrictEquipmentName,
AgreementIds = agreements.Select(y => y.RentalAgreementId).Distinct().ToList(),
ProjectIds = agreements.Select(y => y.ProjectId).Distinct().ToList(),

})
.ToList();

Expand Down
79 changes: 70 additions & 9 deletions client/src/js/views/AitReport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const THIS_FISCAL = 'This Fiscal';
const LAST_FISCAL = 'Last Fiscal';
const CUSTOM = 'Custom';

var projectsRetrieved = [];
var districtEquipmentTypesRetrieved = [];
var equipmentRetrieved = [];
var shouldReRender = true;

class AitReport extends React.Component {
static propTypes = {
currentUser: PropTypes.object,
Expand All @@ -53,6 +58,7 @@ class AitReport extends React.Component {
constructor(props) {
super(props);


var today = Moment();

this.state = {
Expand All @@ -69,6 +75,7 @@ class AitReport extends React.Component {
sortField: props.ui.sortField || 'rentalAgreementNumber',
sortDesc: props.ui.sortDesc === true,
},

};
}

Expand Down Expand Up @@ -108,6 +115,8 @@ class AitReport extends React.Component {
Api.getDistrictEquipmentTypesAgreementSummary();
Api.getEquipmentAgreementSummary();



// If this is the first load, then look for a default favourite
if (_.isEmpty(this.props.search)) {
var defaultFavourite = _.find(this.props.favourites, (f) => f.isDefault);
Expand All @@ -117,8 +126,13 @@ class AitReport extends React.Component {
}
}

shouldComponentUpdate = (nextProps, nextState) => {
return shouldReRender;
}

fetch = () => {
Api.searchAitReport(this.buildSearchParams());
shouldReRender = true;
};

search = (e) => {
Expand Down Expand Up @@ -149,6 +163,7 @@ class AitReport extends React.Component {
};

updateSearchState = (state, callback) => {
shouldReRender = false;
this.setState({ search: { ...this.state.search, ...state, ...{ loaded: true } } }, () => {
store.dispatch({
type: Action.UPDATE_AIT_SEARCH,
Expand Down Expand Up @@ -338,10 +353,12 @@ class AitReport extends React.Component {
};

getFilteredDistrictEquipmentType = () => {
return _.chain(this.props.districtEquipmentTypes.data)
.filter((x) => this.matchesDateFilter(x.agreementIds) && this.matchesProjectFilter(x.projectIds))
.sortBy('name')
.value();
var result = _.chain(this.props.districtEquipmentTypes.data)
.filter((x) => this.matchesDateFilter(x.agreementIds) && this.matchesProjectFilter(x.projectIds))
.sortBy('name')
.value();
return result;

};

getFilteredEquipment = () => {
Expand All @@ -356,15 +373,55 @@ class AitReport extends React.Component {
.value();
};

getAllData = () => {
if(projectsRetrieved.length === 0){
projectsRetrieved = _.chain(this.props.projects.data)
.filter((x) => this.matchesDateFilter(x.agreementIds))
.sortBy('name')
.value();
}

if(projectsRetrieved.length > 0){
districtEquipmentTypesRetrieved = _.chain(this.props.districtEquipmentTypes.data)
.filter((x) => this.matchesDateFilter(x.agreementIds) && this.matchesProjectFilter(x.projectIds))
.sortBy('name')
.value();

if(districtEquipmentTypesRetrieved.length > 0){
equipmentRetrieved = _.chain(this.props.equipment.data)
.filter(
(x) =>
this.matchesDateFilter(x.agreementIds) &&
this.matchesProjectFilter(x.projectIds) &&
this.matchesDistrictEquipmentTypeFilter(x.districtEquipmentTypeId)
)
.sortBy('equipmentCode')
.value();
}

}

if(shouldReRender || (projectsRetrieved.length > 0 && districtEquipmentTypesRetrieved.length > 0 && equipmentRetrieved.length > 0)){
shouldReRender = true;
}else{
shouldReRender = false;
}
};

render() {
var resultCount = '';
if (this.props.aitResponses.loaded) {
resultCount = '(' + Object.keys(this.props.aitResponses.data).length + ')';
}

var projects = this.getFilteredProjects();
var districtEquipmentTypes = this.getFilteredDistrictEquipmentType();
var equipment = this.getFilteredEquipment();
// var projects = this.getFilteredProjects();
// var districtEquipmentTypes = this.getFilteredDistrictEquipmentType();
// var equipment = this.getFilteredEquipment();

this.getAllData();
var projects = projectsRetrieved;
var districtEquipmentTypes = districtEquipmentTypesRetrieved;
var equipment = equipmentRetrieved;

return (
<div id="rental-agreement-summary">
Expand Down Expand Up @@ -489,7 +546,9 @@ class AitReport extends React.Component {
}

function mapStateToProps(state) {
return {


var result = {
currentUser: state.user,
agreementSummaryLite: state.lookups.agreementSummaryLite,
projects: state.lookups.projectsAgreementSummary,
Expand All @@ -500,6 +559,8 @@ function mapStateToProps(state) {
search: state.search.aitResponses,
ui: state.ui.aitResponses,
};

return result;
}

export default connect(mapStateToProps)(AitReport);
export default connect(mapStateToProps)(AitReport);
2 changes: 1 addition & 1 deletion openshift/api-build-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kind: Template
apiVersion: v1
apiVersion: template.openshift.io/v1
metadata:
name: ${PROJECT_NAME}
creationTimestamp:
Expand Down
2 changes: 1 addition & 1 deletion openshift/api-deploy-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kind: Template
apiVersion: v1
apiVersion: template.openshift.io/v1
metadata:
name: ${PROJECT_NAME}
creationTimestamp:
Expand Down
2 changes: 1 addition & 1 deletion openshift/backup-deploy-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kind: Template
apiVersion: v1
apiVersion: template.openshift.io/v1
metadata:
name: "${NAME}-deployment-template"
objects:
Expand Down
2 changes: 1 addition & 1 deletion openshift/client-build-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
apiVersion: template.openshift.io/v1
kind: Template
metadata:
creationTimestamp: null
Expand Down
2 changes: 1 addition & 1 deletion openshift/client-deploy-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kind: Template
apiVersion: v1
apiVersion: template.openshift.io/v1
metadata:
name: ${PROJECT_NAME}
creationTimestamp:
Expand Down
2 changes: 1 addition & 1 deletion openshift/postgresql-deploy-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kind: Template
apiVersion: v1
apiVersion: template.openshift.io/v1
metadata:
name: ${PROJECT_NAME}
objects:
Expand Down