Commit 842895b7 authored by mechtelm's avatar mechtelm
Browse files

Add contract week days edit in main data

parent 3bf6d618
......@@ -31,26 +31,14 @@ import { ChangePasswordComponent } from './home/change-password.component';
import {AuthInterceptor} from "./auth.interceptor";
import {IqbComponentsModule} from "@lib/iqb-components";
import {MatRadioModule} from "@angular/material/radio";
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE, MatDateFormats} from "@angular/material/core";
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from "@angular/material/core";
import {
MAT_MOMENT_DATE_ADAPTER_OPTIONS,
MAT_MOMENT_DATE_ADAPTER_OPTIONS, MAT_MOMENT_DATE_FORMATS,
MatMomentDateModule,
MomentDateAdapter
} from "@angular/material-moment-adapter";
import 'moment/locale/de';
export const MOMENT_DATE_FORMATS: MatDateFormats = {
parse: {
dateInput: 'D.MM.YYYY'
},
display: {
dateInput: 'DD.MM.YYYY',
monthYearLabel: 'MMMM Y',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MMMM Y'
}
};
@NgModule({
declarations: [
AppComponent,
......@@ -104,7 +92,7 @@ export const MOMENT_DATE_FORMATS: MatDateFormats = {
useClass: MomentDateAdapter,
deps: [MAT_DATE_LOCALE, MAT_MOMENT_DATE_ADAPTER_OPTIONS],
},
{provide: MAT_DATE_FORMATS, useValue: MOMENT_DATE_FORMATS}
{provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS}
],
entryComponents: [
ChangePasswordComponent
......
......@@ -2,7 +2,6 @@ import {Component, Inject} from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import {MAT_DIALOG_DATA} from "@angular/material/dialog";
import {ContractTypeLabels, SexLabels, StaffMember} from "../staff-list.classes";
import {StaffMemberMainDto} from "@lib/dto";
@Component({
template: `
......@@ -20,7 +19,7 @@ import {StaffMemberMainDto} from "@lib/dto";
</mat-form-field>
<mat-form-field>
<mat-label>Anrede</mat-label>
<input matInput formControlName="salutation" placeholder="Anrede">
<input matInput formControlName="title" placeholder="Titel">
</mat-form-field>
<div fxLayout="row">
<mat-label fxFlex="100px">Geschlecht</mat-label>
......@@ -56,6 +55,14 @@ import {StaffMemberMainDto} from "@lib/dto";
<mat-datepicker #pickerContractEnd></mat-datepicker>
</mat-form-field>
</div>
<div fxLayout="row" fxLayoutAlign="space-between center">
<mat-label fxFlex="100px">Arbeitstage</mat-label>
<mat-checkbox formControlName="weekDayMo">Mo</mat-checkbox>
<mat-checkbox formControlName="weekDayTu">Di</mat-checkbox>
<mat-checkbox formControlName="weekDayWe">Mi</mat-checkbox>
<mat-checkbox formControlName="weekDayTh">Do</mat-checkbox>
<mat-checkbox formControlName="weekDayFr">Fr</mat-checkbox>
</div>
</form>
</mat-dialog-content>
......@@ -77,16 +84,21 @@ export class ChangeMainDataComponent {
constructor(private fb: FormBuilder,
@Inject(MAT_DIALOG_DATA) public data: any) {
const staffMemberData = data as StaffMemberMainDto;
const staffMemberData = data as StaffMember;
this.changeMainDataForm = this.fb.group({
name: this.fb.control(staffMemberData.name, [Validators.required]),
firstName: this.fb.control(staffMemberData.firstName, [Validators.required]),
salutation: this.fb.control(staffMemberData.title),
title: this.fb.control(staffMemberData.title),
sex: this.fb.control(staffMemberData.sex),
contractType: this.fb.control(staffMemberData.contractType),
contractStart: this.fb.control(staffMemberData.contractStart ? StaffMember.stringToDate(staffMemberData.contractStart) : ''),
contractEnd: this.fb.control(staffMemberData.contractEnd ? StaffMember.stringToDate(staffMemberData.contractEnd) : ''),
contractUnlimited: this.fb.control(!staffMemberData.contractEnd)
});
contractUnlimited: this.fb.control(!staffMemberData.contractEnd),
weekDayMo: this.fb.control(staffMemberData.weekDayMonday),
weekDayTu: this.fb.control(staffMemberData.weekDayTuesday),
weekDayWe: this.fb.control(staffMemberData.weekDayWednesday),
weekDayTh: this.fb.control(staffMemberData.weekDayThursday),
weekDayFr: this.fb.control(staffMemberData.weekDayFriday)
})
}
}
......@@ -53,20 +53,24 @@ export class MainDataComponent implements OnInit, OnDestroy {
this.appService.dataLoading = true;
const newName: string = (<FormGroup>result).get('name')?.value;
const newFirstName: string = (<FormGroup>result).get('firstName')?.value;
const newTitle: string = (<FormGroup>result).get('title')?.value;
const newSex: string = (<FormGroup>result).get('sex')?.value;
const newSalutation: string = (<FormGroup>result).get('salutation')?.value;
const newContractType: string = (<FormGroup>result).get('contractType')?.value;
const newContractStart = StaffMember.dateToString((<FormGroup>result).get('contractStart')?.value);
const newContractUnlimited: boolean = (<FormGroup>result).get('contractUnlimited')?.value;
const newContractEnd = newContractUnlimited ? '' : StaffMember.dateToString((<FormGroup>result).get('contractEnd')?.value);
const newContractWeekDays = StaffMember.weekDaysToString((<FormGroup>result).get('weekDayMo')?.value,
(<FormGroup>result).get('weekDayTu')?.value, (<FormGroup>result).get('weekDayWe')?.value,
(<FormGroup>result).get('weekDayTh')?.value, (<FormGroup>result).get('weekDayFr')?.value);
const changedData: StaffMemberMainDto = {id: this.mainData.id};
if (newName !== this.mainData.name) changedData.name = newName;
if (newFirstName !== this.mainData.firstName) changedData.firstName = newFirstName;
if (newSex !== this.mainData.sex) changedData.sex = newSex;
if (newSalutation !== this.mainData.salutation) changedData.title = newSalutation;
if (newTitle !== this.mainData.title) changedData.title = newTitle;
if (newContractType !== this.mainData.contractType) changedData.contractType = newContractType;
if (newContractStart !== this.mainData.contractStart) changedData.contractStart = newContractStart;
if (newContractEnd !== this.mainData.contractEnd) changedData.contractEnd = newContractEnd;
if (newContractWeekDays !== this.mainData.contractWeekDays) changedData.contractWeekDays = newContractWeekDays;
this.backendService.changeMainData(changedData).subscribe(
respOk => {
if (respOk) {
......
......@@ -40,14 +40,14 @@ export class StaffMember {
name?: string;
firstName?: string;
idmId?: string;
canonicalName?: string;
contractWeekDays?: string;
contractStart?: string;
contractEnd?: string;
contractType?: string;
payrollId?: string;
address?: string;
sex?: string;
salutation?: string;
title?: string;
get fullName(): string {
return `${this.name}${this.firstName ? ', ' + this.firstName : ''}`
......@@ -56,35 +56,56 @@ export class StaffMember {
get contractData(): string {
let returnText = `${this.contractType ? (ContractTypeLabels as {[key: string]: string})[this.contractType] : '<kein Vertragstyp>'} `;
if (this.contractStart) {
returnText += 'vom ' + this.contractStart + ' ';
returnText += 'vom ' + _moment(this.contractStart).format('DD.MM.YYYY') + ' ';
} else {
returnText += '<kein Start-Datum> '
}
if (this.contractEnd) {
returnText += 'bis ' + this.contractEnd;
returnText += 'bis ' + _moment(this.contractEnd).format('DD.MM.YYYY');
} else {
returnText += ' (unbefristet)'
}
return returnText
}
get weekDayMonday(): boolean {
if (this.contractWeekDays) return this.contractWeekDays.substring(0,1) === 'x';
return true
}
get weekDayTuesday(): boolean {
if (this.contractWeekDays) return this.contractWeekDays.substring(1,2) === 'x';
return true
}
get weekDayWednesday(): boolean {
if (this.contractWeekDays) return this.contractWeekDays.substring(2,3) === 'x';
return true
}
get weekDayThursday(): boolean {
if (this.contractWeekDays) return this.contractWeekDays.substring(3,4) === 'x';
return true
}
get weekDayFriday(): boolean {
if (this.contractWeekDays) return this.contractWeekDays.substring(4) === 'x';
return true
}
constructor (staffData: StaffMemberMainDto) {
this.id = staffData.id;
this.name = staffData.name;
this.firstName = staffData.firstName;
this.idmId = staffData.idmId;
this.salutation = staffData.title;
this.title = staffData.title;
this.sex = staffData.sex;
this.contractType = staffData.contractType;
this.contractStart = staffData.contractStart;
this.contractEnd = staffData.contractEnd;
this.contractWeekDays = staffData.contractWeekDays;
this.address = staffData.address;
this.payrollId = staffData.payrollId;
}
static dateToString(someDate?: _moment.Moment): string {
if (someDate) {
console.log(someDate);
let returnString = someDate.year().toString();
const month = someDate.month() as number;
returnString += (month < 9 ? '-0' : '-') + (month + 1).toString();
......@@ -100,4 +121,11 @@ export class StaffMember {
}
return null;
}
static weekDaysToString(isMonday: boolean, isTuesday: boolean, isWednesday: boolean,
isThursday: boolean, isFriday: boolean): string {
const myReturn = `${isMonday ? 'x' : '-'}${isTuesday ? 'x' : '-'}${isWednesday ? 'x' : '-'}${isThursday ? 'x' : '-'}${isFriday ? 'x' : '-'}`;
if (myReturn === 'xxxxx') return ''
return myReturn;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment