-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add-tii-integration' of https://github.com/doubtfire-lm…
…s/doubtfire-web into add-tii-integration
- Loading branch information
Showing
17 changed files
with
389 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/app/admin/tii-action-log/tii-action-log.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<div class="action-log-container"> | ||
<div class="flex items-center my-10"> | ||
<h1>Turnitin Actions</h1> | ||
<span class="flex-grow"></span> | ||
<div> | ||
<mat-form-field appearance="outline"> | ||
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter" [(ngModel)]="filter" /> | ||
</mat-form-field> | ||
</div> | ||
</div> | ||
|
||
<table | ||
class="flex-grow f-table selectable" | ||
mat-table | ||
[dataSource]="tiiActionsSource" | ||
matSort | ||
(matSortChange)="sortData($event)" | ||
> | ||
<ng-container matColumnDef="type" sticky> | ||
<th mat-header-cell *matHeaderCellDef mat-sort-header>Action Type</th> | ||
<td mat-cell *matCellDef="let action"> | ||
{{ action.description }} | ||
</td> | ||
</ng-container> | ||
<ng-container matColumnDef="lastRun" sticky> | ||
<th mat-header-cell *matHeaderCellDef mat-sort-header>Last Run</th> | ||
<td mat-cell *matCellDef="let action"> | ||
{{ (action.lastRun ? (action.lastRun | date: 'd LLL y') : "") }} | ||
</td> | ||
</ng-container> | ||
<ng-container matColumnDef="retries" sticky> | ||
<th mat-header-cell *matHeaderCellDef mat-sort-header>Retries</th> | ||
<td mat-cell *matCellDef="let action"> | ||
{{ action.retries }} | ||
</td> | ||
</ng-container> | ||
<ng-container matColumnDef="retry" sticky> | ||
<th mat-header-cell *matHeaderCellDef mat-sort-header>Retry?</th> | ||
<td mat-cell *matCellDef="let action"> | ||
{{ action.retry }} | ||
</td> | ||
</ng-container> | ||
<ng-container matColumnDef="errorCode" sticky> | ||
<th mat-header-cell *matHeaderCellDef mat-sort-header>Error Code</th> | ||
<td mat-cell *matCellDef="let action"> | ||
{{ action.errorCode }} | ||
</td> | ||
</ng-container> | ||
<ng-container matColumnDef="complete" sticky> | ||
<th mat-header-cell *matHeaderCellDef mat-sort-header>Complete?</th> | ||
<td mat-cell *matCellDef="let action"> | ||
{{ action.complete }} | ||
</td> | ||
</ng-container> | ||
<ng-container matColumnDef="errorMessage" sticky> | ||
<th mat-header-cell *matHeaderCellDef mat-sort-header>Error Message</th> | ||
<td mat-cell *matCellDef="let action"> | ||
{{ action.errorMessage }} | ||
</td> | ||
</ng-container> | ||
|
||
<ng-container matColumnDef="tiiActionTools" sticky> | ||
<th mat-header-cell *matHeaderCellDef></th> | ||
<td mat-cell *matCellDef="let action"> | ||
<button | ||
mat-icon-button | ||
aria-label="retry" | ||
color="primary" | ||
(click)="retryAction(action)" | ||
*ngIf="!(action.complete || action.retry)" | ||
> | ||
<mat-icon>redo</mat-icon> | ||
</button> | ||
</td> | ||
</ng-container> | ||
|
||
<!-- Action footer row --> | ||
<ng-container matColumnDef="actions"> | ||
<td mat-footer-cell *matFooterCellDef [colSpan]="columns.length"></td> | ||
</ng-container> | ||
|
||
<tr mat-header-row *matHeaderRowDef="columns"></tr> | ||
<tr | ||
mat-row | ||
*matRowDef="let row; columns: columns" | ||
[style.background]="selectedTaskDefinition === row ? 'lightblue' : ''" | ||
></tr> | ||
</table> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.action-log-container { | ||
padding: 1rem; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/app/admin/tii-action-log/tii-action-log.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { TiiActionLogComponent } from './tii-action-log.component'; | ||
|
||
describe('TiiActionLogComponent', () => { | ||
let component: TiiActionLogComponent; | ||
let fixture: ComponentFixture<TiiActionLogComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [TiiActionLogComponent] | ||
}); | ||
fixture = TestBed.createComponent(TiiActionLogComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { AfterViewInit, Component, ViewChild } from '@angular/core'; | ||
import { MatPaginator } from '@angular/material/paginator'; | ||
import { MatSort, Sort } from '@angular/material/sort'; | ||
import { MatTable, MatTableDataSource } from '@angular/material/table'; | ||
import { TiiAction } from 'src/app/api/models/doubtfire-model'; | ||
import { TiiActionService } from 'src/app/api/services/tii-action.service'; | ||
import { AlertService } from 'src/app/common/services/alert.service'; | ||
|
||
@Component({ | ||
selector: 'f-tii-action-log', | ||
templateUrl: './tii-action-log.component.html', | ||
styleUrls: ['./tii-action-log.component.scss'] | ||
}) | ||
export class TiiActionLogComponent implements AfterViewInit { | ||
@ViewChild(MatTable, { static: false }) table: MatTable<TiiAction>; | ||
@ViewChild(MatSort, { static: false }) sort: MatSort; | ||
@ViewChild(MatPaginator, { static: false }) paginator: MatPaginator; | ||
|
||
public tiiActionsSource: MatTableDataSource<TiiAction>; | ||
public columns: string[] = ['type', 'lastRun', 'retries', 'retry', 'errorMessage', 'tiiActionTools']; //, 'complete', 'retries', 'lastRun', 'errorCode', 'log', 'tiiActionAction']; | ||
public filter: string; | ||
|
||
constructor(private tiiActionService: TiiActionService, private alertService: AlertService) { | ||
|
||
} | ||
|
||
ngAfterViewInit(): void { | ||
this.tiiActionService.query().subscribe((actions) => { | ||
console.log(actions); | ||
this.tiiActionsSource = new MatTableDataSource<TiiAction>(actions); | ||
this.tiiActionsSource.paginator = this.paginator; | ||
this.tiiActionsSource.sort = this.sort; | ||
this.tiiActionsSource.filterPredicate = (data: any, filter: string) => data.matches(filter); | ||
|
||
}); | ||
} | ||
|
||
public sortData(sort: Sort) { | ||
const data = this.tiiActionsSource.data; | ||
|
||
if (!sort.active || sort.direction === '') { | ||
this.tiiActionsSource.data = data; | ||
return; | ||
} | ||
|
||
this.tiiActionsSource.data = data.sort((a, b) => { | ||
const isAsc = sort.direction === 'asc'; | ||
switch (sort.active) { | ||
case 'type': | ||
return this.compare(a.type, b.type, isAsc); | ||
default: | ||
return 0; | ||
} | ||
}); | ||
} | ||
|
||
public compare(a: number | string, b: number | string, isAsc: boolean): number { | ||
return (a < b ? -1 : 1) * (isAsc ? 1 : -1); | ||
} | ||
|
||
applyFilter(filterValue: string) { | ||
this.tiiActionsSource.filter = filterValue.trim().toLowerCase(); | ||
|
||
if (this.tiiActionsSource.paginator) { | ||
this.tiiActionsSource.paginator.firstPage(); | ||
} | ||
} | ||
|
||
public retryAction(action: TiiAction) { | ||
this.tiiActionService.put(action, { | ||
body: { | ||
action: 'retry' | ||
} | ||
}).subscribe({ | ||
next: (updatedAction) => { | ||
action.retry = true; | ||
this.alertService.success('Action has been queued for retry'); | ||
}, | ||
error: (error) => { | ||
this.alertService.error('Failed to queue action for retry'); | ||
} | ||
}); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Entity, EntityCache, EntityMapping } from 'ngx-entity-service'; | ||
import { Observable } from 'rxjs'; | ||
import { Unit } from './doubtfire-model'; | ||
|
||
export class TiiAction extends Entity { | ||
id: number; | ||
type: string; | ||
complete: boolean; | ||
retries: number; | ||
retry: boolean; | ||
lastRun: Date; | ||
errorCode: string; | ||
errorMessage: string; | ||
log: string; | ||
|
||
description: string; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { CachedEntityService, Entity } from 'ngx-entity-service'; | ||
import { TiiAction, Unit, UnitService, UserService } from 'src/app/api/models/doubtfire-model'; | ||
import { Injectable } from '@angular/core'; | ||
import API_URL from 'src/app/config/constants/apiURL'; | ||
import { AppInjector } from 'src/app/app-injector'; | ||
import { MappingFunctions } from './mapping-fn'; | ||
import { MappingProcess } from 'ngx-entity-service/lib/mapping-process'; | ||
|
||
@Injectable() | ||
export class TiiActionService extends CachedEntityService<TiiAction> { | ||
protected readonly endpointFormat = 'tii_actions/:id:'; | ||
|
||
public static readonly rolloverEndpointFormat = 'teaching_periods/:id:/rollover'; | ||
|
||
constructor(httpClient: HttpClient) { | ||
super(httpClient, API_URL); | ||
|
||
this.mapping.addKeys( | ||
'id', | ||
'type', | ||
'description', | ||
'complete', | ||
'retries', | ||
'retry', | ||
{ | ||
keys: 'lastRun', | ||
toEntityFn: MappingFunctions.mapDateToDay, | ||
toJsonFn: MappingFunctions.mapDayToJson, | ||
}, | ||
'errorCode', | ||
'errorMessage', | ||
'log' | ||
); | ||
|
||
this.mapping.addJsonKey('id', 'retry'); | ||
// this.cacheBehaviourOnGet = 'cacheQuery'; | ||
} | ||
|
||
public createInstanceFrom(json: any, other?: any): TiiAction { | ||
return new TiiAction(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { TiiService } from './tii.service'; | ||
|
||
describe('TiiServiceService', () => { | ||
let service: TiiService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(TiiService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.