Skip to content

Commit 52364a2

Browse files
committed
Added episode edit component & route
1 parent 03da0a1 commit 52364a2

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<template>
2+
<div class="hello">
3+
<h1>Edit {{episode.title}}</h1>
4+
<form enctype="multipart/form-data" action="/admin/edit" method="post">
5+
<label for="title">Episode Title</label>
6+
<input type="text" id="title" name="title" :value="episode.title">
7+
<label for="description">Episode Description</label>
8+
<textarea name="description" id="description" cols="100" rows="20" style="resize: none;">{{ episode.description }}</textarea>
9+
<label for="date">Publish Date</label>
10+
<input type="date" id="date" name="date" :value="episode.time">
11+
<input name="previousfilename" id="previousfilename" :value="episode.previousfilename" type="hidden">
12+
<input type="submit" class="button" value="Publish"></form>
13+
</div>
14+
</template>
15+
16+
<script>
17+
export default {
18+
name: 'EpisodeEdit',
19+
data () {
20+
return {
21+
loading: false,
22+
episode: {},
23+
error: null
24+
}
25+
},
26+
created () {
27+
// fetch the data when the view is created and the data is
28+
// already being observed
29+
this.fetchData()
30+
},
31+
watch: {
32+
// call again the method if the route changes
33+
'$route': 'fetchData'
34+
},
35+
methods: {
36+
fetchData () {
37+
this.error = this.items = []
38+
this.loading = true
39+
40+
fetch('/static/feed.json').then(response => {
41+
return response.text()
42+
}).then(blob => {
43+
this.loading = false
44+
var t = JSON.parse(blob).items
45+
for (var i = t.length - 1; i >= 0; i--) {
46+
if (t[i].id === this.$route.params.id) {
47+
var time = t[i].date_published.split('T')
48+
var prev = time[0] + '_' + t[i].title
49+
this.episode = {
50+
title: t[i].title,
51+
description: t[i].summary,
52+
url: t[i].url,
53+
id: t[i].id,
54+
time: time[0],
55+
previousfilename: prev
56+
}
57+
}
58+
}
59+
})
60+
}
61+
}
62+
}
63+
</script>
64+
65+
<!-- Add "scoped" attribute to limit CSS to this component only -->
66+
<style scoped>
67+
h1, h2 {
68+
font-weight: normal;
69+
}
70+
ul {
71+
list-style-type: none;
72+
padding: 0;
73+
}
74+
li {
75+
display: inline-block;
76+
margin: 0 10px;
77+
}
78+
</style>

admin/src/router/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Vue from 'vue'
22
import Router from 'vue-router'
33
import Publish from '@/components/Publish'
44
import EpisodeList from '@/components/EpisodeList'
5+
import EpisodeEdit from '@/components/EpisodeEdit'
56

67
Vue.use(Router)
78

@@ -16,6 +17,11 @@ export default new Router({
1617
path: '/manage',
1718
name: 'EpisodeList',
1819
component: EpisodeList
20+
},
21+
{
22+
path: '/edit/:id',
23+
name: 'EpisodeEdit',
24+
component: EpisodeEdit
1925
}
2026
]
2127
})

0 commit comments

Comments
 (0)