Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {Component, OnInit, EventEmitter} from '@angular/core';
  2. import {ResourcesRetrieveService} from '../services/resources-retrieve.service';
  3. import * as moment from 'moment';
  4.  
  5. @Component({
  6.   selector: 'app-resources',
  7.   templateUrl: './resources.component.html',
  8.   styleUrls: ['./resources.component.css']
  9. })
  10. export class ResourcesComponent implements OnInit {
  11.   public DocumentsAll: Array<any>;
  12.   public Documents: Array<any>;
  13.   public DocumentCount: number;
  14.  
  15.   public initialSlice: number = 10;
  16.   public pageNum: number = 0;
  17.  
  18.   public sliceCurrent: number;
  19.   public sliceRewind: number;
  20.   public sliceForward: number;
  21.  
  22.  
  23.   constructor(private resourcesRetrieveService: ResourcesRetrieveService) {
  24.  
  25.   }
  26.  
  27.   async ngOnInit() {
  28.     await this.getDocuments();
  29.     this.checkDocumentCount();
  30.  
  31.     if (this.DocumentCount > 10){
  32.      this.Documents = this.DocumentsAll.slice(0, this.initialSlice);
  33.      this.pageNum = 0;
  34.      this.sliceCurrent = 10;
  35.     }
  36.   }
  37.  
  38.   public async getDocuments() {
  39.     await this.resourcesRetrieveService.httpGetResources().then((res) =>{
  40.       this.DocumentsAll = res['data']['resources'];
  41.     }).catch((err) =>{
  42.       console.log(err);
  43.     })
  44.   }
  45.  
  46.   public checkDocumentCount(){
  47.     this.DocumentCount = this.DocumentsAll.length;
  48.   }
  49.  
  50.   public navToFirstPage(){
  51.     this.Documents = this.DocumentsAll.slice(0, this.initialSlice);
  52.     this.sliceCurrent = 10;
  53.     this.pageNum = 0;
  54.   }
  55.  
  56.   public navToPreviousPage(){
  57.     if (this.pageNum) {
  58.       this.sliceRewind = this.sliceCurrent - 20;
  59.       this.sliceCurrent = this.sliceCurrent - 10;
  60.       this.Documents = this.DocumentsAll.slice(this.sliceRewind, this.sliceCurrent);
  61.       console.log(this.sliceRewind + " and " + this.sliceCurrent );
  62.       this.sliceCurrent = this.sliceRewind + 10;
  63.       console.log(this.sliceCurrent)
  64.       this.pageNum--;
  65.     }
  66.     else{
  67.       this.Documents = this.DocumentsAll.slice(0, this.initialSlice);
  68.       this.pageNum = 0;
  69.     }
  70.   }
  71.  
  72.   public navToNextPage(){
  73.     if (this.sliceCurrent <= this.DocumentCount) {
  74.     this.sliceForward = this.sliceCurrent + 10;
  75.     this.Documents = this.DocumentsAll.slice(this.sliceCurrent, this.sliceForward);
  76.     console.log(this.sliceCurrent + " and " + this.sliceForward );
  77.     this.sliceCurrent = this.sliceForward;
  78.     console.log(this.sliceCurrent);
  79.     this.pageNum++;
  80.   }
  81.   else{
  82.     this.Documents = this.DocumentsAll.slice(this.sliceCurrent, this.sliceForward);
  83.     }
  84.   }
  85.  
  86.   public navToLastPage(){
  87.    this.Documents = this.DocumentsAll.slice(this.DocumentCount - 10,this.DocumentCount)
  88.     //console.log((this.DocumentCount - 10 )+ " and " + Math.round(10* this.DocumentCount) / 10))
  89.   }
  90.  
  91.  
  92.   public filterTable() {
  93.     let input, filter, table, tr, td, i;
  94.     input = document.getElementById("search-input");
  95.     filter = input.value.toUpperCase();
  96.     table = document.getElementById("document-table");
  97.     tr = table.getElementsByTagName("tr");
  98.  
  99.     for (i = 0; i < tr.length; i++) {
  100.       td = tr[i].getElementsByTagName("td")[0];
  101.       if (td) {
  102.         if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
  103.           tr[i].style.display = "";
  104.         } else {
  105.           tr[i].style.display = "none";
  106.         }
  107.       }
  108.     }
  109.   }
  110.  
  111.   public reformatDateString(dateTimeString: string): string {
  112.     return moment(dateTimeString, 'YYYY-MM-DD HH:mm:ss').format('DD/MM/YY');
  113.   }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement