blob: bd81939e307d91a9fe9c0e601b9f6f6442ebac72 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
<template>
<div class="running_processes">
<article class="studip">
<section>
<template v-if="sortedContexts.length === 0">
{{ $gettext('Es sind derzeit keine laufenden Prozesse vorhanden. Sobald für Sie relevante Aufgaben – zum Beispiel Fragebögen aus Ihren Veranstaltungen oder Einrichtungen – verfügbar sind, erscheinen diese hier.') }}
</template>
<ul class="clean" v-if="sortedContexts.length > 0">
<li v-for="context in sortedContexts" :key="context.id">
<a class="context" :href="context.url">
<span class="my-courses-avatar course-avatar-small"
:style="'background-image: url(' + context.avatar + ')'"></span>
{{ context.name }}
</a>
<div class="processes">
<div v-for="process in getProcessesForContext(context)" :key="process.id" class="running_process">
<a :href="process.url"
aria-hidden="true"
tabindex="-1"
:data-dialog="process.dialog ? 'size=auto' : null">
<img :src="process.icon" aria-hidden="true">
</a>
<div class="process_right_side">
<div class="process_text_info">
<div>
<a :href="process.url"
:data-dialog="process.dialog ? 'size=auto' : null">
{{ process.type }}
{{ process.title }}
</a>
<span v-if="process.additionalShortInfo"
:title="process.additionalInfoTitleTag"
class="additionalShortInfo">
{{ process.additionalShortInfo }}
</span>
</div>
<div :title="getDatetimeInfo(process)" aria-live="off">
{{ getRemainingTime(process) }}
</div>
</div>
<div class="progressbar_container">
<div class="progress_bar"
role="progressbar"
:aria-valuenow="Math.floor(((currentTime / 1000) - process.begin) / (process.end - process.begin) * 100)"
aria-valuemax="100"
aria-valuemin="0">
<div :class="process.end - (currentTime / 1000) <= 86400 ? 'progress alerted' : 'progress'"
:style="'width: ' + getProcessPercentage(process) + '%;'"></div>
</div>
</div>
</div>
</div>
</div>
</li>
</ul>
</section>
</article>
</div>
</template>
<script setup>
import { ref, computed, onMounted, onBeforeUnmount } from 'vue';
import { $ngettext } from "../../assets/javascripts/lib/gettext";
import { getRemainingTime as calculateRemainingTime } from "../utils/getRemainingTime";
import { datetime } from "../../assets/javascripts/lib/datetime";
const props = defineProps({
contexts: {
type: Object,
required: true
},
processes: {
type: Array,
required: true
}
});
const currentTime = ref(Date.now());
const intervalId = ref(null);
const sortedContexts = computed(() => {
const contexts = Object.values(props.contexts);
return contexts.sort((a, b) => {
const a_short_end = getProcessesForContext(a)[0].end;
const b_short_end = getProcessesForContext(b)[0].end;
return a_short_end > b_short_end ? 1 : -1;
});
});
function getProcessesForContext(context) {
const processes = props.processes.filter(process => process.context_id === context.id);
return processes.sort((a, b) => {
return a.end > b.end ? 1 : -1;
});
}
function getProcessPercentage(process) {
const now = currentTime.value / 1000;
if (now > process.end) {
return 100;
}
if (now < process.begin) {
return 0;
}
return Math.round((now - process.begin) / (process.end - process.begin) * 100);
}
function getRemainingTime(process) {
const now = Math.floor(currentTime.value / 1000);
if (now > process.end) {
return this.$gettext('Beendet');
}
if (now < process.begin) {
return this.$gettext('Noch nicht gestartet');
}
return calculateRemainingTime(process.end - now, $ngettext);
}
function getDatetimeInfo(process) {
return datetime.getStudipDate(new Date(process.end * 1000));
}
onMounted(() => {
intervalId.value = window.setInterval(() => {
currentTime.value = Date.now();
}, 1000);
});
onBeforeUnmount(() => {
if (intervalId.value) {
clearInterval(intervalId.value);
}
});
</script>
|