From b2da83fbfb86be6d40ee930c5cf6f8a15de6d373 Mon Sep 17 00:00:00 2001 From: maniamartial Date: Wed, 26 Feb 2025 17:57:39 +0300 Subject: [PATCH 1/5] feat: Creating announcement page on frontend from newletters doctype --- education/education/api.py | 7 ++ .../doctype/school_announcement/__init__.py | 0 .../school_announcement.js | 8 ++ .../school_announcement.json | 90 +++++++++++++++++++ .../school_announcement.py | 9 ++ .../test_school_announcement.py | 9 ++ education/public/frontend/index.html | 4 +- education/public/node_modules | 2 +- frontend/src/pages/Announcement.vue | 66 ++++++++++++++ frontend/src/router.js | 5 ++ node_modules/.yarn-integrity | 2 +- 11 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 education/education/doctype/school_announcement/__init__.py create mode 100644 education/education/doctype/school_announcement/school_announcement.js create mode 100644 education/education/doctype/school_announcement/school_announcement.json create mode 100644 education/education/doctype/school_announcement/school_announcement.py create mode 100644 education/education/doctype/school_announcement/test_school_announcement.py create mode 100644 frontend/src/pages/Announcement.vue diff --git a/education/education/api.py b/education/education/api.py index 77c5962e..2da170f1 100644 --- a/education/education/api.py +++ b/education/education/api.py @@ -759,3 +759,10 @@ def get_student_attendance(student, student_group): filters={"student": student, "student_group": student_group, "docstatus": 1}, fields=["date", "status", "name"], ) + +@frappe.whitelist() +def get_announcements(): + announcements = frappe.get_all("Newsletter", + filters={"published": 1}, + fields=["subject", "content", "creation as announcement_date"]) + return announcements diff --git a/education/education/doctype/school_announcement/__init__.py b/education/education/doctype/school_announcement/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/education/education/doctype/school_announcement/school_announcement.js b/education/education/doctype/school_announcement/school_announcement.js new file mode 100644 index 00000000..7e7df6a4 --- /dev/null +++ b/education/education/doctype/school_announcement/school_announcement.js @@ -0,0 +1,8 @@ +// Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +// frappe.ui.form.on("School Announcement", { +// refresh(frm) { + +// }, +// }); diff --git a/education/education/doctype/school_announcement/school_announcement.json b/education/education/doctype/school_announcement/school_announcement.json new file mode 100644 index 00000000..efd824ee --- /dev/null +++ b/education/education/doctype/school_announcement/school_announcement.json @@ -0,0 +1,90 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "format:ANC-{MM}-{#####}", + "creation": "2025-02-26 16:22:04.198050", + "doctype": "DocType", + "engine": "InnoDB", + "field_order": [ + "title", + "column_break_ywyl", + "posting_date", + "descriptions_section", + "description", + "section_break_uyky", + "announcement_date", + "column_break_uhyk", + "is_published" + ], + "fields": [ + { + "fieldname": "title", + "fieldtype": "Data", + "label": "Title" + }, + { + "fieldname": "column_break_ywyl", + "fieldtype": "Column Break" + }, + { + "default": "Today", + "fieldname": "posting_date", + "fieldtype": "Date", + "label": "Posting Date" + }, + { + "default": "0", + "fieldname": "is_published", + "fieldtype": "Check", + "label": "Is Published?" + }, + { + "fieldname": "descriptions_section", + "fieldtype": "Section Break", + "label": "Descriptions" + }, + { + "fieldname": "description", + "fieldtype": "Text Editor", + "label": "Description" + }, + { + "fieldname": "section_break_uyky", + "fieldtype": "Section Break" + }, + { + "fieldname": "announcement_date", + "fieldtype": "Date", + "label": "Announcement Date" + }, + { + "fieldname": "column_break_uhyk", + "fieldtype": "Column Break" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2025-02-26 16:33:07.237999", + "modified_by": "Administrator", + "module": "Education", + "name": "School Announcement", + "naming_rule": "Expression", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/education/education/doctype/school_announcement/school_announcement.py b/education/education/doctype/school_announcement/school_announcement.py new file mode 100644 index 00000000..5b7b607d --- /dev/null +++ b/education/education/doctype/school_announcement/school_announcement.py @@ -0,0 +1,9 @@ +# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class SchoolAnnouncement(Document): + pass diff --git a/education/education/doctype/school_announcement/test_school_announcement.py b/education/education/doctype/school_announcement/test_school_announcement.py new file mode 100644 index 00000000..cf391059 --- /dev/null +++ b/education/education/doctype/school_announcement/test_school_announcement.py @@ -0,0 +1,9 @@ +# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt + +# import frappe +from frappe.tests.utils import FrappeTestCase + + +class TestSchoolAnnouncement(FrappeTestCase): + pass diff --git a/education/public/frontend/index.html b/education/public/frontend/index.html index ecc8bbb2..e998f657 100644 --- a/education/public/frontend/index.html +++ b/education/public/frontend/index.html @@ -5,7 +5,7 @@ Frappe Education - + @@ -26,6 +26,6 @@ } link.href = '{{ logo }}' - + diff --git a/education/public/node_modules b/education/public/node_modules index 9f54fd75..740a1ece 120000 --- a/education/public/node_modules +++ b/education/public/node_modules @@ -1 +1 @@ -/Users/ritviksardana/version-15/apps/education/node_modules \ No newline at end of file +/home/techmaniacc/Documents/frappe-bench/apps/education/node_modules \ No newline at end of file diff --git a/frontend/src/pages/Announcement.vue b/frontend/src/pages/Announcement.vue new file mode 100644 index 00000000..9ea4017a --- /dev/null +++ b/frontend/src/pages/Announcement.vue @@ -0,0 +1,66 @@ + + + \ No newline at end of file diff --git a/frontend/src/router.js b/frontend/src/router.js index 3152f196..3a00f38c 100644 --- a/frontend/src/router.js +++ b/frontend/src/router.js @@ -25,6 +25,11 @@ const routes = [ name: 'Attendance', component: () => import('@/pages/Attendance.vue'), }, + { + path: '/announcements', + name: 'Announcements', + component: () => import('@/pages/Announcement.vue'), + }, { path: '/:catchAll(.*)', redirect: '/schedule', diff --git a/node_modules/.yarn-integrity b/node_modules/.yarn-integrity index f2c0af78..369ac877 100644 --- a/node_modules/.yarn-integrity +++ b/node_modules/.yarn-integrity @@ -1,5 +1,5 @@ { - "systemParams": "darwin-arm64-108", + "systemParams": "linux-x64-120", "modulesFolders": [ "node_modules" ], From b068180f7f41c0e4ea8d256eb578bd6114b09432 Mon Sep 17 00:00:00 2001 From: maniamartial Date: Mon, 3 Mar 2025 10:47:53 +0300 Subject: [PATCH 2/5] feat: Add dialog box to display announcement message from newsletters --- education/education/api.py | 14 ++- education/public/frontend/index.html | 4 +- frontend/src/components/Sidebar.vue | 6 ++ frontend/src/pages/Announcement.vue | 129 ++++++++++++++------------- 4 files changed, 87 insertions(+), 66 deletions(-) diff --git a/education/education/api.py b/education/education/api.py index 2da170f1..348ecff5 100644 --- a/education/education/api.py +++ b/education/education/api.py @@ -10,6 +10,7 @@ from frappe.model.mapper import get_mapped_doc from frappe.utils import cstr, flt, getdate from frappe.utils.dateutils import get_dates_from_timegrain +from datetime import datetime def get_course(program): @@ -762,7 +763,14 @@ def get_student_attendance(student, student_group): @frappe.whitelist() def get_announcements(): - announcements = frappe.get_all("Newsletter", - filters={"published": 1}, - fields=["subject", "content", "creation as announcement_date"]) + announcements = frappe.get_all( + "Newsletter", + filters={"published": 1}, + fields=["subject", "creation","message"] + ) + + for announcement in announcements: + if "creation" in announcement: + announcement["creation"] = datetime.strftime(announcement["creation"], "%d-%m-%Y") + return announcements diff --git a/education/public/frontend/index.html b/education/public/frontend/index.html index e998f657..5415b097 100644 --- a/education/public/frontend/index.html +++ b/education/public/frontend/index.html @@ -5,10 +5,10 @@ Frappe Education - + - +
diff --git a/frontend/src/components/Sidebar.vue b/frontend/src/components/Sidebar.vue index 702820ed..cdbaf2f0 100644 --- a/frontend/src/components/Sidebar.vue +++ b/frontend/src/components/Sidebar.vue @@ -82,6 +82,12 @@ const links = [ to: '/attendance', icon: UserCheck, }, + { + label: 'Announcement', + to: '/announcements', + icon: UserCheck, + }, + // { // // TODO: create School Diary Page with card like CRM and from ListView go to Resource Document of each Card // label: 'Notes', diff --git a/frontend/src/pages/Announcement.vue b/frontend/src/pages/Announcement.vue index 9ea4017a..7a495909 100644 --- a/frontend/src/pages/Announcement.vue +++ b/frontend/src/pages/Announcement.vue @@ -1,66 +1,73 @@ - - \ No newline at end of file +}) + +onMounted(() => { + fetchAnnouncements.reload() +}) + +const openAnnouncement = (announcement) => { + selectedAnnouncement.value = announcement + showDialog.value = true +} + From 5cbfcc68ddca358717f324bbc5b06c1b8e40b6da Mon Sep 17 00:00:00 2001 From: maniamartial Date: Tue, 22 Apr 2025 12:33:20 +0300 Subject: [PATCH 3/5] chore: refactor to use FrappeUI ListView for consistency --- education/education/api.py | 2 +- frontend/src/pages/Announcement.vue | 123 ++++++++++++++++++---------- 2 files changed, 80 insertions(+), 45 deletions(-) diff --git a/education/education/api.py b/education/education/api.py index 348ecff5..49c314ec 100644 --- a/education/education/api.py +++ b/education/education/api.py @@ -771,6 +771,6 @@ def get_announcements(): for announcement in announcements: if "creation" in announcement: - announcement["creation"] = datetime.strftime(announcement["creation"], "%d-%m-%Y") + announcement["creation"] = datetime.strftime(announcement["creation"], "%m-%d-%Y") return announcements diff --git a/frontend/src/pages/Announcement.vue b/frontend/src/pages/Announcement.vue index 7a495909..9e67af7c 100644 --- a/frontend/src/pages/Announcement.vue +++ b/frontend/src/pages/Announcement.vue @@ -1,70 +1,105 @@ + diff --git a/education/public/node_modules b/education/public/node_modules index 740a1ece..d6970248 120000 --- a/education/public/node_modules +++ b/education/public/node_modules @@ -1 +1 @@ -/home/techmaniacc/Documents/frappe-bench/apps/education/node_modules \ No newline at end of file +/Users/techmaniacc/Code/Bench/frappe-bench/apps/education/node_modules \ No newline at end of file From 56ed63ffb8b3ad4950b689e1ed40340038532744 Mon Sep 17 00:00:00 2001 From: maniamartial Date: Thu, 24 Apr 2025 16:41:05 +0300 Subject: [PATCH 5/5] fix: Change the date format to show elapsed time since it was posted --- education/education/api.py | 6 ++++-- frontend/src/pages/Announcement.vue | 6 +----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/education/education/api.py b/education/education/api.py index 49c314ec..b2f8dbbe 100644 --- a/education/education/api.py +++ b/education/education/api.py @@ -761,16 +761,18 @@ def get_student_attendance(student, student_group): fields=["date", "status", "name"], ) + @frappe.whitelist() def get_announcements(): announcements = frappe.get_all( "Newsletter", filters={"published": 1}, - fields=["subject", "creation","message"] + fields=["subject", "creation", "message"] ) for announcement in announcements: if "creation" in announcement: - announcement["creation"] = datetime.strftime(announcement["creation"], "%m-%d-%Y") + announcement["creation"] = frappe.utils.pretty_date(announcement["creation"]) return announcements + diff --git a/frontend/src/pages/Announcement.vue b/frontend/src/pages/Announcement.vue index 9e67af7c..4de15e1c 100644 --- a/frontend/src/pages/Announcement.vue +++ b/frontend/src/pages/Announcement.vue @@ -29,7 +29,7 @@ {{ item }} @@ -97,10 +97,6 @@ const fetchAnnouncements = createResource({ auto: true, }) -const formatDate = (dateString) => { - return new Date(dateString).toLocaleDateString() -} - const openAnnouncement = (announcement) => { selectedAnnouncement.value = announcement showDialog.value = true