diff --git a/src/main/webapp/app/course/course-access-storage.service.ts b/src/main/webapp/app/course/course-access-storage.service.ts index 0c20d56f651c..b0660d7f748b 100644 --- a/src/main/webapp/app/course/course-access-storage.service.ts +++ b/src/main/webapp/app/course/course-access-storage.service.ts @@ -5,25 +5,29 @@ import { LocalStorageService } from 'ngx-webstorage'; providedIn: 'root', }) export class CourseAccessStorageService { - private static readonly STORAGE_KEY = 'artemis.courseAccess'; + public static readonly STORAGE_KEY = 'artemis.courseAccess'; + public static readonly STORAGE_KEY_DROPDOWN = 'artemis.courseAccessDropdown'; + public static readonly MAX_DISPLAYED_RECENTLY_ACCESSED_COURSES_OVERVIEW = 3; + // Maximum number of recently accessed courses displayed in the dropdown, including the current course. The current course will be removed before displaying the dropdown so only 6 - 1 courses will be displayed in the dropdown. + public static readonly MAX_DISPLAYED_RECENTLY_ACCESSED_COURSES_DROPDOWN = 6; constructor(private localStorage: LocalStorageService) {} - onCourseAccessed(courseId: number): void { - const courseAccessMap: { [key: number]: number } = this.localStorage.retrieve(CourseAccessStorageService.STORAGE_KEY) || {}; + onCourseAccessed(courseId: number, storageKey: string, maxAccessedCourses: number): void { + const courseAccessMap: { [key: number]: number } = this.localStorage.retrieve(storageKey) || {}; courseAccessMap[courseId] = Date.now(); - if (Object.keys(courseAccessMap).length > 3) { + if (Object.keys(courseAccessMap).length > maxAccessedCourses) { const oldestEntry = Object.entries(courseAccessMap).reduce((prev, curr) => (prev[1] < curr[1] ? prev : curr)); delete courseAccessMap[oldestEntry[0]]; } - this.localStorage.store(CourseAccessStorageService.STORAGE_KEY, courseAccessMap); + this.localStorage.store(storageKey, courseAccessMap); } - getLastAccessedCourses(): number[] { - const courseAccessMap: { [key: number]: number } = this.localStorage.retrieve(CourseAccessStorageService.STORAGE_KEY) || {}; + getLastAccessedCourses(storageKey: string): number[] { + const courseAccessMap: { [key: number]: number } = this.localStorage.retrieve(storageKey) || {}; return Object.entries(courseAccessMap) .sort((a, b) => b[1] - a[1]) diff --git a/src/main/webapp/app/course/manage/course-management-tab-bar/course-management-tab-bar.component.ts b/src/main/webapp/app/course/manage/course-management-tab-bar/course-management-tab-bar.component.ts index c2a0e96da3fa..b87587fa8503 100644 --- a/src/main/webapp/app/course/manage/course-management-tab-bar/course-management-tab-bar.component.ts +++ b/src/main/webapp/app/course/manage/course-management-tab-bar/course-management-tab-bar.component.ts @@ -117,7 +117,16 @@ export class CourseManagementTabBarComponent implements OnInit, OnDestroy, After }); // Notify the course access storage service that the course has been accessed - this.courseAccessStorageService.onCourseAccessed(courseId); + this.courseAccessStorageService.onCourseAccessed( + courseId, + CourseAccessStorageService.STORAGE_KEY, + CourseAccessStorageService.MAX_DISPLAYED_RECENTLY_ACCESSED_COURSES_OVERVIEW, + ); + this.courseAccessStorageService.onCourseAccessed( + courseId, + CourseAccessStorageService.STORAGE_KEY_DROPDOWN, + CourseAccessStorageService.MAX_DISPLAYED_RECENTLY_ACCESSED_COURSES_DROPDOWN, + ); } ngAfterViewInit() { diff --git a/src/main/webapp/app/course/manage/course-management.component.ts b/src/main/webapp/app/course/manage/course-management.component.ts index b9d525c5ae86..7d7b0d9b9604 100644 --- a/src/main/webapp/app/course/manage/course-management.component.ts +++ b/src/main/webapp/app/course/manage/course-management.component.ts @@ -145,7 +145,7 @@ export class CourseManagementComponent implements OnInit, OnDestroy, AfterViewIn this.coursesBySemester = {}; // Get last accessed courses - const lastAccessedCourseIds = this.courseAccessStorageService.getLastAccessedCourses(); + const lastAccessedCourseIds = this.courseAccessStorageService.getLastAccessedCourses(CourseAccessStorageService.STORAGE_KEY); const recentlyAccessedCourses = this.courses.filter((course) => lastAccessedCourseIds.includes(course.id!)); let firstExpanded = false; diff --git a/src/main/webapp/app/overview/course-overview.component.html b/src/main/webapp/app/overview/course-overview.component.html index 527b8ad82659..2ae30a6960cd 100644 --- a/src/main/webapp/app/overview/course-overview.component.html +++ b/src/main/webapp/app/overview/course-overview.component.html @@ -1,55 +1,80 @@