-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_javascript_firestore.html
132 lines (101 loc) · 3.84 KB
/
index_javascript_firestore.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<html ng-app="myApp">
<head>
<title>My App (test Angularjs + Firebase)</title>
<!-- AngularJS -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js"></script>
<!-- AngularFire -->
<!-- <script src="https://cdn.firebase.com/libs/angularfire/2.3.0/angularfire.min.js"></script>-->
<!-- Firebase -->
<script src="https://www.gstatic.com/firebasejs/4.7.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.7.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.7.0/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.7.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.7.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.7.0/firebase-messaging.js"></script>
<!-- Initialize Firebase -->
<script>
/*var config = {
apiKey: "AIzaSyCAjIvPSOjz9Rmxui_eXn9QgX3nqs6-NYw",
authDomain: "testangularjsfirestore.firebaseapp.com",
databaseURL: "https://testangularjsfirestore.firebaseio.com",
projectId: "testangularjsfirestore",
storageBucket: "",
messagingSenderId: "925116971401"
};*/
var config = {
apiKey: "AIzaSyBSu-3ahJg_66LcLTz-F1Aow_4UVpvGnh8",
authDomain: "gina-parigina.firebaseapp.com",
databaseURL: "https://gina-parigina.firebaseio.com",
projectId: "gina-parigina",
storageBucket: "gina-parigina.appspot.com",
messagingSenderId: "710211075327"
};
firebase.initializeApp(config);
var firestore = firebase.firestore();
// Write
/*for(var i=1; i<=10; i++){
const docRef = firestore.doc("readings/"+i);
docRef.set({
cycleId:rndString(40),
fileId:rndString(40),
chargeId:rndString(40),
customer:rndString(40),
address:rndString(40),
streetNumber:rndNumber(4),
postalCode:rndNumber(5),
city:rndString(40),
province:rndString(2),
customerCode:rndNumber(14),
pod:rndNumber(24),
counterCode:rndString(24),
counterDigits:rndNumber(1),
previousRead:rndNumber(9),
previousReadData:'01/01/2017',
minimumRead:rndNumber(9),
maximumRead:rndNumber(9)
}).then(function(result) {
console.log("Saved");
}).catch(function (error) {
console.log("Error:", error);
});
}*/
var myApp = angular.module("myApp", []);
myApp.controller("myCtrl", ["$scope", "$window", function($scope, $window) {
$scope.readings=[];
$scope.readings.push("via verdi");
$scope.readings.push("via rossi");
$window.firestore.collection("readings").get()
.then(function(result) {
result.forEach(function(doc) {
$scope.readings.push(doc.data().address);
});
$scope.$apply();
});
}]);
</script>
</head>
<body ng-controller="myCtrl">
<div ng-repeat="item in readings">
ADD: {{ item }}
</div>
</body>
<script>
function rndString(length) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < length; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
function rndNumber(length) {
var text = "";
var possible = "0123456789";
for (var i = 0; i < length; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
// Read
//const docRef = firestore.collection("readings").doc("0001916930719195880333547449333142284937");
function CL(s){ console.log(s); }
</script>
</html>