hospital-list.component.ts 14 KB

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