Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

Commit 5059b48

Browse files
authored
Merge pull request #222 from ashwin-sureshkumar/issue-10
Implement showcase of companies using RxJS
2 parents a6affdc + 8c5164c commit 5059b48

11 files changed

+125
-8
lines changed

src/app/companies/companies-list.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Company } from './companies.model';
2+
3+
export const COMPANIES_LIST: Company[] = [
4+
{
5+
name: 'Google',
6+
location: 'California',
7+
logo: '../../assets/companies/google.png',
8+
website: 'http://google.com'
9+
},
10+
{
11+
name: 'Microsoft',
12+
location: 'Seattle',
13+
logo: '../../assets/companies/microsoft.png',
14+
website: 'http://microsoft.com'
15+
}
16+
];
+20
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1+
<div fxLayout="row" fxLayoutAlign="space-evenly center" fxLayoutGap="10px" fxLayoutWrap class="companies-container">
2+
<mat-card *ngFor="let company of companies | async" fxFlex.xs="100" fxFlex.sm="45" fxFlex.md="30" fxFlex.lg="23">
3+
<mat-card-header>
4+
<div mat-card-avatar>
5+
<img [src]="company.logo" class="company-logo">
6+
</div>
7+
<mat-card-title>{{company.name}}</mat-card-title>
8+
<mat-card-subtitle>
9+
{{company.location}}
10+
<a class="website-button" mat-icon-button aria-label="website" [href]="company.website" target="_blank">
11+
<mat-icon>
12+
link
13+
</mat-icon>
14+
</a>
15+
</mat-card-subtitle>
16+
</mat-card-header>
17+
<mat-card-content>
118

19+
</mat-card-content>
20+
</mat-card>
21+
</div>
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.example-header-image {
2+
background-image: url('../../assets/img/Rx_Logo-96-96.png');
3+
background-size: cover;
4+
}
5+
6+
.companies-container {
7+
margin: 0 15px;
8+
}
9+
10+
.website-button {
11+
position: absolute;
12+
right: 0;
13+
top: 0;
14+
}
15+
16+
mat-card {
17+
margin-top: 15px;
18+
}
19+
20+
mat-card-avatar {
21+
margin-right: 10px;
22+
}
23+
24+
.company-logo{
25+
height: 40px;
26+
width: 40px;
27+
}
+11-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
import { Component } from '@angular/core';
1+
import { COMPANIES_LIST } from './companies-list';
2+
import { Component, OnInit } from '@angular/core';
3+
import { Observable } from 'rxjs/Observable';
4+
import { MatDialog } from '@angular/material';
5+
6+
import { CompanyService } from './company.service';
7+
import { Company } from './companies.model';
28

39
@Component({
410
selector: 'app-companies',
511
templateUrl: './companies.component.html',
612
styleUrls: ['./companies.component.scss']
713
})
814
export class CompaniesComponent {
9-
constructor() {}
15+
companies: Observable<Company[]>;
16+
constructor(private companyService: CompanyService) {
17+
this.companies = this.companyService.getCompanies();
18+
}
1019
}

src/app/companies/companies.model.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface Company {
2+
name: string;
3+
location: string;
4+
website: string;
5+
logo: string;
6+
}

src/app/companies/companies.module.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
import { CommonModule } from '@angular/common';
2+
import { MaterialModule } from './../material/material.module';
13
import { NgModule } from '@angular/core';
4+
25
import { CompaniesComponent } from './companies.component';
36
import { CompaniesRoutingModule } from './companies-routing.module';
4-
7+
import { environment } from '../../environments/environment';
8+
import { CompanyService } from './company.service';
59
@NgModule({
6-
imports: [CompaniesRoutingModule],
7-
declarations: [CompaniesComponent]
10+
imports: [CommonModule, CompaniesRoutingModule, MaterialModule],
11+
declarations: [CompaniesComponent],
12+
providers: [CompanyService]
813
})
914
export class CompaniesModule {}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { TestBed, inject } from '@angular/core/testing';
2+
3+
import { CompanyService } from './company.service';
4+
import { environment } from '../../environments/environment';
5+
6+
describe('CompanyService', () => {
7+
beforeEach(() => {
8+
TestBed.configureTestingModule({
9+
imports: [],
10+
providers: [CompanyService]
11+
});
12+
});
13+
14+
it(
15+
'should be created',
16+
inject([CompanyService], (service: CompanyService) => {
17+
expect(service).toBeTruthy();
18+
})
19+
);
20+
});

src/app/companies/company.service.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Injectable } from '@angular/core';
2+
import { Observable } from 'rxjs/Observable';
3+
import { of } from 'rxjs/observable/of';
4+
import { COMPANIES_LIST } from './companies-list';
5+
import { Company } from './companies.model';
6+
7+
@Injectable()
8+
export class CompanyService {
9+
getCompanies(): Observable<Company[]> {
10+
return of(COMPANIES_LIST);
11+
}
12+
}

src/app/material/material.module.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { FlexLayoutModule } from '@angular/flex-layout';
44
import {
55
MatToolbarModule,
66
MatIconModule,
7+
MatButtonModule,
78
MatListModule,
89
MatSidenavModule,
9-
MatButtonModule,
1010
MatExpansionModule,
1111
MatCardModule,
1212
MatInputModule,
@@ -20,27 +20,29 @@ import {
2020
imports: [
2121
MatToolbarModule,
2222
MatIconModule,
23+
MatButtonModule,
2324
MatListModule,
2425
MatSidenavModule,
25-
MatButtonModule,
2626
MatExpansionModule,
2727
MatCardModule,
2828
MatInputModule,
2929
MatMenuModule,
3030
MatTooltipModule,
31+
FlexLayoutModule,
3132
MatSnackBarModule
3233
],
3334
exports: [
3435
MatToolbarModule,
3536
MatIconModule,
37+
MatButtonModule,
3638
MatListModule,
3739
MatSidenavModule,
38-
MatButtonModule,
3940
MatExpansionModule,
4041
MatCardModule,
4142
MatInputModule,
4243
MatMenuModule,
4344
MatTooltipModule,
45+
FlexLayoutModule,
4446
MatSnackBarModule
4547
]
4648
})

src/assets/companies/google.png

7.66 KB
Loading

src/assets/companies/microsoft.png

5.47 KB
Loading

0 commit comments

Comments
 (0)