Vous êtes sur la page 1sur 11

import { Component, OnInit, ɵEMPTY_ARRAY, Output, EventEmitter } from '@angular/core';

import { FormControl, FormGroup, Validators, FormBuilder } from "@angular/forms";


import { composeValidators } from "@angular/forms/src/directives/shared";
import { UserService } from "../user.service";
import { ActivatedRoute, Router, Params } from "@angular/router";
import { s } from "@angular/core/src/render3";
import { Location } from "@angular/common";
import { FunctionCall, analyzeAndValidateNgModules } from '@angular/compiler';
import { Subscription } from 'rxjs';
import { LeadService } from '../services/lead.service';
import { NgForm } from '@angular/forms';
import { CampaignService } from '../services/campaign.service';
import { Sort } from '@angular/material';
import { bloomFindPossibleInjector } from '@angular/core/src/render3/di';

@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({

company: new FormControl(null, [Validators.required]),


contactname: new FormControl(null, [Validators.required]),
createdby: new FormControl(null, [Validators.required])
});

constructor(private _router: Router, private _campaignservice: CampaignService, private


_userService: UserService, private location: Location,
private activeRoute: ActivatedRoute, private formBuilder: FormBuilder, private leadService:
LeadService) {
}
submitted = false;
leadsDeatils: any;
createdby: String = '';
uid: any;
userCredentials = JSON.parse(localStorage.getItem('userid'));

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)

if ((FiltArr[2] == undefined) && status) {


return FilDat;
}
else if ((FiltArr[0] == undefined) && dat) {
return FilDat;
}
else if (dat && status) {
return FilDat;
}
});
}

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);

for (let i = 0; i < files.length; i++) {


formData.append("uploads[]", files[i], files[i]['name']);
}
console.log('form data variable : ' + formData.toString());
this._userService.CsvUpload(formData, this.campaigns._id)
.map((files: Response) => files.json())
.subscribe(files => console.log('files', 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]);

company: String = '';


testing: any;
collection: any[];
OriginalData: any;
constDetail: any;
defaultData: any;
defaultDataFltr: any;
FileteredLeadData: any;
FilteredLeadArray = [];
FilteredLeadArrayConst = [];
test_array: any[];
leadlength: String = '';
myplaceHolder: string = 'Add';

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

campaignsForm: FormGroup = new FormGroup({


name: new FormControl(null, [Validators.required]),
timezone: new FormControl(null, [Validators.required])
})
get f() { return this.leadspageForm.controls; }

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++) {

if (this.templates[i].templatename === target) {


this.templateid = this.templates[i]._id;
this.templatename = this.templates[i].templatename;
// this.temptype=this.opp[i].templatetype;
this.tempsubject = this.templates[i].subject;

// 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),
);

//end of geting templates

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() {

for (let i = 0; i < 3; i++) {


this.getContactsOfLead(this.testing._id);
}
}

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) {

let check = this.FilteredLeadArrayConst.length == 0;


this.OriginalData = (check ? this.defaultData : this.defaultDataFltr);
debugger;
if (!sort.active || sort.direction === '') {
this.testing = this.constDetail;
this.FilteredLeadArray = this.FilteredLeadArrayConst;
return;
}

this.FilteredLeadArray = this.sortMyLead(sort);
this.testing = this.sortMyLead(sort);

function compare(a: number | string, b: number | string, isAsc: boolean) {


return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
}

Vous aimerez peut-être aussi