const episodepublishform = {
template: `
Publish Episode
`
}
const message = {
template: `{{ this.$route.params.message }}
`
}
const userlist = {
template: `
New
Username |
Email |
|
{{ item.username }} |
{{ item.email }} |
Edit
|
`,
data() {
return {
loading: false,
items: null,
error: null
}
},
created() {
// fetch the data when the view is created and the data is
// already being observed
this.fetchData()
},
watch: {
// call again the method if the route changes
'$route': 'fetchData'
},
methods: {
fetchData() {
this.error = this.items = []
this.loading = true
get("/admin/listusers", (err, items) => {
this.loading = false
if (err) {
this.error = err.toString()
} else {
var t = JSON.parse(items).reverse();
for (var i = t.length - 1; i >= 0; i--) {
this.items.push({
id: t[i].id,
username: t[i].username,
email: t[i].email,
})
}
}
})
}
}
}
const usernew = {
template: ``
}
const useredit = {
template: ``,
data() {
return {
loading: false,
user: null,
error: null
}
},
created() {
// fetch the data when the view is created and the data is
// already being observed
this.fetchData()
},
watch: {
// call again the method if the route changes
'$route': 'fetchData'
},
methods: {
fetchData() {
this.error = this.user = []
this.loading = true
get("/admin/listusers", (err, items) => {
this.loading = false
if (err) {
this.error = err.toString()
} else {
var t = JSON.parse(items)
for (var i = t.length - 1; i >= 0; i--) {
if (t[i].id == this.$route.params.id) {
this.user = {
id: t[i].id,
username: t[i].username,
email: t[i].email,
realname: t[i].realname
}
}
}
}
})
}
}
}
const episodemanagement = {
template: `
Title |
URL |
|
{{ item.id }}: {{ item.title }} | {{ item.url }} | Edit |
`,
data() {
return {
loading: false,
items: null,
error: null
}
},
created() {
// fetch the data when the view is created and the data is
// already being observed
this.fetchData()
},
watch: {
// call again the method if the route changes
'$route': 'fetchData'
},
methods: {
fetchData() {
this.error = this.items = []
this.loading = true
get("/json", (err, items) => {
this.loading = false
if (err) {
this.error = err.toString()
} else {
var t = JSON.parse(items).items
for (var i = t.length - 1; i >= 0; i--) {
console.log(i)
this.items.push({
title: t[i].title,
url: t[i].url,
id: t[i].id
})
}
}
})
}
}
}
const episodeedit = {
template: ``,
data() {
return {
loading: false,
episode: null,
error: null
}
},
created() {
// fetch the data when the view is created and the data is
// already being observed
this.fetchData()
},
watch: {
// call again the method if the route changes
'$route': 'fetchData'
},
methods: {
fetchData() {
this.error = this.episode = {}
this.loading = true
get("/json", (err, items) => {
this.loading = false
if (err) {
this.error = err.toString()
} else {
var t = JSON.parse(items).items
for (var i = t.length - 1; i >= 0; i--) {
if (t[i].id == this.$route.params.id) {
time = t[i].date_published.split("T")
var prev = time[0] + "_" + t[i].title
this.episode = {
title: t[i].title,
description: t[i].summary,
url: t[i].url,
id: t[i].id,
time: time[0],
previousfilename: prev
}
}
}
}
console.log(this.episode)
})
}
}
}
const customcss = {
template: `
Theme
`,
data() {
return {
loading: false,
css: null,
error: null
}
},
created() {
// fetch the data when the view is created and the data is
// already being observed
this.fetchData()
},
watch: {
// call again the method if the route changes
'$route': 'fetchData'
},
methods: {
fetchData() {
this.error = this.css = null
this.loading = true
get("/admin/css", (err, css) => {
this.loading = false
if (css == "{}") {
this.css = "You aren't allowed to edit this CSS!"
} else {
if (err) {
this.error = err.toString()
} else {
this.css = css
}
}
})
}
}
}
const routes = [
{path: '/', redirect: '/publish'},
{ path: '/publish', component: episodepublishform },
{ path: '/manage', component: episodemanagement },
{ path: '/theme', component: customcss },
{ path: '/edit/:id', component: episodeedit },
{ path: '/users/', component: userlist },
{ path: '/msg/:message', component: message },
{ path: '/user/:id', component: useredit },
{ path: '/users/new', component: usernew }
]
const router = new VueRouter({
routes
})
const app = new Vue({
router,
data: {
header: 'Pogo Admin',
}
}).$mount('#app')
function get(url,callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
if (xmlHttp.responseText == "Unauthorized") {
callback(null, "{}")
} else {
callback(null, xmlHttp.responseText)
}
}
}
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}