Revize 4bd9d9f6
Přidáno uživatelem Hung Hoang před téměř 6 roky(ů)
webapp/src/app/app-routing.module.ts | ||
---|---|---|
2 | 2 |
import { Routes, RouterModule } from '@angular/router'; |
3 | 3 |
import {EmployeesListComponent} from './employees/employees-list.component'; |
4 | 4 |
import {DashboardComponent} from './dashboard/dashboard.component'; |
5 |
import {PageNotFoundComponent} from './page-not-found/page-not-found.component'; |
|
5 | 6 |
|
6 | 7 |
const routes: Routes = [ |
7 | 8 |
{ path: 'employees', component: EmployeesListComponent }, |
8 | 9 |
{ path: 'dashboard', component: DashboardComponent }, |
9 | 10 |
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' }, |
11 |
{ path: '**', component: PageNotFoundComponent } |
|
10 | 12 |
]; |
11 | 13 |
|
12 | 14 |
@NgModule({ |
webapp/src/app/app.module.ts | ||
---|---|---|
12 | 12 |
import { EmployeesModule } from './employees/employees.module'; |
13 | 13 |
import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; |
14 | 14 |
import { TranslateHttpLoader } from '@ngx-translate/http-loader'; |
15 |
import { PageNotFoundComponent } from './page-not-found/page-not-found.component'; |
|
15 | 16 |
|
16 | 17 |
@NgModule({ |
17 | 18 |
declarations: [ |
18 | 19 |
AppComponent, |
19 | 20 |
MenuComponent, |
20 |
HeaderComponent |
|
21 |
HeaderComponent, |
|
22 |
PageNotFoundComponent |
|
21 | 23 |
], |
22 | 24 |
imports: [ |
23 | 25 |
BrowserModule, |
webapp/src/app/menu/menu-item.ts | ||
---|---|---|
1 |
export class MenuItem { |
|
2 |
name: string; |
|
3 |
routePath: string; |
|
4 |
} |
webapp/src/app/menu/menu.component.ts | ||
---|---|---|
1 |
import { Component, OnInit } from '@angular/core'; |
|
2 |
import { MenuItem } from './menu-item'; |
|
3 |
|
|
4 |
const MENU_ITEMS: MenuItem[] = [ |
|
5 |
{name: 'Dashboard', routePath: 'dashboard'}, |
|
6 |
{name: 'Zaměstnanci', routePath: 'employees'}, |
|
7 |
]; |
|
1 |
import {Component, OnInit} from '@angular/core'; |
|
2 |
import {MenuItem} from '../models/menu-item.model'; |
|
3 |
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common'; |
|
4 |
import {MenuService} from '../services/util/menu.service'; |
|
8 | 5 |
|
9 | 6 |
@Component({ |
10 | 7 |
selector: 'app-menu', |
11 | 8 |
templateUrl: './menu.component.html', |
12 |
styleUrls: ['./menu.component.sass'] |
|
9 |
styleUrls: ['./menu.component.sass'], |
|
10 |
providers: [Location, {provide: LocationStrategy, useClass: PathLocationStrategy}] |
|
13 | 11 |
}) |
14 | 12 |
export class MenuComponent implements OnInit { |
15 | 13 |
_menuItems: MenuItem[]; |
16 | 14 |
private _selectedMenuItem: MenuItem; |
17 | 15 |
|
18 |
constructor() { |
|
19 |
this._menuItems = MENU_ITEMS; |
|
16 |
constructor(private location: Location, private menuService: MenuService) { |
|
20 | 17 |
} |
21 | 18 |
|
22 | 19 |
ngOnInit() { |
20 |
this.menuService.getMenuItems() |
|
21 |
.subscribe((data: MenuItem[]) => { |
|
22 |
this._menuItems = data; |
|
23 |
|
|
24 |
this._selectedMenuItem = this._menuItems[0]; |
|
25 |
const path = this.location.path().split('/'); |
|
26 |
const endOfPath = path[path.length - 1]; |
|
27 |
|
|
28 |
for (const item of this._menuItems) { |
|
29 |
if (item.routePath === endOfPath) { |
|
30 |
this._selectedMenuItem = item; |
|
31 |
} |
|
32 |
} |
|
33 |
}); |
|
23 | 34 |
} |
24 | 35 |
|
25 | 36 |
onSelect(menuItem: MenuItem): void { |
webapp/src/app/models/menu-item.model.ts | ||
---|---|---|
1 |
export class MenuItem { |
|
2 |
name: string; |
|
3 |
routePath: string; |
|
4 |
} |
webapp/src/app/page-not-found/page-not-found.component.html | ||
---|---|---|
1 |
<div id="notfound"> |
|
2 |
<div class="notfound"> |
|
3 |
<div class="notfound-404"> |
|
4 |
<h1>404</h1> |
|
5 |
</div> |
|
6 |
<h2>We are sorry, Page not found!</h2> |
|
7 |
<p>The page you are looking for might have been removed had its name changed or is temporarily unavailable.</p> |
|
8 |
<a href="#">Back To Homepage</a> |
|
9 |
</div> |
|
10 |
</div> |
|
11 |
|
|
12 |
<!-- This templates was made by Colorlib (https://colorlib.com) --> |
webapp/src/app/page-not-found/page-not-found.component.sass | ||
---|---|---|
1 |
* |
|
2 |
-webkit-box-sizing: border-box |
|
3 |
box-sizing: border-box |
|
4 |
|
|
5 |
|
|
6 |
body |
|
7 |
padding: 0 |
|
8 |
margin: 0 |
|
9 |
|
|
10 |
|
|
11 |
#notfound |
|
12 |
position: relative |
|
13 |
height: 100vh |
|
14 |
|
|
15 |
|
|
16 |
#notfound .notfound |
|
17 |
position: absolute |
|
18 |
left: 50% |
|
19 |
top: 50% |
|
20 |
-webkit-transform: translate(-50%, -50%) |
|
21 |
-ms-transform: translate(-50%, -50%) |
|
22 |
transform: translate(-50%, -50%) |
|
23 |
|
|
24 |
|
|
25 |
.notfound |
|
26 |
max-width: 920px |
|
27 |
width: 100% |
|
28 |
line-height: 1.4 |
|
29 |
text-align: center |
|
30 |
padding-left: 15px |
|
31 |
padding-right: 15px |
|
32 |
|
|
33 |
|
|
34 |
.notfound .notfound-404 |
|
35 |
position: absolute |
|
36 |
height: 100px |
|
37 |
top: 0 |
|
38 |
left: 50% |
|
39 |
-webkit-transform: translateX(-50%) |
|
40 |
-ms-transform: translateX(-50%) |
|
41 |
transform: translateX(-50%) |
|
42 |
z-index: -1 |
|
43 |
|
|
44 |
|
|
45 |
.notfound .notfound-404 h1 |
|
46 |
font-family: 'Maven Pro', sans-serif |
|
47 |
color: #ececec |
|
48 |
font-weight: 900 |
|
49 |
font-size: 276px |
|
50 |
margin: 0px |
|
51 |
position: absolute |
|
52 |
left: 50% |
|
53 |
top: 50% |
|
54 |
-webkit-transform: translate(-50%, -50%) |
|
55 |
-ms-transform: translate(-50%, -50%) |
|
56 |
transform: translate(-50%, -50%) |
|
57 |
|
|
58 |
|
|
59 |
.notfound h2 |
|
60 |
font-family: 'Maven Pro', sans-serif |
|
61 |
font-size: 46px |
|
62 |
color: #000 |
|
63 |
font-weight: 900 |
|
64 |
text-transform: uppercase |
|
65 |
margin: 0px |
|
66 |
|
|
67 |
|
|
68 |
.notfound p |
|
69 |
font-family: 'Maven Pro', sans-serif |
|
70 |
font-size: 16px |
|
71 |
color: #000 |
|
72 |
font-weight: 400 |
|
73 |
text-transform: uppercase |
|
74 |
margin-top: 15px |
|
75 |
|
|
76 |
|
|
77 |
.notfound a |
|
78 |
font-family: 'Maven Pro', sans-serif |
|
79 |
font-size: 14px |
|
80 |
text-decoration: none |
|
81 |
text-transform: uppercase |
|
82 |
background: #189cf0 |
|
83 |
display: inline-block |
|
84 |
padding: 16px 38px |
|
85 |
border: 2px solid transparent |
|
86 |
border-radius: 40px |
|
87 |
color: #fff |
|
88 |
font-weight: 400 |
|
89 |
-webkit-transition: 0.2s all |
|
90 |
transition: 0.2s all |
|
91 |
|
|
92 |
|
|
93 |
.notfound a:hover |
|
94 |
background-color: #fff |
|
95 |
border-color: #189cf0 |
|
96 |
color: #189cf0 |
|
97 |
|
|
98 |
|
|
99 |
@media only screen and (max-width: 480px) |
|
100 |
.notfound .notfound-404 h1 |
|
101 |
font-size: 162px |
|
102 |
|
|
103 |
.notfound h2 |
|
104 |
font-size: 26px |
|
105 |
|
|
106 |
|
webapp/src/app/page-not-found/page-not-found.component.ts | ||
---|---|---|
1 |
import { Component, OnInit } from '@angular/core'; |
|
2 |
|
|
3 |
@Component({ |
|
4 |
selector: 'app-page-not-found', |
|
5 |
templateUrl: './page-not-found.component.html', |
|
6 |
styleUrls: ['./page-not-found.component.sass'] |
|
7 |
}) |
|
8 |
export class PageNotFoundComponent implements OnInit { |
|
9 |
|
|
10 |
constructor() { } |
|
11 |
|
|
12 |
ngOnInit() { |
|
13 |
} |
|
14 |
|
|
15 |
} |
webapp/src/app/services/api/user.service.ts | ||
---|---|---|
24 | 24 |
* Returns user profile if the user making this call |
25 | 25 |
* is logged as admin |
26 | 26 |
* UserProfile.notification might be returned as string instead of date |
27 |
* @param id employee id
|
|
27 |
* @param id user profile id
|
|
28 | 28 |
*/ |
29 | 29 |
getUserProfile(id: number) { |
30 | 30 |
return this.makeGetProfileApiCall(id.toString(), null); |
webapp/src/app/services/util/menu.service.ts | ||
---|---|---|
1 |
import {Injectable} from '@angular/core'; |
|
2 |
import {UserService} from '../api/user.service'; |
|
3 |
import {UserProfile} from '../../models/user.model'; |
|
4 |
import {MenuItem} from '../../models/menu-item.model'; |
|
5 |
import {UserType} from '../../enums/common.enum'; |
|
6 |
import {Observable, of} from 'rxjs'; |
|
7 |
|
|
8 |
const MENU_ITEMS: MenuItem[] = [ |
|
9 |
{name: 'Zaměstnanci', routePath: 'employees'}, |
|
10 |
{name: 'Dashboard', routePath: 'dashboard'}, |
|
11 |
]; |
|
12 |
|
|
13 |
@Injectable({ |
|
14 |
providedIn: 'root' |
|
15 |
}) |
|
16 |
export class MenuService { |
|
17 |
|
|
18 |
constructor(private userService: UserService) { } |
|
19 |
|
|
20 |
getMenuItems() { |
|
21 |
const menuItems: MenuItem[] = []; |
|
22 |
menuItems.push({name: 'Dashboard', routePath: 'dashboard'}); |
|
23 |
|
|
24 |
return new Observable((observer) => { |
|
25 |
this.userService.getLoggedUserProfile() |
|
26 |
.subscribe((profile: UserProfile) => { |
|
27 |
if (profile.role === UserType.EMPLOYER) { |
|
28 |
menuItems.push({name: 'Zaměstnanci', routePath: 'employees'}); |
|
29 |
} |
|
30 |
|
|
31 |
observer.next(menuItems); |
|
32 |
observer.complete(); |
|
33 |
}); |
|
34 |
}); |
|
35 |
} |
|
36 |
} |
Také k dispozici: Unified diff
Re#7528 Menu items are highlighted with correct default, added 404 page