Can not produce angular 6 timestamp, missing imports - firebase

I am trying to produce a timestamp on click (of a button) and another timestamp on click of another button. Essentially a punch clock. I understand how to create the buttons, but have no clue with packages to import that would produce the timestamp ....yes, I've search the entire web for this.
Ultimately I'd like to register that to firebase db for a each registered user, but we'll get to that later.

import * as firebase from 'firebase'
user.createdAt = firebase.firestore.FieldValue.serverTimestamp()
user.updatedAt = firebase.firestore.FieldValue.serverTimestamp()
From the docs: https://firebase.google.com/docs/reference/js/firebase.firestore.FieldValue#.serverTimestamp

Related

How to remove the notification badge count in react-native-firebase/messaging after opening the app

I'm trying to update the notification count to 0 once the app is opened but I couldn't find any relevant methods to update the badge count in #react-native-firebase/messaging package. Is there any possible way to update the notification count inside the app?
This is my listener
messaging().onNotificationOpenedApp(async (remoteMessage) => {
console.log(remoteMessage);
})
Are there any methods provided by rnfirebase package to set the badge count inside the app? If there then that would be a great help 😊
I've used the below package to solve this problem
react-native-push-notification
Here's the code for it,
import PushNotification from "react-native-push-notification";
PushNotification.setApplicationIconBadgeNumber(0);
This will reset the badge count to 0 once you open the app, You can also set the count as you want dynamically and it will get updated.
import firebase from 'react-native-firebase';
using code:
firebase.notifications().removeAllDeliveredNotifications();
or:
firebase.notifications().removeDeliveredNotification(notificationId);

Automatically import google forms quiz results to google classroom

When students in google classroom submit my google forms, they are automatically graded and students can see their results. Despite that when I want to import these quiz results into my google classroom, I need to do it manually with import grades button. Is there a way to automate this process? That means that when student submits the form, the results will be immediately visible in his google classroom.
Please do not tell me to change LMS, google classroom is a requirement for me.
There's no need to use Forms outside Classroom, you can integrate it
As a teacher go to your Class > Classwork and click on Create > Quiz assignment, fill the needed data like Title, Instructions, Students, Points, etc. Then click on the Form and edit it as required.
When you are done editing, save it and close the Form, then on the Classroom side click on Assign. Once you assigned the quiz to the students, this automatically will be reflected on the student classwork and this student can access your quiz trough the Classroom Platform.
If you want to export this data to another service then use Google Apps Script in order to automate your process
You can skip this if it's not necessary
As an approach to export this data using Apps Script, open the Form and open the Script Editor then copy this code:
function myFunction() {
var form = FormApp.getActiveForm();
form.setCollectEmail(true);
var responses = form.getResponses();
responses.forEach(response => {
let email = response.getRespondentEmail();
let score = 0;
response.getGradableItemResponses().forEach(item => {
score += Number.parseFloat(item.getScore());
});
// Handle your submit and export this data to an extra service
});
}
Then you can handle the submit event by creating a onSubmit trigger in your Apps Script project.
Reference
Class FormApp
FormApp.getActiveForm()
Class Form
Form.setCollectEmail(collect)
Form.getResponses()
Class FormResponse
FormResponse.getRespondentEmail()
FormResponse.getGradableItemResponses()
Class ItemResponse
ItemResponse.getScore()
What you want cannot be achieved for now.
The reason for this is essentially because before importing the grades, the teacher can modify/change the already existing grades if needed before sending them to the students.
What you can do in this situation is to file a Feature Request on Google Issue Tracker here and provide all the necessary details.

How to get current System Timestamp for Firebase? in Android Kotlin

I am using Firebase pagging and therefore i need current timestamp for queries database in firebase ? can anyone knows how to get current timestamp from system?
FirebaseFirestore.getInstance().collection("news")
.orderBy("timestamp",Query.Direction.DESCENDING)
.startAfter(timestamp) // for here i need current system timestamp..?? how can i??
.limit(4)
.get()
firebase.firestore.FieldValue.serverTimestamp()
If you want the date value of firebase.firestore.FieldValue.serverTimestamp() you can use .toDate().
See FireStore Timesteamp.
If you want the current Date as a timestamp you can use the following
For Firebase Functions
import admin = require('firebase-admin');
const todayAsTimestamp = admin.firestore.Timestamp.now()
For local projects
import { Timestamp } from '#google-cloud/firestore';
const myTimestampAsDate = Timestamp.now()
Ferin's answer led me in the right direction. This what worked for me in my current project using Kotlin when getting the timestamp value to store in firebase cloud firestore.
val createdAt = FieldValue.serverTimestamp()
If anyone is confused I can explain further. Happy coding everyone!

Firebase Analytics: How to get and integrate UA-type measurement ID instead of G-type measurement ID for Firebase Analytics?

I am running a React web app on Firebase. Firebase automatically generates G-type measurement ID (G-XXXX). I'd like to get a UA-type measurement ID (UA-XXXX) and somehow integrate it into Firebase project.
Reason: I want to use React-GA package (https://github.com/react-ga/react-ga) but the package apparently does not support G type measurement IDs.
Is there any way to create and integrate the UA-type measurement ID somehow to Firebase project configuration? I'd love to see the data reflected into the Firebase console dashboard, not having to leave the console to see the data.
Any idea on how to do this? Thanks!
I had done it before with the same package.
First; you need to add a "universal analytics property" manually on google analytics page. Because Firebase is only using latest version. Click admin icon at the bottom-left and then click + Create Property
You will see Show Advanced Options button. Enable this of an earlier version of Google Analytics. Once you finish you get your UA-xxxx code.
import ReactGA from 'react-ga';
class GAService {
init() {
ReactGA.initialize('UA-XXXXXXX-X');
//ReactGA.pageview(window.location.pathname + window.location.search);
}
}
const instance = new GAService();
export default instance;

How to increment Firestore field value in python?

shard_ref.update("count", firebase.firestore.FieldValue.increment(1));
I am looking for way to increment and update in python, I am not abe to even update it with a predefined value in python. the doc doesn't specify any python samples.
I am using firebase_admin sdk like this,
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
for more check docs https://firebase.google.com/docs/firestore/solutions/counters
Unfortunately (to me it just doesn't feel right), adding support for transforms in your codebase means you have to use google-cloud-firestore next to firebase_admin.
You can then use Transforms such as Increment, ArrayRemove, etc.
Sample code:
from google.cloud.firestore_v1 import Increment
# assuming shard_ref is a firestore document reference
shard_ref.update({'count': Increment(1)})
another option is use Firebase Realtime Database URL as a REST endpoint. ( All we need to do is append .json to the end of the URL and send a request from our favorite HTTPS client)
for your case, use conditional request. explanation and example described at https://firebase.google.com/docs/database/rest/save-data#section-conditional-requests

Resources