Forums

OverviewV-Play 2 Support (Qt 5) › Recommended way to add mark to calendar?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #20600

    Edward

    Hello!

     

    I had a little development break due to loosing the desk to the better halfs work for a month +

    Now i have reclaimed, i am back with the struggle i was previously, i recently spent the time reading through the shopping list tutorial with firebase sent out and it has raised a question.

     

    I am trying to add a marker to a calendar, so far trying to use a for loop in my callback advised elsewhere but this isn’t working :( my code is;

     

    FirebaseDatabase {
      config: customConfig
      onFirebaseReady: {
          firebaseDb.getUserValue("dates", {
                                      }
                        }, function(success, key, value) {
                                  if(success) {
                                      console.log(JSON.stringify(value))
                                      // value here is JSON ARRAY
                                      // value =[{"date":"2018-10-01T21:17:00.926"},{"date":"2018-10-02T12:00:00.000"}]
                                      // so value[0].date ="2018-10-01T21:17:00.926"
                                      //then you gonna insert here your dates in arrayFromFireBase as strings as follow
                                      for(i=0 ; i < arrayFromFireBase.length-1 ; i++) 
                                        arrayFromFireBase.push(new Date(value[i].date).getTime())
                                      }
                              })
      }
    }
    Calendar {
        ...
        style: CalendarStyle {
            dayDelegate: Item {
                ...
                Image {
                    // HERE WE MUST COMPARE TIME (we used Date.getTime()) FROM FIREBASE with the calendar's date converted to time also 
                    visible: arrayFromFireBase.indexOf(styleData.date.getTime()) > -1
                    ...
                    source: "qrc:/images/eventindicator.png"
                }
            }
        }
    }

     

     

    Now like i say this doesn’t work, i’ve tried adapting, the code/loop in various ways, is it unable to read the date due to how it’s saved in firebase? when i read the JSON.stringify in the console log it’s human readable as shown in the code example but when i just log the value it appears as [object Object] (one for however many dates), now if i say try to push the JSON.stringify to another array for the for loop it still doesn’t work?

     

    is it because of the “date” : key in firebase confusing the loop to not read the date? or should i format the date to unix epoch or would this not make a difference? i only want whole dates to be saved those not time periods, so when my app reads for example  24/11/18 it will mark that date?

     

    Is there any immediate fixes you can see with this? alternatively would you say to scrap the for loop all together and work with an adapted dataModel as described in the tutortial

     

     

     

    #20604

    Günther
    V-Play Team

    Hi,

    from what I see the loop always iterates through the current firebase array, which I guess is empty at first?

    I think you mean to use the for loop to iterate over the value, e.g. somehow like this? (did not try the code)

    console.log(JSON.stringify(value))
                                      // value here is JSON ARRAY
                                      // value =[{"date":"2018-10-01T21:17:00.926"},{"date":"2018-10-02T12:00:00.000"}]
                                      // so value[0].date ="2018-10-01T21:17:00.926"
                                      //then you gonna insert here your dates in arrayFromFireBase as strings as follow
                                      for(var idx in value) 
                                        arrayFromFireBase.push(new Date(value[idx].date).getTime())
                                      }

     

     

    In any case, I suggest to verify the value that you add store etc with additional log output to make sure the data you retrieve from Firebase to QML is managed correctly. Only after that you can make sure that the comparison in your delegate works.

    #20607

    Edward

    Hello!

    And horrrayyyy!

     

    after some minor tweaking, it is working, adding a marker to the dates that are read from firebase!

    the following code is the areas that apply to it (removing any excess)

    Note that the Image {} is within my Calendar { style: CalendarStyle { dayDelegate: Item {…….}}}

     

        property var arrayFromFireBase: []
    
        property var userData: {
          "selectedDates": [
              {}]
        }
    
    onLoggedIn:  {
     firebaseDb.getUserValue("dates/selectedDates", {},
                                            function(success, key, value) {
                                            if(success) {
                                                console.log(JSON.stringify(value))
                                                arrayFromFireBase.push(value)
                                                
    
                                                for(var idx in value)
                                                    arrayFromFireBase.push(new Date(value[idx].date).getTime())
                                            }})}
    
    AppButton {
              id: saveButton
              text: "Save & Request"
              onClicked: {
                userData.selectedDates.push({"date": calendar.selectedDate});
                console.log(JSON.stringify(userData));
                firebaseDb.setUserValue("dates", userData)
              }
          }
    
    Image {
                           visible: arrayFromFireBase.indexOf(styleData.date.getTime()) > -1
                           
                       }

     

     

     

     

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support