event-calendars-list.component.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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-event-calendars-list',
  12. templateUrl: './event-calendars-list.component.html',
  13. styleUrls: ['./event-calendars-list.component.css']
  14. })
  15. export class EventCalendarsListComponent 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. eventCalendarsList = [];
  26. pages= [];
  27. pageId: number;
  28. eventCalendarsListIds = [];
  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.params.subscribe(
  52. (parmas: Params) => {
  53. this.pageId = parmas['listPageId'];
  54. localStorage.setItem('pageIdActive', parmas['listPageId']);
  55. }
  56. );
  57. this.route.parent.params.subscribe(
  58. (params:Params) => {
  59. this.userLoginId = params['userID'];
  60. this.serviceId = params['serviceID'];
  61. this.userSer.getPagesPermetiotns(this.userLoginId, this.serviceId).subscribe(
  62. (responce) => {
  63. console.log(responce);
  64. this.pages = responce['pages'];
  65. for(let i = 0; i< this.pages.length; i++) {
  66. if(this.pages[i].id == 25) {
  67. for(let j = 0; j < this.pages[i].permissions.length; j++) {
  68. if(this.pages[i].permissions[j].name == "add_event_calendar"){
  69. this.authSer.showAddBtn = true;
  70. }
  71. if(this.pages[i].permissions[j].name == "edit_event_calendar"){
  72. this.authSer.showEditBtn = true;
  73. }
  74. if(this.pages[i].permissions[j].name == "delete_event_calendars"){
  75. this.authSer.showDeleteBtn = true;
  76. }
  77. }
  78. }else {
  79. console.log('no event calendars');
  80. }
  81. }
  82. this.spinner.hide();
  83. },
  84. (error) => {console.log(error)}
  85. );
  86. }
  87. );
  88. this.dashboardSer.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  89. (responce) => {
  90. console.log(responce);
  91. this.eventCalendarsList = responce['event_calendars'];
  92. this.count = responce['count'];
  93. this.perPagePagenation = responce['per_page'];
  94. },
  95. (error) => {
  96. console.log(error);
  97. }
  98. );
  99. } //ngOnInit
  100. //make all checkbox of user checked
  101. selectAll() {
  102. for (var i = 0; i < this.eventCalendarsList.length; i++) {
  103. this.eventCalendarsList[i].selected = this.selectedAll;
  104. }
  105. };
  106. checkIfAllSelected() {
  107. this.selectedAll = this.eventCalendarsList.every(function(item:any) {
  108. return item.selected == true;
  109. });
  110. };
  111. //filtter function
  112. filtterFunc(data) {
  113. this.eventCalendarsList = [];
  114. console.log(data.target.value);
  115. const dataSearch = data.target.value;
  116. this.currentPage = 1;
  117. console.log('search curent page', this.currentPage);
  118. this.dashboardSer.getDataUSerSearchBar(dataSearch, this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  119. (responce) => {
  120. console.log(responce);
  121. this.eventCalendarsList = responce['event_calendars'];
  122. this.count = responce['count'];
  123. this.perPagePagenation = responce['per_page'];
  124. console.log('filtter count', this.count);
  125. console.log('filtter perPagePAgenation', this.perPagePagenation);
  126. },
  127. (error) => {
  128. console.log(error)
  129. }
  130. );
  131. };
  132. //change page
  133. onPageChange(pagenationNumber) {
  134. this.spinner.show();
  135. this.currentPage = pagenationNumber;
  136. this.eventCalendarsList = [];
  137. //console.log(pagenationNumber);
  138. //console.log(this.pageId);
  139. this.dashboardSer.getListData(this.pageId, pagenationNumber, this.dataTableNumber).subscribe(
  140. (responce) => {
  141. console.log(responce);
  142. this.eventCalendarsList = responce['event_calendars'];
  143. this.count = responce['count'];
  144. this.perPagePagenation = responce['per_page'];
  145. console.log(this.eventCalendarsList);
  146. this.spinner.hide();
  147. },
  148. (error) => {
  149. console.log(error);
  150. this.spinner.hide();
  151. }
  152. );
  153. };
  154. //determine the list count from select element
  155. onGetValue(event) {
  156. this.spinner.show();
  157. this.eventCalendarsList = [];
  158. this.dataTableNumber = event.target.value;
  159. this.dashboardSer.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  160. (responce) => {
  161. console.log(responce);
  162. this.eventCalendarsList = responce['event_calendars'];
  163. this.count = responce['count'];
  164. this.perPagePagenation = responce['per_page'];
  165. this.spinner.hide();
  166. },
  167. (error) => {
  168. console.log(error);
  169. this.spinner.hide();
  170. }
  171. );
  172. }
  173. onDelete() {
  174. this.eventCalendarsListIds = [];
  175. for(let i = 0; i < this.eventCalendarsList.length; i++) {
  176. if(this.eventCalendarsList[i].selected == true) {
  177. this.eventCalendarsListIds.push(this.eventCalendarsList[i].id);
  178. }
  179. }
  180. console.log(this.eventCalendarsListIds);
  181. if(this.eventCalendarsListIds.length > 0) {
  182. const dialogRef = this.modal.alert()
  183. .size('sm')
  184. .showClose(true)
  185. .title('تأكيد الحذف')
  186. .body(`
  187. <h4>هل ترغب في حذف العناصر المحدده ؟ </h4>
  188. `)
  189. .open();
  190. dialogRef.result
  191. .then( result =>
  192. this.dashboardSer.deleteItem(this.eventCalendarsListIds, this.pageId).subscribe(
  193. (responce) => {
  194. console.log(responce);
  195. this.toastr.success('تم الحذف');
  196. this.spinner.show();
  197. this.eventCalendarsList = [];
  198. this.dashboardSer.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  199. (responce) => {
  200. console.log(responce);
  201. this.eventCalendarsList = responce['event_calendars'];
  202. this.count = responce['count'];
  203. this.perPagePagenation = responce['per_page'];
  204. this.spinner.hide();
  205. },
  206. (error) => {
  207. console.log(error);
  208. this.spinner.hide();
  209. }
  210. );
  211. },
  212. (error) => {
  213. console.log(error);
  214. this.spinner.hide();
  215. },
  216. )
  217. );
  218. } else {
  219. this.toastr.warning('لم يتم إختيار أي عنصر للمسح !');
  220. }
  221. };
  222. //add function
  223. onAdd() {
  224. console.log('service/' + this.userLoginId + '/' + this.serviceId + '/addEventCalendar');
  225. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/addEventCalendar']);
  226. }
  227. //edit function
  228. onEdit(editTabID) {
  229. // localStorage.setItem('editeventCalendarIdStorage', editTabID);
  230. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/eventCalendar/edit/' + editTabID]);
  231. console.log('service/' + this.userLoginId + '/' + this.serviceId + '/eventCalendar/edit/' + editTabID);
  232. };
  233. }