Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of gitlab.com:ctoon/cn-schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
mkody committed Jun 22, 2018
2 parents 096e93e + 820de7c commit 1645179
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 41 deletions.
54 changes: 23 additions & 31 deletions src/App.vue
Expand Up @@ -36,6 +36,7 @@ export default {
data () {
return {
appTitle: 'CN Schedule',
apiBase: 'https://api.ctoon.network/schedule/future',
status: {
error: false,
offline: false,
Expand All @@ -52,8 +53,7 @@ export default {
schedule: {
available: [],
days: {},
selected: [],
stats: {}
selected: []
}
}
},
Expand Down Expand Up @@ -85,15 +85,15 @@ export default {
let sel = this.$route.params.date
// Fetch our API
fetch('https://api.ctoon.network/schedule/days')
fetch(this.apiBase + '/days')
.then(response => {
// Directly return the JSON to our next promise
return response.json()
}, err => {
throw Error(err)
})
.then(data => {
let offset = -2
let offset = -1
let early = data.indexOf(getDate(null, offset))
let late = 0
let firstRange = data.slice(late, early)
Expand All @@ -120,7 +120,7 @@ export default {
this.status.offline = true
this.appTitle += ' (offline)'
let cached = store.get('cachedSchedules')
let cached = store.get('cachedSchedule')
if (cached === undefined) {
this.status.error = 'We asked the browser, it says you\'re offline.\n Also, no cached schedule was found.'
} else {
Expand All @@ -133,47 +133,39 @@ export default {
this.status.ready = false
if (from !== undefined) {
fetch('https://api.ctoon.network/schedule/range/' + from + '/' + to)
fetch(this.apiBase + '/range/' + from + '/' + to)
.then(response => {
// Directly return the JSON to our next promise
return response.json()
}, err => {
console.error(err)
})
.then(data => {
this.schedule.selected = Object.keys(data)
this.schedule.days = data
this.schedule.selected = Object.keys(data)
let cache = store.get('cachedSchedules')
if (!cache) cache = {}
Object.keys(data).forEach(i => {
cache[i] = data[i]
})
store.set('cachedSchedules', cache)
fetch('https://api.ctoon.network/schedule/range/' + from + '/' + to + '/stats')
.then(response => {
// Directly return the JSON to our next promise
return response.json()
}, err => {
console.error(err)
try {
let cache = {}
Object.keys(data).forEach(i => {
cache[i] = data[i]
})
.then(data => {
this.schedule.stats = data
store.set('cachedSchedule', cache)
} catch (err) {
console.log('Couldn\'t save to localstorage', err)
}
// If the current route isn't in the selection, change path
if (this.$route.name === 'Schedule' && this.schedule.selected.indexOf(this.$route.params.date) === -1) {
this.$router.push({ name: 'Schedule', params: { date: from } })
}
// If the current route isn't in the selection, change path
if (this.$route.name === 'Schedule' && this.schedule.selected.indexOf(this.$route.params.date) === -1) {
this.$router.push({ name: 'Schedule', params: { date: from } })
}
setTimeout(_ => {
this.status.ready = true
}, 1000)
})
setTimeout(_ => {
this.status.ready = true
}, 1000)
})
} else {
// load everything we have when offline
this.schedule.days = store.get('cachedSchedules')
this.schedule.days = store.get('cachedSchedule')
this.schedule.selected = Object.keys(this.schedule.days)
setTimeout(_ => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/Grid.vue
Expand Up @@ -101,6 +101,7 @@ export default {
}
},
displaySource (day, index) {
day = day['schedule']
// Add classes to specify source and if it's an old entry
return {
'zap2it': (day.cn === null && day.zap && this.$parent.config.fallback === 'zap'),
Expand All @@ -111,6 +112,7 @@ export default {
}
},
getSchedule (day) {
day = day['schedule']
if (day.cn) return day.cn
if (day.zap && this.$parent.config.fallback === 'zap') return day.zap
if (day.tvguide) return day.tvguide
Expand Down
10 changes: 5 additions & 5 deletions src/components/Schedule.vue
Expand Up @@ -45,7 +45,7 @@

<tab name="[as]">
<div class="message warn" v-if="!schedule.as">
No data from [adult swim]
No data from [adult swim].
</div>
<table>
<schedule-el
Expand All @@ -59,8 +59,8 @@

<tab name="Stats">
<schedule-stats v-if="stats" :day="stats" :fallback="$parent.config.fallback"></schedule-stats>
<div class="message warn" v-if="$parent.status.offline">
No stats available when browsing offline.
<div class="message warn" v-else>
No stats available.
</div>
</tab>
</tabs>
Expand Down Expand Up @@ -101,8 +101,8 @@ export default {
return
}
this.schedule = this.$parent.schedule.days[d]
this.stats = this.$parent.schedule.stats[d]
this.schedule = this.$parent.schedule.days[d]['schedule']
this.stats = this.$parent.schedule.days[d]['stats']
}
},
watch: {
Expand Down
6 changes: 1 addition & 5 deletions src/components/Stats.vue
@@ -1,7 +1,7 @@
<template>
<div class="stats">
<div class="stats-resume">
There's {{ dayStats.length }} shows listed for {{ pd(day.date) }}.
There's {{ dayStats.length }} shows listed.
</div>

<div class="source">
Expand Down Expand Up @@ -36,7 +36,6 @@
</template>

<script>
import { parseDate } from '../assets/dates'
import ColorHash from 'color-hash'
import Chart from 'chart.js/dist/Chart.min.js'
Expand All @@ -53,9 +52,6 @@ export default {
}
},
methods: {
pd (date) {
return parseDate(date, true)
},
showStats (day) {
// Clear data
this.statsCharts = {
Expand Down

0 comments on commit 1645179

Please sign in to comment.