Skip to content

Commit df134ff

Browse files
Changed operation of multiple exercise uploads
The simultaneous upload of multiple exercises has been modified, eliminating the intermediate directory that was previously generated.
1 parent b22859e commit df134ff

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

vscode4teaching-extension/src/components/courses/CoursesTreeProvider.ts

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import * as path from "path";
2323
* - Exercises actions
2424
*/
2525
export class CoursesProvider implements vscode.TreeDataProvider<V4TItem> {
26-
2726
/**
2827
* Update tree view. Use when there are changes that should be reflected on the view.
2928
* Calls getChildren() and displays returned elements onto the view
@@ -247,11 +246,13 @@ export class CoursesProvider implements vscode.TreeDataProvider<V4TItem> {
247246
public refreshCourses() {
248247
if (CurrentUser.isLoggedIn()) {
249248
// If not logged refresh shouldn't do anything
250-
CurrentUser.updateUserInfo().then(() => {
251-
CoursesProvider.triggerTreeReload();
252-
}).catch((error) => {
253-
APIClient.handleAxiosError(error);
254-
});
249+
CurrentUser.updateUserInfo()
250+
.then(() => {
251+
CoursesProvider.triggerTreeReload();
252+
})
253+
.catch((error) => {
254+
APIClient.handleAxiosError(error);
255+
});
255256
}
256257
}
257258

@@ -353,12 +354,13 @@ export class CoursesProvider implements vscode.TreeDataProvider<V4TItem> {
353354

354355
// When added to DB, templates of each exercise are sent
355356
exerciseData.data.map(async (ex, index) => {
356-
APIClient.uploadExerciseTemplate(ex.id, await FileZipUtil.getZipFromUris([vscode.Uri.parse(fsUri + path.sep + exercisesDirChunk[index].name)]), false)
357+
const directoryFiles = fs.readdirSync(fsUri + path.sep + exercisesDirChunk[index].name).map((e) => vscode.Uri.parse(fsUri + path.sep + exercisesDirChunk[index].name + path.sep + e));
358+
APIClient.uploadExerciseTemplate(ex.id, await FileZipUtil.getZipFromUris(directoryFiles), false)
357359
.then((_) => uploadedExercises++)
358360
.catch((_) => (errorCaught = true));
359361
});
360362
}
361-
if (errorCaught || availableFolderNumber !== uploadedExercises) {
363+
if (!errorCaught || availableFolderNumber !== uploadedExercises) {
362364
vscode.window.showInformationMessage("All exercises were successfully uploaded.");
363365
} else {
364366
vscode.window.showErrorMessage("One or more exercises were not properly uploaded.");
@@ -429,7 +431,8 @@ export class CoursesProvider implements vscode.TreeDataProvider<V4TItem> {
429431
console.debug(courseUsersResponse);
430432
const courseUsers = courseUsersResponse.data;
431433
// Remove from the list the users that are already in the course
432-
const showArray = users.filter((user: User) => courseUsers.filter((courseUser: User) => courseUser.id === user.id).length === 0)
434+
const showArray = users
435+
.filter((user: User) => courseUsers.filter((courseUser: User) => courseUser.id === user.id).length === 0)
433436
.map((user: User) => {
434437
// Get pickable items from users
435438
return this.userPickFromUser(user);
@@ -460,10 +463,12 @@ export class CoursesProvider implements vscode.TreeDataProvider<V4TItem> {
460463
const creator: User = creatorResponse.data;
461464
const courseUsers = courseUsersResponse.data;
462465
// Remove creator of course from list
463-
const showArray = courseUsers.filter((user: User) => user.id !== creator.id).map((user: User) => {
464-
// Get pickable items from users
465-
return this.userPickFromUser(user);
466-
});
466+
const showArray = courseUsers
467+
.filter((user: User) => user.id !== creator.id)
468+
.map((user: User) => {
469+
// Get pickable items from users
470+
return this.userPickFromUser(user);
471+
});
467472
const ids = await this.manageUsersFromCourse(showArray, item);
468473
if (ids) {
469474
const response = await APIClient.removeUsersFromCourse(item.item.id, { ids });
@@ -518,11 +523,14 @@ export class CoursesProvider implements vscode.TreeDataProvider<V4TItem> {
518523
type = V4TItemType.ExerciseStudent;
519524
commandName = "vscode4teaching.getexercisefiles";
520525
}
521-
const exerciseItems = course.exercises.map((exercise) => new V4TItem(exercise.name, type, vscode.TreeItemCollapsibleState.None, element, exercise, {
522-
command: commandName,
523-
title: "Get exercise files",
524-
arguments: [course ? course.name : null, exercise],
525-
}));
526+
const exerciseItems = course.exercises.map(
527+
(exercise) =>
528+
new V4TItem(exercise.name, type, vscode.TreeItemCollapsibleState.None, element, exercise, {
529+
command: commandName,
530+
title: "Get exercise files",
531+
arguments: [course ? course.name : null, exercise],
532+
})
533+
);
526534
return exerciseItems.length > 0 ? exerciseItems : [V4TBuildItems.NO_EXERCISES_ITEM];
527535
}
528536
}
@@ -534,16 +542,18 @@ export class CoursesProvider implements vscode.TreeDataProvider<V4TItem> {
534542
*/
535543
private updateUserInfo(): V4TItem[] {
536544
this.loading = true;
537-
CurrentUser.updateUserInfo().then(() => {
538-
// Calls getChildren again, which will go through the else statement in this method (logged in and user info initialized)
539-
CoursesProvider.triggerTreeReload();
540-
}).catch((error) => {
541-
APIClient.handleAxiosError(error);
542-
CoursesProvider.triggerTreeReload();
543-
},
544-
).finally(() => {
545-
this.loading = false;
546-
});
545+
CurrentUser.updateUserInfo()
546+
.then(() => {
547+
// Calls getChildren again, which will go through the else statement in this method (logged in and user info initialized)
548+
CoursesProvider.triggerTreeReload();
549+
})
550+
.catch((error) => {
551+
APIClient.handleAxiosError(error);
552+
CoursesProvider.triggerTreeReload();
553+
})
554+
.finally(() => {
555+
this.loading = false;
556+
});
547557
return [];
548558
}
549559

0 commit comments

Comments
 (0)