|
| 1 | +import { COMPANIES_LIST } from './companies-list'; |
1 | 2 | import { Component, OnInit } from '@angular/core'; |
2 | 3 | import { Observable } from 'rxjs/Observable'; |
3 | | -import { |
4 | | - AngularFirestore, |
5 | | - AngularFirestoreCollection |
6 | | -} from 'angularfire2/firestore'; |
7 | | -import * as firebase from 'firebase'; |
8 | 4 | import { MatDialog } from '@angular/material'; |
9 | 5 |
|
10 | | -import { CompanyDialogComponent } from '../company-dialog/company-dialog.component'; |
11 | 6 | import { CompanyService } from './company.service'; |
| 7 | +import { Company } from './companies.model'; |
12 | 8 |
|
13 | 9 | @Component({ |
14 | 10 | selector: 'app-companies', |
15 | 11 | templateUrl: './companies.component.html', |
16 | 12 | styleUrls: ['./companies.component.scss'] |
17 | 13 | }) |
18 | 14 | 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(); |
51 | 18 | } |
52 | 19 | } |
0 commit comments