import { Component, OnInit, Input } from '@angular/core'; import { MenuItem } from 'primeng/api'; import { StaffService } from '../shared/service/staff.service'; import { IPersonSocialMedia } from '../shared/core/IPersonSocialMedia'; import { IPersonCustomSocialMedia } from '../shared/core/IPersonCustomSocialMedia'; import { IPlaceLived } from '../shared/core/IPlacesLived'; import { IFamilyRelationship } from '../shared/core/IFamilyRelationship'; import { IFamilyMember } from '../shared/core/IFamilyMember'; import { ILifeEvents } from '../shared/core/ILifeEvents'; import { debug } from 'util'; @Component({ selector: 'app-staff-social', templateUrl: './staff-social.component.html', styleUrls: ['./staff-social.component.css'] }) export class StaffSocialComponent implements OnInit { //use when get existing staff id as a input @Input() staffId: number; //bind staff social media accounts data accounts : IPersonSocialMedia; //get new social media accounts from social-media component newAccounts : IPersonSocialMedia; //bind staff custom social media account data customAccounts : IPersonCustomSocialMedia[]; //get new social media accounts from social-media component newCustomAccounts: IPersonCustomSocialMedia[]; //bind staff places lived data places : IPlaceLived; //get new place lived from place-lived component newPlaceLived : any; //bind family data family : IFamilyRelationship; //get new family from family-relationship component newFamily : any; //bind family member data members : IFamilyMember[]; //get new fmaily member from family-relationship component newMembers : any; //bind staff life events data lifeEvents : ILifeEvents[]; //get new life event from staff life event component newLifeEvent : any; //menu items for left verticle menu list items: MenuItem[]; //use to check which right side content is active and displays isSocialMediaOn : boolean = true; isPlaceLivedOn : boolean = false; isFamilyOn : boolean = false; isLifeEventsOn : boolean =false; constructor(private staffService: StaffService) { } ngOnInit() { //set all menu items this.prepareMenuItems(); //inititlaize accounts obj when new staff adding this.accounts = {Id:0,LinkedIn:"",Twitter:"", Facebook:"", Google:"", Website:"",MessengerType:0, MessengerName:""} //initialize palces obj when new staff adding this.places = {Id:0, StaffId:this.staffId, CurrentCity:"", HomeTown: "", CityFlag:"", HomeFlag:""} //initialize family obj when new staff adding this.family = {Id:0, StaffId:this.staffId, RelationshipId:"0", Staff:null, Relationship:"", RelationshipDate:new Date(), PartnerName:""} //initialize family member obj when new staff adding this.members = [ {Id:0, StaffId: 0, MemberName: "", MemberTypeId: "", EventDate: new Date(), EventTypeId: ""} ] //initialize life events obj when new staff adding this.lifeEvents = [{Id : 0, Staff: null, StaffId: this.staffId, EventCategory:"", EventDate : new Date(), EventType : "", EventLable:"", Description :""}] //initialize custom social media obj when new staff adding this.customAccounts = [{ Id:0, Staff: null, StaffId:this.staffId, Name: "", Details:""}] //calling social media account get method if(this.staffId > 0){ //call serivce this.getStaffSocialMedia(this.staffId); //call service this.getStaffPalcesLived(this.staffId); //call service this.getStaffFamily(this.staffId); //call service this.getStaffFamilyMembers(this.staffId); //call service this.getStaffCustomSocialMedia(this.staffId); //call service this.getStaffLifeEvent(this.staffId); } else{} } //get staff social media by staff id and bind response to the object getStaffSocialMedia(id: number){ var staff = id.toString(); this.staffService.getStaffSocialAccounts(staff).subscribe( accounts => { this.accounts = accounts; this.newAccounts = accounts; }); } //get staff custom social media by staff id and bind response to the object getStaffCustomSocialMedia(id: number){ var staff = id.toString(); this.staffService.getStaffCustomSocialAccounts(staff).subscribe( accounts => { this.customAccounts = accounts; console.log(accounts); }); } //this method used to get output social media object from social media component, optional method getModifiedAccounts(newAccountObject : IPersonSocialMedia){ //console.log(newAccountObject); //this.accounts = newAccountObject; } //this method used to get output new social media accounts from social media component getNewAccounts(newAccountObject : IPersonCustomSocialMedia[]){ //console.log(newAccountObject); this.newCustomAccounts = newAccountObject; } //get staff social media by staff id and bind response to the object getStaffPalcesLived(id: number){ var staff = id.toString(); this.staffService.getStaffPlacesLived(staff).subscribe( places => { this.places = places; this.newPlaceLived = this.places; }); } //this method used to get modified output from place lived component getPlaceLived(placeLived: any){ //console.log(placeLived); this.newPlaceLived = placeLived; } //get staff family by staff id and bind response to the object getStaffFamily(id: number){ var staff = id.toString(); this.staffService.getStaffFamily(staff).subscribe( family => { if(family.Id > 0){ this.family = family; this.newFamily = this.family; } }); } //this method use to get modifed output from fmaily relationship component for relationships getFamily(family: any){ this.newFamily = family; this.family = family; //console.log(this.newFamily); } //get staff family by staff id and bind response to the object getStaffFamilyMembers(id: number){ var staff = id.toString(); this.staffService.getStaffMember(staff).subscribe( members => { this.members = members; this.newMembers = members; }); } //this method use to get modifed output from family relationship component for family members getMember(members : any){ this.newMembers = members; } //get staff life events from service and bind data to the object getStaffLifeEvent(id: number){ let idVal = id.toString(); this.staffService.getStaffEvents(idVal).subscribe( events =>{ this.lifeEvents = events; this.newLifeEvent = events; }) } //this will get new life events added getEvent(event : any){ this.newLifeEvent = event; } //this method prepare verticle menu bar prepareMenuItems(){ this.items = [{ id: "1", label: 'Social accounts' }, { id: "2", label: 'Place lived' }, { id: "3", label: 'Family and relationships' }, { id: "4", label: 'Life events' }]; } //this method hide and show depend on the link clicked showContent(id : any){ //first hide all sections by this method this.turnOffAll(); //depend on the id, relavant section will display and style class will be added switch(id){ case "1": this.isSocialMediaOn = true; document.getElementById("link1").className = "linkactive"; break; case "2": this.isPlaceLivedOn = true; document.getElementById("link2").className = "linkactive"; break; case "3": this.isFamilyOn = true; document.getElementById("link3").className = "linkactive"; break; case "4": this.isLifeEventsOn = true; document.getElementById("link4").className = "linkactive"; break; } } //this method turn off all right side contents before turn on any content turnOffAll(){ this.isSocialMediaOn = false; this.isPlaceLivedOn = false; this.isFamilyOn = false; this.isLifeEventsOn = false; document.getElementById("link1").className = ""; document.getElementById("link2").className = ""; document.getElementById("link3").className = ""; document.getElementById("link4").className = ""; } }