-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KURSP-926: add announcements link on the course page
- Loading branch information
1 parent
a2336d2
commit 11bda6f
Showing
8 changed files
with
152 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import api from "../../api/api"; | ||
|
||
export async function getAllUnreadAnnouncementsForCourse() { | ||
const courseId = api.getCurrentCourseId(); | ||
let totalUnread = 0; | ||
|
||
try { | ||
const announcements = await new Promise((resolve, reject) => { | ||
api.getAnnouncementsForCourse(courseId, (announcements) => { | ||
resolve(announcements); | ||
}, reject); | ||
}); | ||
|
||
announcements.forEach((announcement) => { | ||
if (announcement.read_state === 'unread' || announcement.unread_count > 0) { | ||
totalUnread++; | ||
} | ||
}); | ||
|
||
return { | ||
url: `/courses/${courseId}/announcements`, | ||
count: totalUnread, | ||
}; | ||
} catch (error) { | ||
// Handle any errors, e.g., invalid URLs or API failures | ||
console.error('Error:', error); | ||
return { | ||
url: '', | ||
count: 0, | ||
}; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { getAllUnreadAnnouncementsForCourse } from './data' |
43 changes: 43 additions & 0 deletions
43
src/vue/components/announcements/Announcements-container.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<template> | ||
<Announcements :count="data.count" :url="data.url" v-if="!loading" /> | ||
</template> | ||
|
||
<script> | ||
import { defineComponent, ref, onMounted } from 'vue'; | ||
import { getAllUnreadAnnouncementsForCourse } from '../../../js/modules/announcements/index' | ||
import Announcements from './Announcements'; | ||
export default defineComponent({ | ||
name: 'AnnouncementsContainer', | ||
setup() { | ||
const data = ref({ | ||
url: '', | ||
count: 0 | ||
}); | ||
const loading = ref(true); | ||
onMounted( | ||
async () => { | ||
try { | ||
const response = await getAllUnreadAnnouncementsForCourse(); | ||
data.value = { | ||
url: response.url, | ||
count: response.count | ||
}; | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
} finally { | ||
loading.value = false; | ||
} | ||
}); | ||
return { | ||
data, | ||
loading | ||
}; | ||
}, | ||
components: { | ||
Announcements | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
import Announcements from './announcements.vue'; | ||
import Announcements from './Announcements.vue'; | ||
|
||
export default { | ||
title: 'Components/Announcements', | ||
}; | ||
|
||
export const Default = () => ({ | ||
components: { Announcements }, | ||
template: '<Announcements :count="3" />', | ||
template: '<Announcements :count="3" :url=" " />', | ||
}); | ||
|
||
export const NoNewAnnouncements = () => ({ | ||
components: { Announcements }, | ||
template: '<Announcements :count="0" :url=" " />', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import AnnouncementContainer from './Announcements-container.vue' | ||
export default AnnouncementContainer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,36 @@ | ||
// Import the necessary Vue and component | ||
import { createApp } from "vue"; | ||
import CourseModuleContainer from "./CourseModuleContainer"; | ||
|
||
import AnnouncementsContainer from "../announcements/index"; | ||
import CourseModuleContainer from "./CourseModuleContainer"; | ||
|
||
export function renderCourseModules(id) { | ||
// Create a Vue app instance | ||
const app = createApp(CourseModuleContainer); | ||
const appContainer = document.createElement('div'); | ||
appContainer.id= 'moduleSelector' | ||
// Mount the Vue app to a specific HTML element with an ID | ||
// Get the parent element | ||
const parentElement = document.getElementById(id); | ||
parentElement.insertBefore(appContainer, parentElement.firstChild); | ||
|
||
// Mount the Vue app to the element | ||
app.mount(appContainer); | ||
// Create a Vue app instance for Announcements | ||
const announcementsApp = createApp(AnnouncementsContainer); | ||
const announcementsContainer = document.createElement("div"); | ||
announcementsContainer.id = "announcementsContainer"; | ||
|
||
// Create a Vue app instance for CourseModuleContainer | ||
const courseModuleApp = createApp(CourseModuleContainer); | ||
const courseModuleContainer = document.createElement("div"); | ||
courseModuleContainer.id = "moduleSelector"; | ||
|
||
// Mount the Announcements app to its container | ||
announcementsApp.mount(announcementsContainer); | ||
|
||
// Mount the CourseModuleContainer app to its container | ||
courseModuleApp.mount(courseModuleContainer); | ||
|
||
// Insert courseModuleContainer before any other content | ||
parentElement.insertBefore(courseModuleContainer, parentElement.firstChild); | ||
|
||
// Insert announcementsContainer before any other content | ||
parentElement.insertBefore(announcementsContainer, parentElement.firstChild); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|