From 04fbb6d93d6217812dc1b594b65f237bcee692a7 Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Thu, 17 Mar 2022 16:51:32 -0400 Subject: [PATCH] Show announcement dates --- src/components/announcement/announcement.js | 35 ++++++++++++ src/components/announcement/announcement.vue | 54 +++++++++++++------ .../announcement_editor.js | 13 +++++ .../announcement_editor.vue | 52 ++++++++++++++++++ .../announcements_page/announcements_page.js | 4 +- .../announcements_page/announcements_page.vue | 41 +------------- src/modules/announcements.js | 7 ++- src/services/api/api.service.js | 8 ++- 8 files changed, 156 insertions(+), 58 deletions(-) create mode 100644 src/components/announcement_editor/announcement_editor.js create mode 100644 src/components/announcement_editor/announcement_editor.vue diff --git a/src/components/announcement/announcement.js b/src/components/announcement/announcement.js index b1f5ee77a4..309eecea75 100644 --- a/src/components/announcement/announcement.js +++ b/src/components/announcement/announcement.js @@ -1,6 +1,21 @@ import { mapState } from 'vuex' +import AnnouncementEditor from '../announcement_editor/announcement_editor.vue' +import localeService from '../../services/locale/locale.service.js' const Announcement = { + components: { + AnnouncementEditor + }, + data () { + return { + editing: false, + newAnnouncement: { + content: '', + startsAt: undefined, + endsAt: undefined + } + } + }, props: { announcement: Object }, @@ -13,6 +28,22 @@ const Announcement = { }, isRead () { return this.announcement.read + }, + startsAt () { + const time = this.announcement['starts_at'] + if (!time) { + return + } + + return this.formatTimeOrDate(time, localeService.internalToBrowserLocale(this.$i18n.locale)) + }, + endsAt () { + const time = this.announcement['ends_at'] + if (!time) { + return + } + + return this.formatTimeOrDate(time, localeService.internalToBrowserLocale(this.$i18n.locale)) } }, methods: { @@ -23,6 +54,10 @@ const Announcement = { }, deleteAnnouncement () { return this.$store.dispatch('deleteAnnouncement', this.announcement.id) + }, + formatTimeOrDate (time, locale) { + const d = new Date(time) + return this.announcement['all_day'] ? d.toLocaleDateString(locale) : d.toLocaleString(locale) } } } diff --git a/src/components/announcement/announcement.vue b/src/components/announcement/announcement.vue index d6f35b9f8e..5ddeebf586 100644 --- a/src/components/announcement/announcement.vue +++ b/src/components/announcement/announcement.vue @@ -5,27 +5,42 @@
+
@@ -47,6 +62,15 @@ } .footer { + display: flex; + flex-direction: column; + .times { + display: flex; + flex-direction: column; + } + } + + .footer .actions { display: flex; flex-direction: row; justify-content: space-around; diff --git a/src/components/announcement_editor/announcement_editor.js b/src/components/announcement_editor/announcement_editor.js new file mode 100644 index 0000000000..79a03afe1c --- /dev/null +++ b/src/components/announcement_editor/announcement_editor.js @@ -0,0 +1,13 @@ +import Checkbox from '../checkbox/checkbox.vue' + +const AnnouncementEditor = { + components: { + Checkbox + }, + props: { + announcement: Object, + disabled: Boolean + } +} + +export default AnnouncementEditor diff --git a/src/components/announcement_editor/announcement_editor.vue b/src/components/announcement_editor/announcement_editor.vue new file mode 100644 index 0000000000..e2418b8d49 --- /dev/null +++ b/src/components/announcement_editor/announcement_editor.vue @@ -0,0 +1,52 @@ +