Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 51679b8

Browse files
committed
Category listing from JSON file, sorting each column and category details with Types.
1 parent b4b506e commit 51679b8

16 files changed

+134
-179
lines changed

src/app/about/about.component.html

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/app/app.component.html

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
<h1>Products</h1>
44
</header>
55

6-
</div>
76

8-
<main>
9-
<router-outlet></router-outlet>
10-
</main>
7+
<main>
8+
<home></home>
9+
</main>
1110

12-
13-
<footer>
14-
15-
</footer>
11+
</div>

src/app/app.module.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,26 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
88
import { BrowserModule } from '@angular/platform-browser';
99
import { HttpModule } from '@angular/http';
1010

11-
import { AboutComponent } from './about/about.component';
11+
1212
import { HomeComponent } from './home/home.component';
13+
import { CategoriesComponent } from './categories/categories.component';
14+
import { DetailsComponent } from './details/details.component';
1315
import { RepoBrowserComponent } from './github/repo-browser/repo-browser.component';
1416
import { RepoListComponent } from './github/repo-list/repo-list.component';
1517
import { RepoDetailComponent } from './github/repo-detail/repo-detail.component';
1618
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
17-
import { ContactComponent } from './contact/contact.component';
1819
import { SortPipe } from './app.sort';
1920

2021
@NgModule({
2122
declarations: [
2223
SortPipe,
2324
AppComponent,
24-
AboutComponent,
25+
CategoriesComponent,
26+
DetailsComponent,
2527
RepoBrowserComponent,
2628
RepoListComponent,
2729
RepoDetailComponent,
28-
HomeComponent,
29-
ContactComponent
30+
HomeComponent
3031
],
3132
imports: [
3233
BrowserModule,

src/app/app.routes.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { Routes } from '@angular/router';
22

3-
import { AboutComponent } from './about/about.component';
3+
import { CategoriesComponent } from './categories/categories.component';
4+
import { DetailsComponent } from './details/details.component';
45
import { HomeComponent } from './home/home.component';
56
import { RepoBrowserComponent } from './github/repo-browser/repo-browser.component';
67
import { RepoListComponent } from './github/repo-list/repo-list.component';
78
import { RepoDetailComponent } from './github/repo-detail/repo-detail.component';
8-
import { ContactComponent } from './contact/contact.component';
99

1010
export const rootRouterConfig: Routes = [
1111
{ path: '', redirectTo: 'home', pathMatch: 'full' },
12-
{ path: 'home', component: HomeComponent },
13-
{ path: 'about', component: AboutComponent },
12+
{ path: 'home', component: CategoriesComponent },
13+
{ path: 'categories', component: CategoriesComponent },
14+
{ path: 'details', component: DetailsComponent },
1415
{ path: 'github', component: RepoBrowserComponent,
1516
children: [
1617
{ path: '', component: RepoListComponent },
@@ -20,7 +21,6 @@ export const rootRouterConfig: Routes = [
2021
{ path: ':repo', component: RepoDetailComponent }
2122
]
2223
}]
23-
},
24-
{ path: 'contact', component: ContactComponent }
24+
}
2525
];
2626

File renamed without changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
<div>
3+
<h3>Category List</h3>
4+
5+
<table>
6+
<thead>
7+
<tr>
8+
<td><a href="#" (click)="setSortBy('name')">Name</a></td>
9+
<td><a href="#" (click)="setSortBy('category')">Category</a></td>
10+
<td><span><a href="#" (click)="setSortBy('amount')">amount</a></span></td>
11+
</tr>
12+
</thead>
13+
<tbody>
14+
<tr *ngFor="let category of categories">
15+
<td>{{category.name}}</td>
16+
<td>{{category.category}}</td>
17+
<td><span>${{category.amount}}</span></td>
18+
</tr>
19+
</tbody>
20+
</table>
21+
</div>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {Component, OnInit} from '@angular/core';
2+
import { CategoriesService } from '../categories.service';
3+
import { Http } from '@angular/http';
4+
import * as _ from "lodash";
5+
6+
@Component({
7+
selector: 'categories',
8+
styleUrls: ['./categories.component.css'],
9+
templateUrl: './categories.component.html'
10+
})
11+
export class CategoriesComponent implements OnInit {
12+
categories = [];
13+
sortBy = '';
14+
reverseSort = false;
15+
constructor(private _categoriesService: CategoriesService){}
16+
ngOnInit() {
17+
this._categoriesService.getCategories()
18+
.subscribe(resCategoriesData => this.categories = resCategoriesData);
19+
}
20+
21+
sortedCategories = function() {
22+
let orderSort = this.reverseSort ? 'desc' : 'asc';
23+
this.categories = _.orderBy(this.categories, [this.sortBy], [orderSort]);
24+
}
25+
setSortBy = function(value) {
26+
this.reverseSort = this.sortBy == value ? !this.reverseSort : false;
27+
this.sortBy = value;
28+
this.sortedCategories();
29+
}
30+
}

src/app/contact/contact-component.css

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/app/contact/contact.component.html

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/app/contact/contact.component.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)