Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kolibri/plugins/learn/frontend/__mocks__/apiResources.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const LearnerClassroomResource = {
fetchCollection: jest.fn(),
list: jest.fn(),
};
6 changes: 2 additions & 4 deletions kolibri/plugins/learn/frontend/apiResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { Resource } from 'kolibri/apiResource';
/**
* Gets all of the Classrooms in which a Learner is enrolled.
* @example To get Classrooms without assignments and progress:
* LearnerClassroomResource.fetchCollection({
* getParams: { no_assignments: true },
* })
* LearnerClassroomResource.list({ no_assignments: true })
*/
export const LearnerClassroomResource = new Resource({
name: 'learnerclassroom',
Expand All @@ -24,7 +22,7 @@ export const LearnerCourseResource = new Resource({
name: 'learnercourse',
namespace: 'kolibri.plugins.learn',
async getResumeData(id) {
const response = await this.accessDetailEndpoint('get', 'resume', id);
const response = await this.request({ action: 'resume', routeParams: id });
return response.data;
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function finishClasses(classes) {

describe(`useLearnerResources`, () => {
beforeEach(() => {
LearnerClassroomResource.fetchCollection.mockResolvedValue(TEST_CLASSES);
LearnerClassroomResource.list.mockResolvedValue(TEST_CLASSES);
return fetchClasses();
});

Expand Down Expand Up @@ -448,21 +448,21 @@ describe(`useLearnerResources`, () => {

describe(`learnerFinishedAllClasses`, () => {
it(`returns 'true' if a learner has no classes`, () => {
LearnerClassroomResource.fetchCollection.mockResolvedValue([]);
LearnerClassroomResource.list.mockResolvedValue([]);
return fetchClasses().then(() => {
expect(learnerFinishedAllClasses.value).toBe(true);
});
});

it(`returns 'false' if a learner hasn't finished all lessons and quizzes yet`, () => {
LearnerClassroomResource.fetchCollection.mockResolvedValue(TEST_CLASSES);
LearnerClassroomResource.list.mockResolvedValue(TEST_CLASSES);
return fetchClasses().then(() => {
expect(learnerFinishedAllClasses.value).toBe(false);
});
});

it(`returns 'true' if a learner finished all lessons and quizzes`, () => {
LearnerClassroomResource.fetchCollection.mockResolvedValue(finishClasses(TEST_CLASSES));
LearnerClassroomResource.list.mockResolvedValue(finishClasses(TEST_CLASSES));
return fetchClasses().then(() => {
expect(learnerFinishedAllClasses.value).toBe(true);
});
Expand Down
5 changes: 1 addition & 4 deletions kolibri/plugins/learn/frontend/composables/useBookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ export default function useBookmarks() {
* @public
*/
async function fetchBookmarks(getParams) {
const bookmarksData = await BookmarksResource.fetchCollection({
getParams,
force: true,
});
const bookmarksData = await BookmarksResource.list(getParams);
const bookmarks = bookmarksData ? bookmarksData : [];
for (const bookmark of bookmarks) {
setBookmark(bookmark);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ export default function useContentNodeProgress() {
* @public
*/
function fetchContentNodeProgress(getParams) {
return ContentNodeProgressResource.fetchCollection({
getParams,
force: true,
}).then(progressData => {
return ContentNodeProgressResource.list(getParams).then(progressData => {
const progresses = progressData ? progressData : [];
for (const progress of progresses) {
setContentNodeProgress(progress);
Expand All @@ -64,7 +61,7 @@ export default function useContentNodeProgress() {
* @public
*/
function fetchContentNodeTreeProgress({ id, params }) {
return ContentNodeProgressResource.fetchTree({
return ContentNodeProgressResource.fetchTree_v2({
params,
id,
}).then(progressData => {
Expand Down
7 changes: 3 additions & 4 deletions kolibri/plugins/learn/frontend/composables/useDevices.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ function canAccessStudio() {

function fetchDevices() {
return Promise.all([
canAccessStudio() ? RemoteChannelResource.getKolibriStudioStatus() : Promise.resolve(null),
canAccessStudio() ? RemoteChannelResource.getKolibriStudioStatus_v2() : Promise.resolve(null),
NetworkLocationResource.list(),
]).then(([studioResponse, devices]) => {
]).then(([studio, devices]) => {
if (canAccessStudio()) {
const studio = studioResponse.data;
devices = devices.filter(device => isMinimumKolibriVersion(device.kolibri_version));
if (studio.available && isMinimumKolibriVersion(studio.kolibri_version || '0.15.0')) {
return [
Expand All @@ -71,7 +70,7 @@ export function setCurrentDevice(id) {
set(currentDevice, KolibriStudioDeviceData);
return Promise.resolve(KolibriStudioDeviceData);
}
return NetworkLocationResource.fetchModel({ id }).then(device => {
return NetworkLocationResource.retrieve(id).then(device => {
set(currentDevice, device);
return device;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ export default function useDownloadRequests(store) {
if (!contentRequest) {
return Promise.resolve();
}
ContentRequestResource.deleteModel({
id: contentRequest.id,
});
ContentRequestResource.delete(contentRequest.id);
Vue.delete(downloadRequestMap, contentRequest.contentnode_id);
createSnackbar({
text: downloadRequestsTranslator.$tr('resourceRemoved'),
Expand Down
26 changes: 10 additions & 16 deletions kolibri/plugins/learn/frontend/composables/useLearnerResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,11 @@ export default function useLearnerResources() {
* to this composable's store
* @param {object} params - Request parameters
* @param {string} params.classId - Classroom id to load
* @param {boolean} [params.force] - Cache won't be used when `true`
* @returns {Promise} - Resolves with the loaded classroom
* @public
*/
function fetchClass({ classId, force = false }) {
return LearnerClassroomResource.fetchModel({ id: classId, force }).then(classroom => {
function fetchClass({ classId }) {
return LearnerClassroomResource.retrieve(classId).then(classroom => {
const updatedClasses = [...get(classes).filter(c => c.id !== classId), classroom];
set(classes, updatedClasses);
setClassData(classroom);
Expand All @@ -310,19 +309,17 @@ export default function useLearnerResources() {
/**
* Fetches current learner's classes
* and saves data to this composable's store
* @param {object} [params] - Request parameters
* @param {boolean} [params.force] - Cache won't be used when `true`
* @returns {Promise} - Resolves once the classes store has been populated
* @public
*/
function fetchClasses({ force = false } = {}) {
return LearnerClassroomResource.fetchCollection({ force }).then(collection => {
function fetchClasses() {
return LearnerClassroomResource.list().then(collection => {
set(classes, collection);
});
}

function fetchLesson({ lessonId } = {}) {
return LearnerLessonResource.fetchModel({ id: lessonId }).then(lesson => {
return LearnerLessonResource.retrieve(lessonId).then(lesson => {
_cacheLessonResources(lesson);
return lesson;
});
Expand Down Expand Up @@ -413,12 +410,11 @@ export default function useLearnerResources() {
* to this composable's store
* @param {object} params - Request parameters
* @param {string} params.courseSessionId - Learner course session id
* @param {boolean} [params.force] - Cache won't be used when `true`
* @returns {Promise<object>} Course data
* @public
*/
async function fetchCourse({ courseSessionId, force = false }) {
const course = await LearnerCourseResource.fetchModel({ id: courseSessionId, force });
async function fetchCourse({ courseSessionId }) {
const course = await LearnerCourseResource.retrieve(courseSessionId);

if (!course) {
throw new Error('Course not found');
Expand All @@ -430,7 +426,7 @@ export default function useLearnerResources() {

// Fetch course content tree and learner course progress
const [content, progressResponse] = await Promise.all([
course.course_id ? ContentNodeResource.fetchTree({ id: course.course_id }) : null,
course.course_id ? ContentNodeResource.fetchTree_v2({ id: course.course_id }) : null,
LearnerCourseResource.getResumeData(course.id),
]);

Expand All @@ -445,13 +441,11 @@ export default function useLearnerResources() {
/**
* Fetches current learner's courses
* and saves data to this composable's store
* @param {object} [params] - Request parameters
* @param {boolean} [params.force] - Cache won't be used when `true`
* @returns {Promise<Array>} - Resolves with the loaded course collection
* @public
*/
async function fetchCourses({ force = false } = {}) {
const collection = await LearnerCourseResource.fetchCollection({ force });
async function fetchCourses() {
const collection = await LearnerCourseResource.list();
set(courses, collection);
return collection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function usePinnedDevices(networkDevicesWithChannels) {
});

function fetchPinsForUser() {
return PinnedDeviceResource.fetchCollection({ force: true }).then(pins => {
return PinnedDeviceResource.list().then(pins => {
const updatedPins = {};
for (const pin of pins) {
updatedPins[pin.instance_id] = pin;
Expand Down Expand Up @@ -51,7 +51,7 @@ export default function usePinnedDevices(networkDevicesWithChannels) {
delete newMap[instance_id];
set(userPinsMap, newMap);
createSnackbar(PinStrings.$tr('pinRemoved'));
return PinnedDeviceResource.deleteModel({ id });
return PinnedDeviceResource.delete(id);
}

function _isPinnedDevice(device) {
Expand Down
2 changes: 1 addition & 1 deletion kolibri/plugins/learn/frontend/modules/classes/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ClassesPageNames } from '../../constants';
// Shows a list of all the Classrooms a Learner is enrolled in
export function showAllClassesPage(store) {
pageLoading.value = true;
return LearnerClassroomResource.fetchCollection()
return LearnerClassroomResource.list()
.then(classrooms => {
store.commit('SET_PAGE_NAME', ClassesPageNames.ALL_CLASSES);
store.commit('classes/SET_LEARNER_CLASSROOMS', classrooms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ export function showExam(store, params, alreadyOnQuiz, route) {
handleError('You must be logged in as a learner to view this page');
pageLoading.value = false;
} else {
const promises = [
LearnerClassroomResource.fetchModel({ id: classId }),
ExamResource.fetchModel({ id: examId }),
];
const promises = [LearnerClassroomResource.retrieve(classId), ExamResource.retrieve(examId)];
const shouldResolve = samePageCheckGenerator(route);
Promise.all(promises).then(
([classroom, exam]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function showLessonPlaylist(store, { lessonId }) {
fetchContentNodeProgress({ lesson: lessonId });
}
const contentNodePromise = ContentNodeResource.fetchLessonResources(lessonId);
return LearnerLessonResource.fetchModel({ id: lessonId })
return LearnerLessonResource.retrieve(lessonId)
.then(lesson => {
store.commit('SET_PAGE_NAME', ClassesPageNames.LESSON_PLAYLIST);
store.commit('lessonPlaylist/SET_CURRENT_LESSON', lesson);
Expand Down
16 changes: 9 additions & 7 deletions kolibri/plugins/learn/frontend/views/BookmarkPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,20 @@
};
},
created() {
ContentNodeResource.fetchBookmarks({ params: { limit: 25, available: true } }).then(data => {
this.more = data.more;
this.bookmarks = data.results ? data.results : [];
this.loading = false;
this.fetchContentNodeProgress({ ids: this.bookmarks.map(b => b.id) });
});
ContentNodeResource.fetchBookmarks_v2({ params: { limit: 25, available: true } }).then(
data => {
this.more = data.more;
this.bookmarks = data.results ? data.results : [];
this.loading = false;
this.fetchContentNodeProgress({ ids: this.bookmarks.map(b => b.id) });
},
);
},
methods: {
loadMore() {
if (!this.loading) {
this.loading = true;
ContentNodeResource.fetchBookmarks({ params: this.more }).then(data => {
ContentNodeResource.fetchBookmarks_v2({ params: this.more }).then(data => {
this.more = data.more;
this.bookmarks.push(...data.results);
this.loading = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,16 @@
},
},
mounted() {
ContentNodeResource.fetchRecommendationsFor(this.content.id).then(recommendations => {
ContentNodeResource.fetchRecommendationsFor_v2(this.content.id).then(recommendations => {
const threeRecs = recommendations.splice(0, 3);
this.recommendations = threeRecs.length ? threeRecs : null;
});

if (this.showLocationsInChannel) {
// Retreives any topics in this same channel
ContentNodeResource.fetchCollection({
getParams: { content_id: this.content.content_id, channel_id: this.content.channel_id },
ContentNodeResource.list({
content_id: this.content.content_id,
channel_id: this.content.channel_id,
}).then((locations = []) => {
locations = locations.filter(loc => loc.id !== this.content.id);
if (locations && locations.length) {
Expand Down
Loading
Loading