hospital-list.component.ts 14 KB

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