definition-list.component.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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-list',
  12. templateUrl: './definition-list.component.html',
  13. styleUrls: ['./definition-list.component.css']
  14. })
  15. export class DefinitionListComponent implements OnInit {
  16. constructor(private http: HttpClient,
  17. private route: ActivatedRoute,
  18. private router: Router,
  19. private modal: Modal,
  20. private userSer: UserService,
  21. private spinner: NgxSpinnerService,
  22. private authSer: AuthServiceService,
  23. private toastr: ToastrService,
  24. private dashboardSer: DashboardService) { }
  25. dataList = [];
  26. pages= [];
  27. pageId: number;
  28. Ids = [];
  29. count: number;
  30. perPagePagenation: number;
  31. currentPage:number = 1;
  32. filtterStatus = 'all';
  33. selectedAll: any;
  34. userLoginId:number;
  35. serviceId:number;
  36. dataTableNumber: number = 5;
  37. absorpationListIds = [];
  38. dataListIds = [];
  39. ngOnInit() {
  40. //init values of permisions
  41. this.authSer.showAddBtn = false;
  42. this.authSer.showDeleteBtn = false;
  43. this.authSer.showEditBtn = false;
  44. this.authSer.showPermissionsBtn = false;
  45. //show / hide notification search in header
  46. this.authSer.notificationLogin = true;
  47. this.authSer.showSearchHeader = false;
  48. this.authSer.showHeaderLogin = false;
  49. this.authSer.showHeaderDashBoard = true;
  50. this.authSer.showDashboardHeader = true;
  51. this.authSer.internalHeader = false;
  52. //get the page id param and store it in local storage to active status
  53. this.route.params.subscribe(
  54. (parmas: Params) => {
  55. this.pageId = +parmas['listPageId'];
  56. localStorage.setItem('pageIdActive', parmas['listPageId']);
  57. }
  58. );
  59. this.route.parent.params.subscribe(
  60. (params:Params) => {
  61. this.userLoginId = params['userID'];
  62. this.serviceId = params['serviceID'];
  63. this.userSer.getPagesPermetiotns(this.userLoginId, this.serviceId).subscribe(
  64. (responce) => {
  65. console.log(responce);
  66. this.pages = responce['pages'];
  67. for(let i = 0; i< this.pages.length; i++) {
  68. if(this.pages[i].id == 51) {
  69. if(this.pages[i]['permissions'][0].name == 'define_categories') {
  70. this.authSer.showAddBtn = true;
  71. this.authSer.showEditBtn = true;
  72. this.authSer.showDeleteBtn = true;
  73. } else {
  74. console.log('no permissions');
  75. }
  76. } else {
  77. console.log('no events');
  78. }
  79. }
  80. this.spinner.hide();
  81. },
  82. (error) => {console.log(error)}
  83. );
  84. }
  85. );
  86. this.dashboardSer.getListData(this.pageId, this.currentPage ,this.dataTableNumber).subscribe(
  87. (response) => {
  88. console.log(response);
  89. this.dataList = response['categories'];
  90. this.count = response['count'];
  91. this.perPagePagenation = response['per_page'];
  92. },
  93. (error) => {
  94. console.log(error);
  95. }
  96. );
  97. }
  98. //make all checkbox of user checked
  99. selectAll() {
  100. console.log('selected alllllll');
  101. for(let i = 0; i < this.dataList.length; i++){
  102. this.dataList[i].selected = this.selectedAll;
  103. }
  104. }
  105. checkIfAllSelected() {
  106. this.selectedAll = this.absorpationListIds.every(function(item: any) {
  107. return item.selected == true;
  108. });
  109. }
  110. //filtter function
  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. (responce) => {
  121. console.log(responce);
  122. this.dataList = responce['categories'];
  123. this.count = responce['count'];
  124. this.perPagePagenation = responce['per_page'];
  125. console.log('filtter count', this.count);
  126. console.log('filtter perPagePAgenation', this.perPagePagenation);
  127. },
  128. (error) => {
  129. console.log(error)
  130. }
  131. );
  132. };
  133. onPageChange(pagenationNumber) {
  134. this.spinner.show();
  135. this.dataList = [];
  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. (responce) => {
  142. console.log(responce);
  143. this.dataList = responce['categories'];
  144. this.count = responce['count'];
  145. this.perPagePagenation = responce['per_page'];
  146. console.log('FFFFFF',this.absorpationListIds);
  147. this.spinner.hide();
  148. },
  149. (error) => {
  150. console.log(error);
  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. (responce) => {
  162. console.log(responce);
  163. this.absorpationListIds = responce['categories'];
  164. this.count = responce['count'];
  165. this.perPagePagenation = responce['per_page'];
  166. this.spinner.hide();
  167. },
  168. (error) => {
  169. console.log(error);
  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. (responce) => {
  183. console.log(responce);
  184. this.dataList = responce['categories'];
  185. this.count = responce['count'];
  186. this.perPagePagenation = responce['per_page'];
  187. this.spinner.hide();
  188. console.log('UrL>>', this.authSer.pathApi +'/page_list/' + this.pageId + '/' + this.currentPage + '/' + this.dataTableNumber + '/' + typeId)
  189. },
  190. (error) => {
  191. console.log(error);
  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['categories'];
  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 + '/' + 'definitionClassification/add']);
  247. }
  248. onEdit(editId: number) {
  249. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'definitionClassification/edit/ ' + editId]);
  250. }
  251. }