Retrieve and display last entry indatabase - firebase

Frank · 2 hours ago
Using Ionic 2, I am unsuccessfully trying to retrieve and display the newGoalWt, newMaxReps, newMinReps, repsToday, and wtToday shown at the bottom of the firebase data image. I do not want to retrieve the other data. I thought I found the answer to this several times, but I haven't. I am not trying to get others to do work I should be doing but I am new to coding and need help at this point. If you have another course that covers this by example please let me know. sample database

I hope this makes sense/is clear.
First thing is to create a provider which gets the details. So in the provider there will be a function like this :
public getRequiredObject(objectKey : String){
return this.database.object('wideGripBPTwo-list/'+ objectKey)
}
Then in the controller/typescript file i would have a variable assigned to the return value of the provider :
this.variableName = this.Provider.getRequiredObject(objectKey);
this.variableName.subscribe(snapshot => {
this.newGoalWt = snapshot.newGoalWt;
this.newMaxReps = snapshot.newMaxReps;
//add other variables here
Lastly in the html file just bind the data :
<ion-label>{{newGoalWt}}</ion-label>
Note I have not added entire provider, .ts file and html file.
Please advise if this makes sense and if you need more assistance.

Related

Understand Dynamic Links Firebase

I would like to understand better Firebase Dynamic Links because i am very new to this subject.
What i would like to know :
FirebaseDynamicLinks.instance.getInitialLink() is supposed to return "only" the last dynamic link created with the "initial" url (before it was shorten) ?
Or why FirebaseDynamicLinks.instance.getInitialLink() doesn't take a String url as a parameter ?
FirebaseDynamicLinks.instance.getDynamicLink(String url) doesn't read custom parameters if the url was shorten, so how can we retrieve custom parameters from a shorten link ?
My use case is quite simple, i am trying to share an object through messages in my application, so i want to save the dynamic link in my database and be able to read it to run a query according to specific parameters.
FirebaseDynamicLinks.instance.getInitialLink() returns the link that opened the app and if the app was not opened by a dynamic link, then it will return null.
Future<PendingDynamicLinkData?> getInitialLink()
Attempts to retrieve the dynamic link which launched the app.
This method always returns a Future. That Future completes to null if
there is no pending dynamic link or any call to this method after the
the first attempt.
https://pub.dev/documentation/firebase_dynamic_links/latest/firebase_dynamic_links/FirebaseDynamicLinks/getInitialLink.html
FirebaseDynamicLinks.instance.getInitialLink() does not accept a string url as parameter because it is just meant to return the link that opened the app.
Looks like there's no straightforward answer to getting the query parameters back from a shortened link. Take a look at this discussion to see if any of the workarounds fit your use case.

basic firebase + dialogflow - repeated agent add dialogflow

really appreciate the helps
I have been following this video with this code.
My code looks like this
function angerEmotionCapture(agent) {
const angryTo = agent.parameters.angryDirectedTo;
return admin.database().ref('directedTo').transaction((directedTo)=>{
let target = directedTo;
agent.add(`previous entry was ${target}`);
target = angryTo;
agent.add(`new entry is ${target}`);
return directedTo;
});
}
The purpose of this is to capture a conversation topic and store it in the database.
I'm planning to use it for multiple purposes that's why I don't use context.
This code is only the first step to see if I can capture it properly.
When doing this, the agent response always look like this
previous entry was null
new entry is boss
previous entry was friends
new entry is boss
Here "friends" and "boss" are expected. However, the first repetition is not expected and it always gives null. Despite of that, this correctly update the database
I want to understand why is there a repetition here
Thanks, really appreciate the time

Firebase Storage : Get the token of the URL

I currently have an application that works with Firebase.
I repeatedly load profile pictures. However the link is quite long, it consumes a certain amount of data. To reduce this load, I would like to put the link in raw and only load the token that is added to the link.
To explain, a link looks like this: “https://firebasestorage.googleapis.com/v0/b/fir-development.appspot.com/o/9pGveKDGphYVNTzRE5U3KTpSdpl2?alt=media&token=f408c3be-07d2-4ec2-bad7-acafedf59708”
So I would like to put in gross: https://firebasestorage.googleapis.com/v0/b/fir-developpement.appspot.com/o/
In continuation: “9pGveKDGphYVNTzRE5U3KTpSdpl2” which is the UID of the user that I recover already and the or my problem this poses: “alt = media & token = f408c3be-07d2-4ec2-bad7-acafedf59708” which adds randomly for each photo .
I would like to get back only this last random piece …
Is it possible ?
Thank you
UP : 01/11 Still no solution
It's not supported to break apart and reassemble download URLs. You should be treating these strings as if their implementation details might change without warning.

Polymer Firebase Binding for Location

I've been trying to bind a location value to a "note" (as in the na-notes example in codelabs) via firebase. I'm using the paper-input-place, but have tried with several other elements to no avail. So far, this is what I have (corresponding to the na-note.html document):
<paper-input-place is="iron-input" bind-value="{{address}}" value="{{address}}" label="Address" api-key="key">
And then I have this on my na-editor.html:
<na-note id="note" title="{{note.title}}" location="{{note.place_id}}" price="{{note.price}}" rooms="{{note.rooms}}" beds="{{note.beds}}" baths="{{note.baths}}" editable></na-note>
I am thinking that it probably is a silly mistake, but I've been going at it for two days and I'm starting to loose my patience, so any help would be appreciated!
Thanks!
at above na-note element, note is an object retrieved from firebase. so, to this path, you will need to save location data of the note. So, when you received the proper data from paper-input-place element, you will need to save it to the note's path as a location. So, first retrive the address:
<paper-input-place hide-error place="{{place}}" api-key="[[apiKey]]" on-place-changed="searchPlaceChanged" > </paper-input-place>
...
searchPlaceChanged(p){
console.log(p.detail.value); // You will need to see the place data, which you may like to save only some detail like: p.detail.value.formatted_address;
this.set('note.place', p.detail.value.formatted_address);
}
Asuming just abobe note object (at set operation) is firebase-document's two way binding retrived data that you just editing.

Firebase and Angularfire nightmare migration for Update

I am new to firebase and I am having a bit of a nightmare trying to adapt old code to what is now deprecated and what is not. I am trying to write a function which updates one "single" record in my datasource using the now approved $save()promise but it is doing some really strange stuff to my data source.
My function (should) enables you to modify a single record then update the posts json array. However, instead of doing this, it deletes the whole datasource on the firebase server and it is lucky that I am only working with testdata at this point because everything would be gone.
$scope.update = function() {
var fb = new Firebase("https://mysource.firebaseio.com/Articles/" + $scope.postToUpdate.$id);
var article = $firebaseObject(ref);
article.$save({
Title: $scope.postToUpdate.Title,
Body: $scope.postToUpdate.Body
}).then(function(ref) {
$('#editModal').modal('hide');
console.log($scope.postToUpdate);
}, function(error) {
console.log("Error:", error);
});
}
Funnily enough I then get a warning in the console "after" I click the button:
Storing data using array indices in Firebase can result in unexpected behavior. See https://www.firebase.com/docs/web/guide/understanding-data.html#section-arrays-in-firebase for more information. Also note that you probably wanted $firebaseArray and not $firebaseObject.
(No shit?) I am assuming here that $save() is not the right call, so what is the equivalent of $routeParams/$firebase $update()to do a simple binding of the modified data and my source? I have been spending hours on this and really don't know what is the right solution.
Unless there's additional code that you've left out, your article $firebaseObject should most likely use the fb variable you created just before it.
var article = $firebaseObject(fb);
Additionally, the way in which you're using $save() is incorrect. You need to modify the properties on the $firebaseObject directly and then call $save() with no arguments. See the docs for more.
article.Title = $scope.postToUpdate.Title;
article.Body = $scope.postToUpdate.Body;
article.$save().then(...

Resources