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: fix teaching periods service keys #825

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h3 class="panel-title">Update Teaching Period</h3>
<label class="col-sm-2 control-label" for="enddate">End Date</label>
<div class="col-sm-9">
<div class="col-sm-4 input-group">
<input datepicker-popup="{{format}}" id="enddate" type="text" class="form-control" ng-model="teachingPeriod.endDate" is-open="calOptions.endOpened" ng-required="true" close-text="Close" />
<input datepicker-popup="yyyy-MM-dd" id="enddate" type="text" class="form-control" ng-model="teachingPeriod.endDate" is-open="calOptions.endOpened" ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button class="btn btn-default" type="button" ng-click="open($event,'end')">
<i class="fa fa-calendar"></i>
Expand All @@ -56,7 +56,7 @@ <h3 class="panel-title">Update Teaching Period</h3>
<label class="col-sm-2 control-label" for="activeuntil">Active Until</label>
<div class="col-sm-9">
<div class="col-sm-4 input-group">
<input datepicker-popup="{{format}}" id="activeuntil" type="text" class="form-control" ng-model="teachingPeriod.activeUntil" is-open="calOptions.activeUntilOpened" ng-required="true" close-text="Close" />
<input datepicker-popup="yyyy-MM-dd" id="activeuntil" type="text" class="form-control" ng-model="teachingPeriod.activeUntil" is-open="calOptions.activeUntilOpened" ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button class="btn btn-default" type="button" ng-click="open($event,'active')">
<i class="fa fa-calendar"></i>
Expand Down
23 changes: 9 additions & 14 deletions src/app/api/services/teaching-period.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export class TeachingPeriodService extends CachedEntityService<TeachingPeriod> {

public static readonly rolloverEndpointFormat = 'teaching_periods/:id:/rollover';

constructor( httpClient: HttpClient,
private teachingPeriodBreakService: TeachingPeriodBreakService) {
constructor(httpClient: HttpClient, private teachingPeriodBreakService: TeachingPeriodBreakService) {
super(httpClient, API_URL);

this.mapping.addKeys(
Expand All @@ -23,42 +22,38 @@ export class TeachingPeriodService extends CachedEntityService<TeachingPeriod> {
{
keys: 'startDate',
toEntityFn: MappingFunctions.mapDateToDay,
toJsonFn: MappingFunctions.mapDayToJson
toJsonFn: MappingFunctions.mapDayToJson,
},
{
keys: 'endDate',
toEntityFn: MappingFunctions.mapDateToDay,
toJsonFn: MappingFunctions.mapDayToJson
toJsonFn: MappingFunctions.mapDayToJson,
},
'activeUntil',
'active',
{
keys: 'breaks',
toEntityOp: (data, key, entity) => {
data['breaks']?.forEach(breakJson => {
data['breaks']?.forEach((breakJson) => {
const teachingPeriod = entity as TeachingPeriod;
const breakEntity = this.teachingPeriodBreakService.buildInstance(breakJson);
teachingPeriod.breaksCache.add(breakEntity);
});
}
},
},
{
keys: 'units',
toEntityOp: (data, key, entity) => {
data[key]?.forEach(unitJson => {
data[key]?.forEach((unitJson) => {
const unitService: UnitService = AppInjector.get(UnitService);
const unit = unitService.cache.getOrCreate(
unitJson['id'],
unitService,
unitJson
);
const unit = unitService.cache.getOrCreate(unitJson['id'], unitService, unitJson);
entity.unitsCache.add(unit);
});
}
},
}
);

this.mapping.mapAllKeysToJsonExcept('id', 'unit', 'breaks');
this.mapping.mapAllKeysToJsonExcept('id', 'units', 'breaks');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macite - I think this was the issue, please review

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - this should avoid the issue.

this.cacheBehaviourOnGet = 'cacheQuery';
}

Expand Down
Loading