registration-vehicle-list.component.ts 7.9 KB

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