Ponent Ts
Ponent Ts
@Component({
selector: 'app-leadspage',
templateUrl: './leadspage.component.html',
styleUrls: ['./leadspage.component.scss']
})
export class LeadspageComponent implements OnInit {
mycontactInput: FormGroup;
listhide = false;
arrowStyle = true;
ContactF = false
ResetFilter = false;
subscription: Subscription
leadspageForm: FormGroup = new FormGroup({
getdata() {
let userCredentials = JSON.parse(localStorage.getItem('userid'));
// console.log(userCredentials.username);
this.createdby = userCredentials.username;
}
logout() {
localStorage.clear();
this._userService.logout()
.subscribe(
// localStorage.clearAll();
data => {
// console.log(data);
this._router.navigate(['/login']);
//location.reload();
},
error => {
// console.log(error)
}
// localStorage.clearAll();
)
MoveToprofile() {
let userCredentials = JSON.parse(localStorage.getItem('userid'));
this.uid = userCredentials._id;
// console.log("test2", this.uid);
this._router.navigate(['/profilepage/', this.uid]);
}
FiletredValues = new Array<string>(3);
displayLeadsMenu() {
this.myplaceHolder = 'Add';
(this.arrowStyle == true ? this.arrowStyle = false : this.arrowStyle = true);
if (this.arrowStyle == false) {
document.getElementById("arrowPointer").className = "fa fa-caret-down arrow-right";
} else {
document.getElementById("arrowPointer").className = "fa fa-caret-right arrow-right";
}
(this.listhide == false ? this.listhide = true : this.listhide = false);
}
fliterLeadsStatus(filterStatusOption) {
this.FiletredValues.splice(0, 1, filterStatusOption);
this.FileterLeadTable(this.FiletredValues);
}
fliterLeadsUser(filterUserOption) {
this.FiletredValues.splice(1, 1, filterUserOption);
this.FileterLeadTable(this.FiletredValues);
}
fliterLeadDate(filterDateOption) {
this.FiletredValues.splice(2, 1, filterDateOption);
this.FileterLeadTable(this.FiletredValues);
}
filterContacts(FiletrCon) {
let myholder: any;
console.log(this.FileteredLeadData);
this.ContactF = true;
FiletrCon = FiletrCon.toLowerCase();
this.FilteredLeadArray = this.FileteredLeadData.filter(FilDat => {
for (var i = 0; i < FilDat.contacts.length; i++) {
if (FilDat.contacts[i].name.toLowerCase().indexOf(FiletrCon) !== -1) {
return FilDat;
}
}
});
}
FileterLeadTable(FiltArr) {
debugger;
this.FilteredLeadArray = this.getMydata(FiltArr);
this.FilteredLeadArrayConst = this.getMydata(FiltArr);
this.defaultDataFltr = this.FilteredLeadArray;
}
getMydata(FiltArr) {
debugger;
return this.FileteredLeadData.filter(FilDat => {
debugger;
let status = this.checkStatus(FiltArr[0], FilDat.status)
let dat = this.checkDate(FiltArr[2], FilDat.created)
checkStatus(actaulstatus, comparableStatus) {
if (actaulstatus == comparableStatus) {
return true;
}
else {
return false;
}
}
GetMeMyDate(d) {
d = new Date(d);
var month = '' + (d.getMonth() + 1);
var day = '' + d.getDate();
var year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [year, month, day].join('-');
}
checkDate(actauldate, comparabledate) {
let Today: any;
let WeekSunday: any;
var Comparingdate = comparabledate.substring(0, 10);
var CurrentDate = new Date();
Today = this.GetMeMyDate(new Date(CurrentDate));
var d = new Date();
var theDay = d.getDay();
var dif = d.getDate() - theDay + (theDay == 0 ? -6 : 1);
WeekSunday = this.GetMeMyDate(new Date(d.setDate(dif)));
if (actauldate == "Today") {
if (Comparingdate == Today) {
return true;
}
else {
return false;
}
}
if (actauldate == "yesterday") {
if (Today.substring(8) - 1 == Comparingdate.substring(8)) {
return true;
}
else {
return false;
}
}
if (actauldate == "This Week") {
if (Today >= Comparingdate && Comparingdate >= WeekSunday) {
return true;
}
else {
return false;
}
}
if (actauldate == "This Month") {
if (Today.substring(0, 7) == Comparingdate.substring(0, 7)) {
return true;
}
else {
return false;
}
}
if (actauldate == "Last Month") {
if (Today.substring(0, 7) - 1 == Comparingdate.substring(0, 7) - 1) {
return true;
}
else {
return false;
}
}
if (actauldate == "This year") {
if (Today.substring(0, 4) == Comparingdate.substring(0, 4)) {
return true;
}
else {
return false;
}
}
if (actauldate == "Last Year") {
if (Today.substring(0, 4) - 1 == Comparingdate.substring(0, 4) - 1) {
return true;
}
else {
return false;
}
}
}
checkUser(actauluser, comparableuser) {
}
ResetFilters() {
(this.ResetFilter == false ? this.ResetFilter = true : this.ResetFilter = false);
}
filesToUpload: Array<File> = [];
campaigns: any;
upload() {
const formData: any = new FormData();
const files: Array<File> = this.filesToUpload;
console.log(files);
fileChangeEvent(fileInput: any) {
this.filesToUpload = <Array<File>>fileInput.target.files;
//this.product.photo = fileInput.target.files[0]['name'];
}
MoveToCampaigns() {
let x = '';
x = this.activeRoute.snapshot.params['createdBy'];
this._router.navigate(['/campaigns/', x]);
currentPage: number = 0;
itemsPerPage: number = 50;
checkPlaceHolder() {
if (this.myplaceHolder) {
this.myplaceHolder = null
return;
}
}
leaddata(data) {
this.company = data.company;
this.testing = data;
this.collection = this.test_array;
this.defaultData = data.slice();
this.constDetail = data;
this.FileteredLeadData = data;
this.leadlength = data.length;
// console.log(data, "Leads");
}
// templates get
username: any;
templates: any;
template(data) {
this.templates = data;
}
templateid: any;
templatename: any;
tempsubject: any;
subject: any;
tempcontent: any;
onChange(deviceValue, arrval) {
var target = deviceValue;
let i;
for (i = 0; i < this.templates.length; i++) {
// this.tempcontent = this.templates[i].tempcontent;
this.campaignsForm.patchValue({
steps: [...Array(arrval), { tempsubject: this.templates[i].subject }]
})
this.campaignsForm.patchValue({
steps: [...Array(arrval), { tempcontentData: this.templates[i].tempcontent }]
})
this.campaignsForm.patchValue({
steps: [...Array(arrval), { templateid: this.templates[i]._id }]
})
}
}
}
onSubmit() {
}
denim(eve) {
debugger;
}
GetLead() {
let userCredentials = JSON.parse(localStorage.getItem('userid'));
var created = userCredentials.username;
this._userService.getleadbycreated(created)
.subscribe(
data => { }, error => console.log(error),
)
}
leadspage() {
let userCredentials = JSON.parse(localStorage.getItem('userid'));
this.createdby = userCredentials._id;
this.leadspageForm.value.createdby = userCredentials.username;
this._userService.leadspage(this.leadspageForm.value, userCredentials._id)
.subscribe(
data => {
// console.log(data);
// let leadCredentials = localStorage.setItem('leadid', JSON.stringify(data));
// let userCredentials = JSON.parse(localStorage.getItem('userid'));
// console.log(userCredentials._id);
// this.getLeadsInfo();
console.log(data);
this.displayData(data);
let userCredential = JSON.parse(localStorage.getItem('lead iddd'));
console.log(userCredentials._id);
// this.getLeadsInfo();
this._router.navigate(['./allleadspage/' + String(userCredential)]);
console.log(userCredential, 'success');
},
)
}
// MoveToAllleadspagee(){
// this._router.navigate(['/allleadspage/5beae86a8d68884ab1a52980']);
// location.reload();
// }
MoveToLead(leadid) {
this._router.navigate(['allleadspage/:', leadid]);
}
identity: any;
displayData(data) {
this.identity = data._id;
console.log(this.identity, 'lead idd');
localStorage.setItem('lead iddd', JSON.stringify(this.identity))
console.log(this.identity, 'lead dsds');
}
menu() {
this._router.navigate(['/leadspage']);
}
contactdata(data) {
let contactName = null;
}
allContact: any
allcontactdata(data) {
this.allContact = data;
}
//templates
ngOnInit() {
// geting templates
this._campaignservice.templatesGet()
.subscribe(
data => { this.template(data); }, error => console.log(error),
);
this.leadspageForm = this.formBuilder.group({
company: ['', Validators.required],
contactname: ['', Validators.required],
});
this.getLeadsInfo();
this.subscription = this.leadService.getName().subscribe(name => {
// console.log(name);
this.leadsDeatils.push(name);
// console.log(this.leadsDeatils);
this.leaddata(this.leadsDeatils);
// this.getLeadsInfo();
});
this.getContact();
getContact() {
this._userService.allContactTableGet()
.subscribe(
data => { this.allcontactdata(data); }, error => console.log(error),
);
}
getLeadsInfo() {
let userCredentials = JSON.parse(localStorage.getItem('userid'));
this.createdby = userCredentials.username;
var created = userCredentials._id;
this._userService.getleadbycreated(created)
.subscribe(
data => { this.leadsDeatils = data; this.leaddata(data); }, error => console.log(error),
)
}
getAllContactsOfLeads() {
getContactsOfLead(leadId) {
this._userService.getcontacts(leadId)
.subscribe(
data => {
this.contactdata(data);
// console.log(data);
}, error => console.log(error),
);
}
sortMyLead(sort: Sort) {
return this.OriginalData.sort((a, b) => {
const isAsc = sort.direction === 'asc';
switch (sort.active) {
case 'company': return compare(a.company, b.company, isAsc);
case 'name': return compare(a.name, b.name, isAsc);
case 'status': return compare(a.status, b.status, isAsc);
default: return 0;
}
});
}
sortData(sort: Sort) {
this.FilteredLeadArray = this.sortMyLead(sort);
this.testing = this.sortMyLead(sort);