more-news.component.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { HttpClient } from '@angular/common/http';
  2. import { AuthServiceService } from './../../shared/auth-service.service';
  3. import { Component, OnInit } from '@angular/core';
  4. import { NgxSpinnerService } from 'ngx-spinner';
  5. import { Router } from '@angular/router';
  6. import { ExternalPageService } from '../../shared/external-page.service';
  7. @Component({
  8. selector: 'app-more-news',
  9. templateUrl: './more-news.component.html',
  10. styleUrls: ['./more-news.component.css']
  11. })
  12. export class MoreNewsComponent implements OnInit {
  13. constructor(public authSer: AuthServiceService,
  14. private http: HttpClient,
  15. private router: Router,
  16. private externalSer: ExternalPageService,
  17. private spinner: NgxSpinnerService) {
  18. this.spinner.show();
  19. }
  20. dataPagesNews = [];
  21. externalService = [];
  22. perPagePagenation: number = 10;
  23. count: number;
  24. currentPage:number = 1;
  25. ngOnInit() {
  26. this.authSer.homeActivate = false;
  27. this.externalSer.getExternalServices().subscribe(
  28. (responce) => {
  29. console.log(responce);
  30. this.externalService = responce['external_services'];
  31. },
  32. (error) => {
  33. console.log(error);
  34. }
  35. )
  36. this.http.get(this.authSer.pathApi + '/reports_list_gate/'+ this.currentPage + '/' + this.perPagePagenation + '/1').subscribe(
  37. (responce) => {
  38. console.log(responce);
  39. this.dataPagesNews = responce['reports'];
  40. for(let i = 0 ; i < this.dataPagesNews.length ; i++) {
  41. if(this.dataPagesNews[i].description.length > 60) {
  42. this.dataPagesNews[i].description = this.dataPagesNews[i].description.substring(0,200) + '........' ;
  43. this.dataPagesNews[i].description_en = this.dataPagesNews[i].description_en.substring(0,200) + '......';
  44. }
  45. }
  46. this.spinner.hide();
  47. },
  48. (error) => {
  49. console.log(error);
  50. }
  51. );
  52. }
  53. // /change page
  54. onPageChange(pagenationNumber) {
  55. this.spinner.show();
  56. this.currentPage = pagenationNumber;
  57. this.http.get(this.authSer.pathApi + '/get_reports_list/1/' + this.currentPage + '/' + this.perPagePagenation + '/internal').subscribe(
  58. (responce) => {
  59. console.log(responce);
  60. this.dataPagesNews = responce['reports'];
  61. this.count = responce['count'];
  62. for(let i = 0 ; i < this.dataPagesNews.length ; i++) {
  63. if(this.dataPagesNews[i].description.length > 60) {
  64. this.dataPagesNews[i].description = this.dataPagesNews[i].description.substring(0,200) + '........' ;
  65. this.dataPagesNews[i].description_en = this.dataPagesNews[i].description_en.substring(0,200) + '......';
  66. }
  67. }
  68. this.spinner.hide();
  69. },
  70. (error) => {
  71. console.log(error);
  72. }
  73. )
  74. };
  75. onGetNew(id) {
  76. this.router.navigate(['ExternalPage/newPage/' + id])
  77. }
  78. }