definition-of-covenants-list.component.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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-definition-of-covenants-list',
  12. templateUrl: './definition-of-covenants-list.component.html',
  13. styleUrls: ['./definition-of-covenants-list.component.css']
  14. })
  15. export class DefinitionOfCovenantsListComponent 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 == 64){
  70. if(this.pages[i]['permissions'][0].name == 'covenants') {
  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. console.log('current page',this.pageId)
  88. this.dashboardSer.getListData(this.pageId, this.currentPage ,this.dataTableNumber).subscribe(
  89. res => {
  90. console.log(res);
  91. this.dataList = res['covenants'];
  92. this.count = res['count'];
  93. this.perPagePagenation = res['per_page'];
  94. },
  95. err => {
  96. console.log(err);
  97. }
  98. );
  99. }
  100. //make all checkbox of user checked
  101. selectAll() {
  102. for (var i = 0; i < this.dataList.length; i++) {
  103. this.dataList[i].selected = this.selectedAll;
  104. }
  105. };
  106. checkIfAllSelected() {
  107. this.selectedAll = this.dataList.every(function(item:any) {
  108. return item.selected == true;
  109. });
  110. };
  111. filtterFunc(data) {
  112. this.dataList =[];
  113. this.absorpationListIds = [];
  114. console.log(data.target.value);
  115. const dataSearch = data.target.value;
  116. this.currentPage = 1;
  117. console.log('search curent page', this.currentPage);
  118. console.log('search page id', this.pageId);
  119. this.dashboardSer.getDataUSerSearchBar(dataSearch, this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  120. res => {
  121. console.log(res);
  122. this.dataList = res['covenants'];
  123. console.log('hey',this.dataList)
  124. this.count = res['count'];
  125. this.perPagePagenation = res['per_page'];
  126. console.log('filtter count', this.count);
  127. console.log('filtter perPagePAgenation', this.perPagePagenation);
  128. },
  129. err => {
  130. console.log(err);
  131. }
  132. );
  133. };
  134. onPageChange(pagenationNumber) {
  135. this.spinner.show();
  136. this.currentPage = pagenationNumber;
  137. this.absorpationListIds = [];
  138. console.log(pagenationNumber);
  139. console.log(this.pageId);
  140. this.dashboardSer.getListData(this.pageId, pagenationNumber, this.dataTableNumber).subscribe(
  141. res => {
  142. console.log(res);
  143. this.dataList = res['covenants'];
  144. this.count = res['count'];
  145. this.perPagePagenation = res['per_page'];
  146. console.log('FFFFFF', this.absorpationListIds);
  147. this.spinner.hide();
  148. },
  149. err => {
  150. console.log(err);
  151. this.spinner.hide();
  152. }
  153. );
  154. }
  155. //determine the list count from select element
  156. onGetValue(event) {
  157. this.spinner.show();
  158. this.absorpationListIds = [];
  159. this.dataTableNumber = event.target.value;
  160. this.dashboardSer.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  161. res => {
  162. console.log(res);
  163. this.absorpationListIds = res['covenants'];
  164. this.count = res['count'];
  165. this.perPagePagenation = res['per_page'];
  166. this.spinner.hide();
  167. },
  168. err => {
  169. console.log(err);
  170. this.spinner.hide();
  171. }
  172. );
  173. };
  174. onGetValueFiltter(event) {
  175. console.log(event.target.value)
  176. this.spinner.show();
  177. this.dataList = [];
  178. const typeId = event.target.value;
  179. this.filtterStatus = event.target.value;
  180. console.log(this.filtterStatus);
  181. this.http.get(this.authSer.pathApi +'/page_list/' + this.pageId + '/' + this.currentPage + '/' + this.dataTableNumber + '/' + typeId).subscribe(
  182. res => {
  183. console.log(res);
  184. this.dataList = res['covenants'];
  185. this.count = res['count'];
  186. this.perPagePagenation = res['per_page'];
  187. this.spinner.hide();
  188. console.log('UrL>>', this.authSer.pathApi +'/page_list/' + this.pageId + '/' + this.currentPage + '/' + this.dataTableNumber + '/' + typeId)
  189. },
  190. err=> {
  191. console.log(err);
  192. }
  193. );
  194. }
  195. onDelete() {
  196. this.dataListIds = [];
  197. for(let i = 0; i < this.dataList.length; i++) {
  198. if(this.dataList[i].selected == true) {
  199. this.dataListIds.push(this.dataList[i].id);
  200. }
  201. }
  202. console.log(this.dataListIds);
  203. if(this.dataListIds.length > 0) {
  204. const dialogRef = this.modal.alert()
  205. .size('sm')
  206. .showClose(true)
  207. .title('تأكيد الحذف')
  208. .body(`
  209. <h4>هل ترغب في حذف العناصر المحدده ؟ </h4>
  210. `)
  211. .open();
  212. dialogRef.result
  213. .then( result =>
  214. this.dashboardSer.deleteItem(this.dataListIds , this.pageId).subscribe(
  215. (responce) => {
  216. console.log(responce);
  217. this.toastr.success('تم الحذف');
  218. this.spinner.show();
  219. this.dataList = [];
  220. //get list data
  221. this.dashboardSer.getListData(this.pageId, this.currentPage ,this.dataTableNumber).subscribe(
  222. (responce) => {
  223. console.log(responce);
  224. this.dataList = responce['covenants'];
  225. this.count = responce['count'];
  226. this.perPagePagenation = responce['per_page'];
  227. this.spinner.hide();
  228. },
  229. (error) => {
  230. console.log(error);
  231. this.spinner.hide();
  232. }
  233. );
  234. },
  235. (error) => {
  236. console.log(error);
  237. this.spinner.hide();
  238. },
  239. )
  240. );
  241. } else {
  242. this.toastr.warning('لم يتم إختيار أي عنصر للمسح !');
  243. }
  244. };
  245. onAdd() {
  246. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'definitionOfConvenats']);
  247. }
  248. onEdit(editId: number) {
  249. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'definitionOfConvenats/edit/' + editId]);
  250. }
  251. }