internal-page-header.component.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { Router, ActivatedRoute, Params } from '@angular/router';
  2. import { InternalPageService } from './../../shared/internal-page.service';
  3. import { UserService } from './../../shared/user.service';
  4. import { AuthServiceService } from './../../shared/auth-service.service';
  5. import { Component, OnInit } from '@angular/core';
  6. import 'hijri-date';
  7. import HijriDate,{toHijri} from 'hijri-date/lib/safe';
  8. import { NgxSpinnerService } from 'ngx-spinner';
  9. @Component({
  10. selector: 'app-internal-page-header',
  11. templateUrl: './internal-page-header.component.html',
  12. styleUrls: ['./internal-page-header.component.css']
  13. })
  14. export class InternalPageHeaderComponent implements OnInit {
  15. constructor(public authSer: AuthServiceService,
  16. private userservice: UserService,
  17. private internalService: InternalPageService,
  18. private route: ActivatedRoute,
  19. private spinner: NgxSpinnerService,
  20. private router: Router) {
  21. spinner.show();
  22. }
  23. dataLoginUser = {
  24. name: '',
  25. photo: '',
  26. id: '',
  27. }
  28. currentDate: any = Date.now();
  29. currentEnglishDate: any = Date.now();
  30. showActiveBackground: boolean = false;
  31. ngOnInit() {
  32. this.authSer.footerData = [];
  33. if(!this.authSer.isAuthenticated()) {
  34. const userLoginData = JSON.parse(localStorage.getItem('userData'));
  35. this.dataLoginUser.name = userLoginData ? userLoginData.name : '';
  36. this.dataLoginUser.photo = userLoginData ? userLoginData.photo : '';
  37. this.dataLoginUser.id = userLoginData ? userLoginData.id : null;
  38. }
  39. this.authSer.onGetFooterData('internal').subscribe(
  40. (responce) => {
  41. this.authSer.footerData = responce['footer'];
  42. },
  43. (error) => {
  44. console.log(error);
  45. }
  46. );
  47. this.authSer.setLocalLang();
  48. this.internalService.getParentData().subscribe(
  49. (responce) => {
  50. this.authSer.parentsPage = responce['parents'];
  51. },
  52. (error) => {
  53. console.log(error);
  54. }
  55. );
  56. //this.spinner.show();
  57. this.authSer.showDashboardHeader = false;
  58. this.internalService.getParentData();
  59. this.currentDate = this.authSer.writeHijri(new Date(this.currentDate), 'ar', 'header');
  60. }
  61. onLogin() {
  62. this.router.navigate(['auth/login']);
  63. }
  64. onGetProfile() {
  65. this.router.navigate(['auth/profile/' + this.authSer.dataLoginUser['id']]);
  66. }
  67. //log out function
  68. onLogout() {
  69. localStorage.clear();
  70. this.router.navigate(['auth/login']);
  71. }
  72. onDashBoard() {
  73. this.router.navigate(['services/' + this.authSer.dataLoginUser['id']]);
  74. }
  75. goToHome() {
  76. this.router.navigate(['/InternalPage']);
  77. }
  78. getData(parentData) {
  79. console.log(parentData);
  80. }
  81. }