registration-vehicle-list.component.ts 8.8 KB

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