diff --git a/src/app/_guards/auth.guard.ts b/src/app/_guards/auth.guard.ts
index 5c64d59..3e7a9fc 100644
--- a/src/app/_guards/auth.guard.ts
+++ b/src/app/_guards/auth.guard.ts
@@ -4,18 +4,18 @@ import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from
@Injectable()
export class AuthGuard implements CanActivate {
- constructor(private router: Router) { }
+ constructor(private router: Router) { }
- canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
- if (localStorage.getItem('sessionKey')) {
- console.log('session key found')
- // logged in so return true
- return true;
- }
-
- // not logged in so redirect to login page with the return url
- console.log('no session key found')
- this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
- return false;
+ canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
+ if (localStorage.getItem('sessionKey')) {
+ console.log('session key found')
+ // logged in so return true
+ return true;
}
+
+ // not logged in so redirect to login page with the return url
+ console.log('no session key found')
+ this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
+ return false;
+ }
}
diff --git a/src/app/_guards/index.ts b/src/app/_guards/index.ts
deleted file mode 100644
index 3e48800..0000000
--- a/src/app/_guards/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from './auth.guard';
\ No newline at end of file
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index b3efada..431f0ed 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -16,6 +16,7 @@ import { BreadcrumbsComponent } from './shared/breadcrumb.component';
// Routing & Guard Module
import { AppRoutingModule } from './app.routing';
import { AuthGuard } from './_guards/auth.guard';
+import { ApiService } from './providers/api-service';
// Layouts
import { FullLayoutComponent } from './layouts/full-layout.component';
@@ -27,16 +28,19 @@ import { P500Component } from './pages/500.component';
// Submodules
import { AuthModule } from './auth/auth.module';
+import { DashboardModule } from './dashboard/dashboard.module';
@NgModule({
imports: [
BrowserModule,
- AppRoutingModule,
HttpModule,
BsDropdownModule.forRoot(),
TabsModule.forRoot(),
ChartsModule,
AuthModule,
+ DashboardModule,
+ // Loaded last to allow for 404 catchall
+ AppRoutingModule,
],
declarations: [
AppComponent,
@@ -51,6 +55,7 @@ import { AuthModule } from './auth/auth.module';
],
providers: [
AuthGuard,
+ ApiService,
{
provide: LocationStrategy,
useClass: HashLocationStrategy
diff --git a/src/app/app.routing.ts b/src/app/app.routing.ts
index 4815994..c430c9f 100644
--- a/src/app/app.routing.ts
+++ b/src/app/app.routing.ts
@@ -1,48 +1,14 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
-import { AuthGuard } from './_guards/auth.guard';
-
-// Layouts
-import { FullLayoutComponent } from './layouts/full-layout.component';
-import { SimpleLayoutComponent } from './layouts/simple-layout.component';
import { P404Component } from './pages/404.component';
import { P500Component } from './pages/500.component';
export const routes: Routes = [
- {
- path: '',
- redirectTo: '/dashboard',
- pathMatch: 'full',
- },
- {
- path: '',
- component: FullLayoutComponent,
- canActivate: [AuthGuard],
- data: {
- title: 'Home'
- },
- children: [
- {
- path: 'dashboard',
- loadChildren: './dashboard/dashboard.module#DashboardModule'
- },
- {
- path: 'components',
- loadChildren: './components/components.module#ComponentsModule'
- },
- {
- path: 'widgets',
- loadChildren: './widgets/widgets.module#WidgetsModule'
- },
- {
- path: 'charts',
- loadChildren: './chartjs/chartjs.module#ChartJSModule'
- }
- ]
- },
+ { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
{ path: '404', component: P404Component },
{ path: '500', component: P500Component },
+ { path: '**', redirectTo: '/404' },
];
@NgModule({
diff --git a/src/app/dashboard/dashboard-routing.module.ts b/src/app/dashboard/dashboard-routing.module.ts
deleted file mode 100644
index c56e63a..0000000
--- a/src/app/dashboard/dashboard-routing.module.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { NgModule } from '@angular/core';
-import { Routes,
- RouterModule } from '@angular/router';
-
-import { DashboardComponent } from './dashboard.component';
-
-const routes: Routes = [
- {
- path: '',
- component: DashboardComponent,
- data: {
- title: 'Dashboard'
- }
- }
-];
-
-@NgModule({
- imports: [RouterModule.forChild(routes)],
- exports: [RouterModule]
-})
-export class DashboardRoutingModule {}
diff --git a/src/app/dashboard/dashboard.module.ts b/src/app/dashboard/dashboard.module.ts
index 28b2ea7..5e9956e 100644
--- a/src/app/dashboard/dashboard.module.ts
+++ b/src/app/dashboard/dashboard.module.ts
@@ -1,10 +1,12 @@
import { NgModule } from '@angular/core';
+import { CommonModule } from '@angular/common';
import { ChartsModule } from 'ng2-charts/ng2-charts';
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { DashboardComponent } from './dashboard.component';
-import { DashboardRoutingModule } from './dashboard-routing.module';
-import { CommonModule } from '@angular/common';
+import { LeaderboardsComponent } from './leaderboards.component';
+
+import { DashboardRoutingModule } from './dashboard.routing';
@NgModule({
imports: [
@@ -13,6 +15,9 @@ import { CommonModule } from '@angular/common';
BsDropdownModule,
CommonModule
],
- declarations: [ DashboardComponent ]
+ declarations: [
+ DashboardComponent,
+ LeaderboardsComponent,
+ ]
})
export class DashboardModule { }
diff --git a/src/app/dashboard/dashboard.routing.ts b/src/app/dashboard/dashboard.routing.ts
new file mode 100644
index 0000000..284e853
--- /dev/null
+++ b/src/app/dashboard/dashboard.routing.ts
@@ -0,0 +1,34 @@
+import { NgModule } from '@angular/core';
+import { Routes, RouterModule } from '@angular/router';
+import { AuthGuard } from '../_guards/auth.guard';
+
+import { DashboardComponent } from './dashboard.component';
+import { LeaderboardsComponent } from './leaderboards.component';
+import { FullLayoutComponent } from '../layouts/full-layout.component';
+
+// Using child path to allow for FullLayout theming
+const routes: Routes = [
+ {
+ path: '',
+ component: FullLayoutComponent,
+ canActivate: [AuthGuard],
+ children: [
+ {
+ path: 'dashboard',
+ component: DashboardComponent,
+ data: { title: 'Dashboard' },
+ },
+ {
+ path: 'leaderboards',
+ component: LeaderboardsComponent,
+ data: { title: 'Leaderboards' },
+ }
+ ],
+ }
+];
+
+@NgModule({
+ imports: [RouterModule.forChild(routes)],
+ exports: [RouterModule]
+})
+export class DashboardRoutingModule {}
diff --git a/src/app/components/leaderboards.component.html b/src/app/dashboard/leaderboards.component.html
similarity index 100%
rename from src/app/components/leaderboards.component.html
rename to src/app/dashboard/leaderboards.component.html
diff --git a/src/app/components/leaderboards.component.ts b/src/app/dashboard/leaderboards.component.ts
similarity index 100%
rename from src/app/components/leaderboards.component.ts
rename to src/app/dashboard/leaderboards.component.ts
diff --git a/src/app/layouts/full-layout.component.html b/src/app/layouts/full-layout.component.html
index b4a14a0..73087e7 100644
--- a/src/app/layouts/full-layout.component.html
+++ b/src/app/layouts/full-layout.component.html
@@ -31,7 +31,7 @@
-
+
Leaderboards
diff --git a/src/app/pages/login.component.html b/src/app/pages/login.component.html
deleted file mode 100644
index 277c26c..0000000
--- a/src/app/pages/login.component.html
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
-
-
-
-
-
Login
-
Sign In to your account
-
-
-
-
-
-
-
Sign up
-
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
-
-
-
-
-
-
-
-
-
diff --git a/src/app/pages/login.component.ts b/src/app/pages/login.component.ts
deleted file mode 100644
index f187b74..0000000
--- a/src/app/pages/login.component.ts
+++ /dev/null
@@ -1,64 +0,0 @@
-import { Component, OnInit } from '@angular/core';
-import { Validators, FormBuilder, FormGroup } from '@angular/forms';
-import { Http, Response } from '@angular/http';
-import { ApiService } from '../providers/api-service';
-import { Router, ActivatedRoute } from '@angular/router';
-import 'rxjs/add/operator/map';
-
-@Component({
- templateUrl: 'login.component.html',
- providers: [ApiService]
-})
-export class LoginComponent implements OnInit {
- signin: FormGroup;
- returnUrl: string;
-
- constructor(
- private route: ActivatedRoute,
- private http: Http,
- private formBuilder: FormBuilder,
- private router: Router,
- private api: ApiService
- ) {
- this.signin = this.formBuilder.group({
- email: ['', [Validators.required]],
- password: ['', [Validators.required]],
- });
- }
-
- ngOnInit() {
- // reset login status
- this.api
- .logout()
- .subscribe(
- result => {
- console.log('Logged out!');
- }
- );
-
- this.api.graph_data(undefined).subscribe(
- result => { console.log(result) }
- )
-
- // get return url from route parameters or default to '/'
- this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
- }
-
- onSubmit() {
- console.log(this.signin.value);
-
- this.api
- .login(this.signin.value)
- .subscribe(
- result => {
- console.log('logged in!');
- this.router.navigate([this.returnUrl]);
- },
- error => {
- console.log( error._body );
- }
- );
- }
-
-
-}
\ No newline at end of file
diff --git a/src/app/pages/pages-routing.module.ts b/src/app/pages/pages-routing.module.ts
deleted file mode 100644
index eab88ca..0000000
--- a/src/app/pages/pages-routing.module.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import { NgModule } from '@angular/core';
-import { Routes, RouterModule } from '@angular/router';
-
-import { P404Component } from './404.component';
-import { P500Component } from './500.component';
-import { LoginComponent } from './login.component';
-import { RegisterComponent } from './register.component';
-
-const routes: Routes = [
- {
- path: '',
- data: {
- title: 'Example Pages'
- },
- children: [
- {
- path: '404',
- component: P404Component,
- data: {
- title: 'Page 404'
- }
- },
- {
- path: '500',
- component: P500Component,
- data: {
- title: 'Page 500'
- }
- },
- {
- path: 'login',
- component: LoginComponent,
- data: {
- title: 'Login Page'
- }
- },
- {
- path: 'register',
- component: RegisterComponent,
- data: {
- title: 'Register Page'
- }
- }
- ]
- }
-];
-
-@NgModule({
- imports: [RouterModule.forChild(routes)],
- exports: [RouterModule]
-})
-export class PagesRoutingModule {}
diff --git a/src/app/pages/pages.module.ts b/src/app/pages/pages.module.ts
deleted file mode 100644
index 4c75765..0000000
--- a/src/app/pages/pages.module.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { NgModule } from '@angular/core';
-import { FormsModule, ReactiveFormsModule } from '@angular/forms';
-import { CommonModule } from '@angular/common';
-
-import { P404Component } from './404.component';
-import { P500Component } from './500.component';
-import { LoginComponent } from './login.component';
-import { RegisterComponent } from './register.component';
-
-import { PagesRoutingModule } from './pages-routing.module';
-import { TabsModule } from 'ngx-bootstrap/tabs';
-
-@NgModule({
- imports: [
- CommonModule,
- PagesRoutingModule,
- FormsModule,
- ReactiveFormsModule,
- TabsModule
- ],
- declarations: [
- P404Component,
- P500Component,
- LoginComponent,
- RegisterComponent
- ]
-})
-export class PagesModule { }
diff --git a/src/app/pages/register.component.html b/src/app/pages/register.component.html
deleted file mode 100644
index e311d4b..0000000
--- a/src/app/pages/register.component.html
+++ /dev/null
@@ -1,142 +0,0 @@
-
-
-
-
-
-
-
Register
-
Create your account
-
-
-
-
-
-
-
-
Please Select a User Type
-
-
-
-
-
-
-
diff --git a/src/app/pages/register.component.ts b/src/app/pages/register.component.ts
deleted file mode 100644
index eeb4c7e..0000000
--- a/src/app/pages/register.component.ts
+++ /dev/null
@@ -1,124 +0,0 @@
-import { Component } from '@angular/core';
-import { Validators, FormBuilder, FormGroup } from '@angular/forms';
-import { ValidationManager } from "ng2-validation-manager";
-import { Http, Response } from '@angular/http';
-import { ApiService } from '../providers/api-service';
-import {Router } from '@angular/router';
-import 'rxjs/add/operator/map';
-
-@Component({
- templateUrl: 'register.component.html',
- providers: [ApiService]
-})
-
-export class RegisterComponent {
- signupForm: ValidationManager;
- customerForm: ValidationManager;
- organisationForm: ValidationManager;
- years: Object[];
-
- constructor(
- private http: Http,
- private formBuilder: FormBuilder,
- private router: Router,
- private api: ApiService,
- ) {
- this.years = [];
- let max = new Date().getFullYear() - 10,
- min = max - 140;
-
- for (let i = max; i>=min; i--){
- this.years.push(i);
- }
- this.signupForm = new ValidationManager({
- token: 'required',
- usertype: 'required',
- email: 'required|email',
- password: 'required',
- confirmpassword: 'required|equalTo:password'
- });
- this.customerForm = new ValidationManager({
- display_name: 'required',
- full_name: 'required',
- postcode: 'required',
- year_of_birth:'required',
- });
- this.organisationForm = new ValidationManager({
- name: 'required',
- sector: 'required',
- street_name: 'required',
- town: 'required',
- postcode: 'required',
- });
- }
-
- onSubmitCustomer() {
-
- console.log(this.signupForm.isValid());
- if (!this.signupForm.isValid() && !this.customerForm.isValid()) {
- console.log("Not Valid!");
- return;
- }
- let signupForm = this.signupForm.getForm().value;
- let customerForm = this.customerForm.getForm().value;
-
- let data = {
- token: signupForm.token,
- usertype: signupForm.usertype,
- email: signupForm.email,
- password: signupForm.password,
- display_name: customerForm.display_name,
- full_name: customerForm.full_name,
- postcode: customerForm.postcode,
- year_of_birth:customerForm.year_of_birth,
- };
- console.log(data);
- this.api
- .register(data)
- .subscribe(
- result => {
- console.log('registered!');
- this.router.navigate(['/dashboard']);
- },
- error => {
- console.log( error._body );
- }
- );
- }
- onSubmitOrganisation() {
-
- console.log(this.signupForm.isValid());
- if (!this.signupForm.isValid() || !this.organisationForm.isValid()) {
- console.log("Not Valid!");
- return;
- }
- let signupForm = this.signupForm.getForm().value;
- let organisationForm = this.organisationForm.getForm().value;
-
- let data = {
- token: signupForm.token,
- usertype: signupForm.usertype,
- email: signupForm.email,
- password: signupForm.password,
- name: organisationForm.name,
- sector: organisationForm.sector,
- street_name: organisationForm.street_name,
- town: organisationForm.town,
- postcode: organisationForm.postcode,
- };
- console.log(data);
- this.api
- .register(data)
- .subscribe(
- result => {
- console.log('registered!');
- this.router.navigate(['/dashboard']);
- },
- error => {
- console.log( error._body );
- }
- );
- }
-
-
-}
\ No newline at end of file
diff --git a/src/index.html b/src/index.html
index a094d4f..3e0755e 100644
--- a/src/index.html
+++ b/src/index.html
@@ -1,7 +1,7 @@
-
+
@@ -18,29 +18,7 @@
-
-
-
+