forked from ReactiveX/rxjs-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 ReactiveX#10
- Loading branch information
1 parent
fcc5ec7
commit aad6543
Showing
19 changed files
with
56 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Company } from './companies.model'; | ||
|
||
export const COMPANIES_LIST: Company[] = [ | ||
{ | ||
name: 'Google', | ||
location: 'California', | ||
logo: '../../assets/companies/google.png', | ||
website: 'http://google.com' | ||
}, | ||
{ | ||
name: 'Microsoft', | ||
location: 'Seattle', | ||
logo: '../../assets/companies/microsoft.png', | ||
website: 'http://microsoft.com' | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
<div fxLayout="row" fxLayoutAlign="space-evenly center" fxLayoutGap="10px" fxLayoutWrap class="companies-container"> | ||
<button mat-fab color="primary" class="company-add-button" (click)="addCompany()"> | ||
<mat-icon>add</mat-icon> | ||
</button> | ||
<mat-card *ngFor="let company of companies | async" fxFlex.xs="100" fxFlex.sm="45" fxFlex.md="30" fxFlex.lg="23"> | ||
<mat-card-header> | ||
<div mat-card-avatar> | ||
<img [src]="company.File" class="company-logo"> | ||
<img [src]="company.logo" class="company-logo"> | ||
</div> | ||
<mat-card-title>{{company.Name}}</mat-card-title> | ||
<mat-card-title>{{company.name}}</mat-card-title> | ||
<mat-card-subtitle> | ||
{{company.Location}} | ||
<button class="website-button" mat-icon-button aria-label="website" (click)="openWindow(company.Website)"> | ||
{{company.location}} | ||
<a class="website-button" mat-icon-button aria-label="website" [href]="company.website" target="_blank"> | ||
<mat-icon> | ||
link | ||
</mat-icon> | ||
</button> | ||
</a> | ||
</mat-card-subtitle> | ||
</mat-card-header> | ||
<mat-card-content> | ||
|
||
</mat-card-content> | ||
</mat-card> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,19 @@ | ||
import { COMPANIES_LIST } from './companies-list'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import { | ||
AngularFirestore, | ||
AngularFirestoreCollection | ||
} from 'angularfire2/firestore'; | ||
import * as firebase from 'firebase'; | ||
import { MatDialog } from '@angular/material'; | ||
|
||
import { CompanyDialogComponent } from '../company-dialog/company-dialog.component'; | ||
import { CompanyService } from './company.service'; | ||
import { Company } from './companies.model'; | ||
|
||
@Component({ | ||
selector: 'app-companies', | ||
templateUrl: './companies.component.html', | ||
styleUrls: ['./companies.component.scss'] | ||
}) | ||
export class CompaniesComponent { | ||
companies: Observable<any[]>; | ||
private uploadTask: firebase.storage.UploadTask; | ||
private companiesCollection: AngularFirestoreCollection<any>; | ||
constructor( | ||
db: AngularFirestore, | ||
private dialog: MatDialog, | ||
private companyService: CompanyService | ||
) { | ||
this.companiesCollection = db.collection('companies'); | ||
this.companies = this.companiesCollection.valueChanges(); | ||
} | ||
|
||
uploadSingle(file: any) { | ||
return this.companyService.pushUpload(file); | ||
} | ||
|
||
addCompany() { | ||
const dialogRef = this.dialog.open(CompanyDialogComponent, {}); | ||
dialogRef.afterClosed().subscribe(company => { | ||
if (company) { | ||
const file = this.uploadSingle(company.File).then((fileResult: any) => { | ||
company.File = fileResult.downloadURL; | ||
this.companiesCollection.add(company).then(result => { | ||
console.log(result); | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
openWindow(url: string) { | ||
window.open(url, '_blank'); | ||
companies: Observable<Company[]>; | ||
constructor(private companyService: CompanyService) { | ||
this.companies = this.companyService.getCompanies(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface Company { | ||
name: string; | ||
location: string; | ||
website: string; | ||
logo: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,14 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { MaterialModule } from './../material/material.module'; | ||
import { NgModule } from '@angular/core'; | ||
import { AngularFireModule } from 'angularfire2'; | ||
import { AngularFirestoreModule } from 'angularfire2/firestore'; | ||
|
||
import { CompaniesComponent } from './companies.component'; | ||
import { CompaniesRoutingModule } from './companies-routing.module'; | ||
import { environment } from '../../environments/environment'; | ||
import { CompanyDialogComponent } from '../company-dialog/company-dialog.component'; | ||
import { MatDialogRef } from '@angular/material'; | ||
import { CompanyService } from './company.service'; | ||
import { AngularFireDatabase } from 'angularfire2/database'; | ||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
CompaniesRoutingModule, | ||
MaterialModule, | ||
AngularFirestoreModule, | ||
AngularFireModule.initializeApp(environment.firebase) | ||
], | ||
declarations: [CompaniesComponent, CompanyDialogComponent], | ||
entryComponents: [CompanyDialogComponent], | ||
providers: [CompanyService, AngularFireDatabase] | ||
imports: [CommonModule, CompaniesRoutingModule, MaterialModule], | ||
declarations: [CompaniesComponent], | ||
providers: [CompanyService] | ||
}) | ||
export class CompaniesModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,12 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { AngularFireDatabase, AngularFireList } from "angularfire2/database"; | ||
import * as firebase from "firebase"; | ||
import { Observable } from "rxjs/Observable"; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import { of } from 'rxjs/observable/of'; | ||
import { COMPANIES_LIST } from './companies-list'; | ||
import { Company } from './companies.model'; | ||
|
||
@Injectable() | ||
export class CompanyService { | ||
constructor(private db: AngularFireDatabase) {} | ||
basePath = "uploads"; | ||
uploadsRef: AngularFireList<any>; | ||
uploads: Observable<any[]>; | ||
// Executes the file uploading to firebase https://firebase.google.com/docs/storage/web/upload-files | ||
|
||
pushUpload(upload: any) { | ||
const storageRef = firebase.storage().ref(); | ||
const uploadTask = storageRef | ||
.child(`${this.basePath}/${upload.name}`) | ||
.put(upload); | ||
return uploadTask; | ||
getCompanies(): Observable<Company[]> { | ||
return of(COMPANIES_LIST); | ||
} | ||
} |
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.