Skip to content

Commit

Permalink
adds profile page and updates profile points on upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sdellis committed Jul 28, 2018
1 parent d422303 commit 4cd7379
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 54 deletions.
5 changes: 1 addition & 4 deletions src/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
</q-btn>
</q-toolbar>
</q-layout-header>



<q-page-container>
<router-view />
</q-page-container>
Expand Down Expand Up @@ -103,7 +100,7 @@ export default {
main
text-align center
margin-top 40px
margin-top 0px
header
margin 0
Expand Down
177 changes: 177 additions & 0 deletions src/pages/Profile.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<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>
<p class="total">
<span class="points">{{profile.points}}</span>
<br/>
Total points
</p>
</div>
</q-page>
</template>
<script>
import { Alert } from 'quasar'
import 'quasar-extras/animate/bounceInDown.css'
import 'quasar-extras/animate/bounceOutUp.css'
import { db } from '../plugins/firebase'
export default {
name: 'profile',
firebase: {
trees: db.ref('tree_photos'),
verifiedSimple: db.ref('verified_simple')
},
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: [],
photo: '',
userId: '',
name: '',
email: '',
user: {},
// simplePoints: this.$store.state.simplePoints,
// tagPoints: this.$store.state.tagPoints,
flagToSpamThreshold: this.$store.state.flagToSpamThreshold,
totalFlagged: 0,
flagged: [],
spamToll: 0
}
},
computed: {
profile: {
get () {
return this.$store.state.profile
},
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: {
// tagList () {
// this.tagList = this.trees.filter(tree => tree.user_id === this.userId)
// this.$store.dispatch('setTaglist', tagList)
// return tagList
// },
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
// const alert = Alert.create({
// enter: 'bounceInDown',
// leave: 'bounceOutUp',
// color: 'negative',
// icon: 'tag_faces',
// html: 'Some of your photos were flagged costing you ' + this.spamToll + ' points. <br/>Please be more careful!',
// position: 'top-center',
// actions: [
// {
// label: 'Dismiss',
// handler () {
// reducePoints()
// alert.dismiss()
// }
// }
// ]
// })
}
},
beforeMount: function () {
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
this.profile = this.$store.state.profile
}
this.tagList = this.trees.filter(tree => tree.user_id === this.userId)
this.$store.dispatch('setTaglist', this.tagList)
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>

h1 {
font-size: 30px;
padding-top:20px;
padding-bottom: 0px;
}

.points {
font-size: 7rem;
font-weight: 700;
}
.total {
margin-top: 200px;
width: 100%;
}

</style>
6 changes: 3 additions & 3 deletions src/pages/success.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
detail="You just got points for your tag."
appear
:actions="[
{ label: 'Tag Another', icon: 'alarm', handler: () => { window.location = '#/tag' } },
{ label: 'Verify Photos', icon: 'done', handler: () => { window.location = '#/hello' } }
{ label: 'Tag Another', icon: 'alarm', handler: () => { this.$router.push('/tag') } },
{ label: 'Verify Photos', icon: 'done', handler: () => { this.$router.push('/istree') } }
]"
class="q-mt-md"
>
Expand All @@ -30,7 +30,7 @@

<!-- Marker -->
<gmap-marker
title="Paris"
title="Ash tree"
:position="userPosition" />
</gmap-map>
</div>
Expand Down
61 changes: 23 additions & 38 deletions src/pages/tag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
<div v-if="treePic">
<q-btn @click="uploadPhotos" id="upload" round color="positive" icon="backup" style="cursor:pointer;" size="lg"/>
</div>
<div v-if="tree">
<label v-else for="tree">
<q-btn @click="triggerFileInput" round color="secondary" icon="add_a_photo" style="cursor:pointer;" size="lg"/>
</div>
<!--<label v-else for="tree">
<q-btn @click="triggerFileInput" round color="secondary" icon="add_a_photo" style="cursor:pointer;" size="lg"/>
</label>-->
</label>
</q-page-sticky>
<q-page-sticky v-if="treePic" position="bottom-left" :offset="[18, 18]">
<q-btn @click="reset" round color="negative" icon="cancel" style="cursor:pointer;" size="lg"/>
Expand All @@ -34,9 +31,6 @@
<q-page-sticky position="bottom-right" :offset="[18, 18]">
<q-btn @click="reset" id="success" round color="positive" icon="check" style="cursor:pointer;" size="lg"/>
</q-page-sticky>
<q-page-sticky position="bottom-left" :offset="[18, 18]">
<q-btn @click="updateProfilePoints" id="filesaved" round color="positive" icon="thumb_up" style="cursor:pointer;" size="lg"/>
</q-page-sticky>
</div>
</q-layout>
<input style="display:none" type="file" ref="fileInput" @change="fileAdded($event)" id="fileinput" accept="image/*" :name="uploadFieldName">
Expand Down Expand Up @@ -182,28 +176,13 @@
Loading.hide()
console.error(err.message)
})
//this.updateProfilePoints
},
save (formData) {
// upload data to the server
let key
let imageUrl
// let blob
this.currentStatus = STATUS_SAVING
this.uploadaws(formData)
.then(x => {
Loading.hide()
//this.currentStatus = STATUS_SUCCESS
console.log("Loaded AWS - About to upload firebase")
// save data to database
})
.catch(err => {
Loading.hide()
console.log(error)
// this.uploadError = err.response
this.currentStatus = STATUS_FAILED
})
this.$treesRef.push(this.tree)
.then((data) => {
console.log("Pushed to firebase")
Expand All @@ -230,7 +209,6 @@
})
.then(downloadURL => {
console.log(`Successfully uploaded file and got download link - ${downloadURL}`);
//return downloadURL;
return this.$treesRef.child(key).update({imageUrl: downloadURL})
})
.then(() => {
Expand All @@ -245,16 +223,16 @@
// 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())
})
},
// 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()
Expand All @@ -263,10 +241,17 @@
console.log("about to go to success page")
const p = Object.assign({}, this.profile)
p.points = p.points + this.tagPoints
// add userPoints in firebase
// this.profilesRef.child(this.tree.user_id).update({points: p.points})
// .then(this.$store.dispatch('setProfile', p))
// add userPoints in firebase then update our local store
this.$profilesRef.child(this.tree.user_id).update({points: p.points})
.then(() => {
this.$store.dispatch('setProfile', p)
})
.catch(err => {
console.log(error)
this.currentStatus = STATUS_FAILED
Loading.hide()
})
Loading.hide()
console.log("going to success page")
this.$router.push('/success')
},
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export default ({ app, router, Vue }) => {
Vue.prototype.$firebase = fireb
Vue.prototype.$auth = auth
Vue.prototype.$treesRef = treesRef
Vue.prototype.$profilesRef = profilesRef
Vue.prototype.$storefb = storefb.ref()
Vue.prototype.$db = db
// Vue.use(VueFire)

}
16 changes: 9 additions & 7 deletions src/router/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
export default [
{
path: '/',
component: () => import('layouts/default'),
component: () => import('layouts/Default'),
children: [
{ path: '/', component: () => import('pages/login') },
{ path: '/login', component: () => import('pages/login') },
{ path: '/hello', component: () => import('pages/hello'), meta: {
{ path: '/', component: () => import('pages/Login') },
{ path: '/login', component: () => import('pages/Login') },
{ path: '/hello', component: () => import('pages/Hello'), meta: {
requiresAuth: true }},
{ path: '/tag', component: () => import('pages/tag'), meta: {
{ path: '/tag', component: () => import('pages/Tag'), meta: {
requiresAuth: true }},
{ path: '/identification', component: () => import('pages/Identification'), meta: {
requiresAuth: true }},
{ path: '/success', component: () => import('pages/success'), meta: {
{ path: '/profile', component: () => import('pages/Profile'), meta: {
requiresAuth: true }},
{ path: '/nearbyTrees', component: () => import('pages/nearbyTrees') }
{ path: '/success', component: () => import('pages/Success'), meta: {
requiresAuth: true }},
{ path: '/nearbyTrees', component: () => import('pages/NearbyTrees') }
]
},

Expand Down

0 comments on commit 4cd7379

Please sign in to comment.