/*eslint no-var: "error"*/
/*eslint no-console: "off"*/
/*eslint-disable no-trailing-spaces */
/*eslint-env es6*/
// Put this file in path/to/plugin/amd/src
import {load_strings} from './util/string-helper';
import {format_date, studyplanDates} from './util/date-helper';
export default {
studyplanTiming(plan) {
const now = new Date().getTime();
const dates = studyplanDates(plan);
if(dates.start < now){
if( dates.end && now > dates.end) {
return 'past';
} else {
return 'present';
}
} else {
return 'future';
}
},
install(Vue/*,options*/){
let strings = load_strings({
studyplancard: {
open: "open",
noenddate: "noenddate",
idnumber: "studyplan_idnumber",
description: "studyplan_description",
completed: "completed",
details: "studyplan_details",
},
details: {
details: "studyplan_details",
}
});
// Create new eventbus for interaction between item components
const ItemEventBus = new Vue();
Vue.component('s-studyplan-card', {
props: {
value: {
type: Object,
},
open: {
type: Boolean
},
},
data() {
return {
text: strings.studyplancard
};
},
computed: {
timing(){
const now = new Date().getTime();
const startdate = new Date(this.value.pages[0].startdate).getTime();
const enddate = new Date(this.value.pages[0].enddate).getTime();
let timing = 'future';
if(startdate < now){
if(this.value.pages[0].enddate && now > enddate) {
timing = 'past';
} else {
timing = 'present';
}
}
return timing;
},
dates(){
const dates = studyplanDates(this.value);
return {
start: format_date(dates.start),
end: (dates.end)?format_date(dates.end):this.text.noenddate,
};
},
width_completed() {
if(this.value.progress) {
return this.value.progress * 100;
} else {
return 0;
}
},
width_incomplete() {
if(this.value.progress) {
return (1-this.value.progress) * 100;
} else {
return 100;
}
},
percentage_complete() {
if(this.value.progress) {
return Math.round(this.value.progress * 100) + "%";
} else {
return "0%";
}
}
},
methods: {
onOpenClick(e) {
this.$emit('open',e);
}
},
template: `
{{ value.shortname }}
{{ startdate }} - {{ enddate }}
{{ startdate }} - {{ enddate }}