gjestebok
This commit is contained in:
@@ -2,9 +2,7 @@
|
||||
var db = firebase.firestore()
|
||||
|
||||
var list = function(user) {
|
||||
// db.collection('bibliotek').doc("8ZBX5gmIaRwQBCjgLLg0").get().then(function(doc){console.log(doc.data())})
|
||||
// db.collection('bibliotek').get().then(function(query){query.forEach(function(doc){console.log(doc.data())})})
|
||||
db.collection('bibliotek')
|
||||
db.collection("bibliotek")
|
||||
.withConverter(bookConverter)
|
||||
.get()
|
||||
.then(function(query) {
|
||||
@@ -52,9 +50,3 @@ firebase.auth().onAuthStateChanged(function(user) {
|
||||
list(user)
|
||||
})
|
||||
|
||||
/*
|
||||
$(document).ready(function() {
|
||||
list(firebase.auth().currentUser)
|
||||
})
|
||||
*/
|
||||
|
||||
|
@@ -1,47 +0,0 @@
|
||||
|
||||
class Book {
|
||||
constructor(title, author, publisher, rating, published, id=0) {
|
||||
this.cfid = id
|
||||
this.title = title
|
||||
this.author = author
|
||||
this.publisher = publisher
|
||||
this.rating = rating
|
||||
this.published = published
|
||||
}
|
||||
toString() {
|
||||
return this.title+' av '+this.author+', terningkast '+this.rating+', utgitt '+this.published.toString().slice(0,15)+', forlag; '+this.publisher
|
||||
}
|
||||
toHtml(user=false) {
|
||||
let span = function(string, color='red') {
|
||||
return '<span style="color: '+color+'">'+string+'</span>'
|
||||
}
|
||||
return '<p>'+span(this.title)+' av '+span(this.author)+', terningkast '+span(this.rating)+', utgitt '
|
||||
+span(this.published.toString().slice(0,15), 'green')+', forlag; '+span(this.publisher, 'yellow')
|
||||
+(user?' <a class="btn btn-primary" href="javascript: remove(\''+this.cfid+'\')">Slett</a>':'')+'</p>'
|
||||
}
|
||||
}
|
||||
|
||||
bookConverter = {
|
||||
toFirestore: function(book) {
|
||||
let millis = Date.parse(book.published)
|
||||
return {
|
||||
tittel: book.title,
|
||||
forfatter: book.author,
|
||||
forlag: book.publisher,
|
||||
terningkast: book.rating,
|
||||
utgitt: new firebase.firestore.Timestamp(millis/1000, 0)
|
||||
}
|
||||
},
|
||||
fromFirestore: function(snapshot, options) {
|
||||
const data = snapshot.data(options)
|
||||
return new Book(
|
||||
data.tittel,
|
||||
data.forfatter,
|
||||
data.forlag,
|
||||
data.terningkast,
|
||||
data.utgitt.toDate(),
|
||||
snapshot.id
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
<script src="https://www.gstatic.com/firebasejs/7.12.0/firebase-firestore.js"></script>
|
||||
<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
||||
<script type="text/javascript" src="/it1/js/init-firebase.js"></script>
|
||||
<script type="text/javascript" src="/it1/bibliotek/bok.js"></script>
|
||||
<script type="text/javascript" src="/it1/js/converters/bok.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript" id="navbar" src="/it1/js/navbar.js"></script>
|
||||
|
Reference in New Issue
Block a user