vehicle-maintenance-list.component.ts 8.2 KB

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