Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

angular #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion user-app/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down
8 changes: 2 additions & 6 deletions user-app/src/app/pages/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
<h2>
Congratulations! Angular set up is complete.
<br />
<br />
You are ready to begin the workshop3.
</h2>
<app-header [title]="name"(changeValue)="changeName()"></app-header>
<router-outlet></router-outlet>
8 changes: 8 additions & 0 deletions user-app/src/app/pages/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
.normal {
font-size: 15px;
color: blue;

}
.error {
font-size: 18px;
color: red;
}
15 changes: 14 additions & 1 deletion user-app/src/app/pages/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
}
48 changes: 40 additions & 8 deletions user-app/src/app/pages/create-user/create-user.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
<div class="container">
<form>
<div class="form">
<h2>Enter Details</h2>
<div class="input-form">
<label>Name </label>
<input placeholder="Enter the name" formControlName="name" />
</div>
<form [formGroup]="userFormBuilder" (keydown.enter)="addUser()">
<div class="form">
<h2>Enter Details</h2>
<div class="input-form">
<label>Name </label>
<input placeholder="Enter the name" formControlName="name" />
</div>
<div class="input-form">
<label>Email</label>
<input placeholder="Enter the email id" formControlName="emailId" />
</div>
<div class="input-form">
<label>Phone</label>
<input placeholder="Enter the phone number" formControlName="phoneNumber" />
</div>
<div class="input-form">
<label>Company</label>
<input placeholder="Enter the company name" formControlName="companyName" />
</div>
<div class="input-form">
<label>Street</label>
<input placeholder="Enter the street" formControlName="street" />
</div>
<div class="input-form">
<label>City</label>
<input placeholder="Enter the city" formControlName="city" />
</div>
<div class="input-form">
<label>Zipcode</label>
<input placeholder="Enter the zipcode" formControlName="zipCode" />
</div>
<div class="error" *ngIf="hasError">
<span>Please enter all the details</span>
</div>
<div class="form-btn">
<button (click)="addUser()">Add User</button>
</div>
</div>
</form>
</div>
</div>


35 changes: 34 additions & 1 deletion user-app/src/app/pages/create-user/create-user.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
15 changes: 14 additions & 1 deletion user-app/src/app/pages/header/header.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
<p>Header Works</p>
<div class="header">
<img routerLink="" src="../../../assets/unicourt-logo.png"
alt="logo"
height="54"
/>
<div class="menu">
<label routerLink="/user-list">Home</label>
<label routerLink="/about-us">AboutUs</label>

<label routerLink="/contact">Contact</label>


</div>
</div>
12 changes: 10 additions & 2 deletions user-app/src/app/pages/header/header.component.ts
Original file line number Diff line number Diff line change
@@ -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<any>;

onClick(){
this.changeValue.emit();
}
}
8 changes: 7 additions & 1 deletion user-app/src/app/pages/user-card/user-card.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<div class="user-card">
<p>User Card works</p>
<label>{{ name }}</label> <br /><br/>
<span>{{ emailId }}</span> <br /> <br>
<span>{{ city }}</span> <br />
<button class="detail-btn" routerLink="user-detail" (click)="setUserId(id)">
DETAIL
</button>
<button class="delete-btn" (click)="deleteUserById(id)">DELETE</button>
</div>
19 changes: 18 additions & 1 deletion user-app/src/app/pages/user-card/user-card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Number>();

constructor(private userService: UserService) {}

setUserId(id: number) {
this.userService.userId = id;
}

deleteUserById(id) {
this.deleteUser.emit(id);
}
}
10 changes: 9 additions & 1 deletion user-app/src/app/pages/user-list/user-list.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@

<div class="container">
<p>User List Works</p>
</div>
<button routerLink="create-user">Create uers</button>
<app-user-card *ngFor="let user of userService.users"
[id]="user.id"
[name]="user.name"
[emailId]="user.email"
[city]="user.phone"
></app-user-card>
</div>
2 changes: 1 addition & 1 deletion user-app/src/app/pages/user-list/user-list.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 24 additions & 1 deletion user-app/src/app/pages/user-list/user-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:'[email protected]',
id:1,
}
]
constructor(public userService: UserService) {}

ngOnInit() {
this.userService.getUsers();
if(!this.userService.userAleadyAdded())
{

this.userService.getUsers();
}
}

deleteUser(event) {
this.userService.deleteUser(event)
}
}
10 changes: 8 additions & 2 deletions user-app/src/app/services/user.service.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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) {}

Expand Down