registration-vehicle-list.component.ts 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 = 'all';
  24. selectedAll: any;
  25. userLoginId:number;
  26. serviceId:number;
  27. dataTableNumber: number = 5;
  28. pages = [];
  29. vehicle_types:any [] = [];
  30. constructor(private route: ActivatedRoute,
  31. private userSer: UserService,
  32. private spinner: NgxSpinnerService,
  33. private authSer: AuthServiceService,
  34. private toastr: ToastrService,
  35. private http: HttpClient,
  36. private modal: Modal,
  37. private dashBoardSer: DashboardService,
  38. private router: Router) { }
  39. ngOnInit() {
  40. //this.spinner.show();
  41. //init the values of permision boolean
  42. this.authSer.showAddBtn = false;
  43. this.authSer.showDeleteBtn = false;
  44. this.authSer.showEditBtn = false;
  45. //show / hide notification search in header
  46. this.authSer.notificationLogin = true;
  47. this.authSer.showSearchHeader = false;
  48. this.authSer.showHeaderLogin = false;
  49. this.authSer.showHeaderDashBoard = true;
  50. this.authSer.showDashboardHeader = true;
  51. this.authSer.internalHeader = false;
  52. //init the values of permision boolean
  53. this.route.params.subscribe(
  54. (params: Params) => {
  55. this.pageId = +params['listPageId'];
  56. localStorage.setItem('pageIdActive', params['listPageId']);
  57. }
  58. );
  59. this.http.get(this.authSer.pathApi + '/get_vehicle_types_list').subscribe(
  60. (response) => {
  61. console.log(response);
  62. this.vehicle_types = response['types'];
  63. },
  64. (error) => {
  65. console.log(error);
  66. }
  67. );
  68. this.route.parent.params.subscribe(
  69. (params:Params) => {
  70. this.userLoginId = params['userID'];
  71. this.serviceId = params['serviceID'];
  72. this.userSer.getPagesPermetiotns(this.userLoginId, this.serviceId).subscribe(
  73. (responce) => {
  74. console.log('permission list', responce);
  75. this.pages = responce['pages'];
  76. for(let i = 0; i< this.pages.length; i++) {
  77. if(this.pages[i].id == 45) {
  78. if(this.pages[i].permissions[0].name == 'registration_of_vehicle_data') {
  79. this.authSer.showAddBtn = true;
  80. this.authSer.showEditBtn = true;
  81. this.authSer.showDeleteBtn = true;
  82. }
  83. }else {
  84. console.log('no lectures');
  85. }
  86. }
  87. this.spinner.hide();
  88. },
  89. (error) => {console.log(error)}
  90. );
  91. }
  92. );
  93. this.dashBoardSer.getListData(this.pageId, this.currentPage ,this.dataTableNumber).subscribe(
  94. (responce) => {
  95. console.log(responce);
  96. this.dataList = responce['vehicle_datas'];
  97. this.count = responce['count'];
  98. this.perPagePagenation = responce['per_page'];
  99. this.spinner.hide();
  100. },
  101. (error) => {
  102. console.log(error);
  103. }
  104. );
  105. }
  106. //make all checkbox of user checked
  107. selectAll() {
  108. for (var i = 0; i < this.dataList.length; i++) {
  109. this.dataList[i].selected = this.selectedAll;
  110. }
  111. };
  112. checkIfAllSelected() {
  113. this.selectedAll = this.dataList.every(function(item:any) {
  114. return item.selected == true;
  115. });
  116. };
  117. //filtter function
  118. filtterFunc(data) {
  119. this.dataList = [];
  120. console.log(data.target.value);
  121. const dataSearch = data.target.value;
  122. this.currentPage = 1;
  123. console.log('search curent page', this.currentPage);
  124. this.dashBoardSer.getDataUSerSearchBar(dataSearch, this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  125. (responce) => {
  126. console.log(responce);
  127. this.dataList = responce['vehicle_datas'];
  128. this.count = responce['count'];
  129. this.perPagePagenation = responce['per_page'];
  130. console.log('filtter count', this.count);
  131. console.log('filtter perPagePAgenation', this.perPagePagenation);
  132. },
  133. (error) => {
  134. console.log(error)
  135. }
  136. );
  137. };
  138. //change page
  139. onPageChange(pagenationNumber) {
  140. this.spinner.show();
  141. this.currentPage = pagenationNumber;
  142. this.dataList = [];
  143. //console.log(pagenationNumber);
  144. //console.log(this.pageId);
  145. this.dashBoardSer.getListData(this.pageId, pagenationNumber, this.dataTableNumber).subscribe(
  146. (responce) => {
  147. console.log(responce);
  148. this.dataList = responce['vehicle_datas'];
  149. this.count = responce['count'];
  150. this.perPagePagenation = responce['per_page'];
  151. console.log(this.dataList);
  152. this.spinner.hide();
  153. },
  154. (error) => {
  155. console.log(error);
  156. this.spinner.hide();
  157. }
  158. );
  159. };
  160. //determine the list count from select element
  161. onGetValue(event) {
  162. this.spinner.show();
  163. this.dataList = [];
  164. this.dataTableNumber = event.target.value;
  165. this.dashBoardSer.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  166. (responce) => {
  167. console.log(responce);
  168. this.dataList = responce['vehicle_datas'];
  169. this.count = responce['count'];
  170. this.perPagePagenation = responce['per_page'];
  171. this.spinner.hide();
  172. },
  173. (error) => {
  174. console.log(error);
  175. this.spinner.hide();
  176. }
  177. );
  178. };
  179. onGetValueFiltter(event) {
  180. this.spinner.show();
  181. this.dataList = [];
  182. const typeId = event.target.value;
  183. console.log(typeId);
  184. this.http.get(this.authSer.pathApi +'/page_list/' + this.pageId + '/' + this.currentPage + '/' + this.dataTableNumber + '/' + typeId).subscribe(
  185. (responce) => {
  186. console.log(responce);
  187. this.dataList = responce['vehicle_datas'];
  188. this.count = responce['count'];
  189. this.perPagePagenation = responce['per_page'];
  190. this.spinner.hide();
  191. console.log('UrL>>', this.authSer.pathApi +'/page_list/' + this.pageId + '/' + this.currentPage + '/' + this.dataTableNumber + '/' + typeId)
  192. },
  193. (error) => {
  194. console.log(error);
  195. }
  196. );
  197. };
  198. onDelete() {
  199. this.dataListIds = [];
  200. for(let i = 0; i < this.dataList.length; i++) {
  201. if(this.dataList[i].selected == true) {
  202. this.dataListIds.push(this.dataList[i].id);
  203. }
  204. }
  205. console.log(this.dataListIds);
  206. if(this.dataListIds.length > 0) {
  207. const dialogRef = this.modal.alert()
  208. .size('sm')
  209. .showClose(true)
  210. .title('تأكيد الحذف')
  211. .body(`
  212. <h4>هل ترغب في حذف العناصر المحدده ؟ </h4>
  213. `)
  214. .open();
  215. dialogRef.result
  216. .then( result =>
  217. this.dashBoardSer.deleteItem(this.dataListIds , this.pageId).subscribe(
  218. (responce) => {
  219. console.log(responce);
  220. this.toastr.success('تم الحذف');
  221. this.spinner.show();
  222. this.dataList = [];
  223. //get list data
  224. this.dashBoardSer.getListData(this.pageId, this.currentPage ,this.dataTableNumber).subscribe(
  225. (responce) => {
  226. console.log(responce);
  227. this.dataList = responce['vehicle_datas'];
  228. this.count = responce['count'];
  229. this.perPagePagenation = responce['per_page'];
  230. this.spinner.hide();
  231. },
  232. (error) => {
  233. console.log(error);
  234. this.spinner.hide();
  235. }
  236. );
  237. },
  238. (error) => {
  239. console.log(error);
  240. this.spinner.hide();
  241. },
  242. )
  243. );
  244. } else {
  245. this.toastr.warning('لم يتم إختيار أي عنصر للمسح !');
  246. }
  247. };
  248. //add function
  249. onAdd() {
  250. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/registrationVehicle/add']);
  251. }
  252. //edit function
  253. onEdit(editTabID) {
  254. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'registrationVehicle/edit/' + editTabID]);
  255. };
  256. }