Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 7c56b223

Přidáno uživatelem Hung Hoang před téměř 6 roky(ů)

Re#7470 Implemented basic table

Zobrazit rozdíly:

webapp/src/app/app-routing.module.ts
1 1
import { NgModule } from '@angular/core';
2 2
import { Routes, RouterModule } from '@angular/router';
3
import {EmployeesListComponent} from './employees-list/employees-list.component';
3
import {EmployeesListComponent} from './employees/employees-list.component';
4 4
import {DashboardComponent} from './dashboard/dashboard.component';
5 5

  
6 6
const routes: Routes = [
webapp/src/app/app.module.ts
4 4
import { AppRoutingModule } from './app-routing.module';
5 5
import { AppComponent } from './app.component';
6 6
import { MenuComponent } from './menu/menu.component';
7
import { EmployeesListComponent } from './employees-list/employees-list.component';
8 7
import { DashboardModule } from './dashboard/dashboard.module';
9 8
import { HeaderComponent } from './header/header.component';
10 9
import { MatDialogModule } from '@angular/material';
11 10
import {ProfileSettingsModule} from './profile-settings/profile-settings.module';
12 11
import {HttpClientModule} from '@angular/common/http';
12
import {EmployeesModule} from './employees/employees.module';
13 13

  
14 14
@NgModule({
15 15
  declarations: [
16 16
    AppComponent,
17 17
    MenuComponent,
18
    EmployeesListComponent,
19 18
    HeaderComponent
20 19
  ],
21 20
  imports: [
......
24 23
    AppRoutingModule,
25 24
    DashboardModule,
26 25
    MatDialogModule,
27
    ProfileSettingsModule
26
    ProfileSettingsModule,
27
    EmployeesModule
28 28
  ],
29 29
  providers: [],
30 30
  bootstrap: [AppComponent]
webapp/src/app/employee-list-item/employee-list-item.component.html
1
<p>
2
  employee-list-item works!
3
</p>
webapp/src/app/employee-list-item/employee-list-item.component.spec.ts
1
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2

  
3
import { EmployeeListItemComponent } from './employee-list-item.component';
4

  
5
describe('EmployeeListItemComponent', () => {
6
  let component: EmployeeListItemComponent;
7
  let fixture: ComponentFixture<EmployeeListItemComponent>;
8

  
9
  beforeEach(async(() => {
10
    TestBed.configureTestingModule({
11
      declarations: [ EmployeeListItemComponent ]
12
    })
13
    .compileComponents();
14
  }));
15

  
16
  beforeEach(() => {
17
    fixture = TestBed.createComponent(EmployeeListItemComponent);
18
    component = fixture.componentInstance;
19
    fixture.detectChanges();
20
  });
21

  
22
  it('should create', () => {
23
    expect(component).toBeTruthy();
24
  });
25
});
webapp/src/app/employee-list-item/employee-list-item.component.ts
1
import { Component, OnInit } from '@angular/core';
2

  
3
@Component({
4
  selector: 'app-employee-list-item',
5
  templateUrl: './employee-list-item.component.html',
6
  styleUrls: ['./employee-list-item.component.sass']
7
})
8
export class EmployeeListItemComponent implements OnInit {
9

  
10
  constructor() { }
11

  
12
  ngOnInit() {
13
  }
14

  
15
}
webapp/src/app/employees-list/employees-list.component.html
1
<div>
2
  <div>
3
    <h3>Zaměstnanci
4
      <span class="material-icons">add</span>
5
      <span class="material-icons">edit</span>
6
    </h3>
7
    <div *ngIf="employeesBasicInformation">
8
      {{employeesBasicInformation[0].name.first}}
9
      {{employeesBasicInformation[0].calendar[0].date}}
10
      {{employeesBasicInformation[0].calendar[0].from}}
11
      {{employeesBasicInformation[0].calendar[0].to}}
12
<!--      {{employeesBasicInformation[0].calendar[1].date}}-->
13
    </div>
14
    <div *ngIf="employeeProfile">
15
      {{employeeProfile.photo}}
16
      {{employeeProfile.name.last}}
17
    </div>
18
    <div *ngIf="requests">
19
<!--      {{requests.vacation[0].user.name.first}}-->
20
<!--      {{requests.vacation[0].date}}-->
21
      {{requests.vacation[0].from}}
22
<!--      {{requests.authorization[0].date}}-->
23
    </div>
24
    <div *ngIf="calendars">
25
      {{calendars[0].status}}
26
      {{calendars[0].to}}
27
    </div>
28

  
29
    <div *ngIf="settings">
30
      {{settings.sickDay.unit}}
31
    </div>
32
    <button (click)="doSomethingFancy()">SUPER BUTTON ZKUS ME</button>
33
  </div>
34
  <hr>
35
</div>
webapp/src/app/employees-list/employees-list.component.sass
1
.material-icons
2
    display: inline-flex
3
    align-items: center
4
    justify-content: center
5
    vertical-align: middle
6

  
webapp/src/app/employees-list/employees-list.component.ts
1
import {Component, OnInit} from '@angular/core';
2
import {UserBasicInformation} from '../models/user-basic-information.model';
3
import {UserProfile} from '../models/user-profile.model';
4
import {UsersService} from '../services/users.service';
5
import {UserService} from '../services/user.service';
6
import {Requests} from '../models/requests.model';
7
import {Calendar} from '../models/calendar.model';
8
import {SettingsService} from '../services/settings.service';
9
import {Settings} from '../models/settings.model';
10
import {PostRequest, PostSettings} from '../models/post-requests.model';
11
import {RequestStatus, TimeUnit, UserType} from '../enums/common.enum';
12

  
13
@Component({
14
  selector: 'app-employees-list',
15
  templateUrl: './employees-list.component.html',
16
  styleUrls: ['./employees-list.component.sass']
17
})
18
export class EmployeesListComponent implements OnInit {
19

  
20
  employeesBasicInformation: UserBasicInformation[];
21
  employeeProfile: UserProfile;
22
  requests: Requests;
23
  calendars: Calendar[];
24
  settings: Settings;
25

  
26
  doSomethingFancy(): void {
27
    console.log('klikam');
28
    this.settingsService.postDefaultSettingsWithResponse(this.settings)
29
      .subscribe(resp => console.log(resp));
30

  
31
    this.userService.postCalendarWithResponse(this.calendars)
32
      .subscribe(resp => console.log(resp));
33

  
34
    const request: PostRequest = {
35
      id: 10,
36
      status: RequestStatus.ACCEPTED,
37
    };
38
    this.userService.postAuthorizationRequestWithResponse(request)
39
      .subscribe(resp => console.log(resp));
40

  
41
    const settings: PostSettings = {
42
      role: UserType.EMPLOYEE,
43
      sickday: {
44
        unit: TimeUnit.DAY,
45
        value: 10,
46
      },
47
      vacation: {
48
        unit: TimeUnit.DAY,
49
        value: 10,
50
      },
51
    };
52

  
53
    this.userService.postUserSettingsWithResponse(1, settings)
54
      .subscribe(resp => console.log(resp));
55
  }
56

  
57
  constructor(private usersService: UsersService,
58
              private userService: UserService,
59
              private settingsService: SettingsService) {
60
  }
61

  
62
  ngOnInit() {
63
    this.usersService.getAuthorizedUsers()
64
      .subscribe((data: UserBasicInformation[]) => this.employeesBasicInformation = { ...data});
65

  
66
    this.userService.getEmployeeProfile(1)
67
      .subscribe((data: UserProfile) => this.employeeProfile = { ...data});
68

  
69
    this.usersService.getAuthorizationRequests()
70
      .subscribe((data: Requests) => this.requests = { ...data});
71

  
72
    this.userService.getMonthlyCalendar(1)
73
      .subscribe((data: Calendar[]) => this.calendars = { ...data});
74

  
75
    this.settingsService.getDefaultSettings()
76
      .subscribe((data: Settings) => this.settings = { ...data});
77
  }
78

  
79
}
webapp/src/app/employees/employees-list.component.html
1
<div class="employee-component">
2
  <h3>Zaměstnanci
3
    <span class="material-icons" style="font-size: medium; margin-right: 5px">add</span>
4
    <span class="material-icons" style="font-size: medium">edit</span>
5
  </h3>
6

  
7
  <table class="table text-center table-hover">
8
    <thead class="thead-light">
9
    <tr>
10
      <th scope="col" style="width: 15%">Celé jméno</th>
11
      <th scope="col" style="width: 5.0%" *ngFor="let day of days">{{day}}</th>
12
      <th></th>
13
    </tr>
14
    </thead>
15
    <tbody>
16
    <tr *ngFor="let user of users">
17
      <th scope="row">{{user.name}}</th>
18
      <td *ngFor="let date of user.dates">
19

  
20
        <div
21
          [class.sickday]="date.type === 'SICKDAY'"
22
          [class.vacation]="date.type === 'VACATION'"
23
        >
24
          {{date.date.getDate()}}
25
        </div>
26
      </td>
27
      <td>
28
        <span class="material-icons" style="font-size: small">edit</span>
29
      </td>
30
    </tr>
31
    </tbody>
32
  </table>
33
</div>
webapp/src/app/employees/employees-list.component.sass
1
@import '../../common-styles/basic-component'
2

  
3
.material-icons
4
    display: inline-flex
5
    align-items: center
6
    justify-content: center
7
    vertical-align: middle
8

  
9
.employee-component
10
  @extend .basic-component
11
  margin-top: 15px
12

  
13

  
14
.sickday
15
  background: #ffc0c0
16
  border-radius: 40%
17

  
18
.vacation
19
  background-color: #68b040
20
  border-radius: 40%
21
  width: 40px
webapp/src/app/employees/employees-list.component.ts
1
import {Component, OnInit} from '@angular/core';
2
import {UserBasicInformation} from '../models/user-basic-information.model';
3
import {UsersService} from '../services/users.service';
4
import {VacationType} from '../enums/common.enum';
5

  
6
class DayInfo {
7
  date: Date;
8
  type: VacationType;
9
}
10

  
11
class User {
12
  id: number;
13
  name: string;
14
  dates: DayInfo[];
15
}
16

  
17
const daysOfWeek: string[] = [
18
  'po',
19
  'ut',
20
  'st',
21
  'ct',
22
  'pa',
23
  'so',
24
  'ne',
25
];
26

  
27
@Component({
28
  selector: 'app-employees-list',
29
  templateUrl: './employees-list.component.html',
30
  styleUrls: ['./employees-list.component.sass']
31
})
32
export class EmployeesListComponent implements OnInit {
33
  private users: User[];
34
  private days: string[];
35
  private dates: Date[];
36
  private employeesBasicInformation: UserBasicInformation[] = [];
37
  readonly todayDate: Date = new Date();
38

  
39
  constructor(private usersService: UsersService) {
40
    this.generateDays();
41
    this.generateDates();
42
    this.editDates();
43
  }
44

  
45
  private generateDays(): void {
46
    this.days = [];
47

  
48
    for (let i = this.todayDate.getDay() - 8; i < this.todayDate.getDay() + 7; i++) {
49
      this.days.push(daysOfWeek[((i % 7) + 7) % 7]);
50
    }
51
  }
52

  
53
  private generateDates() {
54
    this.dates = [];
55
    for (let i = 0; i < 15; i++) {
56
      this.dates.push(new Date());
57
    }
58
  }
59

  
60
  private editDates(): void {
61
    let j = 0;
62
    let date: Date;
63

  
64
    for (let i = -7; i < 8; i++) {
65
      date = this.dates[j++];
66
      date.setDate(date.getDate() + i);
67
    }
68
  }
69

  
70
  private mapUsers(): void {
71
    let user: User;
72
    this.users = [];
73

  
74
    for (const info of this.employeesBasicInformation) {
75
      user = new User();
76
      user.name = info.name.first + ' ' + info.name.last;
77
      user.id = info.id;
78
      user.dates = this.mapDays(info);
79
      this.users.push(user);
80
    }
81
  }
82

  
83
  private mapDays(user: UserBasicInformation): DayInfo[] {
84
    const dayInfo: DayInfo[] = [];
85

  
86
    for (const date of this.dates) {
87
      const day: DayInfo = new DayInfo();
88
      day.type = VacationType.NONE;
89

  
90
      for (const vacationDay of user.calendar) {
91
        const vacationDate: Date = new Date(vacationDay.date);
92

  
93
        if (vacationDate.getDate() === date.getDate()) {
94
          day.type = vacationDay.type;
95
        }
96
      }
97

  
98
      day.date = date;
99
      dayInfo.push(day);
100
    }
101

  
102
    return dayInfo;
103
  }
104

  
105
  ngOnInit() {
106
    this.usersService.getAuthorizedUsers()
107
      .subscribe((data: UserBasicInformation[]) => {
108
        for (const entry of data) {
109
          this.employeesBasicInformation.push(entry);
110
        }
111
        this.mapUsers();
112
        console.log(this.users);
113
      });
114
  }
115

  
116
}
webapp/src/app/employees/employees.module.ts
1
import { NgModule } from '@angular/core';
2
import { CommonModule } from '@angular/common';
3
import {EmployeesListComponent} from './employees-list.component';
4
import {MatTableModule} from '@angular/material';
5

  
6
@NgModule({
7
  declarations: [
8
    EmployeesListComponent,
9
  ],
10
  imports: [
11
    CommonModule,
12
    MatTableModule
13
  ]
14
})
15
export class EmployeesModule { }

Také k dispozici: Unified diff