forked from learningequality/kolibri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelectFromBookmarks.vue
174 lines (155 loc) · 4.29 KB
/
SelectFromBookmarks.vue
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
<template>
<div>
<QuizResourceSelectionHeader
v-if="target === SelectionTarget.QUIZ && !settings.selectPracticeQuiz"
class="mb-16"
hideSearch
:settings="settings"
/>
<UpdatedResourceSelection
canSelectAll
:contentList="contentList"
:hasMore="hasMore"
:disabled="disabled"
:channelsLink="channelsLink"
:fetchMore="fetchMore"
:loadingMore="loadingMore"
:multi="!settings?.selectPracticeQuiz"
:selectionRules="selectionRules"
:selectAllRules="selectAllRules"
:getResourceLink="getResourceLink"
:selectedResources="selectedResources"
:contentCardMessage="contentCardMessage"
:unselectableResourceIds="unselectableResourceIds"
@selectResources="$emit('selectResources', $event)"
@deselectResources="$emit('deselectResources', $event)"
@setSelectedResources="$emit('setSelectedResources', $event)"
/>
</div>
</template>
<script>
import { getCurrentInstance } from 'vue';
import { now } from 'kolibri/utils/serverClock';
import { coreStrings } from 'kolibri/uiText/commonCoreStrings';
import UpdatedResourceSelection from '../UpdatedResourceSelection.vue';
import { PageNames } from '../../../../constants';
import { SelectionTarget } from '../contants';
import QuizResourceSelectionHeader from '../QuizResourceSelectionHeader.vue';
/**
* @typedef {import('../../../../composables/useFetch').FetchObject} FetchObject
*/
export default {
name: 'SelectFromBookmarks',
components: {
UpdatedResourceSelection,
QuizResourceSelectionHeader,
},
setup(props) {
const { selectFromBookmarks$, bookmarkedTimeAgoLabel$ } = coreStrings;
const instance = getCurrentInstance();
props.setTitle(selectFromBookmarks$());
const redirectBack = () => {
instance.proxy.$router.push({
name:
props.target === SelectionTarget.LESSON
? PageNames.LESSON_SELECT_RESOURCES_INDEX
: PageNames.QUIZ_SELECT_RESOURCES_INDEX,
});
};
props.setGoBack(redirectBack);
const channelsLink = {
name:
props.target === SelectionTarget.LESSON
? PageNames.LESSON_SELECT_RESOURCES_INDEX
: PageNames.QUIZ_SELECT_RESOURCES_INDEX,
};
const { data, hasMore, fetchMore, loadingMore } = props.bookmarksFetch;
const contentCardMessage = content => {
if (!content.bookmark?.created) {
return null;
}
const createdDate = new Date(content.bookmark.created);
const time = instance.proxy.$formatRelative(createdDate, { now: now() });
return bookmarkedTimeAgoLabel$({ time });
};
return {
channelsLink,
contentList: data,
hasMore,
fetchMore,
loadingMore,
contentCardMessage,
SelectionTarget,
};
},
props: {
setTitle: {
type: Function,
default: () => {},
},
setGoBack: {
type: Function,
default: () => {},
},
/**
* Fetch object for fetching bookmarks.
* @type {FetchObject}
*/
bookmarksFetch: {
type: Object,
required: true,
},
selectionRules: {
type: Array,
required: false,
default: () => [],
},
selectAllRules: {
type: Array,
required: false,
default: () => [],
},
selectedResources: {
type: Array,
required: true,
},
unselectableResourceIds: {
type: Array,
required: false,
default: null,
},
disabled: {
type: Boolean,
default: false,
},
/**
* The target entity for the selection.
* It can be either 'quiz' or 'lesson'.
*/
target: {
type: String,
required: true,
},
/**
* Selection settings used for quizzes.
*/
settings: {
type: Object,
required: false,
default: null,
},
/**
* Function that receives a resourceId and returns a link to the resource.
*/
getResourceLink: {
type: Function,
required: true,
},
},
};
</script>
<style lang="scss" scoped>
.mb-16 {
margin-bottom: 16px;
}
</style>