Moved from tslint to eslint as tslint was depreciated.
Added prettier and also prettied all the typescript files using prettier ESLint is using the AirBnB rules which are the most strict to lint the files.
This commit is contained in:
@ -1,10 +1,8 @@
|
||||
import {DataSource} from '@angular/cdk/collections';
|
||||
import {Observable} from 'rxjs';
|
||||
import {AttendanceItem} from './attendance';
|
||||
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AttendanceItem } from './attendance';
|
||||
|
||||
export class AttendanceDataSource extends DataSource<AttendanceItem> {
|
||||
|
||||
constructor(private data: Observable<AttendanceItem[]>) {
|
||||
super();
|
||||
}
|
||||
@ -13,6 +11,5 @@ export class AttendanceDataSource extends DataSource<AttendanceItem> {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
disconnect() {}
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {AttendanceResolver} from './attendance-resolver.service';
|
||||
import { AttendanceResolver } from './attendance-resolver.service';
|
||||
|
||||
describe('AttendanceResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [AttendanceResolver]
|
||||
providers: [AttendanceResolver],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -1,16 +1,14 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {AttendanceService} from './attendance.service';
|
||||
import {Attendance} from './attendance';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { AttendanceService } from './attendance.service';
|
||||
import { Attendance } from './attendance';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AttendanceResolver implements Resolve<Attendance> {
|
||||
|
||||
constructor(private ser: AttendanceService) {
|
||||
}
|
||||
constructor(private ser: AttendanceService) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Attendance> {
|
||||
const date = route.paramMap.get('date');
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {AttendanceRoutingModule} from './attendance-routing.module';
|
||||
import { AttendanceRoutingModule } from './attendance-routing.module';
|
||||
|
||||
describe('AttendanceRoutingModule', () => {
|
||||
let attendanceRoutingModule: AttendanceRoutingModule;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {AttendanceResolver} from './attendance-resolver.service';
|
||||
import {AuthGuard} from '../auth/auth-guard.service';
|
||||
import {AttendanceComponent} from './attendance.component';
|
||||
import {AttendanceTypeResolver} from './attendance-type-resolver.service';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
import { AttendanceResolver } from './attendance-resolver.service';
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
import { AttendanceComponent } from './attendance.component';
|
||||
import { AttendanceTypeResolver } from './attendance-type-resolver.service';
|
||||
|
||||
const attendanceRoutes: Routes = [
|
||||
{
|
||||
@ -12,41 +12,32 @@ const attendanceRoutes: Routes = [
|
||||
component: AttendanceComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Attendance'
|
||||
permission: 'Attendance',
|
||||
},
|
||||
resolve: {
|
||||
info: AttendanceResolver,
|
||||
attendanceTypes: AttendanceTypeResolver
|
||||
attendanceTypes: AttendanceTypeResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always'
|
||||
runGuardsAndResolvers: 'always',
|
||||
},
|
||||
{
|
||||
path: ':date',
|
||||
component: AttendanceComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Attendance'
|
||||
permission: 'Attendance',
|
||||
},
|
||||
resolve: {
|
||||
info: AttendanceResolver,
|
||||
attendanceTypes: AttendanceTypeResolver
|
||||
attendanceTypes: AttendanceTypeResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always'
|
||||
}
|
||||
runGuardsAndResolvers: 'always',
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule.forChild(attendanceRoutes)
|
||||
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
],
|
||||
providers: [
|
||||
AttendanceResolver
|
||||
]
|
||||
imports: [CommonModule, RouterModule.forChild(attendanceRoutes)],
|
||||
exports: [RouterModule],
|
||||
providers: [AttendanceResolver],
|
||||
})
|
||||
export class AttendanceRoutingModule {
|
||||
}
|
||||
export class AttendanceRoutingModule {}
|
||||
|
||||
@ -1,16 +1,14 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {AttendanceType} from './attendance-type';
|
||||
import {AttendanceTypeService} from './attendance-type.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { AttendanceType } from './attendance-type';
|
||||
import { AttendanceTypeService } from './attendance-type.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AttendanceTypeResolver implements Resolve<AttendanceType[]> {
|
||||
|
||||
constructor(private ser: AttendanceTypeService) {
|
||||
}
|
||||
constructor(private ser: AttendanceTypeService) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<AttendanceType[]> {
|
||||
return this.ser.list();
|
||||
|
||||
@ -1,23 +1,22 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {ErrorLoggerService} from '../core/error-logger.service';
|
||||
import {AttendanceType} from './attendance-type';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
import { AttendanceType } from './attendance-type';
|
||||
|
||||
const url = '/api/attendance-types';
|
||||
const serviceName = 'AttendanceTypeService';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AttendanceTypeService {
|
||||
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
list(): Observable<AttendanceType[]> {
|
||||
return <Observable<AttendanceType[]>>this.http.get<AttendanceType[]>(url)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
return <Observable<AttendanceType[]>>(
|
||||
this.http
|
||||
.get<AttendanceType[]>(url)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list')))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,46 +8,46 @@
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.present :not(.no-bg){
|
||||
background-color: #228B22;
|
||||
.present :not(.no-bg) {
|
||||
background-color: #228b22;
|
||||
}
|
||||
|
||||
.off-day :not(.no-bg){
|
||||
background-color: #87CEFA;
|
||||
.off-day :not(.no-bg) {
|
||||
background-color: #87cefa;
|
||||
}
|
||||
|
||||
.on-leave :not(.no-bg){
|
||||
background-color: #CD5C5C;
|
||||
.on-leave :not(.no-bg) {
|
||||
background-color: #cd5c5c;
|
||||
}
|
||||
|
||||
.absent :not(.no-bg){
|
||||
background-color: #CD0000;
|
||||
.absent :not(.no-bg) {
|
||||
background-color: #cd0000;
|
||||
}
|
||||
|
||||
.half-day :not(.no-bg){
|
||||
background-color: #98FB98;
|
||||
.half-day :not(.no-bg) {
|
||||
background-color: #98fb98;
|
||||
}
|
||||
|
||||
.double-duty :not(.no-bg){
|
||||
.double-duty :not(.no-bg) {
|
||||
background-color: #006400;
|
||||
}
|
||||
|
||||
.paid-leave-availed :not(.no-bg){
|
||||
background-color: #EEEE00;
|
||||
.paid-leave-availed :not(.no-bg) {
|
||||
background-color: #eeee00;
|
||||
}
|
||||
|
||||
.casual-leave-availed :not(.no-bg){
|
||||
.casual-leave-availed :not(.no-bg) {
|
||||
background-color: #800080;
|
||||
}
|
||||
|
||||
.compensatory-off :not(.no-bg){
|
||||
background-color: #F5DEB3;
|
||||
.compensatory-off :not(.no-bg) {
|
||||
background-color: #f5deb3;
|
||||
}
|
||||
|
||||
.half-day-pl :not(.no-bg){
|
||||
background-color: #FFF68F;
|
||||
.half-day-pl :not(.no-bg) {
|
||||
background-color: #fff68f;
|
||||
}
|
||||
|
||||
.half-day-cl :not(.no-bg){
|
||||
background-color: #FF00FF;
|
||||
.half-day-cl :not(.no-bg) {
|
||||
background-color: #ff00ff;
|
||||
}
|
||||
|
||||
@ -6,37 +6,42 @@
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px">
|
||||
<mat-form-field fxFlex="80">
|
||||
<input matInput [matDatepicker]="date" (focus)="date.open()" placeholder="Date" formControlName="date"
|
||||
autocomplete="off">
|
||||
<input
|
||||
matInput
|
||||
[matDatepicker]="date"
|
||||
(focus)="date.open()"
|
||||
placeholder="Date"
|
||||
formControlName="date"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<mat-datepicker-toggle matSuffix [for]="date"></mat-datepicker-toggle>
|
||||
<mat-datepicker #date></mat-datepicker>
|
||||
</mat-form-field>
|
||||
<button mat-raised-button color="primary" (click)="show()" fxFlex="20">Show</button>
|
||||
</div>
|
||||
<mat-table #table [dataSource]="dataSource" formArrayName="attendances">
|
||||
|
||||
<!-- Code Column -->
|
||||
<ng-container matColumnDef="code">
|
||||
<mat-header-cell *matHeaderCellDef class="right">Code</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row" class="right">{{row.code}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row" class="right">{{ row.code }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.name}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.name }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Designation Column -->
|
||||
<ng-container matColumnDef="designation">
|
||||
<mat-header-cell *matHeaderCellDef>Designation</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.designation}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.designation }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Department Column -->
|
||||
<ng-container matColumnDef="department">
|
||||
<mat-header-cell *matHeaderCellDef>Department</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.department}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.department }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Status Column -->
|
||||
@ -55,23 +60,34 @@
|
||||
<ng-container matColumnDef="prints">
|
||||
<mat-header-cell *matHeaderCellDef>Prints</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row; let i = index" class="no-bg">
|
||||
{{row.prints}}
|
||||
<mat-icon *ngIf="!form.controls.attendances.controls[i].pristine">new_releases</mat-icon>
|
||||
{{ row.prints }}
|
||||
<mat-icon *ngIf="!form.controls.attendances.controls[i].pristine"
|
||||
>new_releases</mat-icon
|
||||
>
|
||||
<mat-chip-list class="no-bg">
|
||||
<mat-chip *ngIf="row.hoursWorked.length" class="no-bg" [selected]="true"
|
||||
[color]="row.fullDay === true ? 'primary' : 'warn'">
|
||||
{{row.hoursWorked}}
|
||||
<mat-chip
|
||||
*ngIf="row.hoursWorked.length"
|
||||
class="no-bg"
|
||||
[selected]="true"
|
||||
[color]="row.fullDay === true ? 'primary' : 'warn'"
|
||||
>
|
||||
{{ row.hoursWorked }}
|
||||
</mat-chip>
|
||||
</mat-chip-list>
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; let i = index; columns: displayedColumns;" [class]="getClass(i)"></mat-row>
|
||||
<mat-row
|
||||
*matRowDef="let row; let i = index; columns: displayedColumns"
|
||||
[class]="getClass(i)"
|
||||
></mat-row>
|
||||
</mat-table>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button mat-raised-button color="primary" (click)="save()" [disabled]="form.pristine">Save</button>
|
||||
<button mat-raised-button color="primary" (click)="save()" [disabled]="form.pristine">
|
||||
Save
|
||||
</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {AttendanceComponent} from './attendance.component';
|
||||
import { AttendanceComponent } from './attendance.component';
|
||||
|
||||
describe('AttendanceComponent', () => {
|
||||
let component: AttendanceComponent;
|
||||
@ -8,9 +8,8 @@ describe('AttendanceComponent', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [AttendanceComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
declarations: [AttendanceComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@ -1,20 +1,20 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {FormArray, FormBuilder, FormGroup} from '@angular/forms';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {BehaviorSubject} from 'rxjs';
|
||||
import {AttendanceDataSource} from './attendance-datasource';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { AttendanceDataSource } from './attendance-datasource';
|
||||
import * as moment from 'moment';
|
||||
import {AuthService} from '../auth/auth.service';
|
||||
import {ToasterService} from '../core/toaster.service';
|
||||
import {AttendanceService} from './attendance.service';
|
||||
import {AttendanceType} from './attendance-type';
|
||||
import {Attendance, AttendanceItem} from './attendance';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
import { AttendanceService } from './attendance.service';
|
||||
import { AttendanceType } from './attendance-type';
|
||||
import { Attendance, AttendanceItem } from './attendance';
|
||||
|
||||
@Component({
|
||||
selector: 'app-attendance',
|
||||
templateUrl: './attendance.component.html',
|
||||
styleUrls: ['./attendance.component.css']
|
||||
styleUrls: ['./attendance.component.css'],
|
||||
})
|
||||
export class AttendanceComponent implements OnInit {
|
||||
public attendanceObservable = new BehaviorSubject<AttendanceItem[]>([]);
|
||||
@ -33,7 +33,7 @@ export class AttendanceComponent implements OnInit {
|
||||
private dialog: MatDialog,
|
||||
private toaster: ToasterService,
|
||||
private auth: AuthService,
|
||||
private ser: AttendanceService
|
||||
private ser: AttendanceService,
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
@ -41,32 +41,34 @@ export class AttendanceComponent implements OnInit {
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
date: '',
|
||||
attendances: this.fb.array([])
|
||||
attendances: this.fb.array([]),
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { info: Attendance, attendanceTypes: AttendanceType[] }) => {
|
||||
this.info = data.info;
|
||||
this.attendanceTypes = data.attendanceTypes;
|
||||
this.form.get('date').setValue(moment(this.info.date, 'DD-MMM-YYYY').toDate());
|
||||
this.form.setControl('attendances', this.fb.array(
|
||||
this.info.body.map(
|
||||
x => this.fb.group({
|
||||
attendanceType: x.attendanceType.id
|
||||
})
|
||||
)
|
||||
));
|
||||
this.dataSource = new AttendanceDataSource(this.attendanceObservable);
|
||||
this.attendanceObservable.next(this.info.body);
|
||||
});
|
||||
this.route.data.subscribe((data: { info: Attendance; attendanceTypes: AttendanceType[] }) => {
|
||||
this.info = data.info;
|
||||
this.attendanceTypes = data.attendanceTypes;
|
||||
this.form.get('date').setValue(moment(this.info.date, 'DD-MMM-YYYY').toDate());
|
||||
this.form.setControl(
|
||||
'attendances',
|
||||
this.fb.array(
|
||||
this.info.body.map((x) =>
|
||||
this.fb.group({
|
||||
attendanceType: x.attendanceType.id,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
this.dataSource = new AttendanceDataSource(this.attendanceObservable);
|
||||
this.attendanceObservable.next(this.info.body);
|
||||
});
|
||||
}
|
||||
|
||||
getClass(index: number) {
|
||||
const array = this.form.get('attendances') as FormArray;
|
||||
const id = array.controls[index].value.attendanceType;
|
||||
const name: string = this.attendanceTypes.filter(x => x.id === id)[0].name;
|
||||
const name: string = this.attendanceTypes.filter((x) => x.id === id)[0].name;
|
||||
return name.toLowerCase().replace(/(\s+\+\s+)|(\s+)/g, '-');
|
||||
}
|
||||
|
||||
@ -76,15 +78,14 @@ export class AttendanceComponent implements OnInit {
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.save(this.getAttendance())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.save(this.getAttendance()).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
getAttendance(): Attendance {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {AttendanceModule} from './attendance.module';
|
||||
import { AttendanceModule } from './attendance.module';
|
||||
|
||||
describe('AttendanceModule', () => {
|
||||
let attendanceModule: AttendanceModule;
|
||||
|
||||
@ -1,11 +1,16 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatChipsModule } from '@angular/material/chips';
|
||||
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE, MatNativeDateModule } from '@angular/material/core';
|
||||
import {
|
||||
DateAdapter,
|
||||
MAT_DATE_FORMATS,
|
||||
MAT_DATE_LOCALE,
|
||||
MatNativeDateModule,
|
||||
} from '@angular/material/core';
|
||||
import { MatDatepickerModule } from '@angular/material/datepicker';
|
||||
import { MatDialogModule } from '@angular/material/dialog';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
@ -16,14 +21,14 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatSortModule } from '@angular/material/sort';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import {SharedModule} from '../shared/shared.module';
|
||||
import {ReactiveFormsModule} from '@angular/forms';
|
||||
import {CdkTableModule} from '@angular/cdk/table';
|
||||
import {AttendanceRoutingModule} from './attendance-routing.module';
|
||||
import {AttendanceComponent} from './attendance.component';
|
||||
import {MomentDateAdapter} from '@angular/material-moment-adapter';
|
||||
import {A11yModule} from '@angular/cdk/a11y';
|
||||
import {FlexLayoutModule} from '@angular/flex-layout';
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { CdkTableModule } from '@angular/cdk/table';
|
||||
import { AttendanceRoutingModule } from './attendance-routing.module';
|
||||
import { AttendanceComponent } from './attendance.component';
|
||||
import { MomentDateAdapter } from '@angular/material-moment-adapter';
|
||||
import { A11yModule } from '@angular/cdk/a11y';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
|
||||
export const MY_FORMATS = {
|
||||
parse: {
|
||||
@ -61,15 +66,12 @@ export const MY_FORMATS = {
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
SharedModule,
|
||||
AttendanceRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
AttendanceComponent
|
||||
AttendanceRoutingModule,
|
||||
],
|
||||
declarations: [AttendanceComponent],
|
||||
providers: [
|
||||
{provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
|
||||
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS},
|
||||
]
|
||||
{ provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
|
||||
{ provide: MAT_DATE_FORMATS, useValue: MY_FORMATS },
|
||||
],
|
||||
})
|
||||
export class AttendanceModule {
|
||||
}
|
||||
export class AttendanceModule {}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {VoucherService} from './attendance.service';
|
||||
import { VoucherService } from './attendance.service';
|
||||
|
||||
describe('AttendanceService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [VoucherService]
|
||||
providers: [VoucherService],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -1,35 +1,35 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
import {Attendance} from './attendance';
|
||||
import {ErrorLoggerService} from '../core/error-logger.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Attendance } from './attendance';
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
|
||||
const url = '/api/attendance';
|
||||
const serviceName = 'AttendanceService';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AttendanceService {
|
||||
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(date: string): Observable<Attendance> {
|
||||
const getUrl: string = (date === null) ? url : `${url}/${date}`;
|
||||
return <Observable<Attendance>>this.http.get<Attendance>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get date=${date}`))
|
||||
);
|
||||
const getUrl: string = date === null ? url : `${url}/${date}`;
|
||||
return <Observable<Attendance>>(
|
||||
this.http
|
||||
.get<Attendance>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get date=${date}`)))
|
||||
);
|
||||
}
|
||||
|
||||
save(attendance: Attendance): Observable<Attendance> {
|
||||
return <Observable<Attendance>>this.http.post<Attendance>(`${url}/${attendance.date}`, attendance, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
return <Observable<Attendance>>(
|
||||
this.http
|
||||
.post<Attendance>(`${url}/${attendance.date}`, attendance, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'save')))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {AttendanceType} from './attendance-type';
|
||||
import { AttendanceType } from './attendance-type';
|
||||
|
||||
export class Attendance {
|
||||
date: string;
|
||||
|
||||
Reference in New Issue
Block a user