Angular 6 - How to Join DB object with Subscribe - database

I am working by my own on a app with Angular 6 / Flask. I am currently facing an issue and i am not able to find anything whivh is suitting it on the web. Here is my issue :
I have 3 Model : Project, Consultant and Client. To simplify, a Project have the id of a Consultant and a Client, and also two dates. What i want to do is to :
Get the list of all my projects
Iterate on this list to handle each project
Get the Consultant from its id
Get the Client from its id
Set an object with the Consultant, the Client and the two dates
Add this project to a list
Display the list
In fact, my purpose here is to be able to display information of the Consultant and the Client of each project so i need to get the object and not just their id. So i tried to do something from what i found :
ngOnInit() {
this.projectsListSubs = this.projectsApi
.getProjects()
.flatMap(params => {
params.forEach(elem => {
this.project.start_date = elem.start_date;
this.project.end_date = elem.end_date;
return [this.consultantsApi.getConsultant(elem.consultant_id),this.clientsApi.getClient(elem.client_id)]
}
this.dataSource = new MatTableDataSource(this.dataList);
})
.subscribe(params => {
this.project.consultant = params[0].firstName + " " + params[0].lastName;
this.project.client = params[1].name;
this.dataList.push(this.project);
});
}
Of course, it doesn't work. I think this code is garbage and I am not able to find a proper way to manage this case. Could you please help me on this ?
Thanks in advance.

Related

Hi all, I'm getting an Error Campaigns Filed is Mandatory in new Leads from 2021. when i am trying to create a new lead

QueryResult result1 = connection.query("select id, Name from Campaign where id='" + campaignId +
"'");
LeadDetails lead = new LeadDetails();
lead.setFirstName(leadDeatils.getFirstName());
lead.setLastName(leadDeatils.getLastName());
lead.setSalutation("Mrs.");
lead.setIndus("sasadd");
Campaign campaign = (Campaign)result1.getRecords()[0];
lead.setCampaign(campaign);
SaveResult[] sr = connection.create(new SObject[] { lead });
I am new bee here. please help me out. thank you.
What is it, integration that sends Leads to SF using SOAP API?
You will have to contact Administrators / Developers in charge of that Salesforce org. There's no standard lookup from Lead to Campaign so there's nothing to be made mandatory from 2021. Here's list of standard fields.. And here's the entity relationship diagram showing that Leads (and Contacts) are linked to Campaign via many-to-many helper table called CampaignMember. (bottom left).
Whatever error you're getting - it's probably new custom field/validation rule/some other thing the SF admins in your organisation did without notifying integration team.
P.S. If you have campaign id and there's custom Campaign__c field on lead or something -you don't have to query it? You probably could just call lead.setCampaign(campaignId ); or something like that?
Added Campaign Member to get fixed
CampaignMember campaignMember = new CampaignMember();
campaignMember.setCampaignId(campaignId);
campaignMember.setLeadId(leadId);
SaveResult[] result = connection.create(new SObject[] { campaignMember });
if (result.length == 1 && result[0].isSuccess()) {
System.out.println("LeadAssignment.setCampaignMember() : " + result);
// lead.setAttachments(attachResult.getClass());;
} else {
System.out.println("LeadAssignment.setCampaignMember() : Campaign member added on lead " + leadId);
}

How can i fetch dynamic data from database based on selected language.?

Hi i am working on a project in laravel 7.0, in back-end i have a table called Posts which contains 2 text language input one in french and the other is arabic added by the back-end application.
what i am trying to do is when the user uses the French Language i want the title_fr to be displayed on the view and same thing in Arabic language the title should be title_ar.
P.S data are stored in French and Arabic
I have tried the similar solution given in an other similar question but none of it worked in my case!
Any idea how i might get this to work ?
Thanks in advance.
You can do something similar to below. We have a model Post, this model has an attribute title. I also assume that you have an attribute that will return user's language from the User model.
class Post extends Model
{
public function getTitleAttribute(): string
{
return Auth::user()->language === 'fr' ? $this->title_fr : $this->title_ar;
}
}
FYI above is just a demo on what can be done. For a full blow solution I would recommend decorator pattern.
Also it might be worth considering using morph for things like that. You can have a service provider that will initiate the morph map for you post model relevant to the language that user has, I.e.
Class ModelProvider {
Protected $models = [
‘fr’ => [
‘post’ => App/Models/Fr/Post::class,
],
‘ar’ => [
‘post’ => App/Models/Ar/Post::class,
]
];
Public function boot() {
$language = Auth::user()->Settings->language;
Relation::morphMap($This->models[$language]);
}
}
Afterwards you just need to call to Relation::getMorphModel(‘post’) to grab Post class that will return correct language.
I.e. App/Models/Fr/Post can have a an attribute title:
Public function getTitleAttribute(): string {
Return $this->title_fr;
}
For example above you would also want to utilise interfaces to make sure that all models follow the same contract, something below would do the trick:
Interface I18nPostInterface {
Public function getTitleAttribute(): string
}
Also, depending on the database you use, to store titles (and other language data) in a JSON format in the database. MySQL 8 has an improve support for JSON data, but there are limitations with that.
So I was Able to fetch data from my database based on the Language selected by the user.
Like i said before I have a table called Posts and has columns id,title_fr and title_ar. I am using laravel Localization.
Inside my PostController in the index function i added this code:
public function index()
{
//
$post = Post::all();
$Frtitle = post::get()->pluck('title_fr');
$Artitle = post::get()->pluck('title_ar');
return view('post.index',compact('post','Frtitle','Artitle'));
}
if anyone has a better way then mine please let me know, i am sure
there is a better way.

Listing Form Templates within another Controller view

I have a form_templates table and a forms table. They're connected by form_template_id. I want to be able to list the form_templates that have been created by title within a select.ctp file I have created within the Forms controller. Just wanting some direction on how to do this with cakephp?
At the moment I have the following code within my FormsController:
public function select()
{
$this->set('page_heading', 'Current Forms');
$contain = [];
$formTemplate = $this->FormTemplates->Forms->find('list', ['order' => 'title'])->where(['active'=>true]);
$forms = $this->paginate($this->Forms->FormTemplates);
$this->set(compact('forms', 'formTemplate'));
}
But I am getting a Call to a member function find() on null error.
Any help on how to tackle this would be greatly appreciated. I know it would be simple but I am new to cakephp.
In your FormsController only FormsTable is loaded automatically, and you are trying to access model that is not currently loaded:
$formTemplate = $this->FormTemplates->Forms->find(...
To get what you want, you should access associated FormTemplatesTable like this:
$formTemplate = $this->Forms->FormTemplates->find(...

Tag Manager to two ga properties

I have implemented Google enhanced Ecommerce Via GTM for GA Property (New), keeping the old classic analytics code in the webiste, Now I removed the old classic code and pushing the events data from the same GTM account to (old) GA property (Replicated the Tags with different GA Property, Reference url : http://www.kristaseiden.com/step-by-step-adding-a-second-ga-property-via-google-tag-manager/).
The first GA property transactions are used to track properly, But after adding another GA property the transactions and all other events are not tracking accurately. In both the accounts Transactions are dropped to 50 percent.
Could someone help me. Thanks in advance.
You can create a custom JS variable:
function() {
var newTrackingId = 'UA-XXXXXX-XX'; // Replace here
var globalSendTaskName = '_' + newTrackingId + '_originalSendTask';
return function(customModel) {
window[globalSendTaskName] = window[globalSendTaskName] || customModel.get('sendHitTask');
customModel.set('sendHitTask', function(sendModel) {
var hitPayload = sendModel.get('hitPayload');
var trackingId = new RegExp(sendModel.get('trackingId'), 'gi');
window[globalSendTaskName](sendModel);
sendModel.set('hitPayload', hitPayload.replace(trackingId, newTrackingId), true);
window[globalSendTaskName](sendModel);
});
};
}
And then add this as a custom task on fields to set:
Hope it helps!
PS: Here is a more detail post from Simo Ahava.

key of the value is undefined with Firebase 4.5.2 and ionic 3

I'am using ionic 3 and firebase 4.5.2 to make an application. I have a project in firebase and I would like to add and delete some values in my list "shoppingItems". I can now retrieve the list view and add items.
Screen of my database
My problem I can't remove a task because the $key of my value is undefined.
I get my list like this :
My values are contained in my variable result ( is an array of the object item: which contain 2 string the value and the key).
Thank's
What version of angularfire2 are you using? I've been attempting to learn Angular and in running through a CRUD tutorial while running on angularfire2 v5.0, I discovered that valueChanges() does not return any metadata.
The following information is gleaned from the angularfire2 documentation located at https://github.com/angular/angularfire2/blob/master/docs/version-5-upgrade.md
Calling .valueChanges() returns an Observable without any metadata. If you are already persisting the key as a property then you are fine. However, if you are relying on $key, then you need to use .snapshotChanges() and transform the data with an observable .map().
The documentation does provide an example as well.
constructor(afDb: AngularFireDatabase) {
afDb.list('items').snapshotChanges().map(actions => {
return actions.map(action => ({ key: action.key,...action.payload.val() }));
}).subscribe(items => {
return items.map(item => item.key);
});
}
Hopefully, you've discovered the solution by now. But I thought I'd drop this here in the event someone else finds your post.

Resources