Skip to content

Commit 64bdf56

Browse files
committed
Curriculum: Add canDeactivate
1 parent e25d3db commit 64bdf56

40 files changed

+97394
-0
lines changed

62-candeactivate/.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
9+
# Change these settings to your own preference
10+
indent_style = space
11+
indent_size = 2
12+
13+
# We recommend you to keep these unchanged
14+
end_of_line = lf
15+
charset = utf-8
16+
trim_trailing_whitespace = true
17+
insert_final_newline = true
18+
19+
[*.md]
20+
trim_trailing_whitespace = false

62-candeactivate/.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Project
2+
.idea
3+
4+
# Node
5+
node_modules
6+
7+
# macOS
8+
.DS_Store
9+
.AppleDouble
10+
.LSOverride
11+
Icon
12+
._*
13+
.Spotlight-V100
14+
.Trashes
15+
16+
## Windows
17+
Thumbs.db
18+
ehthumbs.db
19+
Desktop.ini
20+
$RECYCLE.BIN/
21+
22+
# Package Managers
23+
yarn-error.log
24+
npm-debug.log
25+
26+
# Cache
27+
.awcache

62-candeactivate/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<a href="https://ultimateangular.com" target="_blank"><img src="https://toddmotto.com/img/ua.png"></a>
2+
3+
# Angular Fundamentals Seed
4+
5+
> This is the seed project for the [Angular Fundamentals](https://ultimateangular.com/courses/#angular-2) course by [Todd Motto](https://twitter.com/toddmotto).
6+
7+
## Project Setup and Tooling
8+
9+
### Tools
10+
11+
This course is recorded with the following tools, you can optionally follow along using the same, or your favourite text editor/IDE and browser.
12+
13+
*Text editor*: Visual Studio Code, you can [download it here](http://code.visualstudio.com) for both Mac, Windows and Linux.
14+
*Browser*: Google Chrome, you can [download it here](https://www.google.com/chrome)
15+
16+
### Prerequisites
17+
18+
Please make sure that you have the following installed:
19+
20+
* Install the _latest version_ of [Node.js](http://nodejs.org) (Mac or Windows)
21+
* Mac users can optionally `brew install node` if they have [brew](http://brew.sh) installed
22+
23+
* Node Sass, you _may_ need it if you haven't already got it installed:
24+
25+
```bash
26+
npm install -g node-sass
27+
```
28+
29+
### Project Install
30+
31+
To grab the seed project, either Fork this repo or [click here to download](https://github.com/UltimateAngular/angular-fundamentals-seed/archive/master.zip) the `.zip` folder and extract the files wherever you like on your machine.
32+
33+
#### Step 1: Package Manager
34+
35+
To install the project dependencies, you will need to install `yarn`. To install `yarn`, run the following in your terminal:
36+
37+
```bash
38+
npm install -g yarn
39+
```
40+
41+
Mac users can alternatively use `brew` to install `yarn`.
42+
43+
```bash
44+
brew update
45+
brew install yarn
46+
```
47+
48+
If you experience any issues when installing/using `yarn` you can checkout the installation instructions [here](https://yarnpkg.com/en/docs/install).
49+
50+
##### Step 2: Project Dependencies
51+
52+
Now that we have a package manager, we can install the project dependencies. You can do this by running:
53+
54+
```bash
55+
yarn install
56+
```
57+
58+
This will install our dependencies for running our Angular application.
59+
60+
#### Step 3: Running the project
61+
62+
During development, the project is built using `webpack-dev-server`. This provides a local development server as well as having webpack recompile our app when a file changes. The project will also automatically refresh the page whenever we make changes.
63+
64+
To start the project in development, run:
65+
66+
```
67+
yarn start
68+
```
69+
70+
This will output some information about the project (such as the TypeScript version and build progress). Once you see "build completed", you are ready to code!
71+
72+
Open your browser to [localhost:4000](http://localhost:4000) to start running the code.
73+
74+
### Project Tooling
75+
76+
The project uses `webpack` to build and compile all of our assets. This will do the following for us:
77+
78+
- Compile all our TypeScript code into JavaScript (starting from `main.ts` and branching outwards from imported files)
79+
- Bundle all our JavaScript into one file to use
80+
- Allow us to use SASS for our component's CSS files
81+
- Provide the polyfills needed to run our app in all modern browsers
82+
- Mock a JSON backend using [json-server](https://github.com/typicode/json-server)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
:host {
2+
display: inline-block;
3+
flex: 1 0;
4+
width: 100%;
5+
height: 100%;
6+
}
7+
8+
.app {
9+
display: flex;
10+
flex-direction: column;
11+
height: 100%;
12+
13+
&__content {
14+
display: flex;
15+
flex: 1 0;
16+
}
17+
}
18+
19+
nav {
20+
flex: 0 0 15%;
21+
padding: 20px 0;
22+
border-right: 1px solid rgba(0, 0, 0, 0.1);
23+
a {
24+
display: block;
25+
margin-bottom: 10px;
26+
padding: 10px 30px;
27+
color: rgba(0, 0, 0, 0.5);
28+
text-decoration: none;
29+
font-size: 16px;
30+
border-left: 3px solid transparent;
31+
&.active {
32+
color: rgba(0, 0, 0, 0.8);
33+
border-left-color: #9f72e6;
34+
background: rgba(0, 0, 0, 0.03);
35+
}
36+
}
37+
}
38+
39+
header {
40+
background: #2d2d35;
41+
height: 70px;
42+
width: 100%;
43+
display: flex;
44+
align-items: center;
45+
padding-left: 10px;
46+
}

62-candeactivate/app/app.component.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-root',
5+
styleUrls: ['app.component.scss'],
6+
template: `
7+
<div class="app">
8+
<header>
9+
<img src="/img/logo.svg">
10+
</header>
11+
<div class="app__content">
12+
<nav>
13+
<a
14+
[routerLink]="['/mail', { outlets: { primary: 'folder/inbox', pane: null } }]"
15+
routerLinkActive="active">
16+
Inbox
17+
</a>
18+
<a
19+
[routerLink]="['/mail', { outlets: { primary: 'folder/trash', pane: null } }]"
20+
routerLinkActive="active">
21+
Trash
22+
</a>
23+
<a
24+
[routerLink]="['/dashboard']"
25+
routerLinkActive="active">
26+
Dashboard
27+
</a>
28+
</nav>
29+
<router-outlet></router-outlet>
30+
</div>
31+
</div>
32+
`
33+
})
34+
export class AppComponent {}

62-candeactivate/app/app.module.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
import { RouterModule, Routes } from '@angular/router';
4+
import { HttpModule } from '@angular/http';
5+
6+
import { MailModule } from './mail/mail.module';
7+
import { AuthModule } from './auth/auth.module';
8+
import { AuthGuard } from './auth/auth.guard';
9+
10+
import { AppComponent } from './app.component';
11+
12+
export const ROUTES: Routes = [
13+
{ path: 'dashboard', canLoad: [AuthGuard], loadChildren: './dashboard/dashboard.module#DashboardModule' },
14+
{ path: '**', redirectTo: 'mail/folder/inbox' }
15+
];
16+
17+
@NgModule({
18+
declarations: [
19+
AppComponent
20+
],
21+
imports: [
22+
BrowserModule,
23+
HttpModule,
24+
MailModule,
25+
AuthModule,
26+
RouterModule.forRoot(ROUTES)
27+
],
28+
bootstrap: [
29+
AppComponent
30+
]
31+
})
32+
export class AppModule {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Injectable } from '@angular/core';
2+
import { CanLoad, CanActivate, CanActivateChild } from '@angular/router';
3+
4+
import { AuthService } from './auth.service';
5+
6+
@Injectable()
7+
export class AuthGuard implements CanLoad, CanActivate, CanActivateChild {
8+
constructor(private authService: AuthService) {}
9+
canLoad() {
10+
return this.authService.checkPermissions();
11+
}
12+
canActivate() {
13+
return this.authService.isLoggedIn();
14+
}
15+
canActivateChild() {
16+
return this.authService.isLoggedIn();
17+
}
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { NgModule } from '@angular/core';
2+
3+
import { AuthService } from './auth.service';
4+
import { AuthGuard } from './auth.guard';
5+
6+
@NgModule({
7+
providers: [
8+
AuthService,
9+
AuthGuard
10+
]
11+
})
12+
export class AuthModule {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Injectable } from '@angular/core';
2+
import { Observable } from 'rxjs/Observable';
3+
import 'rxjs/add/observable/of';
4+
5+
@Injectable()
6+
export class AuthService {
7+
user = { isAdmin: true };
8+
checkPermissions() {
9+
return Observable.of(this.user.isAdmin);
10+
}
11+
isLoggedIn() {
12+
return Observable.of(true);
13+
}
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.dashboard {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'dashboard-app',
5+
styleUrls: ['dashboard.component.scss'],
6+
template: `
7+
<div>
8+
<h1>Dashboard</h1>
9+
</div>
10+
`
11+
})
12+
export class DashboardComponent {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { RouterModule, Routes } from '@angular/router';
4+
5+
import { DashboardComponent } from './containers/dashboard/dashboard.component';
6+
7+
export const ROUTES: Routes = [
8+
{
9+
path: '',
10+
component: DashboardComponent
11+
}
12+
];
13+
14+
@NgModule({
15+
imports: [
16+
CommonModule,
17+
RouterModule.forChild(ROUTES)
18+
],
19+
declarations: [
20+
DashboardComponent
21+
]
22+
})
23+
export class DashboardModule {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
:host {
2+
display: flex;
3+
width: 100%;
4+
}
5+
6+
nav {
7+
flex: 0 0 15%;
8+
padding: 20px 0;
9+
border-right: 1px solid rgba(0, 0, 0, 0.1);
10+
a {
11+
display: block;
12+
margin-bottom: 10px;
13+
padding: 10px 30px;
14+
color: rgba(0, 0, 0, 0.5);
15+
text-decoration: none;
16+
font-size: 16px;
17+
border-left: 3px solid transparent;
18+
&.active {
19+
color: rgba(0, 0, 0, 0.8);
20+
border-left-color: #9f72e6;
21+
background: rgba(0, 0, 0, 0.03);
22+
}
23+
}
24+
}
25+
26+
.mail {
27+
flex: 0 0 40%;
28+
padding: 20px 0;
29+
overflow: hidden;
30+
border-right: 1px solid rgba(0, 0, 0, 0.1);
31+
overflow-y: auto;
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'mail-app',
5+
styleUrls: ['mail-app.component.scss'],
6+
template: `
7+
<div class="mail">
8+
<router-outlet></router-outlet>
9+
</div>
10+
<div class="mail">
11+
<router-outlet name="pane"></router-outlet>
12+
</div>
13+
`
14+
})
15+
export class MailAppComponent {}

0 commit comments

Comments
 (0)