[ui] feat: Implement loading instructors list

This commit is contained in:
ChronosX88 2019-09-25 20:59:44 +04:00
parent c487612839
commit e9f11bd288
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
4 changed files with 48 additions and 13 deletions

View File

@ -17,9 +17,9 @@
</table>
<div style="text-align: center;"><h1>Instructor Details</h1>
<br>
<label><h5 style="text-align: initial">First Name</h5><input type="text" style="margin-right: 20px"></label>
<label><h5 style="text-align: initial">Middle Name</h5><input type="text" style="margin-right: 20px"></label>
<label><h5 style="text-align: initial">Last Name</h5><input type="text"></label>
<label><h5 style="text-align: initial">First Name</h5><input type="text" style="margin-right: 20px" [(ngModel)]="changingInstructor.firstName"></label>
<label><h5 style="text-align: initial">Middle Name</h5><input type="text" style="margin-right: 20px" [(ngModel)]="changingInstructor.middleName"></label>
<label><h5 style="text-align: initial">Last Name</h5><input type="text" [(ngModel)]="changingInstructor.lastName"></label>
<br>
<button type="button" class="btn btn-primary">ADD/SAVE</button>
</div>

View File

@ -1,22 +1,26 @@
import { Component, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Instructor } from '../models/instructor';
import { InstructorsHttpService } from '../services/instructors-http-service';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
providers: [InstructorsHttpService]
})
export class HomeComponent {
public instructors: any[] = [{id: "1", firstName: "Test", lastName: "Testov"}];
public instructors: Instructor[];
private changingInstructor: Instructor = new Instructor();
constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
/*http.get<Instructor[]>(baseUrl + 'api/v1/instructors').subscribe(result => {
this.instructors = result;
}, error => console.error(error));*/
constructor(private instructorsService: InstructorsHttpService) {}
ngOnInit() {
this.loadInstructors()
}
}
interface Instructor {
id: string,
firstName: string,
lastName: string
private loadInstructors() {
this.instructorsService.getInstructors().subscribe(result => {
this.instructors = result;
})
}
}

View File

@ -0,0 +1,7 @@
export class Instructor {
constructor(
public id?: string,
public firstName?: string,
public middleName?: string,
public lastName?: string) { }
}

View File

@ -0,0 +1,24 @@
import { Injectable, Inject } from '@angular/core';
import { HttpClient} from '@angular/common/http';
import { Instructor } from '../models/instructor';
@Injectable()
export class InstructorsHttpService {
constructor(private http: HttpClient, @Inject('BASE_URL') private baseUrl: string) {}
getInstructors() {
return this.http.get<Instructor[]>(this.baseUrl + "api/v1/instructors")
}
createInstructor(instructor: Instructor) {
return this.http.post(this.baseUrl + "api/v1/instructors/add", instructor)
}
updateInstructor(instructor: Instructor) {
return this.http.put(this.baseUrl + "api/v1/instructors/" + instructor.id, instructor)
}
deleteInstructor(id: string) {
return this.http.delete(this.baseUrl + "api/v1/instructors/" + id)
}
}