Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Felgo 3.0
- import QtQuick 2.12
- Item {
- id: dataModel
- property var productItems: ({})
- readonly property string dbKeyAllProductItems: "products-admin"
- signal loggedIn
- signal loggedOut
- FirebaseConfig {
- id: fbConfig
- projectId: "..."
- databaseUrl: "..."
- apiKey: Qt.platform.os === "android"
- ? "..."
- : ""
- applicationId: Qt.platform.os === "android"
- ? "..."
- : ""
- }
- FirebaseAuth {
- id: auth
- config: fbConfig
- onLoggedIn: if(!success)
- nativeUtils.displayMessageBox(qsTr("Login failed"), qsTr("Reason: %1").arg(message), 1)
- onUserRegistered: if(!success)
- nativeUtils.displayMessageBox(qsTr("Register failed"), qsTr("Reason: %1").arg(message), 1)
- onAuthenticatedChanged: if(authenticated) dataModel.loggedIn()
- }
- function registerAdmin(email, password) {
- auth.registerUser(email, password)
- }
- function loginAdmin(email, password) {
- auth.loginUser(email, password)
- }
- function customer() {
- dataModel.loggedIn()
- }
- function logoutAdmin() {
- auth.logoutUser()
- }
- FirebaseDatabase {
- id: database
- config: fbConfig
- realtimeUserValueKeys: [dbKeyAllProductItems]
- onRealtimeUserValueChanged: if(key === dbKeyAllProductItems) productItemsLoaded(value)
- }
- function productItemsLoaded(value) {
- dataModel.productItems = value || {}
- console.log(JSON.stringify(dataModel.productItems))
- }
- function addProductItem(text) {
- var time = new Date().getTime()
- var productItem = {
- date: time,
- text: text
- }
- database.setUserValue(dbKeyAllProductItems + "/" + time, productItem)
- }
- function saveProductItem(productItem) {
- database.setUserValue(dbKeyAllProductItems + "/" + productItem.date, productItem)
- }
- function deleteProductItem(id) {
- database.setUserValue(dbKeyAllProductItems + "/" + id, null)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement