customers-list.component.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. // settings = {
  27. // edit: {
  28. // editButtonContent: '<i class="nb-edit"></i>',
  29. // saveButtonContent: '<i class="nb-checkmark"></i>',
  30. // cancelButtonContent: '<i class="nb-close"></i>',
  31. // },
  32. // delete: {
  33. // deleteButtonContent: '<i class="nb-trash"></i>',
  34. // confirmDelete: true,
  35. // },
  36. // selectMode: 'multi',
  37. // actions: {
  38. // add: false,
  39. // delete: false,
  40. // select: true,
  41. // },
  42. // columns: {
  43. // name: {
  44. // title: 'Name',
  45. // type: 'string',
  46. // },
  47. // industrial: {
  48. // title: 'industrial',
  49. // type: 'string',
  50. // },
  51. // website_address: {
  52. // title: 'website',
  53. // type: 'string',
  54. // },
  55. // phone: {
  56. // title: 'Phone',
  57. // type: 'string',
  58. // },
  59. // },
  60. // };
  61. dataList = [];
  62. dataListIds= [];
  63. selectListIds = [];
  64. dataTableNumber: number = 5;
  65. currentPage:number = 1;
  66. count: number;
  67. perPagePagenation: number;
  68. selectedAll: any;
  69. ngOnInit() {
  70. this.pageser.getListData(this.currentPage, this.dataTableNumber, 'all', 'customers')
  71. .subscribe(
  72. res => {
  73. console.log(res);
  74. this.dataList = res[('companies')];
  75. console.log(this.dataList);
  76. this.count = res[('count')];
  77. console.log(this.count);
  78. this.perPagePagenation = res[('per_page')];
  79. },
  80. err => {
  81. console.log(err);
  82. }
  83. );
  84. }
  85. onGetValue(event){
  86. this.dataTableNumber = event.target.value;
  87. console.log(this.dataTableNumber);
  88. this.dataList = [];
  89. this.pageser.getListData(this.currentPage, this.dataTableNumber, 'all', 'customers')
  90. .subscribe(
  91. res => {
  92. console.log(res);
  93. this.dataList = res[('companies')];
  94. console.log(this.dataList);
  95. this.count = res[('count')];
  96. this.perPagePagenation = res[('per_page')];
  97. },
  98. err => {
  99. console.log(err);
  100. }
  101. );
  102. }
  103. onPageChange(pagenationNumber){
  104. this.currentPage = pagenationNumber;
  105. this.pageser.getListData(pagenationNumber,this.dataTableNumber , 'all' , 'customers')
  106. .subscribe(
  107. res => {
  108. console.log(res);
  109. this.dataList = [];
  110. this.dataList = res[('users')];
  111. this.count = res[('count')];
  112. this.perPagePagenation = res[('per_page')];
  113. },
  114. err => {
  115. console.log(err);
  116. }
  117. );
  118. }
  119. //make all checkbox of user checked
  120. selectAll() {
  121. console.log('selected alllllll');
  122. for(let i = 0; i < this.dataList.length; i++){
  123. this.dataList[i].selected = this.selectedAll;
  124. }
  125. }
  126. checkIfAllSelected() {
  127. this.selectedAll = this.dataList.every(function(item:any) {
  128. return item.selected == true;
  129. });
  130. }
  131. onDelete(){
  132. this.dataListIds = [];
  133. for (let i = 0; i < this.dataList.length; i++) {
  134. if (this.dataList[i].selected == true) {
  135. this.dataListIds.push(this.dataList[i].id);
  136. }
  137. }
  138. console.log(this.dataListIds);
  139. if(this.dataListIds.length > 0){
  140. this.pageser.deleteItem(this.dataListIds,'customers ').subscribe(
  141. res => {
  142. console.log(res);
  143. this.toaster.success('Deleted');
  144. this.dataList = [];
  145. this.pageser.getListData(this.currentPage, this.dataTableNumber,'all','customers' ).subscribe(
  146. res => {
  147. console.log(res);
  148. this.dataList = res['companies'];
  149. this.count = res['count'];
  150. this.perPagePagenation = res['per_page'];
  151. },
  152. err => {
  153. console.log(err);
  154. ; }
  155. );
  156. },
  157. err => {
  158. console.log(err);
  159. this.toaster.error('sorry something went wrong!')
  160. }
  161. );
  162. }else {
  163. this.toaster.warning('No thing to delete')
  164. }
  165. }
  166. onAdding(){
  167. this.router.navigate(['pages/register']);
  168. }
  169. onEdit(editId: number) {
  170. // this.router.navigate(['edit/' + editId]);
  171. // console.log(editId);
  172. }
  173. }