department-list.component.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import { Modal } from 'ngx-modialog/plugins/bootstrap';
  2. import { UserService } from './../../../shared/user.service';
  3. import { AuthServiceService } from './../../../shared/auth-service.service';
  4. import { DepartmentService } from './../../../shared/department.service';
  5. import { ActivatedRoute, Params, Router } from '@angular/router';
  6. import { NgxSpinnerService } from 'ngx-spinner';
  7. import { Component, OnInit } from '@angular/core';
  8. import { ToastrService } from 'ngx-toastr';
  9. @Component({
  10. selector: 'app-department-list',
  11. templateUrl: './department-list.component.html',
  12. styleUrls: ['./department-list.component.css']
  13. })
  14. export class DepartmentListComponent implements OnInit {
  15. constructor(private route: ActivatedRoute,
  16. private departService: DepartmentService,
  17. private router: Router,
  18. private spinner: NgxSpinnerService,
  19. private modal: Modal,
  20. private authSer: AuthServiceService,
  21. private userSer: UserService,
  22. private toastr: ToastrService) { }
  23. count: number;
  24. departmentsList = [];
  25. departsId = [];
  26. perPagePagenation: number;
  27. p: number[] = [];
  28. currentPage:number = 1;
  29. filtterStatus = '';
  30. selectedAll: any;
  31. pageId: number;
  32. userLoginId:number;
  33. serviceId:number;
  34. dataTableNumber: number = 5;
  35. pages = [];
  36. ngOnInit() {
  37. //init the values of permision boolean
  38. this.authSer.showAddBtn = false;
  39. this.authSer.showDeleteBtn = false;
  40. this.authSer.showEditBtn = false;
  41. //show / hide notification search in header
  42. this.authSer.notificationLogin = true;
  43. this.authSer.showSearchHeader = false;
  44. this.authSer.showHeaderLogin = false;
  45. this.authSer.showHeaderDashBoard = true;
  46. this.authSer.showDashboardHeader = true;
  47. this.authSer.internalHeader = false;
  48. this.route.params.subscribe(
  49. (params:Params) => {
  50. this.pageId = params['listPageId'];
  51. localStorage.setItem('pageIdActive', '3');
  52. },
  53. );
  54. this.route.parent.params.subscribe(
  55. (params:Params) => {
  56. this.userLoginId = params['userID'];
  57. this.serviceId = params['serviceID'];
  58. this.userSer.getPagesPermetiotns(this.userLoginId, this.serviceId).subscribe(
  59. (responce) => {
  60. this.pages = responce['pages'];
  61. for(let i = 0; i< this.pages.length; i++) {
  62. if(this.pages[i].name == 'الإدارات') {
  63. for(let j = 0; j < this.pages[i].permissions.length; j++) {
  64. if(this.pages[i].permissions[j].name == 'add_adminstration'){
  65. this.authSer.showAddBtn = true;
  66. }
  67. if(this.pages[i].permissions[j].name == 'edit_adminstration'){
  68. this.authSer.showEditBtn = true;
  69. }
  70. if(this.pages[i].permissions[j].name == 'delete_adminstration'){
  71. this.authSer.showDeleteBtn = true;
  72. }
  73. }
  74. }else {
  75. console.log('no adminstrations');
  76. }
  77. }
  78. },
  79. (error) => {console.log(error)}
  80. );
  81. }
  82. );
  83. this.departService.getDeparmentsList(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  84. (responce) => {
  85. console.log(responce);
  86. this.departmentsList = responce['adminstrations'];
  87. for (var i = 0; i < this.departmentsList.length; i++) {
  88. this.departmentsList[i].selected = false;
  89. }
  90. this.count = responce['count'];
  91. this.perPagePagenation = responce['per_page'];
  92. console.log(this.departmentsList);
  93. this.spinner.hide();
  94. },
  95. (error) => {
  96. console.log(error);
  97. }
  98. );
  99. };
  100. //change page
  101. onPageChange(pagenationNumber) {
  102. this.spinner.show();
  103. this.currentPage = pagenationNumber;
  104. this.departmentsList = [];
  105. this.departService.getDeparmentsList(this.pageId, pagenationNumber, this.dataTableNumber).subscribe(
  106. (responce) => {
  107. console.log(responce);
  108. this.departmentsList = responce['adminstrations'];
  109. this.count = responce['count'];
  110. this.perPagePagenation = responce['per_page'];
  111. this.spinner.hide();
  112. },
  113. (error) => {
  114. console.log(error);
  115. this.spinner.hide();
  116. }
  117. );
  118. };
  119. //make all checkbox of user checked
  120. selectAll() {
  121. for (var i = 0; i < this.departmentsList.length; i++) {
  122. this.departmentsList[i].selected = this.selectedAll;
  123. }
  124. };
  125. checkIfAllSelected() {
  126. this.selectedAll = this.departmentsList.every(function(item:any) {
  127. return item.selected == true;
  128. });
  129. };
  130. //filtter function
  131. filtterFunc(data) {
  132. this.departmentsList = [];
  133. console.log(data.target.value);
  134. const dataSearch = data.target.value;
  135. this.currentPage = 1;
  136. console.log('search curent page', this.currentPage);
  137. console.log('search page id', this.pageId);
  138. this.departService.getDataUSerSearchBar(dataSearch, this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  139. (responce) => {
  140. console.log(responce);
  141. this.departmentsList = responce['adminstrations'];
  142. this.count = responce['count'];
  143. this.perPagePagenation = responce['per_page'];
  144. console.log('filtter count', this.count);
  145. console.log('filtter perPagePAgenation', this.perPagePagenation);
  146. },
  147. (error) => {
  148. console.log(error)
  149. }
  150. );
  151. };
  152. onGetValue(event) {
  153. this.spinner.show();
  154. this.departmentsList = [];
  155. this.dataTableNumber = event.target.value;
  156. this.departService.getDeparmentsList(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  157. (responce) => {
  158. console.log(responce);
  159. this.departmentsList = responce['adminstrations'];
  160. this.count = responce['count'];
  161. this.perPagePagenation = responce['per_page'];
  162. this.spinner.hide();
  163. },
  164. (error) => {
  165. console.log(error);
  166. this.spinner.hide();
  167. }
  168. );
  169. };
  170. //deleted function
  171. onDeleteDeparts() {
  172. this.departsId = [];
  173. for(let i = 0; i < this.departmentsList.length; i++) {
  174. if(this.departmentsList[i].selected == true) {
  175. this.departsId.push(this.departmentsList[i].id);
  176. }
  177. }
  178. if(this.departsId.length > 0) {
  179. const dialogRef = this.modal.alert()
  180. .size('sm')
  181. .showClose(true)
  182. .title('تأكيد الحذف')
  183. .body(`
  184. <h4>هل ترغب في حذف العناصر المحدده ؟ </h4>
  185. `)
  186. .open();
  187. dialogRef.result
  188. .then( result =>
  189. this.departService.deleteDepart(this.departsId).subscribe(
  190. (responce) => {
  191. console.log(responce);
  192. this.toastr.success('تم المسح');
  193. this.spinner.show();
  194. this.departmentsList = [];
  195. this.departService.getDeparmentsList(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  196. (responce) => {
  197. console.log(responce);
  198. this.departmentsList = responce['adminstrations'];
  199. for (var i = 0; i < this.departmentsList.length; i++) {
  200. this.departmentsList[i].selected = false;
  201. }
  202. this.count = responce['count'];
  203. this.perPagePagenation = responce['per_page'];
  204. console.log(this.departmentsList);
  205. this.spinner.hide();
  206. },
  207. (error) => {
  208. console.log(error);
  209. this.spinner.hide();
  210. }
  211. );
  212. },
  213. (error) => {
  214. console.log(error);
  215. this.spinner.hide();
  216. },
  217. )
  218. );
  219. } else{
  220. this.toastr.warning('لم يتم إختيار أي عنصر للمسح !');
  221. }
  222. };
  223. onAddDepart() {
  224. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'addAdminstration']);
  225. }
  226. onEdit(departmentIdEit: number) {
  227. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'editAdminstration/edit/' + departmentIdEit]);
  228. }
  229. }