hospital-list.component.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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 { HospitalService } from './../../../shared/hospital.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-hospital-list',
  11. templateUrl: './hospital-list.component.html',
  12. styleUrls: ['./hospital-list.component.css']
  13. })
  14. export class HospitalListComponent implements OnInit {
  15. constructor(private route: ActivatedRoute,
  16. private router: Router,
  17. private authSer: AuthServiceService,
  18. private userSer: UserService,
  19. private spinner: NgxSpinnerService,
  20. private toastr: ToastrService,
  21. private modal: Modal,
  22. private hospitalService: HospitalService) { }
  23. dataList = [];
  24. dataListIds = [];
  25. count: number;
  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. typeLink: string = '';
  35. dataTableNumber: number = 5;
  36. pages = [];
  37. typeServices: string = '';
  38. ngOnInit() {
  39. this.spinner.show();
  40. //init the values of permision boolean
  41. this.authSer.showAddBtn = false;
  42. this.authSer.showDeleteBtn = false;
  43. this.authSer.showEditBtn = false;
  44. //show / hide notification search in header
  45. this.authSer.notificationLogin = true;
  46. this.authSer.showSearchHeader = false;
  47. this.authSer.showHeaderLogin = false;
  48. this.authSer.showHeaderDashBoard = true;
  49. this.authSer.showDashboardHeader = true;
  50. this.authSer.internalHeader = false;
  51. this.route.params.subscribe(
  52. (params: Params) => {
  53. //console.log('iddddddddd', params['hospitalListId']);
  54. this.pageId = params['typePageId'];
  55. if(this.pageId == 6) {
  56. this.typeLink = 'المستشفيات والمراكز';
  57. this.typeServices = 'خدمه إداره المحتوي';
  58. } else if(this.pageId == 10) {
  59. this.typeLink = 'الإدرات';
  60. this.typeServices = 'خدمه الصلاحيات';
  61. } else if(this.pageId == 30) {
  62. this.typeLink = 'المستشفيات والمراكز';
  63. this.typeServices = 'خدمه إداره الصفحه الخارجيه';
  64. }
  65. }
  66. );
  67. //get parent params and get list hospitals
  68. this.route.parent.params.subscribe(
  69. (params: Params) => {
  70. this.userLoginId = params['userID'];
  71. this.serviceId = params['serviceID'];
  72. if(this.pageId == 6 || this.pageId == 30) {
  73. this.hospitalService.getHospitalsList(this.pageId , this.currentPage, this.dataTableNumber).subscribe(
  74. (responce) => {
  75. console.log(responce);
  76. this.dataList = responce['hospital_centers'];
  77. this.count = responce['count'];
  78. this.perPagePagenation = responce['per_page'];
  79. },
  80. (error) => {
  81. console.log(error);
  82. }
  83. );
  84. this.userSer.getPagesPermetiotns(this.userLoginId, this.serviceId).subscribe(
  85. (responce) => {
  86. this.pages = responce['pages'];
  87. console.log('paaaages', this.pages);
  88. for(let i = 0; i< this.pages.length; i++) {
  89. if(this.pages[i].id == 6) {
  90. for(let j = 0; j < this.pages[i].permissions.length; j++) {
  91. if(this.pages[i].permissions[j].name == 'add_hospitals_centers'){
  92. this.authSer.showAddBtn = true;
  93. }
  94. if(this.pages[i].permissions[j].name == 'edit_hospitals_centers'){
  95. this.authSer.showEditBtn = true;
  96. }
  97. if(this.pages[i].permissions[j].name == 'delete_hospitals_centers'){
  98. this.authSer.showDeleteBtn = true;
  99. }
  100. }
  101. } else if(this.pages[i].id == 30){
  102. for(let j = 0; j < this.pages[i].permissions.length; j++) {
  103. if(this.pages[i].permissions[j].name == 'add_hospitals_centers_ex'){
  104. this.authSer.showAddBtn = true;
  105. }
  106. if(this.pages[i].permissions[j].name == 'edit_hospitals_centers_ex'){
  107. this.authSer.showEditBtn = true;
  108. }
  109. if(this.pages[i].permissions[j].name == 'delete_hospitals_centers_ex'){
  110. this.authSer.showDeleteBtn = true;
  111. }
  112. }
  113. }else {
  114. console.log('no roles');
  115. }
  116. }
  117. this.spinner.hide();
  118. },
  119. (error) => {console.log(error)}
  120. );
  121. } else if(this.pageId == 10) {
  122. this.hospitalService.getHospitalsList(this.pageId , this.currentPage, this.dataTableNumber).subscribe(
  123. (responce) => {
  124. console.log(responce);
  125. this.dataList = responce['managements'];
  126. this.count = responce['count'];
  127. this.perPagePagenation = responce['per_page'];
  128. },
  129. (error) => {
  130. console.log(error);
  131. }
  132. );
  133. this.userSer.getPagesPermetiotns(this.userLoginId, this.serviceId).subscribe(
  134. (responce) => {
  135. this.pages = responce['pages'];
  136. console.log('paaaages', this.pages);
  137. for(let i = 0; i< this.pages.length; i++) {
  138. if(this.pages[i].id == 10) {
  139. for(let j = 0; j < this.pages[i].permissions.length; j++) {
  140. if(this.pages[i].permissions[j].name == 'add_management'){
  141. this.authSer.showAddBtn = true;
  142. }
  143. if(this.pages[i].permissions[j].name == 'edit_management'){
  144. this.authSer.showEditBtn = true;
  145. }
  146. if(this.pages[i].permissions[j].name == 'delete_managements'){
  147. this.authSer.showDeleteBtn = true;
  148. }
  149. }
  150. }else {
  151. console.log('no roles');
  152. }
  153. }
  154. this.spinner.hide();
  155. },
  156. (error) => {console.log(error)}
  157. );
  158. }
  159. }
  160. );
  161. }
  162. //make all checkbox of user checked
  163. selectAll() {
  164. for (var i = 0; i < this.dataList.length; i++) {
  165. this.dataList[i].selected = this.selectedAll;
  166. }
  167. };
  168. checkIfAllSelected() {
  169. this.selectedAll = this.dataList.every(function(item:any) {
  170. return item.selected == true;
  171. })
  172. };
  173. //deleted function
  174. onDelete() {
  175. this.dataListIds = [];
  176. for(let i = 0; i < this.dataList.length; i++) {
  177. if(this.dataList[i].selected == true) {
  178. this.dataListIds.push(this.dataList[i].id);
  179. }
  180. }
  181. console.log(this.dataListIds);
  182. if(this.dataListIds.length > 0) {
  183. const dialogRef = this.modal.alert()
  184. .size('sm')
  185. .showClose(true)
  186. .title('تأكيد الحذف')
  187. .body(`
  188. <h4>هل ترغب في حذف العناصر المحدده ؟ </h4>
  189. `)
  190. .open();
  191. dialogRef.result
  192. .then( result =>
  193. this.hospitalService.deleteDatas(this.dataListIds, this.pageId).subscribe(
  194. (responce) => {
  195. console.log(responce);
  196. this.toastr.success('تم الحذف');
  197. this.spinner.show();
  198. this.dataList = [];
  199. if(this.pageId == 10) {
  200. this.hospitalService.getHospitalsList(this.pageId , this.currentPage, this.dataTableNumber).subscribe(
  201. (responce) => {
  202. console.log(responce);
  203. this.dataList = responce['managements'];
  204. this.count = responce['count'];
  205. this.perPagePagenation = responce['per_page'];
  206. this.spinner.hide();
  207. },
  208. (error) => {
  209. console.log(error);
  210. }
  211. );
  212. } else if(this.pageId == 6 || this.pageId == 30){
  213. this.hospitalService.getHospitalsList(this.pageId , this.currentPage, this.dataTableNumber).subscribe(
  214. (responce) => {
  215. console.log(responce);
  216. this.dataList = responce['hospital_centers'];
  217. this.count = responce['count'];
  218. this.perPagePagenation = responce['per_page'];
  219. this.spinner.hide();
  220. },
  221. (error) => {
  222. console.log(error);
  223. }
  224. );
  225. }
  226. },
  227. (error) => {
  228. console.log(error);
  229. this.spinner.hide();
  230. },
  231. )
  232. );
  233. } else {
  234. this.toastr.warning('لم يتم إختيار أي عنصر للمسح !');
  235. }
  236. };
  237. //filtter function
  238. filtterFunc(data) {
  239. this.dataList = [];
  240. console.log(data.target.value);
  241. const dataSearch = data.target.value;
  242. this.currentPage = 1;
  243. console.log('search curent page', this.currentPage);
  244. console.log('search page id', this.pageId);
  245. if(this.pageId == 6 || this.pageId == 30){
  246. this.hospitalService.getDataUSerSearchBar(dataSearch, this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  247. (responce) => {
  248. console.log(responce);
  249. this.dataList = responce['hospital_centers'];
  250. this.count = responce['count'];
  251. this.perPagePagenation = responce['per_page'];
  252. console.log('filtter count', this.count);
  253. console.log('filtter perPagePAgenation', this.perPagePagenation);
  254. },
  255. (error) => {
  256. console.log(error)
  257. }
  258. );
  259. } else if(this.pageId == 7) {
  260. this.hospitalService.getDataUSerSearchBar(dataSearch, this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  261. (responce) => {
  262. console.log(responce);
  263. this.dataList = responce['managements'];
  264. this.count = responce['count'];
  265. this.perPagePagenation = responce['per_page'];
  266. console.log('filtter count', this.count);
  267. console.log('filtter perPagePAgenation', this.perPagePagenation);
  268. },
  269. (error) => {
  270. console.log(error)
  271. }
  272. );
  273. }
  274. };
  275. //determine the list count from select element
  276. onGetValue(event) {
  277. this.spinner.show();
  278. this.dataList = [];
  279. this.dataTableNumber = event.target.value;
  280. if(this.pageId == 6 || this.pageId == 30) {
  281. this.hospitalService.getHospitalsList(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  282. (responce) => {
  283. console.log(responce);
  284. this.dataList = responce['hospital_centers'];
  285. this.count = responce['count'];
  286. this.perPagePagenation = responce['per_page'];
  287. this.spinner.hide();
  288. },
  289. (error) => {
  290. console.log(error);
  291. this.spinner.hide();
  292. }
  293. );
  294. } else if(this.pageId == 10) {
  295. this.hospitalService.getHospitalsList(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  296. (responce) => {
  297. console.log(responce);
  298. this.dataList = responce['managements'];
  299. this.count = responce['count'];
  300. this.perPagePagenation = responce['per_page'];
  301. this.spinner.hide();
  302. },
  303. (error) => {
  304. console.log(error);
  305. this.spinner.hide();
  306. }
  307. );
  308. }
  309. };
  310. //add hospitals
  311. onAdd() {
  312. if(this.pageId == 6 || this.pageId == 30) {
  313. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/add/Hospital']);
  314. } else if(this.pageId == 10) {
  315. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/add/Management']);
  316. }
  317. }
  318. //on edit hospital
  319. onEdit(hospitalIndex:number) {
  320. if(this.pageId == 6){
  321. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'Hospital/' + 'edithos/' + hospitalIndex]);
  322. } else if(this.pageId == 10){
  323. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'Management/' + 'editman/' + hospitalIndex]);
  324. }
  325. }
  326. }