Skip to content

Commit 50651fc

Browse files
committed
Refactoring course catalogue - refs BT#22255
1 parent 5bbca45 commit 50651fc

File tree

6 files changed

+287
-343
lines changed

6 files changed

+287
-343
lines changed

assets/css/scss/_catalog_course.scss

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +0,0 @@
1-
::v-deep(.p-paginator) {
2-
.p-paginator-current {
3-
margin-left: auto;
4-
}
5-
}
6-
.course-image {
7-
width: 130px;
8-
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23)
9-
}
10-
.p-input-icon-left > i:first-of-type {
11-
left: 0.75rem;
12-
color: #6c757d;
13-
}
14-
.p-input-icon-left > i, .p-input-icon-right > i {
15-
margin-top: -.5rem;
16-
position: absolute;
17-
top: 50%;
18-
}
19-
::v-deep(.p-datatable.p-datatable-courses) {
20-
.p-datatable-header {
21-
padding: 1rem;
22-
text-align: left;
23-
font-size: 1.5rem;
24-
}
25-
26-
.p-paginator {
27-
padding: 1rem;
28-
}
29-
30-
.p-datatable-thead > tr > th {
31-
text-align: left;
32-
}
33-
34-
.p-datatable-tbody > tr > td {
35-
cursor: auto;
36-
}
37-
}

assets/vue/components/basecomponents/BaseRating.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ const emit = defineEmits(["change"])
2121
v-model="model"
2222
:cancel="false"
2323
:stars="stars"
24-
@change="emit('change', $event, model)"
24+
@change="emit('change', $event)"
2525
/>
2626
</template>

assets/vue/components/basecomponents/ChamiloIcons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const chamiloIconToClass = {
5858
"file-text": "mdi mdi-file-document",
5959
"file-upload": "mdi mdi-file-upload",
6060
"file-video": "mdi mdi-file-video",
61+
"filter": "mdi mdi-filter",
6162
"fit-to-screen": "",
6263
"folder-generic": "mdi mdi-folder",
6364
"folder-multiple-plus": "mdi mdi-folder-multiple-plus",
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { ref } from "vue"
2+
import courseService from "../../services/courseService"
3+
4+
import { useLanguage } from "../language"
5+
import { useNotification } from "../notification"
6+
7+
import { FilterMatchMode } from "primevue/api"
8+
9+
import * as trackCourseRanking from "../../services/trackCourseRankingService"
10+
11+
export function useCatalogueCourseList() {
12+
const isLoading = ref(true)
13+
const courses = ref([])
14+
const filters = ref({})
15+
16+
const { findByIsoCode: findLanguageByIsoCode } = useLanguage()
17+
const { showErrorNotification } = useNotification()
18+
19+
function initFilters() {
20+
filters.value = {
21+
global: { value: null, matchMode: FilterMatchMode.CONTAINS },
22+
}
23+
}
24+
25+
/**
26+
* @returns {Promise<void>}
27+
*/
28+
async function load() {
29+
isLoading.value = true
30+
31+
try {
32+
const { items } = await courseService.listAll()
33+
34+
courses.value = items.map((course) => ({
35+
...course,
36+
courseLanguage: findLanguageByIsoCode(course.courseLanguage)?.originalName,
37+
}))
38+
} catch (error) {
39+
showErrorNotification(error)
40+
} finally {
41+
isLoading.value = false
42+
}
43+
}
44+
45+
/**
46+
* @param {number} courseId
47+
* @param {number} totalScore
48+
* @returns {Promise<void>}
49+
*/
50+
async function createRating(courseId, totalScore) {
51+
try {
52+
const response = await trackCourseRanking.saveRanking({
53+
totalScore,
54+
courseIri: `/api/courses/${courseId}`,
55+
urlId: window.access_url_id,
56+
sessionId: 0,
57+
})
58+
59+
courses.value.forEach((course) => {
60+
if (course.id === courseId) {
61+
course.trackCourseRanking = response
62+
}
63+
})
64+
} catch (e) {
65+
showErrorNotification(e)
66+
}
67+
}
68+
69+
/**
70+
* @param {number} trackCourseRankingId
71+
* @param {number} totalScore
72+
* @returns {Promise<void>}
73+
*/
74+
async function updateRating(trackCourseRankingId, totalScore) {
75+
try {
76+
const response = await trackCourseRanking.updateRanking({
77+
trackCourseRankingId,
78+
totalScore,
79+
})
80+
81+
courses.value.forEach((course) => {
82+
if (course.trackCourseRanking && course.trackCourseRanking.id === trackCourseRankingId) {
83+
course.trackCourseRanking.realTotalScore = response.realTotalScore
84+
}
85+
})
86+
} catch (e) {
87+
showErrorNotification(e)
88+
}
89+
}
90+
91+
/**
92+
* @param {number} value
93+
* @param {Object} course
94+
* @returns {Promise<void>}
95+
*/
96+
async function onRatingChange({ value }, course) {
97+
if (value > 0) {
98+
if (course.trackCourseRanking) {
99+
await updateRating(course.trackCourseRanking.id, value)
100+
} else {
101+
await createRating(course.id, value)
102+
}
103+
}
104+
}
105+
106+
return {
107+
isLoading,
108+
courses,
109+
filters,
110+
load,
111+
initFilters,
112+
onRatingChange,
113+
}
114+
}

assets/vue/services/trackCourseRankingService.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ export async function saveRanking({ courseIri, urlId, sessionId, totalScore }) {
1717
}
1818

1919
/**
20-
* @param {string} iri
20+
* @param {number} trackCourseRankingId
2121
* @param {number} totalScore
2222
* @returns {Promise<Object>}
2323
*/
24-
export async function updateRanking({ iri, totalScore }) {
25-
return await baseService.put(iri, { totalScore })
24+
export async function updateRanking({ trackCourseRankingId, totalScore }) {
25+
return await baseService.put(`/api/track_course_rankings/${trackCourseRankingId}`, { totalScore })
2626
}

0 commit comments

Comments
 (0)