Guest User

Untitled

a guest
Jan 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. import * as firebase from 'firebase';
  2. import firestore from 'firebase/firestore';
  3. import { environment } from '../environments/environment'; // here my configuration is
  4.  
  5. const settings = {timestampsInSnapshots: true}
  6.  
  7. ngOnInit(){
  8. firebase.initializeApp(environment.firebase);
  9. firebase.firestore().settings(settings);
  10. }
  11.  
  12. ref = firebase.firestore().collection('orders');
  13. getOrders(): Observable<any> {
  14. console.log('on get orders snapshot');
  15. return new Observable((observer) => {
  16. this.ref.onSnapshot((querySnapshot) => {
  17. let boards = [];
  18. querySnapshot.forEach((doc) => {
  19. let data = doc.data();
  20. observer.next({
  21. driver_status: data.driver_status,
  22. food_status: data.food_status,
  23. });
  24. });
  25. observer.next(boards);
  26. });
  27. });
  28. }
  29.  
  30. getOrder(id: string): Observable<any> {
  31. return new Observable((observer) => {
  32. this.ref.doc('ref-'+id).get().then((doc) => {
  33. let data = doc.data();
  34. observer.next({
  35. driver_status: data.driver_status,
  36. food_status: data.food_status,
  37. });
  38. });
  39. });
  40. }
  41.  
  42. displayedColumns = ['driver_status', 'food_status'];
  43. dataSource = new OrderDataSource(this.fs);
  44.  
  45. public fireOrder: Observable<any[]>;
  46. ngOnInit(){
  47. this.fs.getOrder(this.order.id).subscribe(res =>{
  48. this.fireOrder = res;
  49. });
  50. }
  51. --------------------------
  52. export class OrderDataSource extends DataSource<any> {
  53.  
  54. constructor(private fs: FirebaseService) {
  55. super();
  56. console.log('in OrderDataSource constructor');
  57. this.connect();
  58. }
  59.  
  60. connect() {
  61. console.log('in connect');
  62. return this.fs.getOrders();
  63. }
  64.  
  65. disconnect() {
  66. }
  67. }
Add Comment
Please, Sign In to add comment