vehicle-list.component.ts 7.9 KB

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