new-page.component.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { HttpClient } from '@angular/common/http';
  2. import { ActivatedRoute, Params } from '@angular/router';
  3. import { AuthServiceService } from './../../shared/auth-service.service';
  4. import { Component, OnInit } from '@angular/core';
  5. import { NgxSpinnerService } from 'ngx-spinner';
  6. import { ExternalPageService } from '../../shared/external-page.service';
  7. @Component({
  8. selector: 'app-new-page',
  9. templateUrl: './new-page.component.html',
  10. styleUrls: ['./new-page.component.css']
  11. })
  12. export class NewPageComponent implements OnInit {
  13. constructor(private authSer: AuthServiceService,
  14. private http: HttpClient,
  15. private spinner: NgxSpinnerService,
  16. private externalService: ExternalPageService,
  17. private route:ActivatedRoute) {
  18. this.spinner.show();
  19. }
  20. reportId: number;
  21. reportData = {
  22. created_at: '',
  23. title: '',
  24. title_en: '',
  25. description: '',
  26. description_en: '',
  27. photos: [],
  28. };
  29. singleImg = {
  30. photo: '',
  31. };
  32. externalServices = [];
  33. ngOnInit() {
  34. this.authSer.homeActivate = false;
  35. this.route.params.subscribe(
  36. (params: Params) => {
  37. this.reportId = params['reportId'];
  38. }
  39. );
  40. //get external services data
  41. this.externalService.getExternalServices().subscribe(
  42. (responce) => {
  43. console.log('serviceees', responce);
  44. this.externalService = responce['external_services'];
  45. },
  46. (error) => {
  47. console.log(error);
  48. }
  49. );
  50. this.http.get(this.authSer.pathApi + '/get_report/' + this.reportId).subscribe(
  51. (responce) => {
  52. console.log(responce);
  53. const singleDataImg = responce['report']['photos'].splice(responce['report']['photos'].indexOf(responce['report']['photos'][0]) , 1);
  54. console.log('single image data' , singleDataImg);
  55. this.singleImg.photo = singleDataImg[0].photo;
  56. console.log('single image ', this.singleImg.photo);
  57. console.log('responnnnnce' , responce['report']);
  58. this.reportData.created_at = responce['report'].created_at;
  59. this.reportData.title = responce['report'].title;
  60. this.reportData.title_en = responce['report'].title_en;
  61. this.reportData.description = responce['report'].description;
  62. this.reportData.description_en = responce['report'].description_en;
  63. for(let i = 1; i < responce['report']['photos'].length; i++) {
  64. this.reportData.photos.push(responce['report']['photos'][i]);
  65. }
  66. console.log('dddddddddddddddddddd', this.reportData);
  67. this.spinner.hide();
  68. },
  69. (error) => {
  70. console.log(error);
  71. }
  72. );
  73. }
  74. }