aboutsummaryrefslogtreecommitdiff
path: root/sandbox/testAppSonja/frontend/front/src/app/edit-page/edit-page.component.ts
diff options
context:
space:
mode:
authorTAMARA JERINIC <tamara.jerinic@gmail.com>2022-03-02 23:38:27 +0100
committerTAMARA JERINIC <tamara.jerinic@gmail.com>2022-03-02 23:38:27 +0100
commitdce4e644d5e5d9c97ff5ac337448b52f2a2a64fd (patch)
treeffdb31f43958e8c557647a4bd61914d6d13486e4 /sandbox/testAppSonja/frontend/front/src/app/edit-page/edit-page.component.ts
parent9826a8079ffcd1d849a8a8821696d51691606133 (diff)
Merge branch 'dev' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into Tamara
# Conflicts: # .gitignore
Diffstat (limited to 'sandbox/testAppSonja/frontend/front/src/app/edit-page/edit-page.component.ts')
-rw-r--r--sandbox/testAppSonja/frontend/front/src/app/edit-page/edit-page.component.ts56
1 files changed, 56 insertions, 0 deletions
diff --git a/sandbox/testAppSonja/frontend/front/src/app/edit-page/edit-page.component.ts b/sandbox/testAppSonja/frontend/front/src/app/edit-page/edit-page.component.ts
new file mode 100644
index 00000000..e86c1f39
--- /dev/null
+++ b/sandbox/testAppSonja/frontend/front/src/app/edit-page/edit-page.component.ts
@@ -0,0 +1,56 @@
+import { Component, OnInit } from '@angular/core';
+import { NgForm } from '@angular/forms';
+import { ActivatedRoute, Router } from '@angular/router';
+import { StudentService } from '../services/student.service';
+import { Student } from '../Student';
+
+@Component({
+ selector: 'app-edit-page',
+ templateUrl: './edit-page.component.html',
+ styleUrls: ['./edit-page.component.css']
+})
+export class EditPageComponent implements OnInit {
+
+ submitted = false;
+ id: number = -1;
+ student = new Student();
+
+ constructor(private studentService: StudentService, private route: ActivatedRoute, private router: Router) { }
+
+ ngOnInit(): void {
+ this.route.paramMap.subscribe(
+ params => this.id = parseInt(params.get('id')!)
+ );
+
+ this.loadOneStudent();
+ }
+
+ loadOneStudent() {
+ this.studentService.getOneStudent(this.id)
+ .subscribe(
+ data => this.student = data
+ )
+ }
+
+ handleSubmit(f: NgForm) { //f.value su name-ovi pokupljeni iz forme pa njihove vrednosti
+ let editedStudent : Student = {
+ id: f.value.id,
+ firstName: f.value.firstname, //znaci ovo je name iz forme
+ lastName: f.value.lastname,
+ regNum: f.value.regNum,
+ address: f.value.address,
+ phoneNum: f.value.phone,
+ gpa: f.value.gpa
+ }
+
+ this.studentService.updateStudent(this.id, editedStudent)
+ .subscribe(
+ data => {
+ this.submitted = true;
+ //console.log("Form:", f.value);
+ this.router.navigate(['']);
+ }
+ )
+ }
+
+}