-
Notifications
You must be signed in to change notification settings - Fork 556
Expand file tree
/
Copy pathCourseTool.vue
More file actions
196 lines (175 loc) · 4.72 KB
/
Copy pathCourseTool.vue
File metadata and controls
196 lines (175 loc) · 4.72 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<template>
<div class="course-tool">
<BaseAppLink
:aria-labelledby="`course-tool-${tool.iid}`"
:class="cardCustomClass"
:to="resolvedToolTo"
:url="resolvedToolUrl"
class="course-tool__link hover:primary-gradient"
>
<svg
class="course-tool__shadow"
fill="none"
viewBox="0 0 117 105"
xmlns="http://www.w3.org/2000/svg"
>
<path
class="fill-current"
d="M104.167 20.2899C104.167 43.3465 116.11 59.1799 116.11 70.2899C116.11 81.3999 109.723 104.733 58.6133 104.733C7.50333 104.733 0 73.3432 0 61.1232C0 3.89987 104.167 -20.5435 104.167 20.2899Z"
/>
</svg>
<span
:class="tool.tool.icon + ' ' + iconCustomClass"
aria-hidden="true"
class="course-tool__icon mdi"
/>
</BaseAppLink>
<BaseAppLink
:id="`course-tool-${tool.iid}`"
:class="titleCustomClass"
:to="resolvedToolTo"
:url="resolvedToolUrl"
class="course-tool__title"
>
{{ $t(tool.tool.titleToShow) }}
</BaseAppLink>
<div class="course-tool__options">
<button
v-if="
isAllowedToEdit &&
tool.allowChangeVisibility !== false &&
!isSorting &&
!isCustomizing &&
(session?.id ? 'true' === getSetting('session.allow_edit_tool_visibility_in_session') : true)
"
@click="changeVisibility(tool)"
>
<BaseIcon
v-if="isVisible"
icon="eye-on"
/>
<BaseIcon
v-else
class="text-gray-50"
icon="eye-off"
/>
</button>
<!-- a
v-if="securityStore.isCurrentTeacher && isCustomizing"
href="#"
>
<BaseIcon
icon="edit"
size="small"
/>
</a -->
</div>
</div>
</template>
<script setup>
import { computed, inject } from "vue"
import BaseIcon from "../basecomponents/BaseIcon.vue"
import { usePlatformConfig } from "../../store/platformConfig"
import { storeToRefs } from "pinia"
import { useCidReqStore } from "../../store/cidReq"
const platformConfigStore = usePlatformConfig()
const cidReqStore = useCidReqStore()
const { course, session } = storeToRefs(cidReqStore)
const { getSetting } = storeToRefs(platformConfigStore)
const isSorting = inject("isSorting")
const isCustomizing = inject("isCustomizing")
const props = defineProps({
isAllowedToEdit: {
type: Boolean,
required: true,
},
tool: {
type: Object,
required: true,
},
changeVisibility: {
type: Function,
required: true,
},
goToSettingCourseTool: {
type: Function,
required: true,
},
})
const cardCustomClass = computed(() => {
if (!isVisible.value) {
return "bg-primary-bgdisabled hover:bg-gray-50/25 border-primary-borderdisabled shadow-none "
}
if (isSorting.value) {
return "border-2 border-dashed border-primary hover:bg-primary-gradient/10 "
}
return "hover:bg-primary-gradient/10 "
})
const iconCustomClass = computed(() => {
if (!isVisible.value) {
return "bg-gradient-to-b from-gray-50 to-gray-25 "
}
return "bg-primary-bgdisabled "
})
const titleCustomClass = computed(() => {
if (!isVisible.value) {
return "text-gray-90 "
}
return ""
})
function getCourseResourceNodeId() {
return Number(cidReqStore.course?.resourceNode?.id) || Number(course.value?.resourceNode?.id) || 0
}
const isExerciseTool = computed(() => {
const values = [
props.tool?.title,
props.tool?.titleToShow,
props.tool?.name,
props.tool?.tool?.title,
props.tool?.tool?.titleToShow,
props.tool?.tool?.name,
props.tool?.url,
]
.filter(Boolean)
.join(" ")
.toLowerCase()
return (
values.includes("quiz") ||
values.includes("exercise/exercise.php") ||
values.includes("/main/exercise/exercise.php") ||
values.includes("tests") ||
values.includes("exercises")
)
})
const exerciseToolRoute = computed(() => {
if (!isExerciseTool.value) {
return null
}
const nodeId = getCourseResourceNodeId()
const courseId = Number(course.value?.id) || Number(cidReqStore.course?.id) || 0
if (nodeId <= 0 || courseId <= 0) {
return null
}
return {
name: "ExerciseList",
params: { node: nodeId },
query: {
cid: courseId,
sid: Number(session.value?.id) || 0,
gid: 0,
},
}
})
const resolvedToolTo = computed(() => {
return exerciseToolRoute.value || props.tool.to || null
})
const resolvedToolUrl = computed(() => {
return exerciseToolRoute.value ? null : props.tool.url || null
})
const isVisible = computed(() => {
if (typeof props.tool.visibility === "boolean") {
return props.tool.visibility
}
return props.tool.resourceNode?.resourceLinks?.[0]?.visibility === 2
})
</script>