-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from x-team/poll_questions_ref-#28
[WIP] Poll questions ref --closes #28
- Loading branch information
Showing
13 changed files
with
398 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FIREBASE_URL=https://xteam-realtime-polling-app.firebaseio.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ yarn-error.log* | |
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
yarn.lock | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
'use strict' | ||
const merge = require('webpack-merge') | ||
const prodEnv = require('./prod.env') | ||
require('dotenv').config() | ||
|
||
module.exports = merge(prodEnv, { | ||
NODE_ENV: '"development"' | ||
NODE_ENV: '"development"', | ||
FIREBASE_URL: `"${process.env.FIREBASE_URL}"` | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
'use strict' | ||
module.exports = { | ||
NODE_ENV: '"production"' | ||
NODE_ENV: '"production"', | ||
FIREBASE_URL: `"${process.env.FIREBASE_URL}"` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<template> | ||
<div class="create-poll"> | ||
<el-form :inline="true" :model="poll" class="demo-form-inline"> | ||
<el-form-item> | ||
<el-input v-model="poll.name" placeholder="Poll name"></el-input> | ||
</el-form-item> | ||
<el-form-item> | ||
<el-button type="primary" @click="createPoll">Activate</el-button> | ||
</el-form-item> | ||
</el-form> | ||
<h3>{{ this.voteUrl }}</h3> | ||
<p><a :href="this.voteUrl" target="_blank">open</a></p> | ||
<p>This is your share link</p> | ||
</div> | ||
</template> | ||
<script> | ||
import ResultsNew from './ResultsNew'; | ||
import db from '../services/firebase'; | ||
const polls = db.ref('/'); | ||
export default { | ||
name: 'CreatePoll', | ||
data() { | ||
return { | ||
isLoading: true, | ||
poll: { | ||
id: polls.push().key, | ||
name: '', | ||
isActive: false, | ||
hasQuestions: false, | ||
questions: [], | ||
}, | ||
}; | ||
}, | ||
computed: { | ||
voteUrl() { | ||
return `${location.href}vote-new/${this.poll.id}`; | ||
}, | ||
}, | ||
components: { | ||
ResultsNew, | ||
}, | ||
firebase: { | ||
polls: { | ||
source: polls, | ||
readyCallback() { | ||
this.isLoading = false; | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
createPoll() { | ||
this.poll.isActive = true; | ||
polls.child(this.poll.id).set(this.poll); | ||
this.$router.push(`/polls/${this.poll.id}`); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
<style scoped> | ||
h1, h2, h3 { | ||
margin: 0; | ||
} | ||
.polls { | ||
max-width: 600px; | ||
margin: auto; | ||
list-style: none; | ||
} | ||
.box-card { | ||
margin: 10px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<template> | ||
<div class="poll" v-loading="isLoading"> | ||
<h2>Add question</h2> | ||
<h3><a :href="`#/vote-new/${poll.id}`">Vote</a></h3> | ||
<el-form :inline="true" :model="question" class="demo-form-inline" v-if="!this.isLoading"> | ||
<el-form-item> | ||
<el-input v-model="question.first.value" placeholder="Option A"></el-input> | ||
</el-form-item> | ||
<el-form-item>OR</el-form-item> | ||
<el-form-item> | ||
<el-input v-model="question.second.value" placeholder="Option B"></el-input> | ||
</el-form-item> | ||
<el-form-item> | ||
<el-button type="primary" @click="addQuestion">Publish</el-button> | ||
</el-form-item> | ||
</el-form> | ||
<ul class="polls" v-loading="isLoading" v-if="poll.hasQuestions"> | ||
<li v-for="question in reverseItems"> | ||
<el-card class="box-card" v-bind:class="{ active: question.isActive }"> | ||
<el-row> | ||
{{ question.first.value }} or {{ question.second.value }} | ||
</el-row> | ||
</el-card> | ||
</li> | ||
</ul> | ||
</div> | ||
</template> | ||
<script> | ||
import db from '../services/firebase'; | ||
const polls = db.ref('/'); | ||
export default { | ||
name: 'ManagePoll', | ||
data() { | ||
return { | ||
isLoading: true, | ||
question: { | ||
isActive: true, | ||
first: { | ||
value: '', | ||
votes: 0, | ||
}, | ||
second: { | ||
value: '', | ||
votes: 0, | ||
}, | ||
}, | ||
}; | ||
}, | ||
firebase() { | ||
return { | ||
poll: { | ||
source: db.ref().child(`/${this.$route.params.id}`), | ||
asObject: true, | ||
readyCallback() { | ||
this.isLoading = false; | ||
}, | ||
}, | ||
}; | ||
}, | ||
computed: { | ||
reverseItems() { | ||
return this.poll.questions.slice().reverse(); | ||
}, | ||
}, | ||
methods: { | ||
addQuestion() { | ||
if (!this.poll.hasQuestions) { | ||
this.poll.hasQuestions = true; | ||
this.poll.questions = []; | ||
} | ||
for (let i = 0; i < this.poll.questions.length; i += 1) { | ||
this.poll.questions[i].isActive = false; | ||
} | ||
this.poll.questions.push(this.question); | ||
polls.child(this.poll.id).set({ | ||
id: this.poll.id, | ||
name: this.poll.name, | ||
isActive: this.poll.isActive, | ||
hasQuestions: this.poll.hasQuestions, | ||
questions: this.poll.questions, | ||
}); | ||
this.question = { | ||
isActive: true, | ||
first: { | ||
value: '', | ||
votes: 0, | ||
}, | ||
second: { | ||
value: '', | ||
votes: 0, | ||
}, | ||
}; | ||
}, | ||
}, | ||
}; | ||
</script> | ||
<style scoped> | ||
.poll { | ||
max-width: 600px; | ||
margin: auto; | ||
list-style: none; | ||
} | ||
.polls { | ||
max-width: 600px; | ||
margin: auto; | ||
list-style: none; | ||
} | ||
.box-card { | ||
margin: 10px; | ||
} | ||
.active { | ||
background-color: #98FB98; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<template> | ||
<div v-loading="isLoading"> | ||
<div v-if="!this.isLoading"> | ||
<el-col :span="12"> | ||
<h2 class="grid-content"> | ||
{{ activeQuestion.first.value }} | ||
</h2> | ||
<h3 class="grid-content"> | ||
{{ activeQuestion.first.votes }} votes | ||
</h3> | ||
</el-col> | ||
<el-col :span="12"> | ||
<h2 class="grid-content"> | ||
{{ activeQuestion.second.value }} | ||
</h2> | ||
<h3 class="grid-content"> | ||
{{ activeQuestion.second.votes }} votes | ||
</h3> | ||
</el-col> | ||
<el-col :span="24" class="bar-container"> | ||
<div v-bind:style="{width: activeQuestion.first.votes / (activeQuestion.first.votes + activeQuestion.second.votes) * 100 + '%' }" class="bar bg-red"/> | ||
<div v-bind:style="{width: activeQuestion.second.votes / (activeQuestion.first.votes + activeQuestion.second.votes) * 100 + '%' }" class="bar bg-blue"/> | ||
</el-col> | ||
</div> | ||
</div> | ||
</template> | ||
<script> | ||
import db from '../services/firebase'; | ||
export default { | ||
name: 'ResultsNew', | ||
props: ['pollId', 'questionId'], | ||
data() { | ||
return { | ||
isLoading: false, | ||
}; | ||
}, | ||
computed: { | ||
activeQuestion() { | ||
return this.poll.questions.filter(question => (question.isActive))[0]; | ||
}, | ||
}, | ||
firebase() { | ||
return { | ||
poll: { | ||
source: db.ref().child(`/${this.pollId}`), | ||
asObject: true, | ||
readyCallback() { | ||
this.isLoading = false; | ||
}, | ||
}, | ||
}; | ||
}, | ||
}; | ||
</script> | ||
<style scoped> | ||
.polls { | ||
max-width: 600px; | ||
margin: auto; | ||
list-style: none; | ||
} | ||
.bg-red { | ||
background-color: #409EFF; | ||
} | ||
.bg-blue { | ||
background-color: #67C23A; | ||
} | ||
.bar { | ||
height: 20px; | ||
margin-top: 5px; | ||
} | ||
.bar-container { | ||
display: flex; | ||
margin: 10px 0 30px; | ||
} | ||
</style> |
Oops, something went wrong.