Skip to content

Commit

Permalink
feat(companies): Implement showcase of companies from list in the repo
Browse files Browse the repository at this point in the history
- 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
ashwin-sureshkumar committed Dec 22, 2017
1 parent 4255fea commit 89b98b0
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 229 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
"@angular/platform-browser-dynamic": "5.0.2",
"@angular/router": "5.0.2",
"@types/hammerjs": "2.0.35",
"angularfire2": "5.0.0-rc.3",
"core-js": "2.4.1",
"firebase": "4.6.2",
"hammerjs": "2.0.8",
"rxjs": "5.5.2",
"ts-loader": "3.1.1",
Expand Down
18 changes: 18 additions & 0 deletions src/app/companies/companies-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Company } from './companies.model';

export const COMPANIES_LIST: Company[] = [
{
name: 'Google',
location: 'California',
logo:
'https://upload.wikimedia.org/wikipedia/commons/thumb/2/2d/Google-favicon-2015.png/150px-Google-favicon-2015.png',
website: 'http://google.com'
},
{
name: 'Microsoft',
location: 'Seattle',
logo:
'http://diylogodesigns.com/blog/wp-content/uploads/2016/04/Microsoft-Logo-icon-png-Transparent-Background.png',
website: 'http://microsoft.com'
}
];
13 changes: 5 additions & 8 deletions src/app/companies/companies.component.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<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}}
<button class="website-button" mat-icon-button aria-label="website" (click)="openWindow(company.website)">
<mat-icon>
link
</mat-icon>
Expand All @@ -21,4 +18,4 @@

</mat-card-content>
</mat-card>
</div>
</div>
10 changes: 4 additions & 6 deletions src/app/companies/companies.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ mat-card {
margin-top: 15px;
}

.company-add-button {
position: absolute;
z-index: 99;
right: 0;
top: 5px;
mat-card-avatar {
margin-right: 10px;
}

.company-logo{
height: 40px;
}
width: 40px;
}
39 changes: 5 additions & 34 deletions src/app/companies/companies.component.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,20 @@
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);
});
});
}
});
companies: Observable<Company[]>;
constructor(private companyService: CompanyService) {
this.companies = this.companyService.getCompanies();
}

openWindow(url: string) {
Expand Down
6 changes: 6 additions & 0 deletions src/app/companies/companies.model.ts
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;
}
18 changes: 3 additions & 15 deletions src/app/companies/companies.module.ts
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 {}
12 changes: 3 additions & 9 deletions src/app/companies/company.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import { TestBed, inject } from '@angular/core/testing';

import { CompanyService } from './company.service';
import { AngularFireDatabase } from 'angularfire2/database';
import { AngularFirestoreModule } from 'angularfire2/firestore';
import { AngularFireModule } from 'angularfire2';
import { environment } from '../../environments/environment';

describe('CompanyService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
AngularFirestoreModule,
AngularFireModule.initializeApp(environment.firebase)
],
providers: [CompanyService, AngularFireDatabase]
imports: [],
providers: [CompanyService]
});
});

it(
'should be created',
inject([CompanyService, AngularFireDatabase], (service: CompanyService) => {
inject([CompanyService], (service: CompanyService) => {
expect(service).toBeTruthy();
})
);
Expand Down
23 changes: 7 additions & 16 deletions src/app/companies/company.service.ts
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 removed src/app/companies/test.js
Empty file.
23 changes: 0 additions & 23 deletions src/app/company-dialog/company-dialog.component.html

This file was deleted.

Empty file.
47 changes: 0 additions & 47 deletions src/app/company-dialog/company-dialog.component.spec.ts

This file was deleted.

41 changes: 0 additions & 41 deletions src/app/company-dialog/company-dialog.component.ts

This file was deleted.

13 changes: 4 additions & 9 deletions src/app/material/material.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ import {
MatToolbarModule,
MatIconModule,
MatButtonModule,
MatDialogModule,
MatListModule,
MatSidenavModule,
MatExpansionModule,
MatCardModule,
MatInputModule,
MatMenuModule,
MatTooltipModule
MatTooltipModule,
MatSnackBarModule
} from '@angular/material';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';

@NgModule({
declarations: [],
imports: [
MatToolbarModule,
MatIconModule,
MatButtonModule,
MatDialogModule,
MatListModule,
MatSidenavModule,
MatExpansionModule,
Expand All @@ -31,14 +29,12 @@ import { ReactiveFormsModule, FormsModule } from '@angular/forms';
MatMenuModule,
MatTooltipModule,
FlexLayoutModule,
ReactiveFormsModule,
FormsModule
MatSnackBarModule
],
exports: [
MatToolbarModule,
MatIconModule,
MatButtonModule,
MatDialogModule,
MatListModule,
MatSidenavModule,
MatExpansionModule,
Expand All @@ -47,8 +43,7 @@ import { ReactiveFormsModule, FormsModule } from '@angular/forms';
MatMenuModule,
MatTooltipModule,
FlexLayoutModule,
ReactiveFormsModule,
FormsModule
MatSnackBarModule
]
})
export class MaterialModule {}
Loading

0 comments on commit 89b98b0

Please sign in to comment.