Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions main/templates/main/calendar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'>
<meta http-equiv='x-ua-compatible' content='ie=edge'>
<!--1. Link VCalendar CSS-->
<link rel='stylesheet' href='https://unpkg.com/v-calendar/lib/v-calendar.min.css'>
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/vue-slider-component@3.0.28/dist-css/vue-slider-component.css'>
</head>
<body>
<div id='app'>
<h2>Preview</h2>
<vue-slider :change="randomInterval(value)" v-model="value" :min="1" :max="7" width="50%"></vue-slider>
{{value}}

<v-calendar :attributes="attrs"></v-calendar>

</div>
<!--2. Link Vue Javascript-->
<script src='https://unpkg.com/vue/dist/vue.js'></script>
<!--3. Link VCalendar Javascript (Plugin automatically installed)-->
<script src='https://unpkg.com/v-calendar'></script>
<script src="https://cdn.jsdelivr.net/npm/vue-slider-component@2.8.13/dist/index.min.js"></script>
<!--4. Create the Vue instance-->
<script src="/static/js/calendar.js"></script>

</body>
</html>
76 changes: 76 additions & 0 deletions static/js/calendar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
*
* @param {Date} start
* @param {Date} end
*/
function randomDate(start, end) {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}

var getDateArray = function(start, end) {
var arr = new Array();
var dt = new Date(start);
while (dt <= end) {
arr.push(new Date(dt));
dt.setDate(dt.getDate() + 1);
}
return arr;
}

function randomInterval(interval) {
var date = new Date();
// make array of all dates in current month
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
var dates = getDateArray(firstDay, lastDay)
// loop over them and "flip a coin" for each day to keep/remove
for (i=0 ; i<dates.length; i = i + interval) {
if (Math.floor(Math.random() * 2) == 0) {
dates.splice(i,interval)
}
}
return dates
}


new Vue({
el: '#app',
components: {
'vueSlider': window[ 'vue-slider-component' ],
},
data: {
// Data used by the date picker
mode: 'single',
value: 1,
calDates: [],
attrs: [
{
key: 'today',
highlight: {
backgroundColor: '#ff8080',
// Other properties are available too, like `height` & `borderRadius`
},
dates: randomInterval(1)
}
],
},
methods: {
randomInterval: function(interval) {
var date = new Date();
// make array of all dates in current month
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
var dates = getDateArray(firstDay, lastDay)
// loop over them and "flip a coin" for each day to keep/remove
for (i=0 ; i<dates.length; i = i + interval) {
if (Math.floor(Math.random() * 2) == 0) {
dates.splice(i,interval)
}
}
console.log("ran method randomint")
// cons
this.calDates = dates
return dates
}
}
})