living-service-list.component.ts 8.9 KB

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