hospital-list.component.ts 14 KB

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