definition-list.component.ts 8.4 KB

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