123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- import { AuthServiceService } from './../../../shared/auth-service.service';
- import { NgxSpinnerService } from 'ngx-spinner';
- import { ActivatedRoute, Router, Params } from '@angular/router';
- import { DashboardService } from './../../../shared/dashboard.service';
- import { HttpClient } from '@angular/common/http';
- import { Component, OnInit } from '@angular/core';
- import { Modal } from 'ngx-modialog/plugins/bootstrap';
- import { UserService } from '../../../shared/user.service';
- import { ToastrService } from 'ngx-toastr';
- @Component({
- selector: 'app-living-service-list',
- templateUrl: './living-service-list.component.html',
- styleUrls: ['./living-service-list.component.css']
- })
- export class LivingServiceListComponent implements OnInit {
- dataList = [];
- pages= [];
- pageId: number;
- Ids = [];
- count: number;
- perPagePagenation: number;
- currentPage:number = 1;
- filtterStatus = 'all';
- selectedAll: any;
- userLoginId:number;
- serviceId:number;
- dataTableNumber: number = 5;
- absorpationListIds = [];
- dataListIds = [];
- constructor(
- private route: ActivatedRoute,
- private router: Router,
- private modal: Modal,
- private userSer: UserService,
- private spinner: NgxSpinnerService,
- public authSer: AuthServiceService,
- private toastr: ToastrService,
- private dashboardSer: DashboardService,
- private http: HttpClient
- ) { }
- ngOnInit() {
- //init the values of permision boolean
- this.authSer.showAddBtn = false;
- this.authSer.showDeleteBtn = false;
- this.authSer.showEditBtn = false;
- //show / hide notification search in header
- this.authSer.notificationLogin = true;
- this.authSer.showSearchHeader = false;
- this.authSer.showHeaderLogin = false;
- this.authSer.showHeaderDashBoard = true;
- this.authSer.showDashboardHeader = true;
- this.authSer.internalHeader = false;
-
- this.route.params.subscribe(
- (parmas: Params) => {
- this.pageId = +parmas['listPageId'];
- localStorage.setItem('pageIdActive', parmas['listPageId']);
- console.log(this.pageId);
- }
- );
-
- this.route.parent.params.subscribe(
- (params:Params) => {
- this.userLoginId = params['userID'];
- this.serviceId = params['serviceID'];
-
-
- this.userSer.getPagesPermetiotns(this.userLoginId, this.serviceId).subscribe(
- (responce) => {
- console.log(responce);
- this.pages = responce['pages'];
- for(let i = 0; i< this.pages.length; i++) {
- if(this.pages[i].id == 63){
- if(this.pages[i]['permissions'][0].name == 'covenant_categories') {
- this.authSer.showAddBtn = true;
- this.authSer.showEditBtn = true;
- this.authSer.showDeleteBtn = true;
- } else {
- console.log('no permissions');
- }
- } else {
- console.log('no events');
- }
- }
- this.spinner.hide();
- },
- (error) => {console.log(error)}
- );
- }
- );
- this.spinner.show();
- console.log('current page',this.pageId)
- this.dashboardSer.getListData(this.pageId, this.currentPage ,this.dataTableNumber).subscribe(
- res => {
- console.log(res);
- this.dataList = res['covenant_categories'];
- this.count = res['count'];
- this.perPagePagenation = res['per_page'];
- this.spinner.hide();
- },
- err => {
- console.log(err);
-
- }
-
- );
-
-
- }
- //make all checkbox of user checked
- //make all checkbox of user checked
- selectAll() {
- for (var 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;
- });
- };
- filtterFunc(data) {
- this.dataList =[];
- this.absorpationListIds = [];
- console.log(data.target.value);
- const dataSearch = data.target.value;
- this.currentPage = 1;
- console.log('search curent page', this.currentPage);
- console.log('search page id', this.pageId);
- this.dashboardSer.getDataUSerSearchBar(dataSearch, this.pageId, this.currentPage, this.dataTableNumber).subscribe(
- res => {
- console.log(res);
- this.dataList = res['covenant_categories'];
- console.log('hey',this.dataList)
- this.count = res['count'];
- this.perPagePagenation = res['per_page'];
- console.log('filtter count', this.count);
- console.log('filtter perPagePAgenation', this.perPagePagenation);
- // alert(this.dataList.length);
- },
- err => {
- console.log(err);
- }
- );
- };
- onPageChange(pagenationNumber) {
- this.spinner.show();
- this.dataList = []
- this.currentPage = pagenationNumber;
- this.absorpationListIds = [];
- console.log(pagenationNumber);
- console.log(this.pageId);
- this.dashboardSer.getListData(this.pageId, pagenationNumber, this.dataTableNumber).subscribe(
- res => {
- console.log(res);
- this.dataList = res['covenant_categories'];
- this.count = res['count'];
- this.perPagePagenation = res['per_page'];
- console.log('FFFFFF', this.absorpationListIds);
- this.spinner.hide();
- console.log(this.dataList.length);
- },
- err => {
- console.log(err);
- this.spinner.hide();
- }
- );
- }
- //determine the list count from select element
- onGetValue(event) {
- this.spinner.show();
- this.absorpationListIds = [];
- this.dataTableNumber = event.target.value;
- this.dashboardSer.getListData(this.pageId, this.currentPage, this.dataTableNumber).subscribe(
- res => {
- console.log(res);
- this.absorpationListIds = res['covenant_categories'];
- this.count = res['count'];
- this.perPagePagenation = res['per_page'];
- this.spinner.hide();
- },
- err => {
- console.log(err);
- this.spinner.hide();
- }
- );
- };
- onGetValueFiltter(event) {
- console.log(event.target.value)
- this.spinner.show();
- this.dataList = [];
- const typeId = event.target.value;
- this.filtterStatus = event.target.value;
- console.log(this.filtterStatus);
- this.http.get(this.authSer.pathApi +'/page_list/' + this.pageId + '/' + this.currentPage + '/' + this.dataTableNumber + '/' + typeId).subscribe(
- res => {
- console.log(res);
- this.dataList = res['covenant_categories'];
- this.count = res['count'];
- this.perPagePagenation = res['per_page'];
- this.spinner.hide();
- console.log('UrL>>', this.authSer.pathApi +'/page_list/' + this.pageId + '/' + this.currentPage + '/' + this.dataTableNumber + '/' + typeId)
- },
- err=> {
- console.log(err);
- }
- );
- }
- 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) {
- const dialogRef = this.modal.alert()
- .size('sm')
- .showClose(true)
- .title('تأكيد الحذف')
- .body(`
- <h4>هل ترغب في حذف العناصر المحدده ؟ </h4>
- `)
- .open();
- dialogRef.result
- .then( result =>
- this.dashboardSer.deleteItem(this.dataListIds , this.pageId).subscribe(
- (responce) => {
- console.log(responce);
- this.toastr.success('تم الحذف');
- this.spinner.show();
- this.dataList = [];
- //get list data
- this.dashboardSer.getListData(this.pageId, this.currentPage ,this.dataTableNumber).subscribe(
- (responce) => {
- console.log(responce);
- this.dataList = responce['covenant_categories'];
- this.count = responce['count'];
- this.perPagePagenation = responce['per_page'];
- this.spinner.hide();
- },
- (error) => {
- console.log(error);
- this.spinner.hide();
- }
- );
- },
- (error) => {
- console.log(error.error.status);
- if(error.error.status == 'covenant category id is already taken'){
- this.toastr.warning('لا يمكنك حذف الصنف لانه جزء من النظام')
- }
- this.spinner.hide();
-
- },
- )
- );
- } else {
- this.toastr.warning('لم يتم إختيار أي عنصر للمسح !');
- }
- };
- onAdd() {
- this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'livingService/add']);
- }
- onEdit(editId: number) {
- this.router.navigate(['service/' + this.userLoginId + '/' + this.serviceId + '/' + 'livingService/edit/' + editId]);
- }
- }
|