visiting-times-list.component.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import { AuthServiceService } from './../../../shared/auth-service.service';
  2. import { NgxSpinnerService } from 'ngx-spinner';
  3. import { ActivatedRoute, Router, Params } from '@angular/router';
  4. import { DashboardService } from './../../../shared/dashboard.service';
  5. import { HttpClient } from '@angular/common/http';
  6. import { Component, OnInit } from '@angular/core';
  7. import { Modal } from 'ngx-modialog/plugins/bootstrap';
  8. import { UserService } from '../../../shared/user.service';
  9. import { ToastrService } from 'ngx-toastr';
  10. @Component({
  11. selector: 'app-visiting-times-list',
  12. templateUrl: './visiting-times-list.component.html',
  13. styleUrls: ['./visiting-times-list.component.css']
  14. })
  15. export class VisitingTimesListComponent implements OnInit {
  16. constructor(private http: HttpClient,
  17. private route: ActivatedRoute,
  18. private router: Router,
  19. private modal: Modal,
  20. private userSer: UserService,
  21. private spinner: NgxSpinnerService,
  22. private authSer: AuthServiceService,
  23. private toastr: ToastrService,
  24. private dashboardSer: DashboardService) { }
  25. visitingTimesList = [];
  26. pages= [];
  27. pageId: number;
  28. visitingTimesListIds = [];
  29. count: number;
  30. perPagePagenation: number;
  31. currentPage:number = 1;
  32. filtterStatus = '';
  33. selectedAll: any;
  34. userLoginId:number;
  35. serviceId:number;
  36. dataTableNumber: number = 5;
  37. ngOnInit() {
  38. //init values of permisions
  39. this.authSer.showAddBtn = false;
  40. this.authSer.showDeleteBtn = false;
  41. this.authSer.showEditBtn = false;
  42. this.authSer.showPermissionsBtn = false;
  43. //show / hide notification search in header
  44. this.authSer.notificationLogin = true;
  45. this.authSer.showSearchHeader = false;
  46. this.authSer.showHeaderLogin = false;
  47. this.authSer.showHeaderDashBoard = true;
  48. this.authSer.showDashboardHeader = true;
  49. this.authSer.internalHeader = false;
  50. //to show / hide permissions
  51. this.route.parent.params.subscribe(
  52. (params:Params) => {
  53. this.userLoginId = params['userID'];
  54. this.serviceId = params['serviceID'];
  55. this.userSer.getPagesPermetiotns(this.userLoginId, this.serviceId).subscribe(
  56. (responce) => {
  57. console.log(responce);
  58. this.pages = responce['pages'];
  59. for(let i = 0; i< this.pages.length; i++) {
  60. if(this.pages[i].id == 23) {
  61. for(let j = 0; j < this.pages[i].permissions.length; j++) {
  62. if(this.pages[i].permissions[j].name == "add_visiting_time"){
  63. this.authSer.showAddBtn = true;
  64. }
  65. if(this.pages[i].permissions[j].name == "edit_visiting_time"){
  66. this.authSer.showEditBtn = true;
  67. }
  68. if(this.pages[i].permissions[j].name == "delete_visiting_times"){
  69. this.authSer.showDeleteBtn = true;
  70. }
  71. }
  72. }else {
  73. console.log('no events');
  74. }
  75. }
  76. this.spinner.hide();
  77. },
  78. (error) => {console.log(error)}
  79. );
  80. }
  81. );
  82. this.route.params.subscribe(
  83. (parmas: Params) => {
  84. this.pageId = parmas['visitingTimesId'];
  85. }
  86. );
  87. this.dashboardSer.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  88. (responce) => {
  89. console.log(responce);
  90. this.visitingTimesList = responce['visiting_times'];
  91. this.count = responce['count'];
  92. this.perPagePagenation = responce['per_page'];
  93. },
  94. (error) => {
  95. console.log(error);
  96. }
  97. );
  98. } //end ngOnInit
  99. //make all checkbox of user checked
  100. selectAll() {
  101. for (var i = 0; i < this.visitingTimesList.length; i++) {
  102. this.visitingTimesList[i].selected = this.selectedAll;
  103. }
  104. };
  105. checkIfAllSelected() {
  106. this.selectedAll = this.visitingTimesList.every(function(item:any) {
  107. return item.selected == true;
  108. });
  109. };
  110. //filtter function
  111. filtterFunc(data) {
  112. this.visitingTimesList = [];
  113. console.log(data.target.value);
  114. const dataSearch = data.target.value;
  115. this.currentPage = 1;
  116. console.log('search curent page', this.currentPage);
  117. this.dashboardSer.getDataUSerSearchBar(dataSearch, this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  118. (responce) => {
  119. console.log(responce);
  120. this.visitingTimesList = responce['visiting_times'];
  121. this.count = responce['count'];
  122. this.perPagePagenation = responce['per_page'];
  123. console.log('filtter count', this.count);
  124. console.log('filtter perPagePAgenation', this.perPagePagenation);
  125. },
  126. (error) => {
  127. console.log(error)
  128. }
  129. );
  130. };
  131. //change page
  132. onPageChange(pagenationNumber) {
  133. this.spinner.show();
  134. this.currentPage = pagenationNumber;
  135. this.visitingTimesList = [];
  136. //console.log(pagenationNumber);
  137. //console.log(this.pageId);
  138. this.dashboardSer.getListData(this.pageId, pagenationNumber, this.dataTableNumber).subscribe(
  139. (responce) => {
  140. console.log(responce);
  141. this.visitingTimesList = responce['visiting_times'];
  142. this.count = responce['count'];
  143. this.perPagePagenation = responce['per_page'];
  144. console.log(this.visitingTimesList);
  145. this.spinner.hide();
  146. },
  147. (error) => {
  148. console.log(error);
  149. this.spinner.hide();
  150. }
  151. );
  152. };
  153. //determine the list count from select element
  154. onGetValue(event) {
  155. this.spinner.show();
  156. this.visitingTimesList = [];
  157. this.dataTableNumber = event.target.value;
  158. this.dashboardSer.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  159. (responce) => {
  160. console.log(responce);
  161. this.visitingTimesList = responce['visiting_times'];
  162. this.count = responce['count'];
  163. this.perPagePagenation = responce['per_page'];
  164. this.spinner.hide();
  165. },
  166. (error) => {
  167. console.log(error);
  168. this.spinner.hide();
  169. }
  170. );
  171. }
  172. onDelete() {
  173. this.visitingTimesListIds = [];
  174. for(let i = 0; i < this.visitingTimesList.length; i++) {
  175. if(this.visitingTimesList[i].selected == true) {
  176. this.visitingTimesListIds.push(this.visitingTimesList[i].id);
  177. }
  178. }
  179. console.log(this.visitingTimesListIds);
  180. if(this.visitingTimesListIds.length > 0) {
  181. const dialogRef = this.modal.alert()
  182. .size('sm')
  183. .showClose(true)
  184. .title('تأكيد الحذف')
  185. .body(`
  186. <h4>هل ترغب في حذف العناصر المحدده ؟ </h4>
  187. `)
  188. .open();
  189. dialogRef.result
  190. .then( result =>
  191. this.dashboardSer.deleteItem(this.visitingTimesListIds, this.pageId).subscribe(
  192. (responce) => {
  193. console.log(responce);
  194. this.toastr.success('تم الحذف');
  195. this.spinner.show();
  196. this.visitingTimesList = [];
  197. this.dashboardSer.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  198. (responce) => {
  199. console.log(responce);
  200. this.visitingTimesList = responce['visiting_times'];
  201. this.count = responce['count'];
  202. this.perPagePagenation = responce['per_page'];
  203. this.spinner.hide();
  204. },
  205. (error) => {
  206. console.log(error);
  207. this.spinner.hide();
  208. }
  209. );
  210. },
  211. (error) => {
  212. console.log(error);
  213. this.spinner.hide();
  214. },
  215. )
  216. );
  217. } else {
  218. this.toastr.warning('لم يتم إختيار أي عنصر للمسح !');
  219. }
  220. };
  221. //add function
  222. onAdd() {
  223. console.log('service/' + this.userLoginId + '/' + this.serviceId + '/visitingTime/add');
  224. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/visitingTime/add']);
  225. }
  226. //edit function
  227. onEdit(editTabID) {
  228. localStorage.setItem('editvisitingTimeIdStorage', editTabID);
  229. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/visitingTime/edit/'+ editTabID]);
  230. console.log('service/' + this.userLoginId + '/' + this.serviceId + '/visitingTime/edit/'+ editTabID);
  231. };
  232. }