BackEnd/YTManager/frontend/index.js

60 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-09-01 08:55:02 +00:00
$(document).foundation();
// How many chars at most for the description.
var maxcharsdescriptionfield = 100;
// Grid if images.
var vidholder = new Vue({
el: '#vidholder-0',
data: {
2017-09-03 01:05:50 +00:00
Videos: []
2017-09-01 08:55:02 +00:00
},
2017-09-03 01:05:50 +00:00
// Template has wrapping div because v-for can't be in root it seems.
template: `
<div>
2018-02-20 21:36:01 +00:00
<div class="grid-x large-up-6">
2017-09-03 01:35:07 +00:00
<div v-for="video in Videos" class="cell">
2018-02-20 21:36:01 +00:00
<div class="card curvedbottom" style="background-color:#ddd9d4; margin:6px;2px;6px;">
2018-02-24 04:14:37 +00:00
<a :href="video.url"><img :src="video.thumbnail"></a>
<div class="card-section" style="padding: 7px 5px 7px">
<div style="font-size: 14px; padding-bottom:10px;">{{ video.title }}</div>
<div style="font-size: 10px; text-align:right">{{ video.channel }}</div>
2017-09-03 01:35:07 +00:00
</div>
2017-09-03 01:05:50 +00:00
</div>
2017-09-03 01:35:07 +00:00
</div>
2017-09-03 01:05:50 +00:00
</div >
</div>
`,
2017-09-01 08:55:02 +00:00
methods: {
// Get new videos from the web api.
retrieve: function (event) {
// Wipe out all old entries.
2017-09-03 01:05:50 +00:00
this.Videos = [];
2017-09-01 08:55:02 +00:00
axios.get('/api/Videos')
.then(function (response) {
// And fill it with all the retrieved entries.
response.data.forEach(function (x) {
// Trim description if needed.
if (x.description.length > maxcharsdescriptionfield) {
x.description = x.description.substring(0, maxcharsdescriptionfield) + " ...";
}
2017-09-03 01:05:50 +00:00
// Generate a new URL by adding the YT ID.
2018-02-24 07:41:45 +00:00
x.url = "https://www.youtube.com/watch?v=" + x.id;
2017-09-01 08:55:02 +00:00
// Add it to our array
2017-09-03 01:05:50 +00:00
this.Videos.push(x);
2017-09-01 08:55:02 +00:00
}.bind(this));
}.bind(this))
.catch(function (error) {
console.log(error);
});
}
}
});
window.addEventListener('load', function () {
vidholder.retrieve();
});