Skip to content

Commit 5724d9a

Browse files
committed
Full application
0 parents commit 5724d9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+24051
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
5+
# local env files
6+
.env.local
7+
.env.*.local
8+
9+
# Log files
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Editor directories and files
15+
.idea
16+
.vscode
17+
*.suo
18+
*.ntvs*
19+
*.njsproj
20+
*.sln
21+
*.sw*
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

bad-puns-tracker-client-vue/package-lock.json

Lines changed: 11736 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "kills-tracker-client",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"serve": "vue-cli-service serve --open",
7+
"build": "vue-cli-service build",
8+
"lint": "vue-cli-service lint"
9+
},
10+
"dependencies": {
11+
"@okta/okta-vue": "^1.0.1",
12+
"axios": "^0.18.0",
13+
"vue": "^2.5.16",
14+
"vue-router": "^3.0.1"
15+
},
16+
"devDependencies": {
17+
"@vue/cli-plugin-babel": "^3.0.0-beta.11",
18+
"@vue/cli-plugin-eslint": "^3.0.0-beta.11",
19+
"@vue/cli-service": "^3.0.0-beta.11",
20+
"vue-template-compiler": "^2.5.16"
21+
},
22+
"babel": {
23+
"presets": [
24+
"@vue/app"
25+
]
26+
},
27+
"eslintConfig": {
28+
"root": true,
29+
"env": {
30+
"node": true
31+
},
32+
"extends": [
33+
"plugin:vue/essential",
34+
"eslint:recommended"
35+
],
36+
"rules": {},
37+
"parserOptions": {
38+
"parser": "babel-eslint"
39+
}
40+
},
41+
"postcss": {
42+
"plugins": {
43+
"autoprefixer": {}
44+
}
45+
},
46+
"browserslist": [
47+
"> 1%",
48+
"last 2 versions",
49+
"not ie <= 8"
50+
]
51+
}
1.12 KB
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
8+
<title>kills-tracker-client</title>
9+
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
10+
</head>
11+
<body>
12+
<noscript>
13+
<strong>We're sorry but kills-tracker-client doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
14+
</noscript>
15+
<div id="app"></div>
16+
<!-- built files will be auto injected -->
17+
</body>
18+
</html>
6.69 KB
Loading
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<template>
2+
<section class="section">
3+
<div class="container">
4+
<nav class="navbar" role="navigation" aria-label="main navigation">
5+
<div class="navbar-menu is-active buttons">
6+
<router-link to="/" tag="button" id='home-button' class="button is-link"> Home </router-link>
7+
<router-link to="/movies" v-if='authenticated' tag="button" id='home-button' class="button is-link"> Movies </router-link>
8+
<button class="button is-link" v-if='authenticated' v-on:click='logout' id='logout-button'> Logout </button>
9+
<button v-else v-on:click='login' id='login-button' class="button is-link"> Login </button>
10+
</div>
11+
</nav>
12+
<router-view></router-view>
13+
</div>
14+
</section>
15+
</template>
16+
17+
<script>
18+
export default {
19+
data: function () {
20+
return {
21+
authenticated: false
22+
}
23+
},
24+
created () {
25+
this.isAuthenticated()
26+
},
27+
watch: {
28+
// Everytime the route changes, check for auth status
29+
'$route': 'isAuthenticated'
30+
},
31+
methods: {
32+
async isAuthenticated () {
33+
this.authenticated = await this.$auth.isAuthenticated()
34+
},
35+
login () {
36+
this.$auth.loginRedirect('/')
37+
},
38+
async logout () {
39+
await this.$auth.logout()
40+
await this.isAuthenticated()
41+
42+
// Navigate back to home
43+
this.$router.push({ path: '/' })
44+
}
45+
}
46+
}
47+
</script>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<template>
2+
<form @submit.prevent="onSubmit">
3+
<span class="help is-danger" v-text="errors"></span>
4+
5+
<div class="field">
6+
<div class="control">
7+
<input class="input" type="title" placeholder="enter movie title..." v-model="title" @keydown="errors = ''">
8+
</div>
9+
</div>
10+
11+
<button class="button is-primary" v-bind:class="{ 'is-loading' : isLoading }">Add Movie</button>
12+
</form>
13+
</template>
14+
15+
<script>
16+
import axios from 'axios'
17+
18+
export default {
19+
data() {
20+
return {
21+
title: '',
22+
errors: '',
23+
isLoading: false
24+
}
25+
},
26+
methods: {
27+
onSubmit() {
28+
this.isLoading = true
29+
this.postMovie()
30+
},
31+
async postMovie() {
32+
axios.defaults.headers.common['Authorization'] = `Bearer ${await this.$auth.getAccessToken()}`
33+
axios.post('http://localhost:8000/movies', this.$data)
34+
.then(response => {
35+
this.title = ''
36+
this.isLoading = false
37+
this.$emit('completed', response.data)
38+
})
39+
.catch(error => {
40+
// handle authentication and validation errors here
41+
this.errors = error.response.data.errors
42+
this.isLoading = false
43+
})
44+
}
45+
}
46+
}
47+
</script>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<template>
2+
<div>
3+
<span class="help is-info" v-if="isLoading">Loading...</span>
4+
<table class="table" v-else>
5+
<thead>
6+
<tr>
7+
<th>ID</th>
8+
<th>Title</th>
9+
<th>Bad Puns Count</th>
10+
<th>Actions</th>
11+
</tr>
12+
</thead>
13+
<tbody>
14+
<template v-for="movie in movies">
15+
<tr v-bind:key="movie.id">
16+
<td>{{ movie.id }}</td>
17+
<td>{{ movie.title }}</td>
18+
<td>{{ movie.count }}</td>
19+
<td>
20+
<form @submit.prevent="onSubmit(movie)">
21+
<button class="button is-primary" v-bind:class="{ 'is-loading' : isCountUpdating(movie.id) }">Increase Count</button>
22+
</form>
23+
</td>
24+
</tr>
25+
</template>
26+
</tbody>
27+
</table>
28+
<movie-form @completed="addMovie"></movie-form>
29+
</div>
30+
</template>
31+
32+
<script>
33+
import axios from 'axios'
34+
import Vue from 'vue'
35+
import MovieForm from './MovieForm.vue'
36+
37+
export default {
38+
components: {
39+
MovieForm
40+
},
41+
data() {
42+
return {
43+
movies: {},
44+
isLoading: true,
45+
countUpdatingTable: []
46+
}
47+
},
48+
async created () {
49+
axios.defaults.headers.common['Authorization'] = `Bearer ${await this.$auth.getAccessToken()}`
50+
try {
51+
const response = await axios.get('http://localhost:8000/movies')
52+
this.movies = response.data
53+
this.isLoading = false
54+
} catch(e) {
55+
// handle authentication error here
56+
}
57+
},
58+
methods: {
59+
onSubmit(movie) {
60+
Vue.set(this.countUpdatingTable, movie.id, true)
61+
this.increaseCount(movie)
62+
},
63+
async increaseCount(movie) {
64+
axios.defaults.headers.common['Authorization'] = `Bearer ${await this.$auth.getAccessToken()}`
65+
axios.post('http://localhost:8000/movies/' + movie.id + '/count')
66+
.then(response => {
67+
movie.count = response.data.count
68+
this.countUpdatingTable[movie.id] = false
69+
})
70+
.catch(() => {
71+
// handle authentication and validation errors here
72+
this.countUpdatingTable[movie.id] = false
73+
})
74+
},
75+
isCountUpdating(id) {
76+
return this.countUpdatingTable[id]
77+
},
78+
addMovie(movie) {
79+
this.movies.push(movie)
80+
}
81+
}
82+
}
83+
</script>

0 commit comments

Comments
 (0)