You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sfh-mohemm/Mohem/src/app/itemforsale/items/items.component.ts

131 lines
4.2 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { CommonService } from 'src/app/hmg-common/services/common/common.service';
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service';
4 years ago
import { ItemForSaleService } from '../services/service.service';
import { deepCopy } from '@angular-devkit/core/src/utils/object';
import * as moment from 'moment';
4 years ago
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
4 years ago
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-items',
templateUrl: './items.component.html',
styleUrls: ['./items.component.scss'],
})
export class ItemsComponent implements OnInit {
segment: any = '1';
4 years ago
items: any;
4 years ago
categories: any = [];
direction: string;
activeClass: any;
pageNo: number = 1;
tempSearch: any = [];
itemsByEmployee: any = [];
4 years ago
constructor(public ts: TranslatorService, public route: ActivatedRoute, private sanitizer: DomSanitizer, public cs: CommonService, private itemService: ItemForSaleService) {
this.route
.params.subscribe(val => {
setTimeout(() => {
this.cs.startLoading();
this.getItemsCategories();
this.getItemsByEmployee();
}, 100);
});
}
4 years ago
ngOnInit() {
this.direction = TranslatorService.getCurrentDirection();
4 years ago
4 years ago
}
getItemsCategories() {
4 years ago
4 years ago
this.itemService.getCategories({}, () => { }, this.ts.trPK('general', 'retry')).subscribe((result) => {
this.categories = this.itemService.parser(result);
4 years ago
this.cs.sharedService.setSharedData(this.categories, ItemForSaleService.CATEGORIES);
4 years ago
})
this.itemService.getItems({ pageNo: this.pageNo }, () => { }, this.ts.trPK('general', 'retry')).subscribe((result) => {
4 years ago
this.items = [];
4 years ago
this.items = this.itemService.parser(result);
this.tempSearch = deepCopy(this.items);
4 years ago
this.cs.stopLoading();
4 years ago
})
}
openDetails(selected) {
this.cs.sharedService.setSharedData(selected, ItemForSaleService.ITEMS_SELECTED);
this.cs.navigateForward('/itemforsale/items-details');
}
segmentChanged(value) {
this.segment = value.detail.value;
}
openSale() {
4 years ago
this.cs.openCreateitems();
}
4 years ago
selectCategory(item) {
4 years ago
this.cs.startLoading();
this.activeClass = item.categoryID;
this.itemService.getItems({ pageNo: this.pageNo, ItgCategoryID: item.categoryID }, () => { }, this.ts.trPK('general', 'retry')).subscribe((result) => {
this.items = [];
this.items = this.itemService.parser(result);
this.tempSearch = deepCopy(this.items);
this.cs.stopLoading();
})
4 years ago
}
getDotted(temp: string, valueCount: number) {
temp = this.stripHtml(temp);
return temp.substring(0, valueCount) + " ...";
}
stripHtml(html) {
var temporalDivElement = document.createElement("div");
temporalDivElement.innerHTML = html;
return temporalDivElement.textContent || temporalDivElement.innerText || "";
}
loadData(event) {
this.pageNo = this.pageNo + 1;
4 years ago
this.itemService.getItems({ pageNo: this.pageNo, categoryID: this.activeClass }, () => { }, this.ts.trPK('general', 'retry')).subscribe((result) => {
4 years ago
this.items.concat(this.itemService.parser(result));
this.tempSearch = deepCopy(this.items);
event.target.complete();
})
}
search(t) {
if (t === '') {
this.items = this.tempSearch;
} else {
this.items = this.tempSearch.filter((post) => {
if (this.direction == 'ltr')
return (post.title.toLowerCase().indexOf(t.toLowerCase()) > -1);
else
return (post.title_Ar.indexOf(t) > -1);
});
}
}
getItemsByEmployee() {
4 years ago
this.cs.startLoading();
4 years ago
this.itemService.getItemsByEmployee({}, () => { }, this.ts.trPK('general', 'retry')).subscribe((result) => {
this.itemsByEmployee = this.itemService.parser(result);
4 years ago
this.cs.stopLoading();
4 years ago
console.log(this.itemsByEmployee);
})
}
4 years ago
4 years ago
getDate(date) {
return moment(date, "YYYY-MM-DD HH:mm:ss").format("DD-MMM-YYYY");
}
4 years ago
getImgContent(imgFile): SafeUrl {
return this.sanitizer.bypassSecurityTrustUrl(imgFile);
}
4 years ago
editItems(items) {
this.cs.sharedService.setSharedData(items, ItemForSaleService.EDIT_ITEMS);
this.cs.openCreateitems();
}
}