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

Training Reports updates #221

Merged
merged 7 commits into from
Feb 22, 2024
Merged
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
1 change: 1 addition & 0 deletions api/models/dto/TrainingReportDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class TrainingReportDto
public bool excluded { get; set; }
public Guid sheriffId { get; set; }
public string status { get; set; }
public string location { get; set; }
public string _rowVariant { get; set; }
}
}
2 changes: 1 addition & 1 deletion api/models/dto/TrainingReportSearchDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class TrainingReportSearchDto
{
public int? regionId { get; set; }
public int? locationId { get; set; }
public int? reportSubtypeId { get; set; }
public int[]? reportSubtypeIds { get; set; }
public DateTimeOffset? startDate { get; set; }
public DateTimeOffset? endDate { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions api/services/ManageTypesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ public async Task<List<LookupCode>> GetAll(LookupTypes? codeType, int? locationI
return lookupCodes;
}

public async Task<List<LookupCode>> GetAllForReports(int? id, LookupTypes? codeType, int? locationId, bool? mandatory, bool showExpired = false)
public async Task<List<LookupCode>> GetAllForReports(int[]? ids, LookupTypes? codeType, int? locationId, bool? mandatory, bool showExpired = false)
{
var lookupCodes = await Db.LookupCode.AsNoTracking()
.Include(lc => lc.SortOrder.Where(so => so.LocationId == locationId))
.Where(lc =>
(id == null || lc.Id == id) &&
(ids == null || ids.Length==0 || ids.Contains(lc.Id)) &&
(codeType == null || lc.Type == codeType) &&
(locationId == null || lc.LocationId == null || lc.LocationId == locationId) &&
(mandatory == null || lc.Mandatory == mandatory) &&
Expand Down
72 changes: 60 additions & 12 deletions api/services/usermanagement/TrainingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public async Task<List<TrainingReportDto>> GetSheriffsTrainingReports(TrainingRe

var sheriffs = await sheriffQuery.ToListAsync();

List<LookupCode> mandatoryTrainings = await ManageTypesService.GetAllForReports(trainingReportSearch.reportSubtypeId, LookupTypes.TrainingType, null, true, false);
List<LookupCode> optionalTrainings = await ManageTypesService.GetAllForReports(trainingReportSearch.reportSubtypeId, LookupTypes.TrainingType, null, false, false);
List<LookupCode> mandatoryTrainings = await ManageTypesService.GetAllForReports(trainingReportSearch.reportSubtypeIds, LookupTypes.TrainingType, null, true, false);
List<LookupCode> optionalTrainings = await ManageTypesService.GetAllForReports(trainingReportSearch.reportSubtypeIds, LookupTypes.TrainingType, null, false, false);

var sheriffTrainings = new List<TrainingReportDto>();

Expand All @@ -100,6 +100,7 @@ public async Task<List<TrainingReportDto>> GetSheriffsTrainingReports(TrainingRe
sheriffTrainings.Add(new TrainingReportDto()
{
name = sheriff.FirstName + ' ' + sheriff.LastName,
location = sheriff.HomeLocation.Name,
trainingType = training.Description,
end = null,
expiryDate = null,
Expand All @@ -111,13 +112,29 @@ public async Task<List<TrainingReportDto>> GetSheriffsTrainingReports(TrainingRe
}
else
{
var takenTraining = sheriff.Training.Find(t => t.TrainingTypeId == training.Id);
var timezone = takenTraining.Timezone == null? "America/Vancouver" : takenTraining.Timezone;
var trainingStatus = GetTrainingStatus(takenTraining.TrainingCertificationExpiry, timezone, training.AdvanceNotice, training, takenTraining.FirstNotice);
var takenTrainings = sheriff.Training.FindAll(t => t.TrainingTypeId == training.Id).OrderByDescending(t => t.EndDate).ToList();
var takenTraining = new SheriffTraining();
var timezone = "";

TrainingStatus trainingStatus = new TrainingStatus();
if(trainingReportSearch.startDate != null && trainingReportSearch.endDate != null)
{
var takenTrainingInRange = takenTrainings.Find(t => t.EndDate < trainingReportSearch.endDate);
takenTraining = takenTrainingInRange !=null ? takenTrainingInRange : takenTrainings.LastOrDefault();
timezone = takenTraining.Timezone == null? "America/Vancouver" : takenTraining.Timezone;
trainingStatus = GetTrainingStatusOnDateRange(trainingReportSearch, takenTraining.TrainingCertificationExpiry, timezone, training, takenTraining.EndDate);
}
else
{
takenTraining = takenTrainings[0];
timezone = takenTraining.Timezone == null? "America/Vancouver" : takenTraining.Timezone;
trainingStatus = GetTrainingStatus(takenTraining.TrainingCertificationExpiry, timezone, training.AdvanceNotice, training, takenTraining.FirstNotice);
}

sheriffTrainings.Add(new TrainingReportDto()
{
name = sheriff.FirstName + ' ' + sheriff.LastName,
location = sheriff.HomeLocation.Name,
trainingType = training.Description,
end = takenTraining.EndDate.ConvertToTimezone(timezone),
expiryDate = takenTraining.TrainingCertificationExpiry != null ? ((DateTimeOffset)takenTraining.TrainingCertificationExpiry).ConvertToTimezone(timezone): null,
Expand All @@ -132,13 +149,13 @@ public async Task<List<TrainingReportDto>> GetSheriffsTrainingReports(TrainingRe

Logger.LogInformation("__________End_Creating_Reports____________");

if(trainingReportSearch.startDate != null && trainingReportSearch.endDate != null)
return sheriffTrainings.FindAll(t =>
t.end>=trainingReportSearch.startDate &&
t.end<=trainingReportSearch.endDate
);
else
return sheriffTrainings;
// if(trainingReportSearch.startDate != null && trainingReportSearch.endDate != null)
// return sheriffTrainings.FindAll(t =>
// t.end>=trainingReportSearch.startDate &&
// t.end<=trainingReportSearch.endDate
// );
// else
return sheriffTrainings;
}

#endregion Training Reports
Expand Down Expand Up @@ -221,6 +238,37 @@ private TrainingStatus GetTrainingStatus(DateTimeOffset? requalificationDate, s
return trainingStatus;
}

private TrainingStatus GetTrainingStatusOnDateRange(TrainingReportSearchDto trainingReportSearch, DateTimeOffset? requalificationDate, string timezone, LookupCode trainingType, DateTimeOffset trainingCompletionDate)
{
TrainingStatus trainingStatus = new TrainingStatus();

var reportEndDate = ((DateTimeOffset)trainingReportSearch.endDate).ConvertToTimezone(timezone);
var expiryDate = IsRotatingTraining(trainingType)? requalificationDate : requalificationDate?.AddYears(1);

if(reportEndDate > expiryDate)
{
trainingStatus.rowType = "alert";
trainingStatus.status = TrainingStatusTypes.alert;
}
else if(reportEndDate > requalificationDate)
{
trainingStatus.rowType = "warning";
trainingStatus.status = TrainingStatusTypes.warning;
}
else if(reportEndDate >= trainingCompletionDate && (reportEndDate <= requalificationDate || requalificationDate == null) )
{
trainingStatus.rowType = "white";
trainingStatus.status = "";
}
else
{
trainingStatus.rowType = "danger";
trainingStatus.status = TrainingStatusTypes.danger;
}

return trainingStatus;
}

public bool IsRotatingTraining(LookupCode trainingType){
return trainingType.Rotating || !YearsInDays.Contains(trainingType.ValidityPeriod);
}
Expand Down
3 changes: 3 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@fortawesome/free-solid-svg-icons": "^5.15.1",
"@fortawesome/vue-fontawesome": "^2.0.0",
"@types/underscore": "^1.10.0",
"@mdi/font": "^6.5.95",
"ansi-regex": "^6.0.1",
"axios": "^0.21.4",
"axios-auth-refresh": "^3.2.1",
Expand Down Expand Up @@ -44,6 +45,7 @@
"vue-property-decorator": "^8.4.2",
"vue-resource": "^1.5.3",
"vue-router": "^3.1.6",
"vuetify": "^2.6.3",
"vuex": "^3.3.0",
"vuex-class": "^0.3.2",
"vuex-module-decorators": "^0.17.0"
Expand All @@ -68,6 +70,7 @@
"ts-loader": "^7.0.1",
"tslib": "^1.11.1",
"typescript": "3.8.3",
"vue-cli-plugin-vuetify": "~2.0.5",
"vue-template-compiler": "2.6.11",
"webpack-bundle-analyzer": "^4.5.0"
},
Expand Down
19 changes: 18 additions & 1 deletion web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<link
rel="icon"
href="<%= BASE_URL %>images/bcid-favicon-32x32.png"
sizes="32x32"
type="image/png"
/>
<link
rel="icon"
href="<%= BASE_URL %>images/bcid-favicon-16x16.png"
sizes="16x16"
type="image/png"
/>
<link
rel="mask-icon"
href="<%= BASE_URL %>images/bcid-apple-icon.svg"
color="#036"
/>
<link rel="icon" href="<%= BASE_URL %>images/bcid-favicon-32x32.png" />
<title>Sheriff Scheduling</title>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class Home extends Vue {
location = {} as locationInfoType;

trainingTypeOptions: leaveTrainingTypeInfoType[] = [];
statusOptions: trainingStatusInfoType = { danger:'Not Taken', alert:'Expired', warning:'Requalification <br> Requierd', notify:'Requalify Soon' };
statusOptions: trainingStatusInfoType = { danger:'Not Taken', alert:'Expired', warning:'Requalification <br> Required', notify:'Requalify Soon' };
training: trainingStatusCardInfoType = { danger: [], alert: [], warning: [], notify: [] };

trainingAlert=false;
Expand Down
19 changes: 11 additions & 8 deletions web/src/components/MyTeam/Components/DateRange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@

<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
import moment from 'moment-timezone';
import * as _ from 'underscore';
import Spinner from "@components/Spinner.vue";
// import moment from 'moment-timezone';
// import * as _ from 'underscore';
// import Spinner from "@components/Spinner.vue";
import { dateRangeInfoType } from '@/types/common';


Expand All @@ -74,17 +74,20 @@
}

public onContextStart(ctx) {
console.log(ctx)
// console.log(ctx)
if(this.dateRange.endDate && ctx>this.dateRange.endDate)
this.dateRange.startDate=""
if(!this.dateRange.endDate) this.dateRange.endDate = this.dateRange.startDate
this.dateRange.endDate = "";
// else if(!this.dateRange.endDate)
// this.dateRange.endDate = this.dateRange.startDate;
this.validateDates()
}

public onContextEnd(ctx) {
console.log(ctx)
// console.log(ctx)
if(this.dateRange.startDate && ctx<this.dateRange.startDate)
this.dateRange.endDate=""
this.dateRange.endDate = "";
// else if(!this.dateRange.startDate)
// this.dateRange.startDate = this.dateRange.endDate;
this.validateDates()
}

Expand Down
Loading
Loading