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

Commit 8c5164c

Browse files
feat(companies): Implement showcase of companies from list in the repo
- Showcase list of companies using RxJS - Remove firebase implementation temporarily to move forward - Added a temporary list of companies to test Close #10
1 parent a744ede commit 8c5164c

19 files changed

+56
-234
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@
4141
"@angular/router": "5.1.1",
4242
"@angular/service-worker": "5.1.1",
4343
"@types/hammerjs": "2.0.35",
44-
"angularfire2": "5.0.0-rc.3",
4544
"core-js": "2.4.1",
46-
"firebase": "4.6.2",
4745
"hammerjs": "2.0.8",
4846
"rxjs": "5.5.5",
4947
"ts-loader": "3.1.1",

src/app/companies/companies-list.ts

Lines changed: 16 additions & 0 deletions
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+
];
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
<div fxLayout="row" fxLayoutAlign="space-evenly center" fxLayoutGap="10px" fxLayoutWrap class="companies-container">
2-
<button mat-fab color="primary" class="company-add-button" (click)="addCompany()">
3-
<mat-icon>add</mat-icon>
4-
</button>
52
<mat-card *ngFor="let company of companies | async" fxFlex.xs="100" fxFlex.sm="45" fxFlex.md="30" fxFlex.lg="23">
63
<mat-card-header>
74
<div mat-card-avatar>
8-
<img [src]="company.File" class="company-logo">
5+
<img [src]="company.logo" class="company-logo">
96
</div>
10-
<mat-card-title>{{company.Name}}</mat-card-title>
7+
<mat-card-title>{{company.name}}</mat-card-title>
118
<mat-card-subtitle>
12-
{{company.Location}}
13-
<button class="website-button" mat-icon-button aria-label="website" (click)="openWindow(company.Website)">
9+
{{company.location}}
10+
<a class="website-button" mat-icon-button aria-label="website" [href]="company.website" target="_blank">
1411
<mat-icon>
1512
link
1613
</mat-icon>
17-
</button>
14+
</a>
1815
</mat-card-subtitle>
1916
</mat-card-header>
2017
<mat-card-content>
2118

2219
</mat-card-content>
2320
</mat-card>
24-
</div>
21+
</div>

src/app/companies/companies.component.scss

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ mat-card {
1717
margin-top: 15px;
1818
}
1919

20-
.company-add-button {
21-
position: absolute;
22-
z-index: 99;
23-
right: 0;
24-
top: 5px;
20+
mat-card-avatar {
21+
margin-right: 10px;
2522
}
2623

2724
.company-logo{
2825
height: 40px;
29-
}
26+
width: 40px;
27+
}
Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,19 @@
1+
import { COMPANIES_LIST } from './companies-list';
12
import { Component, OnInit } from '@angular/core';
23
import { Observable } from 'rxjs/Observable';
3-
import {
4-
AngularFirestore,
5-
AngularFirestoreCollection
6-
} from 'angularfire2/firestore';
7-
import * as firebase from 'firebase';
84
import { MatDialog } from '@angular/material';
95

10-
import { CompanyDialogComponent } from '../company-dialog/company-dialog.component';
116
import { CompanyService } from './company.service';
7+
import { Company } from './companies.model';
128

139
@Component({
1410
selector: 'app-companies',
1511
templateUrl: './companies.component.html',
1612
styleUrls: ['./companies.component.scss']
1713
})
1814
export class CompaniesComponent {
19-
companies: Observable<any[]>;
20-
private uploadTask: firebase.storage.UploadTask;
21-
private companiesCollection: AngularFirestoreCollection<any>;
22-
constructor(
23-
db: AngularFirestore,
24-
private dialog: MatDialog,
25-
private companyService: CompanyService
26-
) {
27-
this.companiesCollection = db.collection('companies');
28-
this.companies = this.companiesCollection.valueChanges();
29-
}
30-
31-
uploadSingle(file: any) {
32-
return this.companyService.pushUpload(file);
33-
}
34-
35-
addCompany() {
36-
const dialogRef = this.dialog.open(CompanyDialogComponent, {});
37-
dialogRef.afterClosed().subscribe(company => {
38-
if (company) {
39-
const file = this.uploadSingle(company.File).then((fileResult: any) => {
40-
company.File = fileResult.downloadURL;
41-
this.companiesCollection.add(company).then(result => {
42-
console.log(result);
43-
});
44-
});
45-
}
46-
});
47-
}
48-
49-
openWindow(url: string) {
50-
window.open(url, '_blank');
15+
companies: Observable<Company[]>;
16+
constructor(private companyService: CompanyService) {
17+
this.companies = this.companyService.getCompanies();
5118
}
5219
}

src/app/companies/companies.model.ts

Lines changed: 6 additions & 0 deletions
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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
import { CommonModule } from '@angular/common';
22
import { MaterialModule } from './../material/material.module';
33
import { NgModule } from '@angular/core';
4-
import { AngularFireModule } from 'angularfire2';
5-
import { AngularFirestoreModule } from 'angularfire2/firestore';
64

75
import { CompaniesComponent } from './companies.component';
86
import { CompaniesRoutingModule } from './companies-routing.module';
97
import { environment } from '../../environments/environment';
10-
import { CompanyDialogComponent } from '../company-dialog/company-dialog.component';
11-
import { MatDialogRef } from '@angular/material';
128
import { CompanyService } from './company.service';
13-
import { AngularFireDatabase } from 'angularfire2/database';
149
@NgModule({
15-
imports: [
16-
CommonModule,
17-
CompaniesRoutingModule,
18-
MaterialModule,
19-
AngularFirestoreModule,
20-
AngularFireModule.initializeApp(environment.firebase)
21-
],
22-
declarations: [CompaniesComponent, CompanyDialogComponent],
23-
entryComponents: [CompanyDialogComponent],
24-
providers: [CompanyService, AngularFireDatabase]
10+
imports: [CommonModule, CompaniesRoutingModule, MaterialModule],
11+
declarations: [CompaniesComponent],
12+
providers: [CompanyService]
2513
})
2614
export class CompaniesModule {}

src/app/companies/company.service.spec.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
import { TestBed, inject } from '@angular/core/testing';
22

33
import { CompanyService } from './company.service';
4-
import { AngularFireDatabase } from 'angularfire2/database';
5-
import { AngularFirestoreModule } from 'angularfire2/firestore';
6-
import { AngularFireModule } from 'angularfire2';
74
import { environment } from '../../environments/environment';
85

96
describe('CompanyService', () => {
107
beforeEach(() => {
118
TestBed.configureTestingModule({
12-
imports: [
13-
AngularFirestoreModule,
14-
AngularFireModule.initializeApp(environment.firebase)
15-
],
16-
providers: [CompanyService, AngularFireDatabase]
9+
imports: [],
10+
providers: [CompanyService]
1711
});
1812
});
1913

2014
it(
2115
'should be created',
22-
inject([CompanyService, AngularFireDatabase], (service: CompanyService) => {
16+
inject([CompanyService], (service: CompanyService) => {
2317
expect(service).toBeTruthy();
2418
})
2519
);

src/app/companies/company.service.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
import { Injectable } from "@angular/core";
2-
import { AngularFireDatabase, AngularFireList } from "angularfire2/database";
3-
import * as firebase from "firebase";
4-
import { Observable } from "rxjs/Observable";
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';
56

67
@Injectable()
78
export class CompanyService {
8-
constructor(private db: AngularFireDatabase) {}
9-
basePath = "uploads";
10-
uploadsRef: AngularFireList<any>;
11-
uploads: Observable<any[]>;
12-
// Executes the file uploading to firebase https://firebase.google.com/docs/storage/web/upload-files
13-
14-
pushUpload(upload: any) {
15-
const storageRef = firebase.storage().ref();
16-
const uploadTask = storageRef
17-
.child(`${this.basePath}/${upload.name}`)
18-
.put(upload);
19-
return uploadTask;
9+
getCompanies(): Observable<Company[]> {
10+
return of(COMPANIES_LIST);
2011
}
2112
}

src/app/companies/test.js

Whitespace-only changes.

0 commit comments

Comments
 (0)