Skip to content

Commit

Permalink
Merge pull request #33 from x-team/poll_questions_ref-#28
Browse files Browse the repository at this point in the history
[WIP] Poll questions ref --closes #28
  • Loading branch information
jacekelgda authored Dec 13, 2017
2 parents f112bee + d7da10a commit 31e189c
Show file tree
Hide file tree
Showing 13 changed files with 398 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env.TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FIREBASE_URL=https://xteam-realtime-polling-app.firebaseio.com
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ yarn-error.log*
*.ntvs*
*.njsproj
*.sln
yarn.lock
.env
3 changes: 2 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"scripts": {},
"env": {
"NPM_CONFIG_PRODUCTION": "false",
"NODE_ENV": "development"
"NODE_ENV": "development",
"FIREBASE_URL": "https://realtime-poll-40c84.firebaseio.com"
},
"formation": {},
"addons": [],
Expand Down
4 changes: 3 additions & 1 deletion config/dev.env.js
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}"`
})
3 changes: 2 additions & 1 deletion config/prod.env.js
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}"`
}
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
"postinstall": "npm run build"
},
"dependencies": {
"dotenv": "^4.0.0",
"element-ui": "^2.0.7",
"firebase": "^4.6.2",
"fs": "0.0.1-security",
"vue": "^2.5.2",
"vue-router": "^3.0.1",
"vuefire": "^1.4.4"
Expand All @@ -31,32 +33,32 @@
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.3.0",
"eslint-friendly-formatter": "^3.0.0",
"eslint-import-resolver-webpack": "^0.8.3",
"eslint-loader": "^1.7.1",
"eslint-plugin-html": "^3.0.0",
"eslint-config-airbnb-base": "^11.3.0",
"eslint-import-resolver-webpack": "^0.8.3",
"eslint-plugin-import": "^2.7.0",
"eventsource-polyfill": "^0.9.6",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1",
"webpack-bundle-analyzer": "^2.9.0",
"node-notifier": "^5.1.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"portfinder": "^1.0.13",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8",
"rimraf": "^2.6.0",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"rimraf": "^2.6.0",
"url-loader": "^0.5.8",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
"portfinder": "^1.0.13",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-server": "^2.9.1",
"webpack-merge": "^4.1.0"
},
Expand Down
74 changes: 74 additions & 0 deletions src/components/CreatePoll.vue
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>
119 changes: 119 additions & 0 deletions src/components/ManagePoll.vue
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>
77 changes: 77 additions & 0 deletions src/components/ResultsNew.vue
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>
Loading

0 comments on commit 31e189c

Please sign in to comment.