-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from mauricerenck/develop
Show stats in panel
- Loading branch information
Showing
13 changed files
with
2,741 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"name": "mauricerenck/podcaster", | ||
"version": "1.1.0", | ||
"description": "A podcast plugin for Kirby 3", | ||
"type": "kirby-plugin", | ||
"license": "MIT", | ||
|
@@ -9,7 +10,6 @@ | |
"email": "[email protected]" | ||
} | ||
], | ||
"version": "1.0.6", | ||
"autoload": { | ||
"files": [ | ||
"utils/PodcasterUtils.php", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "podcaster", | ||
"version": "1.1.0", | ||
"description": "Theme", | ||
"main": "index.js", | ||
"author": "Maurice Renck", | ||
"scripts": { | ||
"dev": "parcel watch src/index.js --no-source-maps -d ./", | ||
"build": "parcel build src/index.js --no-source-maps --experimental-scope-hoisting -d ./" | ||
}, | ||
"devDependencies": { | ||
"@vue/component-compiler-utils": "^3.0.0", | ||
"cssnano": "^4.1.10", | ||
"sass": "^1.20.3", | ||
"vue-template-compiler": "^2.6.10" | ||
}, | ||
"dependencies": { | ||
"date-fns": "^2.0.0-alpha.31", | ||
"frappe-charts": "^1.2.0", | ||
"vue": "^2.2.4", | ||
"vue-hot-reload-api": "^2.3.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
<template> | ||
<section class="k-modified-section"> | ||
<div class="podcaster-prev-next"> | ||
<button class="k-link k-button" v-on:click="prevMonth"><k-icon type="angle-left"></button> | ||
<button class="k-link k-button" v-on:click="nextMonth"><k-icon type="angle-right"></button> | ||
</div> | ||
<k-text>{{ error }}</k-text> | ||
<k-headline>{{ headline }}</k-headline> | ||
<table id="episodeStats"> | ||
<tr v-for="episode in episodes"> | ||
<td>{{ episode.downloads }}</td> | ||
<td>{{ episode.title }}</td> | ||
</tr> | ||
</table> | ||
|
||
</section> | ||
</template> | ||
|
||
<script> | ||
import getMonth from 'date-fns/getMonth' | ||
import addMonths from 'date-fns/addMonths' | ||
import subMonths from 'date-fns/subMonths' | ||
import getYear from 'date-fns/getYear' | ||
export default { | ||
data: function() { | ||
return { | ||
currentDate: new Date(), | ||
currentMonthName: null, | ||
currentMonth: null, | ||
currentYear: null, | ||
headline: null, | ||
episodes: [], | ||
error: null, | ||
podcasterSlug: null | ||
} | ||
}, | ||
created: function() { | ||
this.setNewDateVars() | ||
}, | ||
mounted() { | ||
this.podcasterSlug = this.sanitizeTitle(this.pageValues.podcastertitle) | ||
this.getStats() | ||
}, | ||
computed: { | ||
id() { | ||
return this.$store.state.form.current | ||
}, | ||
pageValues() { | ||
return this.$store.getters['form/values'](this.id) | ||
}, | ||
}, | ||
watch: { | ||
currentDate: { | ||
immediate: false, | ||
handler(newVal, oldVal) { | ||
this.getStats() | ||
}, | ||
} | ||
}, | ||
methods: { | ||
getStats() { | ||
fetch('/api/podcaster/stats/'+ this.podcasterSlug + '/year/' + this.currentYear + '/month/' + (this.currentMonth+1), { | ||
method: 'GET', | ||
headers: { | ||
'X-CSRF': panel.csrf, | ||
}, | ||
}) | ||
.then(response => { | ||
if(response.status !== 200) { | ||
throw 'You are tracking your downloads, using the file method. Stats are currently available only when using mysql' | ||
} | ||
return response | ||
}) | ||
.then(response => response.json()) | ||
.then(response => { | ||
this.episodes = this.computeStats(response.stats) | ||
}) | ||
.catch(error => { | ||
this.error = error | ||
console.log(this.error) | ||
}) | ||
}, | ||
computeStats(stats) { | ||
const episodeStats = stats.episodes.map(function(episode) { | ||
return { title: episode.episode.replace(/-/g, ' '), downloads: episode.downloaded } | ||
}) | ||
return episodeStats | ||
}, | ||
prevMonth() { | ||
const newDate = subMonths(this.currentDate, 1) | ||
this.currentDate = newDate | ||
this.setNewDateVars() | ||
}, | ||
nextMonth() { | ||
const newDate = addMonths(this.currentDate, 1) | ||
this.currentDate = newDate | ||
this.setNewDateVars() | ||
}, | ||
setNewDateVars() { | ||
this.currentMonth = getMonth(this.currentDate) | ||
this.currentYear= getYear(this.currentDate) | ||
this.currentMonthName = this.currentDate.toLocaleString('en', { month: 'long' }) | ||
this.headline = 'Stats for ' + this.currentMonthName + ' ' + this.currentYear | ||
}, | ||
sanitizeTitle: function(title) { | ||
var slug = '' | ||
// Change to lower case | ||
var titleLower = title.toLowerCase() | ||
// Letter "e" | ||
slug = titleLower.replace(/e|é|è|ẽ|ẻ|ẹ|ê|ế|ề|ễ|ể|ệ/gi, 'e') | ||
// Letter "a" | ||
slug = slug.replace(/a|á|à|ã|ả|ạ|ă|ắ|ằ|ẵ|ẳ|ặ|â|ấ|ầ|ẫ|ẩ|ậ/gi, 'a') | ||
// Letter "o" | ||
slug = slug.replace(/o|ó|ò|õ|ỏ|ọ|ô|ố|ồ|ỗ|ổ|ộ|ơ|ớ|ờ|ỡ|ở|ợ/gi, 'o') | ||
// Letter "u" | ||
slug = slug.replace(/u|ú|ù|ũ|ủ|ụ|ư|ứ|ừ|ữ|ử|ự/gi, 'u') | ||
// Letter "d" | ||
slug = slug.replace(/đ/gi, 'd') | ||
// Trim the last whitespace | ||
slug = slug.replace(/\s*$/g, '') | ||
// Change whitespace to "-" | ||
slug = slug.replace(/\s+/g, '-') | ||
return slug | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
.k-section-name-podstatsEpisodic { | ||
table { | ||
width: 100%; | ||
border: 1px solid #ccc; | ||
background: #fff; | ||
margin-top: 0.5em; | ||
} | ||
td { | ||
border-bottom: 1px solid #ccc; | ||
line-height: 2; | ||
padding: 0 10px; | ||
} | ||
td:first-child { | ||
text-align: right; | ||
} | ||
.podcaster-prev-next { | ||
display: inline; | ||
text-align: right; | ||
color: #666; | ||
} | ||
.k-headline { | ||
display: inline; | ||
} | ||
.k-text { | ||
color: red; | ||
} | ||
} | ||
</style> |
Oops, something went wrong.