Skip to content

Commit

Permalink
Merge branch '9900M11AJOS-migrate/unit-table' into add-tii-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jakerenzella committed Nov 8, 2023
2 parents 8311b14 + eb941db commit 733330b
Show file tree
Hide file tree
Showing 11 changed files with 786 additions and 59 deletions.
540 changes: 531 additions & 9 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsdoc": "39.3.6",
"eslint-plugin-prefer-arrow": "1.2.3",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier": "^5.0.1",
"grunt": "^1.0.4",
"grunt-bump": "0.8.0",
"grunt-coffeelint": "0.0.16",
Expand Down Expand Up @@ -162,4 +162,4 @@
"typescript": "~5.1",
"underscore": "^1.8.3"
}
}
}
103 changes: 103 additions & 0 deletions src/app/admin/states/f-units/f-units.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<div class="table-padding">
<div class="flex flex-row gap-8">
<div class="flex-grow flex flex-col gap-8 gap-y-0">
<div class="flex flex-row">
<div>
<h3>Units</h3>
<p>Modify units registered with OnTrack</p>
</div>
<div class="flex-grow"></div>
<div>
<mat-form-field appearance="outline">
<mat-label>Search</mat-label>
<input matInput (keyup)="applyFilter($event)" />
</mat-form-field>
</div>
</div>
<table
class="flex-grow f-table selectable"
mat-table
[dataSource]="dataSource"
matSort
(matSortChange)="sortTableData($event)"
>
<!-- Unit Code Column -->
<ng-container matColumnDef="unit_code" sticky>
<th mat-header-cell *matHeaderCellDef mat-sort-header>Unit Code</th>
<td mat-cell *matCellDef="let element">
<f-chip>{{ element.code }}</f-chip>
</td>
</ng-container>

<!-- Name Column -->
<ng-container matColumnDef="name" sticky>
<th mat-header-cell *matHeaderCellDef mat-sort-header>Name</th>
<td mat-cell *matCellDef="let element">{{ element.name }}</td>
</ng-container>

<!-- Unit Role Column -->
<ng-container matColumnDef="unit_role" sticky>
<th mat-header-cell *matHeaderCellDef mat-sort-header>Unit Role</th>
<td mat-cell *matCellDef="let element">{{ element.myRole }}</td>
</ng-container>

<!-- Teaching Period Column -->
<ng-container matColumnDef="teaching_period" sticky>
<th mat-header-cell *matHeaderCellDef mat-sort-header>Teaching Period</th>
<td mat-cell *matCellDef="let element">
<ng-container *ngIf="element.teachingPeriod; else customTeachingPeriod">
{{ element.teachingPeriod.name }}
</ng-container>

<ng-template #customTeachingPeriod> Custom </ng-template>
</td>
</ng-container>

<!-- Start Date Column -->
<ng-container matColumnDef="start_date" sticky>
<th mat-header-cell *matHeaderCellDef mat-sort-header>Start Time</th>
<td mat-cell *matCellDef="let element">{{ element.startDate | date: 'EEE d MMM y' }}</td>
</ng-container>

<!-- End Date Column -->
<ng-container matColumnDef="end_date" sticky>
<th mat-header-cell *matHeaderCellDef mat-sort-header>End Time</th>
<td mat-cell *matCellDef="let element">{{ element.endDate | date: 'EEE d MMM y' }}</td>
</ng-container>

<!-- Active Column -->
<ng-container matColumnDef="active" sticky>
<th mat-header-cell *matHeaderCellDef mat-sort-header>Active</th>
<td mat-cell *matCellDef="let element">
<!-- If element.teachingPeriod exists -->
<ng-container *ngIf="element.teachingPeriod; else noTeachingPeriod">
<i *ngIf="element.teachingPeriod.active && element.active" class="fa fa-check"></i>
<i *ngIf="!element.teachingPeriod.active || !element.active" class="fa fa-times"></i>
</ng-container>

<!-- If element.teachingPeriod does not exist -->
<ng-template #noTeachingPeriod>
<i *ngIf="element.active" class="fa fa-check"></i>
<i *ngIf="!element.active" class="fa fa-times"></i>
</ng-template>
</td>
</ng-container>

<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr
mat-row
*matRowDef="let row; columns: displayedColumns"
uiSref="units/admin"
[uiParams]="{ unitId: row.id }"
></tr>
</table>
<span class="flex items-center">
<mat-paginator class="mat-elevation-z0" [pageSizeOptions]="[5, 10, 25, 100]"></mat-paginator>
<span class="flex-grow"></span>
<button mat-raised-button color="primary" (click)="createUnit()">
<mat-icon aria-hidden="false" aria-label="Example home icon" class="icon_display">add</mat-icon> Create Unit
</button>
</span>
</div>
</div>
</div>
8 changes: 8 additions & 0 deletions src/app/admin/states/f-units/f-units.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.table-padding {
padding-left: 50px;
padding-right: 50px;
}

.icon_display {
transform: scale(2);
}
Empty file.
101 changes: 101 additions & 0 deletions src/app/admin/states/f-units/f-units.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Component, Inject, AfterViewInit, ViewChild, OnDestroy } from '@angular/core';
import { createUnitModal } from 'src/app/ajs-upgraded-providers';

Check failure on line 2 in src/app/admin/states/f-units/f-units.component.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'createUnitModal' is defined but never used
import { Unit } from 'src/app/api/models/unit';
import { UnitRole } from 'src/app/api/models/unit-role';
import { UnitService } from 'src/app/api/services/unit.service';
import { MatTable, MatTableDataSource } from '@angular/material/table';
import { MatSort, Sort } from '@angular/material/sort';
import { MatPaginator } from '@angular/material/paginator';
import { Subscription } from 'rxjs';

@Component({
selector: 'f-units',
templateUrl: './f-units.component.html',
styleUrls: ['./f-units.component.scss'],
})
export class FUnitsComponent implements AfterViewInit, OnDestroy {
@ViewChild(MatTable, { static: false }) table: MatTable<Unit>;
@ViewChild(MatSort, { static: false }) sort: MatSort;
@ViewChild(MatPaginator, { static: false }) paginator: MatPaginator;

displayedColumns: string[] = [
'unit_code',
'name',
'unit_role',
'teaching_period',
'start_date',
'end_date',
'active',
];
dataSource: MatTableDataSource<Unit>;
clickedRows = new Set<Unit>();

public allUnits: Unit[];
unitRoles: UnitRole[];
dataload: boolean;

private subscriptions: Subscription[] = [];

constructor(
@Inject(createUnitModal) private createUnitModal: any,

Check failure on line 40 in src/app/admin/states/f-units/f-units.component.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type
private unitService: UnitService,
) {
this.dataload = false;
}

ngAfterViewInit(): void {
this.dataSource = new MatTableDataSource(this.unitService.cache.currentValuesClone());
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
this.dataSource.filterPredicate = (data: any, filter: string) => data.matches(filter);

Check failure on line 50 in src/app/admin/states/f-units/f-units.component.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected any. Specify a different type

this.subscriptions.push(
this.unitService.cache.values.subscribe((units) => {
this.dataSource.data = units;
}),
);
}

ngOnDestroy(): void {
this.subscriptions.forEach((s) => s.unsubscribe());
}

createUnit() {
this.createUnitModal.show(this.dataSource);
}

applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value;
this.dataSource.filter = filterValue.trim().toLowerCase();
if (this.dataSource.paginator) {
this.dataSource.paginator.firstPage();
}
}

private sortCompare(aValue: number | string, bValue: number | string, isAsc: boolean) {
return (aValue < bValue ? -1 : 1) * (isAsc ? 1 : -1);
}

// Sorting function to sort data when sort
// event is triggered
sortTableData(sort: Sort) {
if (!sort.active || sort.direction === '') {
return;
}
this.dataSource.data = this.dataSource.data.sort((a, b) => {
const isAsc = sort.direction === 'asc';
switch (sort.active) {
case 'unit_code':
case 'name':
case 'unit_role':
case 'teaching_period':
case 'start_date':
case 'end_date':
case 'active':
return this.sortCompare(a[sort.active], b[sort.active], isAsc);
default:
return 0;
}
});
}
}
71 changes: 24 additions & 47 deletions src/app/admin/states/units/units.tpl.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="container">
<!-- <div class="container">
<div class="large-notice-block" ng-hide="dataLoaded">
<i class="fa fa-pulse fa-2x fa-spinner"></i>
<p>Loading unit details...</p>
Expand All @@ -10,15 +10,9 @@ <h4 class="panel-title">Units</h4>
Modify units registered with {{externalName.value}}
</div>
<form role="search" class="pull-right form-horizontal">
<input
id="searchbar"
class="input-md form-control"
placeholder="Search for units..."
type="search"
ng-model="search"
autocomplete="off"
typeahead="text for text in typeAhead(units) | filter:$viewValue | limitTo:8"
/>
<input id="searchbar" class="input-md form-control" placeholder="Search for units..." type="search"
ng-model="search" autocomplete="off"
typeahead="text for text in typeAhead(units) | filter:$viewValue | limitTo:8" />
<p ng-show="filteredUnits.length < students.length && filteredUnits.length != 0">
Showing {{filteredUnits.length}} of {{users.length}} users.
</p>
Expand All @@ -34,50 +28,39 @@ <h4 class="panel-title">Units</h4>
<thead>
<tr>
<th>
<a ng-click="sortOrder='code'; reverse=!reverse"
>Unit Code <i ng-show="sortOrder=='code'" class="fa fa-caret-{{reverse ? 'down' : 'up'}}"></i
></a>
<a ng-click="sortOrder='code'; reverse=!reverse">Unit Code <i ng-show="sortOrder=='code'"
class="fa fa-caret-{{reverse ? 'down' : 'up'}}"></i></a>
</th>
<th>
<a ng-click="sortOrder='name'; reverse=!reverse"
>Name <i ng-show="sortOrder=='name'" class="fa fa-caret-{{reverse ? 'down' : 'up'}}"></i
></a>
<a ng-click="sortOrder='name'; reverse=!reverse">Name <i ng-show="sortOrder=='name'"
class="fa fa-caret-{{reverse ? 'down' : 'up'}}"></i></a>
</th>
<th>
<a ng-click="sortOrder='unitRole'; reverse=!reverse"
>Unit Role <i ng-show="sortOrder=='unitRole'" class="fa fa-caret-{{reverse ? 'down' : 'up'}}"></i
></a>
<a ng-click="sortOrder='unitRole'; reverse=!reverse">Unit Role <i ng-show="sortOrder=='unitRole'"
class="fa fa-caret-{{reverse ? 'down' : 'up'}}"></i></a>
</th>
<th>
<a ng-click="sortOrder='teachingPeriod.name'; reverse=!reverse"
>Teaching Period<i
ng-show="sortOrder=='teachingPeriod.name'"
class="fa fa-caret-{{reverse ? 'down' : 'up'}}"
></i
></a>
<a ng-click="sortOrder='teachingPeriod.name'; reverse=!reverse">Teaching Period<i
ng-show="sortOrder=='teachingPeriod.name'" class="fa fa-caret-{{reverse ? 'down' : 'up'}}"></i></a>
</th>
<th>
<a ng-click="sortOrder='startDate'; reverse=!reverse"
>Start Date <i ng-show="sortOrder=='startDate'" class="fa fa-caret-{{reverse ? 'down' : 'up'}}"></i
></a>
<a ng-click="sortOrder='startDate'; reverse=!reverse">Start Date <i ng-show="sortOrder=='startDate'"
class="fa fa-caret-{{reverse ? 'down' : 'up'}}"></i></a>
</th>
<th>
<a ng-click="sortOrder='endDate'; reverse=!reverse"
>End Date <i ng-show="sortOrder=='endDate'" class="fa fa-caret-{{reverse ? 'down' : 'up'}}"></i
></a>
<a ng-click="sortOrder='endDate'; reverse=!reverse">End Date <i ng-show="sortOrder=='endDate'"
class="fa fa-caret-{{reverse ? 'down' : 'up'}}"></i></a>
</th>
<th>
<a ng-click="sortOrder='active'; reverse=!reverse"
>Active <i ng-show="sortOrder=='active'" class="fa fa-caret-{{reverse ? 'down' : 'up'}}"></i
></a>
<a ng-click="sortOrder='active'; reverse=!reverse">Active <i ng-show="sortOrder=='active'"
class="fa fa-caret-{{reverse ? 'down' : 'up'}}"></i></a>
</th>
</tr>
</thead>
<tbody>
<tr
ng-repeat="unit in filteredUnits = (units | unitFilter:search) | orderBy:sortOrder:reverse | startFrom:(currentPage - 1) * pageSize | limitTo: pageSize"
ui-sref="units/admin({unitId: unit.id})"
>
ui-sref="units/admin({unitId: unit.id})">
<td>
<label class="label label-info"> {{unit.code}} </label>
</td>
Expand All @@ -101,21 +84,15 @@ <h4 class="panel-title">Units</h4>
</div>
</div>
<div class="panel-footer clearfix">
<pagination
ng-show="filteredUnits.length > pageSize"
total-items="filteredUnits.length"
ng-model="currentPage"
items-per-page="pageSize"
max-size="maxSize"
class="pagination-sm pull-left"
boundary-links="true"
rotate="false"
></pagination>
<pagination ng-show="filteredUnits.length > pageSize" total-items="filteredUnits.length" ng-model="currentPage"
items-per-page="pageSize" max-size="maxSize" class="pagination-sm pull-left" boundary-links="true"
rotate="false"></pagination>
<button class="btn btn-success pull-right" ng-click="createUnit()">
<i class="fa fa-university"></i>
<i class="fa fa-plus"></i>
Create Unit
</button>
</div>
</div>
</div>
</div> -->
<f-units></f-units>
7 changes: 7 additions & 0 deletions src/app/ajs-upgraded-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const rootScope = new InjectionToken('$rootScope');
export const calendarModal = new InjectionToken('CalendarModal');
export const aboutDoubtfireModal = new InjectionToken('AboutDoubtfireModal');
export const plagiarismReportModal = new InjectionToken('PlagiarismReportModal');
export const createUnitModal = new InjectionToken('CreateUnitModal');

// Define a provider for the above injection token...
// It will get the service from AngularJS via the factory
Expand Down Expand Up @@ -131,3 +132,9 @@ export const UnitStudentEnrolmentModalProvider = {
useFactory: (i: any) => i.get('UnitStudentEnrolmentModal'),
deps: ['$injector'],
};

export const CreateUnitModalProvider = {
provide: createUnitModal,
useFactory: (i: any) => i.get('CreateUnitModal'),
deps: ['$injector'],
};
1 change: 1 addition & 0 deletions src/app/common/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { UserService } from 'src/app/api/services/user.service';
import { AuthenticationService, Project, Unit, UnitRole, User } from 'src/app/api/models/doubtfire-model';
import { Subscription } from 'rxjs';
import { MediaObserver } from '@angular/flex-layout';

@Component({
selector: 'app-header',
templateUrl: './header.component.html',
Expand Down
Loading

0 comments on commit 733330b

Please sign in to comment.