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

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