Kaynağa Gözat

Sidebar rework

Alex Ondoa 2 yıl önce
ebeveyn
işleme
a4ea4eebd5

+ 1
- 0
Angular/src/app/pages/candidat/candidat-detail/candidat-detail.component.ts Dosyayı Görüntüle

@@ -12,6 +12,7 @@ import { CandidateService } from 'src/app/shared/services/candidate.service';
12 12
   templateUrl: './candidat-detail.component.html',
13 13
   styleUrls: ['./candidat-detail.component.scss']
14 14
 })
15
+
15 16
 export class CandidatDetailComponent implements OnInit {
16 17
 
17 18
   _candidat: Candidate = new Candidate() ;

+ 53
- 50
Angular/src/app/pages/candidat/candidat-list/candidat-list.component.html Dosyayı Görüntüle

@@ -1,52 +1,55 @@
1
-<div class="card">
2
-    <h5>Candidates List</h5>
3
-    <div><button (click)="showNew()" type="button" class="btn btn-primary">Add</button></div>
4
-    <br/>
5
-    <table class="table table-bordered">
6
-        <thead>
7
-          <tr>
8
-            <th scope="col">#</th>
9
-            <th scope="col">First Name</th>
10
-            <th scope="col">Last Name</th>
11
-            <th scope="col">Emails</th>
12
-          </tr>
13
-        </thead>
14
-        <tbody>
15
-          <tr (click)="showDetail(candidate.id)"  *ngFor="let candidate of candidates | async | paginate: { itemsPerPage: 4, currentPage: cp }" class="listMargin">
16
-                <td>{{candidate.id}}</td>
17
-                <td>{{candidate.firstName}}</td>
18
-                <td>{{candidate.lastName}}</td>
19
-                <td>
20
-                    <tr *ngFor="let ml of candidate.emails">
21
-                      <span>{{ml.email}}</span>
22
-                      <span> - {{ml.type}}</span>
23
-                    </tr>
24
-                </td>
25
-                <td>
26
-                  <button class="btn btn-warning" (click)="showDetail(candidate.id)">Edit</button> - <button class="btn btn-danger" >Delete</button>
27
-               </td>
28
-          </tr>
29
-        </tbody>
30
-      </table>
31
-     <div>
32
-        <form name="editForm" role="form" class="row">
33
-          <div class="col-md-8"> <button type="button" class="btn btn-primary" (click)="open(mymodal)">Search</button></div>
34
-          <div class="col-md-4"><pagination-controls (pageChange)="cp = $event"></pagination-controls></div>
35
-        </form>
36
-     </div>
37
- 
38
-</div>
39 1
 
40
-<!-- Modal -->
41
-<ng-template #mymodal let-modal>
42
-  <div class="modal-header">
43
-    <h4 class="modal-title" id="search-modal">Search candidates</h4>
44
-    <!-- <button type="button" class="close" (click)="modal.close()">Close</button> -->
45
-    <button type="button" class="close" aria-label="Close" (click)="modal.dismiss()">
46
-      <span aria-hidden="true">×</span>
47
-    </button>
48
-  </div>
49
-  <div class="modal-body">
50
-    <app-candidat-search (candidatsListResultEvent)="receiveSearchList($event)"></app-candidat-search>
2
+<div class="container-fluid">
3
+  <div class="row flex-nowrap">
4
+      <div class="col py-3">
5
+        <div class="card">
6
+          <h5>Candidates List</h5>
7
+         <div class="row">
8
+          <div class="col-md-2">
9
+            <button (click)="showNew(null)" type="button" class="btn btn-primary">Add</button>
10
+          </div>
11
+          <div class="col-md-10">
12
+            <app-candidat-search (candidatsListResultEvent)="receiveSearchList($event)"></app-candidat-search>
13
+          </div>
14
+         </div>
15
+          <br/>
16
+          <table class="table table-bordered">
17
+              <thead>
18
+                <tr>
19
+                  <th scope="col">#</th>
20
+                  <th scope="col">First Name</th>
21
+                  <th scope="col">Last Name</th>
22
+                  <th scope="col">Emails</th>
23
+                </tr>
24
+              </thead>
25
+              <tbody>
26
+                <tr (click)="showNew(candidate)"  *ngFor="let candidate of candidates | async | paginate: { itemsPerPage: 4, currentPage: cp }" class="listMargin">
27
+                      <td>{{candidate.id}}</td>
28
+                      <td>{{candidate.firstName}}</td>
29
+                      <td>{{candidate.lastName}}</td>
30
+                      <td>
31
+                          <tr *ngFor="let ml of candidate.emails">
32
+                            <span>{{ml.email}}</span>
33
+                            <span> - {{ml.type}}</span>
34
+                          </tr>
35
+                      </td>
36
+                      <td>
37
+                        <button class="btn btn-warning" (click)="showDetail(candidate.id)">Edit</button> - <button class="btn btn-danger" >Delete</button>
38
+                     </td>
39
+                </tr>
40
+              </tbody>
41
+            </table>
42
+           <div>
43
+              <form name="editForm" role="form" class="row">
44
+                <div class="col-md-8"></div>
45
+                <div class="col-md-4"><pagination-controls (pageChange)="cp = $event"></pagination-controls></div>
46
+              </form>
47
+           </div>
48
+       
49
+        </div>
50
+      </div>
51
+      <div *ngIf="isSidebar == true" class="col-auto">
52
+        <app-candidat-sidebar [currentCandidat] = "receiveCandidate" (candidatResultEvent)="receiveCandidat($event)"></app-candidat-sidebar>
53
+      </div>
51 54
   </div>
52
-</ng-template>
55
+</div>

+ 3
- 1
Angular/src/app/pages/candidat/candidat-list/candidat-list.component.scss Dosyayı Görüntüle

@@ -1,4 +1,6 @@
1 1
 .listMargin{
2 2
  
3 3
     margin : 5px;
4
-}
4
+}
5
+
6
+

+ 51
- 7
Angular/src/app/pages/candidat/candidat-list/candidat-list.component.ts Dosyayı Görüntüle

@@ -1,11 +1,13 @@
1 1
 import { HttpClient } from '@angular/common/http';
2
-import { Component, Input, OnInit, ViewChild } from '@angular/core';
2
+import { Component, Injectable, Input, OnInit, ViewChild } from '@angular/core';
3 3
 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
4
-import { ActivatedRoute, Router } from '@angular/router';
4
+import { ActivatedRoute, Resolve, Router } from '@angular/router';
5 5
 import { ModalDismissReasons, NgbModal } from '@ng-bootstrap/ng-bootstrap';
6 6
 import { BehaviorSubject, Observable } from 'rxjs';
7
+import { map } from 'rxjs/operators';
7 8
 import { AppBreadcrumbService } from 'src/app/app.breadcrumb.service';
8 9
 import { Candidate } from 'src/app/shared/models/candidate';
10
+import { CandidateService } from 'src/app/shared/services/candidate.service';
9 11
 import { candidatListService } from './candidat-list.service';
10 12
 
11 13
 @Component({
@@ -13,17 +15,23 @@ import { candidatListService } from './candidat-list.service';
13 15
   templateUrl: './candidat-list.component.html',
14 16
   styleUrls: ['./candidat-list.component.scss']
15 17
 })
18
+
16 19
 export class CandidatListComponent implements OnInit {
17 20
   
21
+   
18 22
     candidates: Observable<Candidate[]>;
19
-    candidate: Candidate;
23
+    ftCandidates: Observable<Candidate[]>;
24
+    candidatCP: Candidate;
25
+    receiveCandidate = new BehaviorSubject<Candidate>(new Candidate());
20 26
     currentPage = 1;
21 27
     itemsPerPage = 5;
22 28
     pageSize: number;
23 29
     cp: number = 1;
30
+    isSidebar: boolean = false;
31
+    xy: any[];
24 32
 
25 33
     constructor(private breadcrumbService: AppBreadcrumbService,private http: HttpClient, 
26
-      private candidatListService: candidatListService, private route: ActivatedRoute,private router: Router,
34
+      private candidatListService: candidatListService, private candidateService: CandidateService, private route: ActivatedRoute,private router: Router,
27 35
       private modalService: NgbModal,private formBuilder: FormBuilder) {
28 36
       this.breadcrumbService.setItems([
29 37
         { label: 'Candidats' },
@@ -32,19 +40,55 @@ export class CandidatListComponent implements OnInit {
32 40
   }
33 41
 
34 42
   ngOnInit() {
35
-    this.route.data.subscribe((data: { candidats: Observable<Candidate[]> }) => this.candidates = data.candidats);
36 43
     this.candidates = this.candidatListService.getCandidats();
37 44
   }
45
+
38 46
   receiveSearchList(list: Observable<Candidate[]>) {
39 47
     this.candidates = list; 
40 48
    }
49
+
50
+   receiveCandidat(candidatForm: FormGroup) {
51
+     if(candidatForm.controls['id'].value){
52
+       this.candidates.subscribe(e => 
53
+        {
54
+         var x = e.filter(f => f.id == candidatForm.controls['id'].value);
55
+         x[0].id = candidatForm.controls['id'].value;
56
+         x[0].firstName = candidatForm.controls['firstName'].value;
57
+         x[0].lastName = candidatForm.controls['lastName'].value;
58
+         
59
+         this.candidates.subscribe(e => e.push(x[0])); 
60
+        })
61
+     }else{
62
+      var c = new Candidate();
63
+      this.candidates.subscribe(e => c.id = (1 + e.length).toString())
64
+      c.lastName = candidatForm.controls['lastName'].value;
65
+      c.firstName = candidatForm.controls['firstName'].value;
66
+  /* 
67
+      var exampleArray = [];
68
+      exampleArray.push({'email' : c.lastName = candidatForm.controls['emailPro'].value , 'type': "profesionnal"});
69
+      exampleArray.push({'email' : c.lastName = candidatForm.controls['emailPerso'].value , 'type': "personal"});
70
+   */
71
+      this.candidates.subscribe(e => e.push(c)); 
72
+     }
73
+    
74
+   }
41 75
   showDetail(candidateId: string){
42 76
     var myurl = `${"/candidat/candidat-detail"}/${candidateId}`;
43 77
     this.router.navigateByUrl(myurl);
44 78
     
45 79
   }
46
-  showNew(){
47
-    this.router.navigateByUrl("/candidat/candidat-sidebar");  
80
+  showNew(candidate: Candidate){
81
+    if(candidate){
82
+      this.isSidebar = true;
83
+      this.receiveCandidate.next(candidate);
84
+    }else{
85
+      if(this.isSidebar){
86
+        this.isSidebar = false;
87
+      }else{
88
+        this.isSidebar = true;
89
+      }
90
+    }
91
+   
48 92
   }
49 93
 
50 94
   open(content) {

+ 3
- 17
Angular/src/app/pages/candidat/candidat-list/candidat-list.service.ts Dosyayı Görüntüle

@@ -4,29 +4,15 @@ import { switchMap, tap } from 'rxjs/operators';
4 4
 import { TreeNode } from 'primeng/api';
5 5
 import { BehaviorSubject, Observable } from 'rxjs';
6 6
 import { Candidate } from 'src/app/shared/models/candidate';
7
+import { CandidateService } from 'src/app/shared/services/candidate.service';
7 8
 
8 9
 @Injectable({
9 10
     providedIn: 'root'
10 11
 })
11 12
 export class candidatListService {
13
+    constructor(private http: HttpClient, private candidatService: CandidateService) {}
12 14
 
13
-    private _candidats = new BehaviorSubject<Candidate[]>([]);
14
-    private dataStore: { candidats: Candidate[] } = { candidats: [] };
15
-    readonly candidats = this._candidats.asObservable();
16
-
17
-    constructor(private http: HttpClient) {}
18
-
19
-    loadAll() {
20
-        this.http.get<Candidate[]>('assets/demo/data/candidates.json').subscribe(
21
-          data => {
22
-            this.dataStore.candidats = data;
23
-            this._candidats.next(Object.assign({}, this.dataStore).candidats);
24
-          },
25
-          error => console.log('Could not load Candidats.')
26
-        );
27
-      }
28 15
     getCandidats(): Observable<Candidate[]>{
29
-     this.loadAll();
30
-     return this.candidats
16
+     return this.candidatService.getCandidats()
31 17
     }
32 18
 }

+ 11
- 19
Angular/src/app/pages/candidat/candidat-search/candidat-search.component.html Dosyayı Görüntüle

@@ -1,20 +1,12 @@
1
-<form [formGroup]="searchForm">
2
-    <div class="form-group">
3
-        <label for="firstName">First Name</label>
4
-        <input type="text" class="form-control" id="firstName" formControlName="firstName">
5
-    </div>
6
-    <div class="form-group">
7
-        <label for="LastName">Last Name</label>
8
-        <input type="text" class="form-control" id="lastName" formControlName="lastName">
9
-    </div>
10
-    <div>
11
-      <div class="form-group">
12
-        <label for="email">Email</label>
13
-        <input type="email" class="form-control" id="email" formControlName="email">
14
-      </div>
15
-    </div>
1
+<form class="form-row" [formGroup]="searchForm">
2
+    <div class="row">
3
+        <div class="form-group col-md-10">
4
+            <input type="text" class="form-control" id="searchRequest" placeholder="Search: First name, Last name, email" formControlName="searchRequest">
5
+        </div>
6
+        <div class="col-md-2">
7
+            <button type="button" class="btn btn-outline-dark" (click)="onSubmit()">Search</button>
8
+        </div>
9
+    </div>
10
+  
16 11
     <br>
17
-    <div float="right"> 
18
-        <button type="button" class="btn btn-outline-dark" (click)="onSubmit()">Search</button>
19
-    </div>
20
-</form>
12
+</form>

+ 3
- 8
Angular/src/app/pages/candidat/candidat-search/candidat-search.component.ts Dosyayı Görüntüle

@@ -22,18 +22,13 @@ export class CandidatSearchComponent implements OnInit {
22 22
   }
23 23
   private Form() {
24 24
     this.searchForm = this.formBuilder.group({
25
-      firstName: [""],
26
-      lastName: [""],
27
-      email: ["", Validators.email]
25
+      searchRequest: [""]
28 26
     });
29 27
   }
30 28
   
31 29
   search(){
32
-    let FN = this.searchForm.controls['firstName'].value;
33
-    let LN = this.searchForm.controls['lastName'].value;
34
-    let EML = this.searchForm.controls['email'].value;
35
-    this.candidatsListResultEvent.emit(this.candidatService.search(FN,LN,EML))
36
-    //this.candidatService.search(FN,LN,EML).subscribe(s=> this.candidatsListResultEvent.emit(s));
30
+    let SR = this.searchForm.controls['searchRequest'].value;
31
+    this.candidatsListResultEvent.emit(this.candidatService.search(SR))
37 32
   }
38 33
   
39 34
   onSubmit() {

+ 1
- 1
Angular/src/app/pages/candidat/candidat-sidebar/candidat-sidebar.component.html Dosyayı Görüntüle

@@ -33,4 +33,4 @@
33 33
         <div class="modal-footer">
34 34
         </div>
35 35
     </div>
36
-</div>
36
+</div>

+ 33
- 10
Angular/src/app/pages/candidat/candidat-sidebar/candidat-sidebar.component.ts Dosyayı Görüntüle

@@ -1,7 +1,9 @@
1 1
 import { HttpClient } from '@angular/common/http';
2
-import { Component, OnInit } from '@angular/core';
2
+import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
3 3
 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
4
+import { Observable } from 'rxjs';
4 5
 import { AppBreadcrumbService } from 'src/app/app.breadcrumb.service';
6
+import { Candidate } from 'src/app/shared/models/candidate';
5 7
 
6 8
 @Component({
7 9
   selector: 'app-candidat-sidebar',
@@ -10,6 +12,10 @@ import { AppBreadcrumbService } from 'src/app/app.breadcrumb.service';
10 12
 })
11 13
 export class CandidatSidebarComponent implements OnInit {
12 14
   createForm: FormGroup;
15
+  isAddBtn: boolean = false;
16
+  @Input() currentCandidat: Observable<Candidate>;
17
+  @Output() public candidatResultEvent = new EventEmitter<FormGroup>();
18
+  
13 19
   constructor(private breadcrumbService: AppBreadcrumbService,private http: HttpClient, private formBuilder: FormBuilder) {
14 20
     this.breadcrumbService.setItems([
15 21
       { label: 'Candidat' },
@@ -18,15 +24,31 @@ export class CandidatSidebarComponent implements OnInit {
18 24
   }
19 25
 
20 26
   ngOnInit(): void {
21
-    this.Form();
27
+    if(this.currentCandidat && !this.isAddBtn){
28
+      this.currentCandidat.subscribe(e => this.Form(e) );
29
+    }else{
30
+      this.Form(null);
31
+    }
22 32
   }
23
-  private Form() {
24
-    this.createForm = this.formBuilder.group({
25
-      firstName: ["", Validators.required],
26
-      lastName: ["", Validators.required],
27
-      emailPro: ["", Validators.email],
28
-      emailPerso: ["", Validators.email]
29
-    });
33
+
34
+  private Form(c: Candidate) {
35
+    if(c){
36
+      this.createForm = this.formBuilder.group({
37
+        id : [c.id? c.id :""],
38
+        firstName: [c.firstName? c.firstName :"", Validators.required],
39
+        lastName: [c.lastName? c.lastName :"", Validators.required],
40
+        emailPro: ["", Validators.email],
41
+        emailPerso: ["", Validators.email]
42
+      });
43
+    }else{
44
+      this.isAddBtn = true;
45
+      this.createForm = this.formBuilder.group({
46
+        firstName: ["", Validators.required],
47
+        lastName: ["", Validators.required],
48
+        emailPro: ["", Validators.email],
49
+        emailPerso: ["", Validators.email]
50
+      });
51
+    }
30 52
   }
31 53
   
32 54
   onSubmit() {
@@ -34,6 +56,7 @@ export class CandidatSidebarComponent implements OnInit {
34 56
       alert('Data Error!! :\n\n' + JSON.stringify(this.createForm.value, null,4));
35 57
       return;
36 58
     }
37
-    alert('SUCCESS!! :\n\n' + JSON.stringify(this.createForm.value, null,4));
59
+
60
+    this.candidatResultEvent.emit(this.createForm);
38 61
   }
39 62
 }

+ 1
- 1
Angular/src/app/pages/candidat/candidat.module.ts Dosyayı Görüntüle

@@ -3,13 +3,13 @@ import { CommonModule } from '@angular/common';
3 3
 import { CandidatListComponent } from './candidat-list/candidat-list.component';
4 4
 import { RouterModule, Routes } from '@angular/router';
5 5
 import { CandidatSearchComponent } from './candidat-search/candidat-search.component';
6
-import { CandidatsResolver } from 'src/app/shared/resolver/candidats.resolver';
7 6
 import { CandidatDetailComponent } from './candidat-detail/candidat-detail.component';
8 7
 import { CandidatDetailResolver } from 'src/app/shared/resolver/candidat-detail.resolver';
9 8
 import { ReactiveFormsModule } from '@angular/forms';
10 9
 import { CandidatSidebarComponent } from './candidat-sidebar/candidat-sidebar.component';
11 10
 import { NgxPaginationModule } from 'ngx-pagination';
12 11
 import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
12
+import { CandidatsResolver } from 'src/app/shared/resolver/candidats.resolver';
13 13
 
14 14
 
15 15
 export const routes: Routes = [

+ 24
- 18
Angular/src/app/shared/services/candidate.service.ts Dosyayı Görüntüle

@@ -8,35 +8,41 @@ import { Candidate } from '../models/candidate';
8 8
 })
9 9
 export class CandidateService {
10 10
 
11
-  private _candidatsList = new BehaviorSubject<Candidate[]>([]);
11
+  public _candidatsList = new BehaviorSubject<Candidate[]>([]);
12 12
   private _candidat = new BehaviorSubject<Candidate>(new Candidate());
13
-  readonly candidats = this._candidatsList.asObservable();
14
-  readonly candidat = this._candidat.asObservable();
15 13
   private dataStore:  Candidate[];
16 14
   constructor(private http: HttpClient) { }
17
-  
15
+
18 16
  candidatGetById(id: string): Observable<Candidate> {
19 17
    this.http.get<Candidate[]>('assets/demo/data/candidates.json').subscribe(
20
-           e => { 
21
-             var candidatById = e.filter(i => i.id == id); 
22
-             this._candidat.next(Object.assign({}, candidatById[0]));
18
+           data => 
19
+           { 
20
+             var candidatById = data.filter(i => i.id == id); 
21
+             this._candidat.next(candidatById[0]);
23 22
            });
24
-    return this.candidat;
23
+    return this._candidat;
25 24
   }
26 25
 
27
-  search(queryFN: string, queryLN: string, queryEML: string): Observable<Candidate[]> {
26
+  search(queryS: string): Observable<Candidate[]> {
28 27
     this.http.get<Candidate[]>('assets/demo/data/candidates.json').subscribe(
29
-      e => { 
30
-        if(queryFN){
31
-          this.dataStore = e.filter(i => i.firstName == queryFN); 
32
-        this._candidatsList.next(Object.assign({}, this.dataStore));
33
-        }
34
-        if(queryLN){
35
-          this.dataStore = e.filter(i => i.lastName == queryLN); 
36
-        this._candidatsList.next(Object.assign({}, this.dataStore));
28
+      data => 
29
+      { 
30
+        if(queryS){
31
+          this.dataStore = data.filter(i => (i.firstName.toLowerCase() == queryS.toLowerCase() || i.lastName.toLowerCase() == queryS.toLowerCase() /* || i.emails.find(e => e.email === queryS) */ )); 
32
+          this._candidatsList.next(this.dataStore);
37 33
         }
38 34
       });
39 35
      
40
-    return this.candidats;
36
+    return this._candidatsList;
37
+  }
38
+
39
+  getCandidats(): Observable<Candidate[]> {
40
+    this.http.get<Candidate[]>('assets/demo/data/candidates.json').subscribe(
41
+      data => 
42
+      {
43
+        this._candidatsList.next(data);
44
+      }
45
+    );
46
+    return this._candidatsList;
41 47
   }
42 48
 }

Powered by TurnKey Linux.