Skip to content

Commit

Permalink
fixes all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
sdellis committed Jul 29, 2018
1 parent 0ec8d96 commit b38037e
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 143 deletions.
3 changes: 0 additions & 3 deletions src/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ export default {
// this.$store.dispatch('logout')
auth.logout()
this.$store.dispatch('resetState', this.$store.state)
console.log("I logged out")
// this.$store.dispatch('resetState', this.$store.state)
// window.location.reload()
},
help() {
this.$router.push('/identification')
Expand Down
47 changes: 39 additions & 8 deletions src/pages/IsTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<q-carousel ref="carousel">
<q-carousel-slide v-for="isTree in isTreeList" :key="isTree['.key']" >
<img class="slideImg" :src="isTree.s3url"/>
<p style="color:white">{{ isTree['.key'] }}</p>
</q-carousel-slide>
</q-carousel>
<p>Viewing {{ currentSlideIndex + 1 }} out of {{ isTreeList.length }}</p>
Expand Down Expand Up @@ -46,12 +45,14 @@ export default {
// profiles: this.$root.profiles,
// profilesRef: this.$root.$firebaseRefs.profiles,
// verifiedSimpleRef: this.$root.$firebaseRefs.verifiedSimple,
flagToSpamThreshold: this.$store.state.flagToSpamThreshold,
photo: '',
userId: '',
name: '',
email: '',
user: {},
simplePoints: this.$store.state.simplePoints,
tagPoints: this.$store.state.tagPoints,
currentSlideIndex: 0
}
},
Expand All @@ -73,8 +74,8 @@ export default {
return this.currentSlideIndex + 1 === this.isTreeList.length
},
valid (bool) {
// console.log(this.trees[this.currentSlideIndex]['.key'])
let treeRef = this.trees[this.currentSlideIndex]['.key']
let treeRef = this.isTreeList[this.currentSlideIndex]['.key']
let submittedBy = this.isTreeList[this.currentSlideIndex].user_id
let userId = this.userId
let verification = {}
verification[userId] = bool
Expand All @@ -88,16 +89,46 @@ export default {
// instead of logging to console after promise completes
// should it attempt to remove points from user? or do that next time
// the user logs in?
var _this = this
db.ref('verified_simple').orderByKey()
.equalTo(this.trees[this.currentSlideIndex]['.key'])
.equalTo(this.isTreeList[this.currentSlideIndex]['.key'])
.once('value')
.then(function (snapshot) {
var value = snapshot.val()
if (value) {
// if it exists we can update a user to the list
value[treeRef][userId] = bool
db.ref('verified_simple').child(treeRef).set(value[treeRef]).then(console.log('verified!'))
// if it exists, we should first check how many false verifications it has against our threshold
var trueCount = 0
var falseCount = 0
for (var property in value[treeRef]) {
if (value[treeRef].hasOwnProperty(property)) {
if(value[treeRef][property] === true){
trueCount++
} else {
falseCount++
}
}
}
// and if it's spam let's reduce the points of the user who submitted it
// and then remove it from the tree_photos and verifiedSimple
if (falseCount > _this.flagToSpamThreshold){
db.ref('user_profiles').orderByKey()
.equalTo(submittedBy)
.once('value')
.then(function (snapshot) {
var value = snapshot.val()
var newFlagged = value[submittedBy].flagged + 1
var newPoints = value[submittedBy].points - _this.tagPoints
db.ref('user_profiles').child(submittedBy).update({flagged: newFlagged, points: newPoints})
.then(db.ref('tree_photos').child(treeRef).remove())
.then(db.ref('verified_simple').child(treeRef).remove())
})
} else {
// otherwise, we can update a user to the list
value[treeRef][userId] = bool
db.ref('verified_simple').child(treeRef).set(value[treeRef]).then(console.log('verified!'))
}
}
else {
// if it doesn't exist, we need to create the node
Expand Down
5 changes: 0 additions & 5 deletions src/pages/Leaderboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ export default {
},
computed: {
topUsers() {
// let topUsers = this.profiles.orderByChild('points').limitToLast(10)
// let topUsers = db.ref('user_profiles').sort(function (a, b) { return (a.points > b.points) ? 1 : ((b.points > a.points) ? -1 : 0) })
//topUsers = topUsers.slice(-3)
//return topUsers.reverse()
console.log(this.leaders)
return this.leaders.reverse()
}
}
Expand Down
78 changes: 5 additions & 73 deletions src/pages/Profile.vue
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
<template>
<q-page padding>
<div class="panel-body">
<!-- <transition
enter-active-class="animated bounceInLeft"
leave-active-class="animated bounceOutRight"
appear
>
<q-alert
color="secondary"
icon="tag_faces"
message="Hoot, there it is!"
detail="You just got points for your tag."
appear
:actions="[
{ label: 'Tag Another', icon: 'alarm', handler: () => { this.$router.push('/tag') } },
{ label: 'Verify Photos', icon: 'done', handler: () => { this.$router.push('/istree') } }
]"
class="q-mt-md"
>
</q-alert>
</transition> -->

<h1>{{name}} has {{tagList.length}} tags and {{flaggedList.length}} flagged photos.</h1>
<h1>{{name}} has {{tagList.length}} tags and {{profile.flagged}} flagged photos.</h1>
<p class="total">
<span class="points">{{profile.points}}</span>
<br/>
Expand All @@ -44,23 +24,14 @@ export default {
},
data: function () {
return {
// trees: this.$firebase.trees,
// treesRef: this.$treesRef,
// profiles: this.$root.profiles,
// profilesRef: this.$root.$firebaseRefs.profiles,
// verifiedSimple: this.$firebase.verifiedSimple,
// verifiedSimpleRef: this.$root.$firebaseRefs.verifiedSimple,
// taglist: this.trees.filter(tree => tree.user_id === this.userId),
photo: '',
userId: '',
name: '',
email: '',
user: {},
// simplePoints: this.$store.state.simplePoints,
// tagPoints: this.$store.state.tagPoints,
flagToSpamThreshold: this.$store.state.flagToSpamThreshold,
totalFlagged: 0,
flagged: [],
flagged: this.flaggedList,
spamToll: 0
}
},
Expand All @@ -80,52 +51,13 @@ export default {
set () {
// something here
}
},
flaggedList () {
const flagToSpamThreshold = this.flagToSpamThreshold
let tagList = this.tagList
function isFlagged (value) {
let vals = Object.values(value)
var counts = {}
vals.forEach(function (x) { counts[x] = (counts[x] || 0) + 1 })
if (counts.false > flagToSpamThreshold) {
// find flagged in tagList
let found = tagList.find(function (element) {
return element['.key'] === value['.key']
})
return found
}
}
var flaggedList = this.verifiedSimple.filter(isFlagged)
this.totalFlagged = flaggedList.length
this.flagged = flaggedList
if (this.totalFlagged) {
this.photosFlaggedAlert()
}
return flaggedList
}
},
methods: {
removeFlagged () {
// Removes flagged photos from tree_photos and photo references on the flagged list
let i
for (i = 0; i < this.totalFlagged; i++) {
this.treesRef.child(this.flagged[i]['.key']).remove()
.then(this.verifiedSimpleRef.child(this.flagged[i]['.key']).remove())
}
},
reducePoints () {
let newProfile = Object.assign({}, this.profile)
newProfile.points = newProfile.points - this.spamToll
this.$store.dispatch('setProfile', newProfile)
this.$profilesRef.child(this.userId).update({points: newProfile.points})
.then(this.removeFlagged())
},
photosFlaggedAlert () {
this.spamToll = this.totalFlagged * this.tagPoints
console.log(this.spamToll)
// let reducePoints = this.reducePoints
// Here we should let the user know how much the flagged photos have cost them.
// this.spamToll = this.profile.flagged * this.tagPoints
// const alert = Alert.create({
// enter: 'bounceInDown',
// leave: 'bounceOutUp',
Expand Down
10 changes: 0 additions & 10 deletions src/pages/hello.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,8 @@
computed: {
user() {
return this.$store.getters.getUser
console.log("hello: ")
}
}
/*created() {
if (this.$store.state.user) {
this.user = this.$store.state.user
this.name = this.$store.state.user.displayName
this.email = this.$store.state.user.email
// this.photo = this.$store.state.user.photoURL
this.userId = this.$store.state.user.uid
}
}*/
}
</script>

Expand Down
2 changes: 0 additions & 2 deletions src/pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
signInSuccessWithAuthResult: function (authResult, redirectUrl) {
var user = authResult.user;
var credential = authResult.credential;
console.log("user: " + user.displayName);
this.sendToStore(user);
return true;
}.bind(this)
Expand All @@ -37,7 +36,6 @@
},
methods: {
sendToStore(user) {
console.log(user)
this.$store.dispatch('setUser', user); //|| false)
this.$router.push('/hello')
}
Expand Down
14 changes: 0 additions & 14 deletions src/pages/nearbyTrees.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,6 @@ export default {
}
},
methods: {
/*submitTree () {
treeRef.push({ashtype: this.treetype, picsnapper: this.picsnapper, date: new Date().toISOString(), ss3url: this.photoUrl})
.then((data) => {
const key = data.key
geoFire.set(key, [this.testLat, this.testLng])
})
.then(() => {
console.log('key: ' + 'location has been added to geofire')
})
.catch((error) => {
console.log(error)
})*/
//},
getLocations (radius, coords) {
console.log('Coords ' + coords)
this.hits.length = 0
Expand Down
28 changes: 3 additions & 25 deletions src/pages/tag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,35 +185,26 @@
this.$treesRef.push(this.tree)
.then((data) => {
console.log("Pushed to firebase")
key = data.key
console.log(key)
geoFire.set(key, [this.tree.loc.lat, this.tree.loc.lng])
})
.then(() => {
console.log('key: ' + key + ' location has been added to geofire')
})
// .then(() => {
// console.log('key: ' + key + ' location has been added to geofire')
// })
.catch((error) => {
console.log(error)
this.currentStatus = STATUS_FAILED
// this.uploadError = err.response
})
const storageRef = fireb.storage().ref('tree_photos/'+ this.img_name)
const uploadTask = storageRef.put(this.blob)
/* uploadTask.on('state_changed', function progress(snapshot) {
console.log(snapshot.totalBytesTransferred); // progress of upload
})*/
uploadTask.then((snapshot) => {
return snapshot.ref.getDownloadURL(); // Will return a promise with the download link
})
.then(downloadURL => {
console.log(`Successfully uploaded file and got download link - ${downloadURL}`);
return this.$treesRef.child(key).update({s3url: downloadURL})
})
.then(() => {
//this.updateProfilePoints
console.log("downloadURL added to tree_photo in database")
this.currentStatus = STATUS_SUCCESS
this.updateProfilePoints()
})
Expand All @@ -223,22 +214,10 @@
// this.uploadError = err.response
})
},
// uploadaws(formData) {
// const url = 'https://s3.amazonaws.com/ash-tree-photos'
// return this.$axios.post(url, formData)
// .then(function (response) {
// console.log("Loaded AWS") //response.data
// })
// .catch(function (error) {
// console.log(error + Date.now())
// })
// },
triggerFileInput () {
this.$refs.fileInput.click()
},
updateProfilePoints () {
console.log("about to go to success page")
const p = Object.assign({}, this.profile)
p.points = p.points + this.tagPoints
// add userPoints in firebase then update our local store
Expand All @@ -252,7 +231,6 @@
Loading.hide()
})
Loading.hide()
console.log("going to success page")
this.$router.push('/success')
},
getPreciseLocation () {
Expand Down
3 changes: 0 additions & 3 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const state = Object.assign({}, initialState)
const mutations = {
SET_USER (state, user) {
state.user = user
console.log("Mutation User: " + user.displayName)
console.log("New user state: " + state.user.displayName)
},
SET_PROFILE (state, profile) {
state.profile = profile
Expand All @@ -43,7 +41,6 @@ const mutations = {

const actions = {
setUser ({commit}, user) {
console.log("SetUser Action :" + user.displayName)
commit('SET_USER', user)
if (user) {
fireb.database().ref('user_profiles').orderByChild('user_email')
Expand Down

0 comments on commit b38037e

Please sign in to comment.