123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- import { Component, OnInit } from '@angular/core';
- import { SharedService } from '../../../shared/shared.service';
- import { HttpClient } from '@angular/common/http';
- import { ActivatedRoute, Router } from '@angular/router';
- import { ToastrService } from 'ngx-toastr';
- import { PagesService } from '../../../shared/pages.service';
- import { Ng2SmartTableModule } from 'ng2-smart-table';
- import { LocalDataSource } from 'ng2-smart-table';
- import { SmartTableData } from '../../../@core/data/smart-table';
- @Component({
- selector: 'ngx-customers-list',
- templateUrl: './customers-list.component.html',
- styleUrls: ['./customers-list.component.scss']
- })
- export class CustomersListComponent implements OnInit {
- source: LocalDataSource = new LocalDataSource();
- constructor(
- private auth: SharedService,
- private http: HttpClient,
- private route: ActivatedRoute,
- private router: Router,
- private toaster: ToastrService,
- private pageser: PagesService,
- private service: SmartTableData,
- ) { }
- // settings = {
-
- // edit: {
- // editButtonContent: '<i class="nb-edit"></i>',
- // saveButtonContent: '<i class="nb-checkmark"></i>',
- // cancelButtonContent: '<i class="nb-close"></i>',
- // },
- // delete: {
- // deleteButtonContent: '<i class="nb-trash"></i>',
- // confirmDelete: true,
- // },
- // selectMode: 'multi',
- // actions: {
- // add: false,
- // delete: false,
- // select: true,
- // },
- // columns: {
- // name: {
- // title: 'Name',
- // type: 'string',
- // },
- // industrial: {
- // title: 'industrial',
- // type: 'string',
- // },
- // website_address: {
- // title: 'website',
- // type: 'string',
- // },
- // phone: {
- // title: 'Phone',
- // type: 'string',
- // },
- // },
- // };
- dataList = [];
- dataListIds= [];
- selectListIds = [];
- dataTableNumber: number = 5;
- currentPage:number = 1;
- count: number;
- perPagePagenation: number;
- selectedAll: any;
- ngOnInit() {
- this.pageser.getListData(this.currentPage, this.dataTableNumber, 'all', 'customers')
- .subscribe(
- res => {
- console.log(res);
- this.dataList = res[('companies')];
- console.log(this.dataList);
- this.count = res[('count')];
- console.log(this.count);
- this.perPagePagenation = res[('per_page')];
- },
- err => {
- console.log(err);
-
- }
- );
- }
- onGetValue(event){
- this.dataTableNumber = event.target.value;
- console.log(this.dataTableNumber);
- this.dataList = [];
- this.pageser.getListData(this.currentPage, this.dataTableNumber, 'all', 'customers')
- .subscribe(
- res => {
- console.log(res);
- this.dataList = res[('companies')];
- console.log(this.dataList);
- this.count = res[('count')];
- this.perPagePagenation = res[('per_page')];
-
- },
- err => {
- console.log(err);
-
- }
- );
- }
- onPageChange(pagenationNumber){
- this.currentPage = pagenationNumber;
- this.pageser.getListData(pagenationNumber,this.dataTableNumber , 'all' , 'customers')
- .subscribe(
- res => {
- console.log(res);
- this.dataList = [];
- this.dataList = res[('users')];
- this.count = res[('count')];
- this.perPagePagenation = res[('per_page')];
- },
- err => {
- console.log(err);
- }
- );
- }
- //make all checkbox of user checked
- selectAll() {
- console.log('selected alllllll');
- for(let i = 0; i < this.dataList.length; i++){
- this.dataList[i].selected = this.selectedAll;
- }
- }
- checkIfAllSelected() {
- this.selectedAll = this.dataList.every(function(item:any) {
- return item.selected == true;
- });
- }
- onDelete(){
- this.dataListIds = [];
- for (let i = 0; i < this.dataList.length; i++) {
- if (this.dataList[i].selected == true) {
- this.dataListIds.push(this.dataList[i].id);
- }
- }
- console.log(this.dataListIds);
- if(this.dataListIds.length > 0){
- this.pageser.deleteItem(this.dataListIds,'customers ').subscribe(
- res => {
- console.log(res);
- this.toaster.success('Deleted');
- this.dataList = [];
- this.pageser.getListData(this.currentPage, this.dataTableNumber,'all','customers' ).subscribe(
- res => {
- console.log(res);
- this.dataList = res['companies'];
- this.count = res['count'];
- this.perPagePagenation = res['per_page'];
-
- },
- err => {
- console.log(err);
- ; }
- );
- },
- err => {
- console.log(err);
- this.toaster.error('sorry something went wrong!')
- }
- );
- }else {
- this.toaster.warning('No thing to delete')
- }
- }
- onAdding(){
- this.router.navigate(['pages/register']);
- }
- onEdit(editId: number) {
- // this.router.navigate(['edit/' + editId]);
- // console.log(editId);
-
- }
- }
|