external-page-content.component.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import { Subscription } from 'rxjs';
  2. import { Router, ActivatedRoute } from '@angular/router';
  3. import { AuthServiceService } from './../../shared/auth-service.service';
  4. import { ExternalPageService } from './../../shared/external-page.service';
  5. import { Component, OnInit, OnDestroy } from '@angular/core';
  6. import {MapsAPILoader} from '@agm/core';
  7. import * as $ from 'jquery';
  8. import { NgxSpinnerService } from 'ngx-spinner';
  9. import { HttpClient } from '@angular/common/http';
  10. import { ToastrService } from 'ngx-toastr';
  11. import { NgbCarouselConfig } from '@ng-bootstrap/ng-bootstrap';
  12. @Component({
  13. selector: 'app-external-page-content',
  14. templateUrl: './external-page-content.component.html',
  15. styleUrls: ['./external-page-content.component.css'],
  16. providers: [NgbCarouselConfig]
  17. })
  18. export class ExternalPageContentComponent implements OnInit, OnDestroy {
  19. constructor(private externalService: ExternalPageService,
  20. private spinner: NgxSpinnerService,
  21. private router: Router,
  22. private http: HttpClient,
  23. private route: ActivatedRoute,
  24. config: NgbCarouselConfig,
  25. private toastr: ToastrService,
  26. public authSer: AuthServiceService) {
  27. this.spinner.show();
  28. }
  29. reports = [];
  30. events = [];
  31. services = [];
  32. secondAdvertisiment = [];
  33. hypnosisSections = [];
  34. intensiveCare = [];
  35. recordsOfMonth = [];
  36. achievements = [];
  37. initialMonthNumber: number;
  38. checkStatisticShow: boolean = false;
  39. showSmallSpinner: boolean = false;
  40. title: string = 'My first AGM project';
  41. lat: number = 24.380000;
  42. lng: number = 46.430000;
  43. contentSubscription:Subscription;
  44. firstAdvertisiment = [];
  45. ngOnInit() {
  46. this.authSer.homeActivate = true;
  47. //to make class active is "0"
  48. this.externalService.getHeader().subscribe(
  49. (responce) => {
  50. console.log('Header', responce);
  51. this.externalService.headerMenus = responce['parents'];
  52. console.log(this.externalService);
  53. for(let i = 0; i < this.externalService.headerMenus.length; i++) {
  54. this.externalService.headerMenus[i].active = 0;
  55. }
  56. }
  57. );
  58. //get content data of external pages
  59. this.contentSubscription = this.externalService.getContentData().subscribe(
  60. (responce) => {
  61. console.log(responce);
  62. this.reports = responce['data'].reports;
  63. for(let i = 0; i < this.reports.length; i++) {
  64. if(this.reports[i].description.length > 100) {
  65. this.reports[i].description = this.reports[i].description.substring(0,300) + '.......';
  66. this.reports[i].description_en = this.reports[i].description_en.substring(0,300) + '.......';
  67. }
  68. if(this.reports[i].photo == null){
  69. this.reports[i].photo = 'notfound.png'
  70. }
  71. }
  72. console.log(this.reports);
  73. this.events = responce['data'].events;
  74. this.services = responce['data'].external_services;
  75. this.firstAdvertisiment = responce['data'].first_advertising_services_row;
  76. this.secondAdvertisiment = responce['data'].second_advertising_services_row;
  77. this.hypnosisSections = responce['data'].visiting_times_hs;
  78. this.intensiveCare = responce['data'].visiting_times_ic;
  79. this.recordsOfMonth = responce['data']['statistics'];
  80. if(responce['data']['statistics'].statistics_values.length > 0) {
  81. this.checkStatisticShow = false;
  82. } else {
  83. this.checkStatisticShow = true;
  84. }
  85. this.achievements = responce['data'].external_achievements;
  86. this.initialMonthNumber = responce['data']['statistics'].month_id;
  87. //this.lat = responce['data']['reach_map'].latitude;
  88. //this.lng = responce['data']['reach_map'].longitude;
  89. this.spinner.hide();
  90. },
  91. (error) => {
  92. console.log(error);
  93. }
  94. );
  95. }
  96. nextMonth() {
  97. this.showSmallSpinner = true;
  98. this.recordsOfMonth = [];
  99. if(this.initialMonthNumber == 12) {
  100. this.initialMonthNumber = 12;
  101. console.log(this.initialMonthNumber);
  102. this.toastr.warning('أخر شهور العام !');
  103. this.http.get(this.authSer.pathApi + '/get_statistics_by_month_id/' + 12).subscribe(
  104. (responce) => {
  105. console.log(responce);
  106. this.showSmallSpinner = false;
  107. this.recordsOfMonth = responce['statistics'];
  108. if(responce['statistics'].statistics_values.length > 0) {
  109. this.checkStatisticShow = false;
  110. } else {
  111. this.checkStatisticShow = true;
  112. }
  113. },
  114. (error) => {
  115. console.log(error);
  116. }
  117. );
  118. } else {
  119. this.initialMonthNumber++;
  120. console.log(this.initialMonthNumber);
  121. this.http.get(this.authSer.pathApi + '/get_statistics_by_month_id/' + this.initialMonthNumber).subscribe(
  122. (responce) => {
  123. console.log(responce);
  124. this.showSmallSpinner = false;
  125. this.recordsOfMonth = responce['statistics'];
  126. if(responce['statistics'].statistics_values.length > 0) {
  127. this.checkStatisticShow = false;
  128. } else {
  129. this.checkStatisticShow = true;
  130. }
  131. },
  132. (error) => {
  133. console.log(error);
  134. }
  135. );
  136. }
  137. }
  138. prevMonth() {
  139. this.showSmallSpinner = true;
  140. this.recordsOfMonth = [];
  141. console.log(this.initialMonthNumber);
  142. if(this.initialMonthNumber == 1) {
  143. this.initialMonthNumber = 1;
  144. this.toastr.warning('أول شهور العام !');
  145. this.http.get(this.authSer.pathApi + '/get_statistics_by_month_id/' + 1).subscribe(
  146. (responce) => {
  147. this.showSmallSpinner = true;
  148. this.showSmallSpinner = false;
  149. this.recordsOfMonth = responce['statistics'];
  150. if(responce['statistics'].statistics_values.length > 0) {
  151. this.checkStatisticShow = false;
  152. } else {
  153. this.checkStatisticShow = true;
  154. }
  155. },
  156. (error) => {
  157. console.log(error);
  158. }
  159. );
  160. } else {
  161. this.initialMonthNumber--;
  162. this.http.get(this.authSer.pathApi + '/get_statistics_by_month_id/' + this.initialMonthNumber).subscribe(
  163. (responce) => {
  164. console.log(responce);
  165. this.showSmallSpinner = true;
  166. this.showSmallSpinner = false;
  167. this.recordsOfMonth = responce['statistics'];
  168. if(responce['statistics'].statistics_values.length > 0) {
  169. this.checkStatisticShow = false;
  170. } else {
  171. this.checkStatisticShow = true;
  172. }
  173. },
  174. (error) => {
  175. console.log(error);
  176. }
  177. );
  178. }
  179. }
  180. onGetService(serviceData) {
  181. console.log(serviceData);
  182. if(serviceData.type == 'internal') {
  183. this.router.navigate(['ExternalPage/externalServiceDetails/' + serviceData.id]);
  184. } else if(serviceData.type == 'external') {
  185. window.location.href = serviceData.link;
  186. }
  187. }
  188. onGetServiceData(serviceData) {
  189. console.log('service Data' , serviceData);
  190. }
  191. goPageNew(reprotData) {
  192. console.log(reprotData);
  193. this.router.navigate( ['ExternalPage/newPage/' + reprotData.id]);
  194. }
  195. oneventTable() {
  196. this.router.navigate(['/ExternalPage/EventsTable']);
  197. }
  198. ngOnDestroy() {
  199. this.contentSubscription.unsubscribe();
  200. }
  201. moreNewsPage() {
  202. this.router.navigate(['/ExternalPage/moreNews']);
  203. }
  204. }