hospital-list.component.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. private 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. //filtter function
  256. filtterFunc(data) {
  257. this.dataList = [];
  258. console.log(data.target.value);
  259. const dataSearch = data.target.value;
  260. this.currentPage = 1;
  261. console.log('search curent page', this.currentPage);
  262. console.log('search page id', this.pageId);
  263. if(this.pageId == 6 || this.pageId == 30){
  264. this.dashboardService.getDataUSerSearchBar(dataSearch, this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  265. (responce) => {
  266. console.log(responce);
  267. this.dataList = responce['hospital_centers'];
  268. this.count = responce['count'];
  269. this.perPagePagenation = responce['per_page'];
  270. console.log('filtter count', this.count);
  271. console.log('filtter perPagePAgenation', this.perPagePagenation);
  272. },
  273. (error) => {
  274. console.log(error)
  275. }
  276. );
  277. } else if(this.pageId == 10 || this.pageId == 31) {
  278. this.dashboardService.getDataUSerSearchBar(dataSearch, this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  279. (responce) => {
  280. console.log(responce);
  281. this.dataList = responce['managements'];
  282. this.count = responce['count'];
  283. this.perPagePagenation = responce['per_page'];
  284. console.log('filtter count', this.count);
  285. console.log('filtter perPagePAgenation', this.perPagePagenation);
  286. },
  287. (error) => {
  288. console.log(error)
  289. }
  290. );
  291. }
  292. };
  293. //determine the list count from select element
  294. onGetValue(event) {
  295. this.spinner.show();
  296. this.dataList = [];
  297. this.dataTableNumber = event.target.value;
  298. if(this.pageId == 6 || this.pageId == 30) {
  299. this.dashboardService.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  300. (responce) => {
  301. console.log(responce);
  302. this.dataList = responce['hospital_centers'];
  303. this.count = responce['count'];
  304. this.perPagePagenation = responce['per_page'];
  305. this.spinner.hide();
  306. },
  307. (error) => {
  308. console.log(error);
  309. this.spinner.hide();
  310. }
  311. );
  312. } else if(this.pageId == 10 || this.pageId == 31) {
  313. this.dashboardService.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
  314. (responce) => {
  315. console.log(responce);
  316. this.dataList = responce['managements'];
  317. this.count = responce['count'];
  318. this.perPagePagenation = responce['per_page'];
  319. this.spinner.hide();
  320. },
  321. (error) => {
  322. console.log(error);
  323. this.spinner.hide();
  324. }
  325. );
  326. }
  327. };
  328. //add hospitals
  329. onAdd() {
  330. if(this.pageId == 6 || this.pageId == 30) {
  331. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/add/Hospital']);
  332. } else if(this.pageId == 10 || this.pageId == 31) {
  333. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/add/Management']);
  334. }
  335. }
  336. //on edit hospital
  337. onEdit(hospitalIndex:number) {
  338. if(this.pageId == 6 || this.pageId == 30){
  339. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'Hospital/' + 'edithos/' + hospitalIndex]);
  340. } else if(this.pageId == 10 || this.pageId == 31){
  341. this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'Management/' + 'editman/' + hospitalIndex]);
  342. }
  343. }
  344. }