roles-list.component.ts 7.8 KB

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