This commit is contained in:
parent
9976beada2
commit
555cf06a0e
5 changed files with 146 additions and 4 deletions
|
@ -1,4 +1,10 @@
|
|||
import {Routes} from '@angular/router';
|
||||
import {DashboardComponent} from '@app/views/dashboard/dashboard.component';
|
||||
import { Routes } from '@angular/router';
|
||||
import { DashboardComponent } from '@app/views/dashboard/dashboard.component';
|
||||
|
||||
export const routes: Routes = [{path: '', component: DashboardComponent, title: 'Home'}];
|
||||
import { EmployeeDetailComponent } from './views/employee-detail/employee-detail.component';
|
||||
|
||||
export const routes: Routes = [
|
||||
{ path: '', component: DashboardComponent, title: 'Home' },
|
||||
{ path: 'employee/new', component: EmployeeDetailComponent, title: 'New Employee' },
|
||||
{ path: 'employee/:id', component: EmployeeDetailComponent, title: 'Edit Employee' }
|
||||
];
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<p>dashboard works!</p>
|
||||
|
||||
<a href="/employee/new">New Employee</a>
|
||||
<a href="/employee/3">Edit Employee 3</a>
|
||||
<button mat-button (click)="testInfo()">Test Info</button>
|
||||
<button mat-button (click)="testError()">Test Error</button>
|
||||
|
|
53
src/app/views/employee-detail/employee-detail.component.html
Normal file
53
src/app/views/employee-detail/employee-detail.component.html
Normal file
|
@ -0,0 +1,53 @@
|
|||
<form class="employee-detail" [formGroup]="employeeForm" appearance="outline">
|
||||
<div class="employee-detail__info-view">
|
||||
<div class="employee-detail__info-view__base">
|
||||
<mat-form-field>
|
||||
<mat-label>First Name</mat-label>
|
||||
<input matInput formControlName="firstName">
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<mat-label>Last Name</mat-label>
|
||||
<input matInput formControlName="lastName">
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<mat-label>Postcode</mat-label>
|
||||
<mat-icon matSuffix>money</mat-icon>
|
||||
<input matInput formControlName="postcode">
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<mat-label>City</mat-label>
|
||||
<mat-icon matSuffix>location_city</mat-icon>
|
||||
<input matInput formControlName="city">
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<mat-label>Street</mat-label>
|
||||
<mat-icon matSuffix>house</mat-icon>
|
||||
<input matInput formControlName="street">
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<mat-label>Phone</mat-label>
|
||||
<mat-icon matSuffix>phone</mat-icon>
|
||||
<input matInput formControlName="phone">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div class="employee-detail__info-view__qualifications"></div>
|
||||
@if (isNewEmployee) {
|
||||
<p>New Employee View Works</p>
|
||||
}
|
||||
@else {
|
||||
@if ($employee|async;as employee) {
|
||||
<code>{{employee}}</code>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<div class="employee-detail__action-row">
|
||||
<button mat-flat-button (click)="onAbort()" class="abort">Abort</button>
|
||||
@if (isNewEmployee) {
|
||||
<button mat-flat-button (click)="onCreate()">Create</button>
|
||||
}
|
||||
@else {
|
||||
<button mat-flat-button (click)="onSave()">Save</button>
|
||||
}
|
||||
</div>
|
||||
|
||||
</form>
|
27
src/app/views/employee-detail/employee-detail.component.scss
Normal file
27
src/app/views/employee-detail/employee-detail.component.scss
Normal file
|
@ -0,0 +1,27 @@
|
|||
@use '@angular/material' as mat;
|
||||
|
||||
.employee-detail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
|
||||
&__info-view {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
|
||||
>* {
|
||||
flex-basis: 0;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
&__base {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
&__action-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
}
|
55
src/app/views/employee-detail/employee-detail.component.ts
Normal file
55
src/app/views/employee-detail/employee-detail.component.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
import { AsyncPipe } from '@angular/common';
|
||||
import { Component } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatButton } from '@angular/material/button';
|
||||
import { MatFormField, MatLabel, MatSuffix } from '@angular/material/form-field';
|
||||
import { MatIcon } from '@angular/material/icon';
|
||||
import { MatInput } from '@angular/material/input';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Employee, EmployeeService } from '@core/ems';
|
||||
import { Observable, of } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-employee-detail',
|
||||
imports: [AsyncPipe, MatButton, ReactiveFormsModule, MatFormField, MatLabel, MatInput, MatIcon, MatSuffix],
|
||||
templateUrl: './employee-detail.component.html',
|
||||
styleUrl: './employee-detail.component.scss'
|
||||
})
|
||||
export class EmployeeDetailComponent {
|
||||
isNewEmployee: boolean;
|
||||
employeeForm: FormGroup;
|
||||
$employee: Observable<Employee | undefined> = of();
|
||||
constructor(private route: ActivatedRoute, private employeeService: EmployeeService, private formBuilder: FormBuilder) {
|
||||
const idParam = this.route.snapshot.paramMap.get('id');
|
||||
this.isNewEmployee = idParam == null;
|
||||
|
||||
this.employeeForm = this.formBuilder.group<Employee>({
|
||||
id: 0,
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
postcode: '',
|
||||
city: '',
|
||||
street: '',
|
||||
phone: '',
|
||||
skillSet: []
|
||||
});
|
||||
if (this.isNewEmployee) {
|
||||
return;
|
||||
}
|
||||
|
||||
const id = parseInt(idParam as string);
|
||||
this.$employee = this.employeeService.getEmployee({ id });
|
||||
}
|
||||
|
||||
onAbort() {
|
||||
|
||||
}
|
||||
|
||||
onCreate() {
|
||||
|
||||
}
|
||||
|
||||
onSave() {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue