Estefani 7 سال پیش
والد
کامیت
f19f7b0264
53فایلهای تغییر یافته به همراه484 افزوده شده و 29 حذف شده
  1. 0 0
      .editorconfig
  2. 0 0
      .gitignore
  3. 0 0
      README.md
  4. 0 0
      angular.json
  5. 0 0
      e2e/protractor.conf.js
  6. 0 0
      e2e/src/app.e2e-spec.ts
  7. 0 0
      e2e/src/app.po.ts
  8. 0 0
      e2e/tsconfig.e2e.json
  9. 0 0
      package.json
  10. 15 6
      src/app/app-routing.module.ts
  11. 22 0
      src/app/app.component.css
  12. 6 20
      src/app/app.component.html
  13. 0 0
      src/app/app.component.spec.ts
  14. 1 1
      src/app/app.component.ts
  15. 12 2
      src/app/app.module.ts
  16. 62 0
      src/app/dashboard/dashboard.component.css
  17. 9 0
      src/app/dashboard/dashboard.component.html
  18. 25 0
      src/app/dashboard/dashboard.component.spec.ts
  19. 23 0
      src/app/dashboard/dashboard.component.ts
  20. 0 0
      src/app/hero-detail/hero-detail.component.css
  21. 11 0
      src/app/hero-detail/hero-detail.component.html
  22. 25 0
      src/app/hero-detail/hero-detail.component.spec.ts
  23. 34 0
      src/app/hero-detail/hero-detail.component.ts
  24. 12 0
      src/app/hero.service.spec.ts
  25. 24 0
      src/app/hero.service.ts
  26. 5 0
      src/app/hero.ts
  27. 48 0
      src/app/heroes/heroes.component.css
  28. 9 0
      src/app/heroes/heroes.component.html
  29. 25 0
      src/app/heroes/heroes.component.spec.ts
  30. 24 0
      src/app/heroes/heroes.component.ts
  31. 12 0
      src/app/message.service.spec.ts
  32. 16 0
      src/app/message.service.ts
  33. 0 0
      src/app/messages/messages.component.css
  34. 8 0
      src/app/messages/messages.component.html
  35. 25 0
      src/app/messages/messages.component.spec.ts
  36. 16 0
      src/app/messages/messages.component.ts
  37. 15 0
      src/app/mock-heroes.ts
  38. 0 0
      src/assets/.gitkeep
  39. 0 0
      src/browserslist
  40. 0 0
      src/environments/environment.prod.ts
  41. 0 0
      src/environments/environment.ts
  42. 0 0
      src/favicon.ico
  43. 0 0
      src/index.html
  44. 0 0
      src/karma.conf.js
  45. 0 0
      src/main.ts
  46. 0 0
      src/polyfills.ts
  47. 0 0
      src/styles.css
  48. 0 0
      src/test.ts
  49. 0 0
      src/tsconfig.app.json
  50. 0 0
      src/tsconfig.spec.json
  51. 0 0
      src/tslint.json
  52. 0 0
      tsconfig.json
  53. 0 0
      tslint.json

+ 0 - 0
.editorconfig


+ 0 - 0
.gitignore


+ 0 - 0
README.md


+ 0 - 0
angular.json


+ 0 - 0
e2e/protractor.conf.js


+ 0 - 0
e2e/src/app.e2e-spec.ts


+ 0 - 0
e2e/src/app.po.ts


+ 0 - 0
e2e/tsconfig.e2e.json


+ 0 - 0
package.json


+ 15 - 6
src/app/app-routing.module.ts

@@ -1,10 +1,19 @@
 import { NgModule } from '@angular/core';
-import { Routes, RouterModule } from '@angular/router';
-
-const routes: Routes = [];
+import { RouterModule, Routes } from '@angular/router';
+import { HeroesComponent } from './heroes/heroes.component';
+import { DashboardComponent }   from './dashboard/dashboard.component';
+import { HeroDetailComponent }  from './hero-detail/hero-detail.component';
 
+const routes: Routes = [
+  { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
+  { path: 'dashboard', component: DashboardComponent },
+  { path: 'detail/:id', component: HeroDetailComponent },
+  { path: 'heroes', component: HeroesComponent }
+];
+  
 @NgModule({
-  imports: [RouterModule.forRoot(routes)],
-  exports: [RouterModule]
-})
+  imports: [ RouterModule.forRoot(routes) ],
+  exports: [ RouterModule ]
+ })
+  
 export class AppRoutingModule { }

+ 22 - 0
src/app/app.component.css

@@ -0,0 +1,22 @@
+/* Application-wide Styles */
+h1 {
+    color: #369;
+    font-family: Arial, Helvetica, sans-serif;
+    font-size: 250%;
+  }
+  h2, h3 {
+    color: #444;
+    font-family: Arial, Helvetica, sans-serif;
+    font-weight: lighter;
+  }
+  body {
+    margin: 2em;
+  }
+  body, input[type="text"], button {
+    color: #888;
+    font-family: Cambria, Georgia;
+  }
+  /* everywhere else */
+  * {
+    font-family: Arial, Helvetica, sans-serif;
+  }

+ 6 - 20
src/app/app.component.html

@@ -1,21 +1,7 @@
-<!--The content below is only a placeholder and can be replaced.-->
-<div style="text-align:center">
-  <h1>
-    Welcome to {{ title }}!
-  </h1>
-  <img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
-</div>
-<h2>Here are some links to help you start: </h2>
-<ul>
-  <li>
-    <h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
-  </li>
-  <li>
-    <h2><a target="_blank" rel="noopener" href="https://angular.io/cli">CLI Documentation</a></h2>
-  </li>
-  <li>
-    <h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
-  </li>
-</ul>
-
+<h1>{{title}}</h1>
+<nav>
+   <a routerLink="/dashboard">Dashboard</a>
+    <a routerLink="/heroes">Heroes</a>
+</nav>
 <router-outlet></router-outlet>
+<app-messages></app-messages>

+ 0 - 0
src/app/app.component.spec.ts


+ 1 - 1
src/app/app.component.ts

@@ -6,5 +6,5 @@ import { Component } from '@angular/core';
   styleUrls: ['./app.component.css']
 })
 export class AppComponent {
-  title = 'angular-tour-of-heroes';
+  title = 'angular-tour-of-heroes conacaste';
 }

+ 12 - 2
src/app/app.module.ts

@@ -1,16 +1,26 @@
 import { BrowserModule } from '@angular/platform-browser';
 import { NgModule } from '@angular/core';
+import { FormsModule } from '@angular/forms'; // <-- NgModel lives here
 
 import { AppRoutingModule } from './app-routing.module';
 import { AppComponent } from './app.component';
+import { HeroesComponent } from './heroes/heroes.component';
+import { HeroDetailComponent } from './hero-detail/hero-detail.component';
+import { MessagesComponent } from './messages/messages.component';
+import { DashboardComponent } from './dashboard/dashboard.component';
 
 @NgModule({
   declarations: [
-    AppComponent
+    AppComponent,
+    HeroesComponent,
+    HeroDetailComponent,
+    MessagesComponent,
+    DashboardComponent
   ],
   imports: [
     BrowserModule,
-    AppRoutingModule
+    AppRoutingModule,
+    FormsModule
   ],
   providers: [],
   bootstrap: [AppComponent]

+ 62 - 0
src/app/dashboard/dashboard.component.css

@@ -0,0 +1,62 @@
+[class*='col-'] {
+    float: left;
+    padding-right: 20px;
+    padding-bottom: 20px;
+  }
+  [class*='col-']:last-of-type {
+    padding-right: 0;
+  }
+  a {
+    text-decoration: none;
+  }
+  *, *:after, *:before {
+    -webkit-box-sizing: border-box;
+    -moz-box-sizing: border-box;
+    box-sizing: border-box;
+  }
+  h3 {
+    text-align: center;
+    margin-bottom: 0;
+  }
+  h4 {
+    position: relative;
+  }
+  .grid {
+    margin: 0;
+  }
+  .col-1-4 {
+    width: 25%;
+  }
+  .module {
+    padding: 20px;
+    text-align: center;
+    color: #eee;
+    max-height: 120px;
+    min-width: 120px;
+    background-color: #607d8b;
+    border-radius: 2px;
+  }
+  .module:hover {
+    background-color: #eee;
+    cursor: pointer;
+    color: #607d8b;
+  }
+  .grid-pad {
+    padding: 10px 0;
+  }
+  .grid-pad > [class*='col-']:last-of-type {
+    padding-right: 20px;
+  }
+  @media (max-width: 600px) {
+    .module {
+      font-size: 10px;
+      max-height: 75px; }
+  }
+  @media (max-width: 1024px) {
+    .grid {
+      margin: 0;
+    }
+    .module {
+      min-width: 60px;
+    }
+  }

+ 9 - 0
src/app/dashboard/dashboard.component.html

@@ -0,0 +1,9 @@
+<h3>Top Heroes</h3>
+<div class="grid grid-pad">
+   <a *ngFor="let hero of heroes" class="col-1-4"routerLink="/detail/{{hero.id}}">
+  <div class="module hero">
+     <h4>{{hero.name}}</h4>
+    </div>
+   </a>
+</div>
+

+ 25 - 0
src/app/dashboard/dashboard.component.spec.ts

@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { DashboardComponent } from './dashboard.component';
+
+describe('DashboardComponent', () => {
+  let component: DashboardComponent;
+  let fixture: ComponentFixture<DashboardComponent>;
+
+  beforeEach(async(() => {
+    TestBed.configureTestingModule({
+      declarations: [ DashboardComponent ]
+    })
+    .compileComponents();
+  }));
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(DashboardComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 23 - 0
src/app/dashboard/dashboard.component.ts

@@ -0,0 +1,23 @@
+import { Component, OnInit } from '@angular/core';
+import { Hero } from '../hero';
+import { HeroService } from '../hero.service';
+ 
+@Component({
+  selector: 'app-dashboard',
+  templateUrl: './dashboard.component.html',
+  styleUrls: [ './dashboard.component.css' ]
+})
+export class DashboardComponent implements OnInit {
+  heroes: Hero[] = [];
+ 
+  constructor(private heroService: HeroService) { }
+ 
+  ngOnInit() {
+    this.getHeroes();
+  }
+ 
+  getHeroes(): void {
+    this.heroService.getHeroes()
+      .subscribe(heroes => this.heroes = heroes.slice(1, 5));
+  }
+}

+ 0 - 0
src/app/hero-detail/hero-detail.component.css


+ 11 - 0
src/app/hero-detail/hero-detail.component.html

@@ -0,0 +1,11 @@
+<div *ngIf="hero">
+  
+ <h2>{{hero.name | uppercase}} Details</h2>
+    <div><span>id: </span>{{hero.id}}</div>
+    <div>
+      <label>name:
+        <input [(ngModel)]="hero.name" placeholder="name"/>
+      </label>
+    </div>
+  </div>
+  <button (click)="goBack()">go back</button>

+ 25 - 0
src/app/hero-detail/hero-detail.component.spec.ts

@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { HeroDetailComponent } from './hero-detail.component';
+
+describe('HeroDetailComponent', () => {
+  let component: HeroDetailComponent;
+  let fixture: ComponentFixture<HeroDetailComponent>;
+
+  beforeEach(async(() => {
+    TestBed.configureTestingModule({
+      declarations: [ HeroDetailComponent ]
+    })
+    .compileComponents();
+  }));
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(HeroDetailComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 34 - 0
src/app/hero-detail/hero-detail.component.ts

@@ -0,0 +1,34 @@
+import { Component, OnInit, Input } from '@angular/core';
+import { Hero } from '../hero';
+import { ActivatedRoute } from '@angular/router';
+import { Location } from '@angular/common';
+
+import { HeroService }  from '../hero.service';
+
+
+@Component({
+  selector: 'app-hero-detail',
+  templateUrl: './hero-detail.component.html',
+  styleUrls: ['./hero-detail.component.css']
+})
+export class HeroDetailComponent implements OnInit {
+  
+  @Input() hero: Hero;
+  
+  constructor( private route: ActivatedRoute,
+    private heroService: HeroService,
+    private location: Location) { }
+
+  ngOnInit() {
+    void 
+      this.getHero();
+}
+  getHero(): void {
+    const id = +this.route.snapshot.paramMap.get('id');
+    this.heroService.getHero(id)
+      .subscribe(hero => this.hero = hero);
+  }
+  goBack(): void {
+    this.location.back();
+  }
+}

+ 12 - 0
src/app/hero.service.spec.ts

@@ -0,0 +1,12 @@
+import { TestBed } from '@angular/core/testing';
+
+import { HeroService } from './hero.service';
+
+describe('HeroService', () => {
+  beforeEach(() => TestBed.configureTestingModule({}));
+
+  it('should be created', () => {
+    const service: HeroService = TestBed.get(HeroService);
+    expect(service).toBeTruthy();
+  });
+});

+ 24 - 0
src/app/hero.service.ts

@@ -0,0 +1,24 @@
+import { Injectable } from '@angular/core';
+import { Hero } from './hero';
+import { HEROES } from './mock-heroes';
+import { Observable, of } from 'rxjs';
+import { MessageService } from './message.service';
+
+@Injectable({
+providedIn: 'root'
+})
+export class HeroService {
+
+  constructor(private messageService: MessageService) { }
+  
+  getHeroes(): Observable<Hero[]> {
+    // TODO: send the message _after_ fetching the heroes
+    this.messageService.add('HeroService: fetched heroes');
+    return of(HEROES);
+  }
+  getHero(id: number): Observable<Hero> {
+    // TODO: send the message _after_ fetching the hero
+    this.messageService.add(`HeroService: fetched hero id=${id}`);
+    return of(HEROES.find(hero => hero.id === id));
+  }
+}

+ 5 - 0
src/app/hero.ts

@@ -0,0 +1,5 @@
+export class Hero {
+    id: number;
+    name: string;
+  }
+  

+ 48 - 0
src/app/heroes/heroes.component.css

@@ -0,0 +1,48 @@
+/* HeroesComponent's private CSS styles */
+.selected {
+  background-color: #CFD8DC !important;
+  color: white;
+}
+.heroes {
+  margin: 0 0 2em 0;
+  list-style-type: none;
+  padding: 0;
+  width: 15em;
+}
+.heroes li {
+  cursor: pointer;
+  position: relative;
+  left: 0;
+  background-color: #EEE;
+  margin: .5em;
+  padding: .3em 0;
+  height: 1.6em;
+  border-radius: 4px;
+}
+.heroes li.selected:hover {
+  background-color: #BBD8DC !important;
+  color: white;
+}
+.heroes li:hover {
+  color: #607D8B;
+  background-color: #DDD;
+  left: .1em;
+}
+.heroes .text {
+  position: relative;
+  top: -3px;
+}
+.heroes .badge {
+  display: inline-block;
+  font-size: small;
+  color: white;
+  padding: 0.8em 0.7em 0 0.7em;
+  background-color: #607D8B;
+  line-height: 1em;
+  position: relative;
+  left: -1px;
+  top: -4px;
+  height: 1.8em;
+  margin-right: .8em;
+  border-radius: 4px 0 0 4px;
+}

+ 9 - 0
src/app/heroes/heroes.component.html

@@ -0,0 +1,9 @@
+<h2>My Heroes</h2>
+<ul class="heroes">
+    <li *ngFor="let hero of heroes">
+      <a routerLink="/detail/{{hero.id}}">
+        <span class="badge">{{hero.id}}</span> {{hero.name}}
+      </a>
+    </li>
+  </ul>
+

+ 25 - 0
src/app/heroes/heroes.component.spec.ts

@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { HeroesComponent } from './heroes.component';
+
+describe('HeroesComponent', () => {
+  let component: HeroesComponent;
+  let fixture: ComponentFixture<HeroesComponent>;
+
+  beforeEach(async(() => {
+    TestBed.configureTestingModule({
+      declarations: [ HeroesComponent ]
+    })
+    .compileComponents();
+  }));
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(HeroesComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 24 - 0
src/app/heroes/heroes.component.ts

@@ -0,0 +1,24 @@
+import { Component, OnInit } from '@angular/core';
+import { Hero } from '../hero';
+import { HeroService } from '../hero.service';
+
+@Component({
+  selector: 'app-heroes',
+  templateUrl: './heroes.component.html',
+  styleUrls: ['./heroes.component.css']
+})
+
+export class HeroesComponent implements OnInit {
+  heroes: Hero[];
+
+  constructor(private heroService: HeroService) { }
+
+  ngOnInit() {
+    this.getHeroes();
+  }
+
+  getHeroes(): void {
+    this.heroService.getHeroes()
+    .subscribe(heroes => this.heroes = heroes);
+  }
+}

+ 12 - 0
src/app/message.service.spec.ts

@@ -0,0 +1,12 @@
+import { TestBed } from '@angular/core/testing';
+
+import { MessageService } from './message.service';
+
+describe('MessageService', () => {
+  beforeEach(() => TestBed.configureTestingModule({}));
+
+  it('should be created', () => {
+    const service: MessageService = TestBed.get(MessageService);
+    expect(service).toBeTruthy();
+  });
+});

+ 16 - 0
src/app/message.service.ts

@@ -0,0 +1,16 @@
+import { Injectable } from '@angular/core';
+ 
+@Injectable({
+  providedIn: 'root',
+})
+export class MessageService {
+  messages: string[] = [];
+ 
+  add(message: string) {
+    this.messages.push(message);
+  }
+ 
+  clear() {
+    this.messages = [];
+  }
+}

+ 0 - 0
src/app/messages/messages.component.css


+ 8 - 0
src/app/messages/messages.component.html

@@ -0,0 +1,8 @@
+<div *ngIf="messageService.messages.length">
+
+        <h2>Messages</h2>
+        <button class="clear"
+                (click)="messageService.clear()">clear</button>
+        <div *ngFor='let message of messageService.messages'> {{message}} </div>
+      
+      </div>

+ 25 - 0
src/app/messages/messages.component.spec.ts

@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { MessagesComponent } from './messages.component';
+
+describe('MessagesComponent', () => {
+  let component: MessagesComponent;
+  let fixture: ComponentFixture<MessagesComponent>;
+
+  beforeEach(async(() => {
+    TestBed.configureTestingModule({
+      declarations: [ MessagesComponent ]
+    })
+    .compileComponents();
+  }));
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(MessagesComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 16 - 0
src/app/messages/messages.component.ts

@@ -0,0 +1,16 @@
+import { Component, OnInit } from '@angular/core';
+import { MessageService } from '../message.service';
+ 
+@Component({
+  selector: 'app-messages',
+  templateUrl: './messages.component.html',
+  styleUrls: ['./messages.component.css']
+})
+export class MessagesComponent implements OnInit {
+ 
+  constructor(public messageService: MessageService) {}
+ 
+  ngOnInit() {
+  }
+ 
+}

+ 15 - 0
src/app/mock-heroes.ts

@@ -0,0 +1,15 @@
+import { Hero } from './hero';
+
+export const HEROES: Hero[] = [
+{ id: 11, name: 'Mr.Nice'},
+{ id: 12, name: 'Narco'},
+{ id: 13, name: 'Bombasto'},
+{ id: 14, name: 'Celeritas'},
+{ id: 15, name: 'Magneta'},
+{ id: 16, name: 'RubberMan'},
+{ id: 17, name: 'Dynama'},
+{ id: 18, name: 'Dr IQ'},
+{ id: 19, name: 'Magma'},
+{ id: 20, name: 'Tornado'},
+
+];

+ 0 - 0
src/assets/.gitkeep


+ 0 - 0
src/browserslist


+ 0 - 0
src/environments/environment.prod.ts


+ 0 - 0
src/environments/environment.ts


+ 0 - 0
src/favicon.ico


+ 0 - 0
src/index.html


+ 0 - 0
src/karma.conf.js


+ 0 - 0
src/main.ts


+ 0 - 0
src/polyfills.ts


+ 0 - 0
src/styles.css


+ 0 - 0
src/test.ts


+ 0 - 0
src/tsconfig.app.json


+ 0 - 0
src/tsconfig.spec.json


+ 0 - 0
src/tslint.json


+ 0 - 0
tsconfig.json


+ 0 - 0
tslint.json