Skip to content

Commit bfc5cab

Browse files
committed
changed routes structure
1 parent ac8ed32 commit bfc5cab

10 files changed

+215
-54
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"core-js": "2.5.7",
3333
"googleapis": "33.0.0",
3434
"jquery": "3.3.1",
35+
"perfect-scrollbar": "^1.4.0",
3536
"rxjs": "6.3.2",
3637
"rxjs-compat": "6.3.2",
3738
"zone.js": "0.8.26"

src/app/app.component.html

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,2 @@
1-
<div class="wrapper">
2-
<div class="sidebar" data-color="red" data-image="">
3-
<app-sidebar></app-sidebar>
4-
<div class="sidebar-background" style="background-image: url(/assets/img/sidebar-5.jpg)"></div>
5-
</div>
61

7-
<div class="main-panel">
8-
<navbar-cmp></navbar-cmp>
9-
<router-outlet></router-outlet>
10-
<div *ngIf="isMap('maps')">
11-
<footer-cmp></footer-cmp>
12-
</div>
13-
</div>
14-
</div>
2+
<router-outlet></router-outlet>

src/app/app.module.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { BrowserModule } from '@angular/platform-browser';
1+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
22
import { NgModule } from '@angular/core';
33
import { FormsModule } from '@angular/forms';
44
import { HttpModule } from '@angular/http';
55
import { RouterModule } from '@angular/router';
6-
import { NguiMapModule} from '@ngui/map';
76

87
import { AppRoutingModule } from './app.routing';
98
import { NavbarModule } from './shared/navbar/navbar.module';
@@ -13,39 +12,22 @@ import { LbdModule } from './lbd/lbd.module';
1312

1413
import { AppComponent } from './app.component';
1514

16-
import { HomeComponent } from './home/home.component';
17-
import { UserComponent } from './user/user.component';
18-
import { TablesComponent } from './tables/tables.component';
19-
import { TypographyComponent } from './typography/typography.component';
20-
import { IconsComponent } from './icons/icons.component';
21-
import { MapsComponent } from './maps/maps.component';
22-
import { NotificationsComponent } from './notifications/notifications.component';
23-
import { UpgradeComponent } from './upgrade/upgrade.component';
15+
import { AdminLayoutComponent } from './layouts/admin-layout/admin-layout.component';
2416

2517
@NgModule({
2618
declarations: [
2719
AppComponent,
28-
HomeComponent,
29-
UserComponent,
30-
TablesComponent,
31-
TypographyComponent,
32-
IconsComponent,
33-
MapsComponent,
34-
NotificationsComponent,
35-
UpgradeComponent
36-
20+
AdminLayoutComponent
3721
],
3822
imports: [
39-
BrowserModule,
23+
BrowserAnimationsModule,
4024
FormsModule,
25+
RouterModule,
4126
HttpModule,
4227
NavbarModule,
4328
FooterModule,
4429
SidebarModule,
45-
RouterModule,
46-
AppRoutingModule,
47-
LbdModule,
48-
NguiMapModule.forRoot({apiUrl: 'https://maps.google.com/maps/api/js?key=YOUR_KEY_HERE'})
30+
AppRoutingModule
4931
],
5032
providers: [],
5133
bootstrap: [AppComponent]

src/app/app.routing.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ import { CommonModule, } from '@angular/common';
33
import { BrowserModule } from '@angular/platform-browser';
44
import { Routes, RouterModule } from '@angular/router';
55

6-
import { HomeComponent } from './home/home.component';
7-
import { UserComponent } from './user/user.component';
8-
import { TablesComponent } from './tables/tables.component';
9-
import { TypographyComponent } from './typography/typography.component';
10-
import { IconsComponent } from './icons/icons.component';
11-
import { MapsComponent } from './maps/maps.component';
12-
import { NotificationsComponent } from './notifications/notifications.component';
13-
import { UpgradeComponent } from './upgrade/upgrade.component';
6+
import { AdminLayoutComponent } from './layouts/admin-layout/admin-layout.component';
147

158
const routes: Routes =[
16-
{ path: 'dashboard', component: HomeComponent },
17-
{ path: 'user', component: UserComponent },
18-
{ path: 'table', component: TablesComponent },
19-
{ path: 'typography', component: TypographyComponent },
20-
{ path: 'icons', component: IconsComponent },
21-
{ path: 'maps', component: MapsComponent },
22-
{ path: 'notifications', component: NotificationsComponent },
23-
{ path: 'upgrade', component: UpgradeComponent },
24-
{ path: '', redirectTo: 'dashboard', pathMatch: 'full' }
9+
{
10+
path: '',
11+
redirectTo: 'dashboard',
12+
pathMatch: 'full',
13+
}, {
14+
path: '',
15+
component: AdminLayoutComponent,
16+
children: [
17+
{
18+
path: '',
19+
loadChildren: './layouts/admin-layout/admin-layout.module#AdminLayoutModule'
20+
}]},
21+
{
22+
path: '**',
23+
redirectTo: 'dashboard'
24+
}
2525
];
2626

2727
@NgModule({
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
<div class="wrapper">
3+
<div class="sidebar" data-color="red" data-image="">
4+
<app-sidebar></app-sidebar>
5+
<div class="sidebar-background" style="background-image: url(assets/img/sidebar-5.jpg)"></div>
6+
</div>
7+
8+
<div class="main-panel">
9+
<navbar-cmp></navbar-cmp>
10+
<router-outlet></router-outlet>
11+
<div *ngIf="isMap('maps')">
12+
<footer-cmp></footer-cmp>
13+
</div>
14+
</div>
15+
16+
</div>

src/app/layouts/admin-layout/admin-layout.component.scss

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { AdminLayoutComponent } from './admin-layout.component';
4+
5+
describe('AdminLayoutComponent', () => {
6+
let component: AdminLayoutComponent;
7+
let fixture: ComponentFixture<AdminLayoutComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ AdminLayoutComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(AdminLayoutComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
2+
import { Location, LocationStrategy, PathLocationStrategy, PopStateEvent } from '@angular/common';
3+
import 'rxjs/add/operator/filter';
4+
import { NavbarComponent } from '../../shared/navbar/navbar.component';
5+
import { Router, NavigationEnd, NavigationStart } from '@angular/router';
6+
import { Subscription } from 'rxjs/Subscription';
7+
import PerfectScrollbar from 'perfect-scrollbar';
8+
import { Observable } from 'rxjs';
9+
10+
@Component({
11+
selector: 'app-admin-layout',
12+
templateUrl: './admin-layout.component.html',
13+
styleUrls: ['./admin-layout.component.scss']
14+
})
15+
export class AdminLayoutComponent implements OnInit {
16+
private _router: Subscription;
17+
private lastPoppedUrl: string;
18+
private yScrollStack: number[] = [];
19+
20+
constructor( public location: Location, private router: Router) {}
21+
22+
ngOnInit() {
23+
const isWindows = navigator.platform.indexOf('Win') > -1 ? true : false;
24+
25+
if (isWindows && !document.getElementsByTagName('body')[0].classList.contains('sidebar-mini')) {
26+
// if we are on windows OS we activate the perfectScrollbar function
27+
28+
document.getElementsByTagName('body')[0].classList.add('perfect-scrollbar-on');
29+
} else {
30+
document.getElementsByTagName('body')[0].classList.remove('perfect-scrollbar-off');
31+
}
32+
const elemMainPanel = <HTMLElement>document.querySelector('.main-panel');
33+
const elemSidebar = <HTMLElement>document.querySelector('.sidebar .sidebar-wrapper');
34+
35+
this.location.subscribe((ev:PopStateEvent) => {
36+
this.lastPoppedUrl = ev.url;
37+
});
38+
this.router.events.subscribe((event:any) => {
39+
if (event instanceof NavigationStart) {
40+
if (event.url != this.lastPoppedUrl)
41+
this.yScrollStack.push(window.scrollY);
42+
} else if (event instanceof NavigationEnd) {
43+
if (event.url == this.lastPoppedUrl) {
44+
this.lastPoppedUrl = undefined;
45+
window.scrollTo(0, this.yScrollStack.pop());
46+
} else
47+
window.scrollTo(0, 0);
48+
}
49+
});
50+
this._router = this.router.events.filter(event => event instanceof NavigationEnd).subscribe((event: NavigationEnd) => {
51+
elemMainPanel.scrollTop = 0;
52+
elemSidebar.scrollTop = 0;
53+
});
54+
if (window.matchMedia(`(min-width: 960px)`).matches && !this.isMac()) {
55+
let ps = new PerfectScrollbar(elemMainPanel);
56+
ps = new PerfectScrollbar(elemSidebar);
57+
}
58+
}
59+
ngAfterViewInit() {
60+
this.runOnRouteChange();
61+
}
62+
isMap(path){
63+
var titlee = this.location.prepareExternalUrl(this.location.path());
64+
titlee = titlee.slice( 1 );
65+
if(path == titlee){
66+
return false;
67+
}
68+
else {
69+
return true;
70+
}
71+
}
72+
runOnRouteChange(): void {
73+
if (window.matchMedia(`(min-width: 960px)`).matches && !this.isMac()) {
74+
const elemMainPanel = <HTMLElement>document.querySelector('.main-panel');
75+
const ps = new PerfectScrollbar(elemMainPanel);
76+
ps.update();
77+
}
78+
}
79+
isMac(): boolean {
80+
let bool = false;
81+
if (navigator.platform.toUpperCase().indexOf('MAC') >= 0 || navigator.platform.toUpperCase().indexOf('IPAD') >= 0) {
82+
bool = true;
83+
}
84+
return bool;
85+
}
86+
87+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { NgModule } from '@angular/core';
2+
import { RouterModule } from '@angular/router';
3+
import { CommonModule } from '@angular/common';
4+
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
5+
6+
import { LbdModule } from '../../lbd/lbd.module';
7+
import { NguiMapModule} from '@ngui/map';
8+
9+
import { AdminLayoutRoutes } from './admin-layout.routing';
10+
11+
import { HomeComponent } from '../../home/home.component';
12+
import { UserComponent } from '../../user/user.component';
13+
import { TablesComponent } from '../../tables/tables.component';
14+
import { TypographyComponent } from '../../typography/typography.component';
15+
import { IconsComponent } from '../../icons/icons.component';
16+
import { MapsComponent } from '../../maps/maps.component';
17+
import { NotificationsComponent } from '../../notifications/notifications.component';
18+
import { UpgradeComponent } from '../../upgrade/upgrade.component';
19+
20+
21+
@NgModule({
22+
imports: [
23+
CommonModule,
24+
RouterModule.forChild(AdminLayoutRoutes),
25+
FormsModule,
26+
LbdModule,
27+
NguiMapModule.forRoot({apiUrl: 'https://maps.google.com/maps/api/js?key=YOUR_KEY_HERE'})
28+
],
29+
declarations: [
30+
HomeComponent,
31+
UserComponent,
32+
TablesComponent,
33+
TypographyComponent,
34+
IconsComponent,
35+
MapsComponent,
36+
NotificationsComponent,
37+
UpgradeComponent
38+
]
39+
})
40+
41+
export class AdminLayoutModule {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Routes } from '@angular/router';
2+
3+
import { HomeComponent } from '../../home/home.component';
4+
import { UserComponent } from '../../user/user.component';
5+
import { TablesComponent } from '../../tables/tables.component';
6+
import { TypographyComponent } from '../../typography/typography.component';
7+
import { IconsComponent } from '../../icons/icons.component';
8+
import { MapsComponent } from '../../maps/maps.component';
9+
import { NotificationsComponent } from '../../notifications/notifications.component';
10+
import { UpgradeComponent } from '../../upgrade/upgrade.component';
11+
12+
export const AdminLayoutRoutes: Routes = [
13+
{ path: 'dashboard', component: HomeComponent },
14+
{ path: 'user', component: UserComponent },
15+
{ path: 'table', component: TablesComponent },
16+
{ path: 'typography', component: TypographyComponent },
17+
{ path: 'icons', component: IconsComponent },
18+
{ path: 'maps', component: MapsComponent },
19+
{ path: 'notifications', component: NotificationsComponent },
20+
{ path: 'upgrade', component: UpgradeComponent },
21+
];

0 commit comments

Comments
 (0)