import { Component, OnInit, Input } from '@angular/core'; import { IOrganisation } from '../shared/core/IOrganisation'; import { OrganisationService } from '../shared/service/organisation.service'; import { environment } from '../environments/environment'; import { ActivatedRoute } from '@angular/router'; import { Message, MessageService } from 'primeng/api'; @Component({ selector: 'app-organization-detail', templateUrl: './organization-detail.component.html', styleUrls: ['./organization-detail.component.css'] }) export class OrganizationDetailComponent implements OnInit { @Input() profileDetails : IOrganisation; OrganisationId: string; //curent data will be here and bind when page loarding, if click save, new content will bind to these publicProfile: string; privateNote: string; //when richtextbox content editing, it binds to these vars editedPublicProfile: string; editedPrivateNote: string; //new content will assigne to these vars after edited newPublicProfile: string; newPrivateNote: string; //to enable and disable editors isPublicProfileEditing = false; isPrivateNoteEditing = false; showChart:boolean; constructor(private organisationService : OrganisationService, private route: ActivatedRoute, private messageService: MessageService) { } ngOnInit() { this.messageService.clear(); //getting org id from url this.OrganisationId = this.route.snapshot.paramMap.get("id").toString(); this.getOrganization(this.OrganisationId); } //this method call service to get organization main details getOrganization(id?: string){ this.organisationService.getOrganisations(id,null).subscribe(org=> { //orgProfile fill with response this.profileDetails = org[0]; this.profileDetails.LogoUrl = this.getOrgLogoUrl(this.profileDetails.LogoUrl); //inputs will pass data for public and private notes this.publicProfile = this.profileDetails.PublicProfileNote; this.privateNote = this.profileDetails.PrivateProfileNote; this.showChart = true; }) } //this method will simply check if org url is empty, then use default image url getOrgLogoUrl(url:string){ return (!url)?(environment.imageLocation + "default.png"):(environment.imageLocation + url); } //this method makes public profile editable editPublicProfile(){ this.editedPublicProfile = this.publicProfile; this.isPublicProfileEditing = true; } //this method makes private note editable editPrivateNote(){ this.editedPrivateNote = this.privateNote; this.isPrivateNoteEditing = true; } //this method save and close public profile editor savePublicProfile(){ this.messageService.clear(); this.publicProfile = this.newPublicProfile; this.profileDetails.PublicProfileNote = this.publicProfile; this.organisationService.saveOrganisationProfile(this.profileDetails).subscribe(data=>{ this.messageService.add({severity:'success', summary:'Success Message', detail:'Public profile saved successfully!'}); }); this.cancelPublicProfileEdit(); } //this method save and close private note editor savePrivateNote(){ this.messageService.clear(); this.privateNote = this.newPrivateNote; this.profileDetails.PrivateProfileNote = this.privateNote; this.organisationService.saveOrganisationProfile(this.profileDetails).subscribe(data=>{ this.messageService.add({severity:'success', summary:'Success Message', detail:'Private note saved successfully!'}); }); this.cancelPrivateNoteEdit(); } //this method close without saving public profile editor cancelPublicProfileEdit(){ this.isPublicProfileEditing = false; } //this method close without saving private note editor cancelPrivateNoteEdit(){ this.isPrivateNoteEditing = false; } //this method run when public richtextbox content updating onPublicContentChanged({ quill, html, text }) { this.newPublicProfile = html; } //this method run when private richtextbox content updating onPrivateContentChanged({ quill, html, text }) { this.newPrivateNote = html; } }