customers-list.component.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import { Component, OnInit } from '@angular/core';
  2. import { SharedService } from '../../../shared/shared.service';
  3. import { HttpClient } from '@angular/common/http';
  4. import { ActivatedRoute, Router } from '@angular/router';
  5. import { ToastrService } from 'ngx-toastr';
  6. import { PagesService } from '../../../shared/pages.service';
  7. import { Ng2SmartTableModule } from 'ng2-smart-table';
  8. import { LocalDataSource } from 'ng2-smart-table';
  9. import { SmartTableData } from '../../../@core/data/smart-table';
  10. @Component({
  11. selector: 'ngx-customers-list',
  12. templateUrl: './customers-list.component.html',
  13. styleUrls: ['./customers-list.component.scss']
  14. })
  15. export class CustomersListComponent implements OnInit {
  16. source: LocalDataSource = new LocalDataSource();
  17. constructor(
  18. private auth: SharedService,
  19. private http: HttpClient,
  20. private route: ActivatedRoute,
  21. private router: Router,
  22. private toaster: ToastrService,
  23. private pageser: PagesService,
  24. private service: SmartTableData,
  25. ) { }
  26. dataList = [];
  27. dataListIds= [];
  28. selectListIds = [];
  29. dataTableNumber: number = 5;
  30. currentPage:number = 1;
  31. count: number;
  32. perPagePagenation: number;
  33. selectedAll: any;
  34. company_registrtion =
  35. {
  36. company_name : '',
  37. phone : '',
  38. commercial_number : '',
  39. industrial : '',
  40. website_address :'',
  41. address : '',
  42. total_users_request : '',
  43. register_date : '',
  44. expire_date : '',
  45. logo_photo : '',
  46. company_admins : [
  47. {
  48. name : '',
  49. email : '',
  50. password : '',
  51. password_confirmation : ''
  52. }],
  53. company_branches : [
  54. {
  55. branch_name : '',
  56. branch_users : [
  57. {
  58. name: '',
  59. email : '',
  60. type : '',
  61. position : '',
  62. phone : '',
  63. hire_date: '',
  64. is_active: null,
  65. password : '',
  66. password_confirmation : ''
  67. }]
  68. }]
  69. }
  70. ngOnInit() {
  71. this.pageser.getListData(this.currentPage, this.dataTableNumber, 'all', 'customers')
  72. .subscribe(
  73. res => {
  74. console.log(res);
  75. this.dataList = res[('companies')];
  76. console.log(this.dataList);
  77. this.count = res[('count')];
  78. console.log(this.count);
  79. this.perPagePagenation = res[('per_page')];
  80. },
  81. err => {
  82. console.log(err);
  83. }
  84. );
  85. }
  86. onGetValue(event){
  87. this.dataTableNumber = event.target.value;
  88. console.log(this.dataTableNumber);
  89. this.dataList = [];
  90. this.pageser.getListData(this.currentPage, this.dataTableNumber, 'all', 'customers')
  91. .subscribe(
  92. res => {
  93. console.log(res);
  94. this.dataList = res[('companies')];
  95. console.log(this.dataList);
  96. this.count = res[('count')];
  97. this.perPagePagenation = res[('per_page')];
  98. },
  99. err => {
  100. console.log(err);
  101. }
  102. );
  103. }
  104. onPageChange(pagenationNumber){
  105. this.currentPage = pagenationNumber;
  106. this.pageser.getListData(pagenationNumber,this.dataTableNumber , 'all' , 'customers')
  107. .subscribe(
  108. res => {
  109. console.log(res);
  110. this.dataList = [];
  111. this.dataList = res[('users')];
  112. this.count = res[('count')];
  113. this.perPagePagenation = res[('per_page')];
  114. },
  115. err => {
  116. console.log(err);
  117. }
  118. );
  119. }
  120. //make all checkbox of user checked
  121. selectAll() {
  122. console.log('selected alllllll');
  123. for(let i = 0; i < this.dataList.length; i++){
  124. this.dataList[i].selected = this.selectedAll;
  125. }
  126. }
  127. checkIfAllSelected() {
  128. this.selectedAll = this.dataList.every(function(item:any) {
  129. return item.selected == true;
  130. });
  131. }
  132. onDelete(){
  133. this.dataListIds = [];
  134. for (let i = 0; i < this.dataList.length; i++) {
  135. if (this.dataList[i].selected == true) {
  136. this.dataListIds.push(this.dataList[i].id);
  137. }
  138. }
  139. console.log(this.dataListIds);
  140. if(this.dataListIds.length > 0){
  141. this.pageser.deleteItem(this.dataListIds,'customers ').subscribe(
  142. res => {
  143. console.log(res);
  144. this.toaster.success('Deleted');
  145. this.dataList = [];
  146. this.pageser.getListData(this.currentPage, this.dataTableNumber,'all','customers' ).subscribe(
  147. res => {
  148. console.log(res);
  149. this.dataList = res['companies'];
  150. this.count = res['count'];
  151. this.perPagePagenation = res['per_page'];
  152. },
  153. err => {
  154. console.log(err);
  155. ; }
  156. );
  157. },
  158. err => {
  159. console.log(err);
  160. this.toaster.error('sorry something went wrong!')
  161. }
  162. );
  163. }else {
  164. this.toaster.warning('No thing to delete')
  165. }
  166. }
  167. onAdding(){
  168. this.router.navigate(['../register'], {relativeTo: this.route});
  169. localStorage.setItem('company_registrtion', JSON.stringify(this.company_registrtion));
  170. }
  171. onEdit(editId: number) {
  172. this.router.navigate(['../edit/' + editId], {relativeTo: this.route});
  173. console.log(editId);
  174. }
  175. }