Guest User

home.component.ts

a guest
Apr 14th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// <reference path="../../../node_modules/nativescript-pulltorefresh/pulltorefresh.d.ts" />
  2.  
  3. "use strict";
  4.  
  5. import {Component} from "angular2/core";
  6. import {Router} from "angular2/router";
  7. import {UserService} from "../../shared/user/user.service";
  8. import {Config} from "../../shared/config";
  9. import {NotificationsService} from "../../shared/notification/notifications.service";
  10. import {Notification} from "../../shared/notification/notification";
  11. import {MessageService} from "../../shared/message/messages.service";
  12. import {Message} from "../../shared/message/message";
  13.  
  14. import { registerElement, ViewClass } from "nativescript-angular/element-registry";
  15. import {PullToRefresh} from "nativescript-pulltorefresh";
  16.  
  17.  
  18.  
  19. registerElement("PullToRefresh", () => require("nativescript-pulltorefresh").PullToRefresh);
  20.  
  21.  
  22. @Component({
  23.     selector: 'home',
  24.     templateUrl: 'pages/home/home.html',
  25.     providers: [UserService, NotificationsService, MessageService]
  26.  
  27. })
  28.  
  29.  
  30. export class HomePage {
  31.  
  32.     notificationsList: Array<Notification> = [];
  33.     receivedMessagesList: Array<Message> = [];
  34.    
  35.  
  36.     constructor(
  37.         private _userService: UserService,
  38.         private _router: Router,
  39.         private _notificationService: NotificationsService,
  40.         private _messageService: MessageService) {
  41.            this.loadNotifications();
  42.            this.receivedMessages();
  43.            setInterval(()=>{
  44.                this._userService.refreshToken();
  45.                console.log("New access token : "+Config.access_token);
  46.            },3600000);
  47.  
  48.     }
  49.  
  50.     public receivedMessages(){
  51.       this._messageService.loadReceivedMessages()
  52.         .subscribe(res=> {
  53.           res.forEach((resObject)=>{
  54.             this.receivedMessagesList.unshift(resObject);
  55.           });
  56.         });
  57.     }
  58.  
  59.     public loadNotifications(){
  60.        this._notificationService.load()
  61.             .subscribe(res => {
  62.                 res.forEach((resObject) => {
  63.                     this.notificationsList.unshift(resObject);
  64.                 });
  65.             });
  66.     }
  67.  
  68.     public refreshNotificationPage(args: any) {
  69.         setTimeout(() => {
  70.             args.object.refreshing = false;
  71.             this.notificationsList = [];
  72.             this.loadNotifications();
  73.         }, 1000);
  74.     }
  75.  
  76.     public refreshMessagePage(args: any){
  77.       setTimeout(() => {
  78.             args.object.refreshing = false;
  79.             this.receivedMessagesList = [];
  80.             this.receivedMessages();
  81.         }, 1000);
  82.     }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment