I am currently upgrading an old IONIC 1 app (adding new features). I have read a lot of threads but didn't find any answer to my question.
First of all, my Firebase Database structure looks as follows:
-products
--productId
--- imageurl
--- price
--- title
--- likes: 0
I would like to increment the value of child likes everytime a user triggers (for instance clicks a like button).
my service.js function looks as follows:
incrementLikeproduct: function(prodId){
return ref.child('products').child(prodId).child('likes').set( xxxx );
},
I have tried to retrieve the current value of the likes child object from firebase as a var and add +1; but didn't get anything to work properly. I basically do not know how to replace the xxxxx in my function to obtain the expected result.
My question is: How shoud I write the incrementLikeproduct function to increment the likes child value in firebase? I have read about asynchronous listener but can't figure out how to implement it inside my service.js.
I know that IONIC1 is outdated but I had already a solid piece of code to which I wanted to add new features without starting the whole app dev from scratch.
I am quite noob with JS and would be greateful if someone could give me a hint :-).
You should update your likes like below code:
return ref.child('products').child(prodId).update({
likes:xxx
})
thanks
Related
I am extremely new to Flutter, so please forgive my ignorance and please explain things to me like I am a toddler.
I would like to implement a to-do list into my app similar to this project: https://github.com/ishrath-raji/todoey-flutter
It's just a basic list where users can add items, cross them out, and delete them. Very simple.
However, I have absolutely no idea how to take the items that users enter into the to-do list and store them in memory so that the user can review them later.
I've tried googling around, but all the answers I've seen are above my understanding and/or written in a way that is difficult to follow.
Any help would be very much appreciated!
I assume you have a view / page, where the user can give all the necessary information for the new ToDo item. This means you have a class representing a ToDoItem.
class ToDoItem {}
You will want to store them in some List.
As you probably want this list of ToDo items to be accessbible everywhere within the map, you should start researching the topic "state management".
As a starting point, just to name the easiest of all solutions, you could use Riverpod and declare one global variable:
final todoListRereference = StateProvider<List<ToDoItem>>((ref) => <ToDoItem>[]);
Now you have a list of ToDoItem which is accessible from everywhere in your app, provided you follow the steps to make Riverpod providers accessible everywhere. For example, in every build method you can use
final todoList = ref.watch(todoListRereference);
and you have access to all the stored ToDoItems.
In the case of your ToDoItem you can create with all the user information, you will have a construction like:
onPressed: () {
final todoItem = ToDoItem(...);
final todoListProvider = ref.read(todoListReference.notifier);
todoListProvider.state = [... todoListProvider.state, todoItem);
}
I just assumed it would happen after the user clicked something and the onPressed method of the according button is triggered.... However, first you create the ToDoItem. Then you access the List we made accessible with the reference. Then we change the "state" of that provider to a new state which is defined as all the old ToDoItems plus the newly created one.
If you have any pages in your app where you can see all the ToDoItems, you will now see one more.
I hope this is okay as a starting point.
Firstly, Karate UI automation is really awesome tool. I am kind of enjoying it while writing the UI tests using Karate. I ran into a situation where in, i was trying to fetch the shadowRoot elements. I read few similar posts related to javascript executor with karate and learnt that it is already answered. it is recommended to use driver.eval. But in Karate 0.9.5 there is no eval, it has script() or scriptAll(). I have gone through documentation couple of times to figure out how i can fetch element inside an element but no luck.
Using traditional selenium+java, we can fetch shadowRoot like this way:
something like shadowRoot which sits inside a parent element like div or body.
//downloads-manager is the tagname and under that downloads-manager, a shadowRoot element exists
The HTML looks like this. it is from chrome://downloads.
<downloads-manager>
#shadow-root(open)
</download-manager>
WebElement downloadManager =driver.findElement(By.tagName("downloads-manager");
WebElement shadowRoot= (WebElement)((JavaScriptExecutor)driver)
.executeScript("return arguments[0].shadowRoot",downloadManager);
So i tried the following in Karate UI
script("downloads-manager","return _.shadowRoot"); //js injection error
script('downloads-manager', "function(e){ return e.shadowRoot;}"); // same injection error as mentioned above.
def shadowRoot = locate("downloads-manager").script("function(e){return e.shadowRoot};"); //returns an empty string.
I bet there is a way to get this shadowRoot element using Karate UI but i am kind of running out of options and not able to figure out this.
Can someone please look into this & help me?
-San
Can you switch to XPath and see if that helps:
* def temp = script('//downloads-manager', '_.innerHTML')
Else please submit a sample in this format so we can debug: https://github.com/intuit/karate/tree/develop/examples/ui-test
EDIT: after you posted the link to that hangouts example in the comments, I figured out the JS that would work:
* driver 'http://html5-demos.appspot.com/hangouts'
* waitFor('#hangouts')
* def heading = script('hangout-module', "_.shadowRoot.querySelector('h1').textContent")
* match heading == 'Paul Irish'
It took some trial and error and fiddling with the DevTools console to figure this out. So the good news is that it is possible, you can use any JS you need, and you do need to know which HTML element to call .shadowRoot on.
EDIT: for other examples of JS in Karate: https://stackoverflow.com/a/60800181/143475
Sorry to ask. I'm just a noob here :(
Using Ionic 4 + Firebase, just for learning, say I have a button on html with a (click) function and want to be able to get a value!!! Banging my head on the wall!
example:
Firebase DB:
collection "Places"
doc:
id: 1
name: somename
want to click the button and by hard-coding the id, I want to alert(somename)
when I click I get [object Object], cannot get into the object.
code:
export class Tab4Page implements OnInit {
lugar: AngularFirestoreCollection<Places>;
lugares: Observable<Places[]>;
constructor(private _angFireStore: AngularFirestore) {
this.lugar = this._angFireStore.collection('Places');
this.lugares = this.lugar.valueChanges();
}
ngOnInit() { }
//this is the function
pruebaF1() {
alert(this.lugares); //What's next here???!!
}
}
sorry I can't get it.
do not know how to further dig into this.lugares to hardcode an id and just get a value: say, get nombre where id = 1, then nombre = somename
and if I say id = 2, then nombre = the name that's in the db for that doc.
not angular wise :(
Thanks in advance!!!! :)
I can see you are genuinely trying here. I see scenarios like this quite a lot and always wonder how people got this far in the first place. I'm curious, are you following a guide or just trying random bits of code?
The best thing to do is to follow some getting started tutorials which will walk you through each of the steps of the basics. Do what they want to teach you first, and then afterwards start building your own by editing bits until you find yourself writing the whole thing without problems.
This seems like an interesting guide, or the official angularfire2 docs.
Basically you are missing some concepts which would be best explained in a well written tutorial. What you get back with your code so far is an observable. That could be used in the front end with something like this:
<ul>
<li *ngFor="let item of lugares | async">
{{ item.name }} is {{ item.price }} (assuming these properties exist)
</li>
</ul>
But what you are actually asking is not this. You are writing code to access a collection, but to get a single one where id = 1 type query is a document, which would be more like:
this.placeRef = this.afs.collection(''Places'', ref => ref.where('id', '==', '1'));
But then that still gives you the missing understanding of what to do with it after. I think the best thing is to dig into the getting started documentation.
BTW the original tag you had, firebase realtime database is the old database and a very different technology, so if you are searching for information you need to make sure you are using the correct "firestore" search term.
I was going through these pages on ZK documentation ID_Space -Selector and looked at following code
comp.query("#ok"); //look for a component whose ID's ok in the same ID space
comp.query("window #ok");
comp.queryAll("window button");
I am wondering how can I use this in my code? I am creating 2 drop downs and adding Id to both these drop downs
Listbox listbox=createListbox(widget, DetailsListRenderer.ORDERSTATUS.class, null,orderStatus);
listbox.setId(ORDER_STATUS_ID);
So when My page is getting refreshed, I am getting exception of Unique Id, I was wondering if these is a way I can query component and see if same component with same Id already exists and in case it exists, I should not add ID to that component, or should not create component at all
Any suggestion?
I tried something like
widget.getFellow( ORDER_STATUS_ID); but getting `org.zkoss.zk.ui.ComponentNotFoundException` exception.
widget.getFellow("#" + ORDER_STATUS_ID);
For widgets that co-exist in the same ID space (a.k.a fellow widgets), one may use any of the following to refernece a fellow from a certain widget:
var fellow = widget.$f('fellowID');
var fellow = widget.$f().fellowID;
var fellow = zk.Widget.$(jq('$fellowID')[0]);
I'm working on a sample app for Facebook, using Flash Builder and Flex.
Now, I've got everything up and running - but there's one problem, specifically with the work history part.
When I try to display the user's work history..here's the code for logging in:
protected function login():void
{
FacebookDesktop.login(loginHandler, ["user_birthday", "user_work_history"]);
}
Here, loginHandler's a callback function, that then goes ahead and displays data about the user:
protected function loginHandler(success:Object,fail:Object):void
{
if (success){
currentState = "LoggedIn";
fname.text = success.user.name;
userImg.source=FacebookDesktop.getImageUrl(success.uid,"small");
birthdayLbl.text=success.user.birthday;
workLbl.text=success.user.work;
}
}
Now, the problem occurs with success.user.work - it ends up printing the following:
[object,Object],[object,Object],[object,Object],[object,Object]
Obviously, I'm doing something wrong..but I can't figure out what exactly it is. Would be grateful for some pointers!
Thanks!
Rudi.
The object contained in success.user.work is most likely an array of objects, each item representing a work period, so you'll have to treat it as such. Either use a list and a custom renderer for each item, or create a string by iterating over the array, and appending the fields that you're interested in.
To see what the individual objects contain, either use a breakpoint during debug and inspect them, or check to see if they're documented in the facebook development documentation.