From e846e9106481cbc8893a511bdfc0bdba18dd2ff8 Mon Sep 17 00:00:00 2001 From: codebind Date: Fri, 26 May 2023 16:53:19 +0530 Subject: [PATCH] angular --- user-app/src/app/app-routing.module.ts | 21 +++++++- user-app/src/app/pages/app/app.component.html | 8 +--- user-app/src/app/pages/app/app.component.scss | 8 ++++ user-app/src/app/pages/app/app.component.ts | 15 +++++- .../create-user/create-user.component.html | 48 +++++++++++++++---- .../create-user/create-user.component.ts | 35 +++++++++++++- .../app/pages/header/header.component.html | 15 +++++- .../src/app/pages/header/header.component.ts | 12 ++++- .../pages/user-card/user-card.component.html | 8 +++- .../pages/user-card/user-card.component.ts | 19 +++++++- .../pages/user-list/user-list.component.html | 10 +++- .../pages/user-list/user-list.component.scss | 2 +- .../pages/user-list/user-list.component.ts | 25 +++++++++- user-app/src/app/services/user.service.ts | 10 +++- 14 files changed, 209 insertions(+), 27 deletions(-) diff --git a/user-app/src/app/app-routing.module.ts b/user-app/src/app/app-routing.module.ts index 0abcce6..3d495c4 100644 --- a/user-app/src/app/app-routing.module.ts +++ b/user-app/src/app/app-routing.module.ts @@ -7,7 +7,26 @@ import { UserDetailComponent } from './pages/user-detail/user-detail.component'; import { CreateUserComponent } from './pages/create-user/create-user.component'; import { AuthGuard } from './guards/auth.guard'; -const routes: Routes = []; +const routes: Routes = [ + { + path:"user-list", + component : UserListComponent, + }, + { + path:"contact", + component : ContactComponent, + }, + { + path:"about-us", + component : AboutUsComponent, + }, + { + + path:"create-user", + component : CreateUserComponent , + + }, +]; @NgModule({ imports: [RouterModule.forRoot(routes)], diff --git a/user-app/src/app/pages/app/app.component.html b/user-app/src/app/pages/app/app.component.html index c6e9877..0a51816 100644 --- a/user-app/src/app/pages/app/app.component.html +++ b/user-app/src/app/pages/app/app.component.html @@ -1,6 +1,2 @@ -

- Congratulations! Angular set up is complete. -
-
- You are ready to begin the workshop3. -

+ + diff --git a/user-app/src/app/pages/app/app.component.scss b/user-app/src/app/pages/app/app.component.scss index 8b13789..49537c0 100644 --- a/user-app/src/app/pages/app/app.component.scss +++ b/user-app/src/app/pages/app/app.component.scss @@ -1 +1,9 @@ +.normal { + font-size: 15px; + color: blue; +} +.error { + font-size: 18px; + color: red; +} diff --git a/user-app/src/app/pages/app/app.component.ts b/user-app/src/app/pages/app/app.component.ts index ba8e2e0..f51fc54 100644 --- a/user-app/src/app/pages/app/app.component.ts +++ b/user-app/src/app/pages/app/app.component.ts @@ -5,4 +5,17 @@ import { Component } from '@angular/core'; templateUrl: './app.component.html', styleUrls: ['./app.component.scss'], }) -export class AppComponent {} + +export class AppComponent { + name:string='Ashin'; + show : boolean=true; + userName : string =""; + names = ['Arun', 'Mark', 'Smith', 'Jack']; + isError : boolean=false; + +changeName(){ + this.name = this.userName; + console.log(this.userName) + +} +} \ No newline at end of file diff --git a/user-app/src/app/pages/create-user/create-user.component.html b/user-app/src/app/pages/create-user/create-user.component.html index b772924..7b259cf 100644 --- a/user-app/src/app/pages/create-user/create-user.component.html +++ b/user-app/src/app/pages/create-user/create-user.component.html @@ -1,11 +1,43 @@
-
-
-

Enter Details

-
- - -
+ +
+

Enter Details

+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ Please enter all the details +
+
+ +
+
-
+
+ + \ No newline at end of file diff --git a/user-app/src/app/pages/create-user/create-user.component.ts b/user-app/src/app/pages/create-user/create-user.component.ts index 92e4498..512668b 100644 --- a/user-app/src/app/pages/create-user/create-user.component.ts +++ b/user-app/src/app/pages/create-user/create-user.component.ts @@ -7,4 +7,37 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms'; templateUrl: './create-user.component.html', styleUrls: ['./create-user.component.scss'], }) -export class CreateUserComponent {} +export class CreateUserComponent { + hasError: boolean = false; + userFormBuilder: FormGroup; + + constructor(private readonly formBuilder: FormBuilder,private userService: UserService) { + this.userFormBuilder = this.formBuilder.group({ + emailId: formBuilder.control("", [Validators.required, Validators.email]), + name: formBuilder.control("", [Validators.required]), + phoneNumber: formBuilder.control("", [Validators.required]), + companyName: formBuilder.control("", [Validators.required]), + city: formBuilder.control("", [Validators.required]), + street: formBuilder.control("", [Validators.required]), + zipCode: formBuilder.control("", [Validators.required]), + }); + } + + addUser() { + this.hasError = false; + if (this.userFormBuilder.valid) { + this.userService.addUser({ + id: Math.floor(Math.random() * 10), + name: this.userFormBuilder.controls['name'].value, + emailId: this.userFormBuilder.controls['emailId'].value, + phoneNumber: this.userFormBuilder.controls['phoneNumber'].value, + companyName: this.userFormBuilder.controls['companyName'].value, + street: this.userFormBuilder.controls['street'].value, + city: this.userFormBuilder.controls['city'].value, + zipCode: this.userFormBuilder.controls['zipCode'].value, + }); + } else { + this.hasError = true; + } + } +} diff --git a/user-app/src/app/pages/header/header.component.html b/user-app/src/app/pages/header/header.component.html index ad4f732..58c5610 100644 --- a/user-app/src/app/pages/header/header.component.html +++ b/user-app/src/app/pages/header/header.component.html @@ -1 +1,14 @@ -

Header Works

+
+ logo + +
\ No newline at end of file diff --git a/user-app/src/app/pages/header/header.component.ts b/user-app/src/app/pages/header/header.component.ts index 7082d31..95a7d3e 100644 --- a/user-app/src/app/pages/header/header.component.ts +++ b/user-app/src/app/pages/header/header.component.ts @@ -1,8 +1,16 @@ -import { Component } from '@angular/core'; +import { Component,Input,Output,EventEmitter } from '@angular/core'; @Component({ selector: 'app-header', templateUrl: './header.component.html', styleUrls: ['./header.component.scss'], }) -export class HeaderComponent {} +export class HeaderComponent { + @Input() title: string; + + @Output() changeValue =new EventEmitter; + + onClick(){ + this.changeValue.emit(); + } +} \ No newline at end of file diff --git a/user-app/src/app/pages/user-card/user-card.component.html b/user-app/src/app/pages/user-card/user-card.component.html index c05cd52..e172b78 100644 --- a/user-app/src/app/pages/user-card/user-card.component.html +++ b/user-app/src/app/pages/user-card/user-card.component.html @@ -1,3 +1,9 @@
-

User Card works

+

+ {{ emailId }}

+ {{ city }}
+ +
diff --git a/user-app/src/app/pages/user-card/user-card.component.ts b/user-app/src/app/pages/user-card/user-card.component.ts index 8a5b52a..c56cf2a 100644 --- a/user-app/src/app/pages/user-card/user-card.component.ts +++ b/user-app/src/app/pages/user-card/user-card.component.ts @@ -6,4 +6,21 @@ import { UserService } from 'src/app/services/user.service'; templateUrl: './user-card.component.html', styleUrls: ['./user-card.component.scss'], }) -export class UserCardComponent {} +export class UserCardComponent { + @Input() id: number; + @Input() name: string; + @Input() emailId: string; + @Input() city: string; + + @Output() deleteUser = new EventEmitter(); + +constructor(private userService: UserService) {} + +setUserId(id: number) { + this.userService.userId = id; +} + +deleteUserById(id) { + this.deleteUser.emit(id); +} +} \ No newline at end of file diff --git a/user-app/src/app/pages/user-list/user-list.component.html b/user-app/src/app/pages/user-list/user-list.component.html index 9326de9..9e57d6d 100644 --- a/user-app/src/app/pages/user-list/user-list.component.html +++ b/user-app/src/app/pages/user-list/user-list.component.html @@ -1,3 +1,11 @@ +

User List Works

-
+ + + \ No newline at end of file diff --git a/user-app/src/app/pages/user-list/user-list.component.scss b/user-app/src/app/pages/user-list/user-list.component.scss index cad22bc..bfaa680 100644 --- a/user-app/src/app/pages/user-list/user-list.component.scss +++ b/user-app/src/app/pages/user-list/user-list.component.scss @@ -14,7 +14,7 @@ .header > button { width: 100px; height: 50px; - background-color: rgb(65, 166, 212); + background-color: rgb(119, 212, 65); color: white; border-radius: 5px; border: solid 1px white; diff --git a/user-app/src/app/pages/user-list/user-list.component.ts b/user-app/src/app/pages/user-list/user-list.component.ts index 60cb003..d0b9336 100644 --- a/user-app/src/app/pages/user-list/user-list.component.ts +++ b/user-app/src/app/pages/user-list/user-list.component.ts @@ -7,4 +7,27 @@ import { UserService } from 'src/app/services/user.service'; templateUrl: './user-list.component.html', styleUrls: ['./user-list.component.scss'], }) -export class UserListComponent {} +export class UserListComponent { + users:User[]=[ + { + name:'Ashin', + city:'asdc', + emailId:'ashinvarghese@gmail.com', + id:1, + } + ] + constructor(public userService: UserService) {} + +ngOnInit() { + this.userService.getUsers(); + if(!this.userService.userAleadyAdded()) + { + + this.userService.getUsers(); + } +} + +deleteUser(event) { + this.userService.deleteUser(event) +} +} \ No newline at end of file diff --git a/user-app/src/app/services/user.service.ts b/user-app/src/app/services/user.service.ts index 0160cc5..22c9e78 100644 --- a/user-app/src/app/services/user.service.ts +++ b/user-app/src/app/services/user.service.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core'; import { User, UserDetail } from '../model/common.dto'; +import { HttpClient } from '@angular/common/http'; @Injectable({ providedIn: 'root', @@ -9,13 +10,18 @@ export class UserService { userId: number; users: User[] = []; - constructor() {} + constructor(private http:HttpClient) {} userAleadyAdded(): boolean { return true; } - getUsers(): void {} + getUsers() { + this.http.get(this.baseUrl).subscribe((user:User[])=>{ + console.log(user); + this.users=user; + }) + } getUserDetail(id: number) {}