From 8b323add53b1633a372e6198b321b676110a259c Mon Sep 17 00:00:00 2001 From: Thomas Hackl <hackl@data-quest.de> Date: Mon, 5 Aug 2024 11:28:47 +0000 Subject: [PATCH] Resolve "STUDIP.Report in die neuen Notifications integrieren" Closes #4428 Merge request studip/studip!3220 --- .../assets/javascripts/bootstrap/forms.js | 2 +- resources/assets/javascripts/init.js | 2 +- resources/assets/javascripts/lib/dialog.js | 2 +- resources/assets/javascripts/lib/report.js | 48 ------------------- resources/assets/javascripts/lib/report.ts | 45 +++++++++++++++++ 5 files changed, 48 insertions(+), 51 deletions(-) delete mode 100644 resources/assets/javascripts/lib/report.js create mode 100644 resources/assets/javascripts/lib/report.ts diff --git a/resources/assets/javascripts/bootstrap/forms.js b/resources/assets/javascripts/bootstrap/forms.js index 764361291f7..e159699421b 100644 --- a/resources/assets/javascripts/bootstrap/forms.js +++ b/resources/assets/javascripts/bootstrap/forms.js @@ -1,5 +1,5 @@ import { $gettext, $gettextInterpolate } from '../lib/gettext'; -import Report from '../lib/report.js'; +import Report from '../lib/report.ts'; // Allow fieldsets to collapse $(document).on( diff --git a/resources/assets/javascripts/init.js b/resources/assets/javascripts/init.js index b9c1b5bb0ae..8fb9257b5b4 100644 --- a/resources/assets/javascripts/init.js +++ b/resources/assets/javascripts/init.js @@ -61,7 +61,7 @@ import QuickSelection from './lib/quick_selection.js'; import Raumzeit from './lib/raumzeit.js'; import {ready, domReady, dialogReady} from './lib/ready.js'; import register from './lib/register.js'; -import Report from './lib/report.js'; +import Report from './lib/report.ts'; import Resources from './lib/resources.js'; import Responsive from './lib/responsive.js'; import Schedule from './lib/schedule.js'; diff --git a/resources/assets/javascripts/lib/dialog.js b/resources/assets/javascripts/lib/dialog.js index 46f9d981d2c..2ddd7454ac2 100644 --- a/resources/assets/javascripts/lib/dialog.js +++ b/resources/assets/javascripts/lib/dialog.js @@ -3,7 +3,7 @@ import parseOptions from './parse_options.js'; import extractCallback from './extract_callback.js'; import Overlay from './overlay.js'; import PageLayout from './page_layout.js'; -import Report from './report.js'; +import Report from './report.ts'; /** * Specialized dialog handler diff --git a/resources/assets/javascripts/lib/report.js b/resources/assets/javascripts/lib/report.js deleted file mode 100644 index b81e0c4557e..00000000000 --- a/resources/assets/javascripts/lib/report.js +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Message reporting - * - * @author Viktoria Wiebe - * @author Jan-Hendrik Willms <tleilax+studip@gmail.com> - * @version 1.0 - * @since Stud.IP 4.5 - * @license GLP2 or any later version - * @copyright 2019 Stud.IP Core Group - */ - -import Dialog from './dialog.js'; - -let counter = 0; - -function reportMessage(type, title, content, options) { - options.id = `report-${type}-${counter++}`; - options.title = title; - options.size = 'fit'; - options.wikilink = false; - options.dialogClass = `report-${type}`; - - Dialog.show(content, options); -} - -const Report = { - // Info message - info (title, content, options = {}) { - reportMessage('info', title, content, options); - }, - - // Success message - success (title, content, options = {}) { - reportMessage('success', title, content, options); - }, - - // Warning message - warning (title, content, options = {}) { - reportMessage('warning', title, content, options); - }, - - // Error message - error (title, content, options = {}) { - reportMessage('error', title, content, options); - } -}; - -export default Report; diff --git a/resources/assets/javascripts/lib/report.ts b/resources/assets/javascripts/lib/report.ts new file mode 100644 index 00000000000..c1b5fcf96a1 --- /dev/null +++ b/resources/assets/javascripts/lib/report.ts @@ -0,0 +1,45 @@ +/** + * Message reporting + * + * @author Viktoria Wiebe + * @author Jan-Hendrik Willms <tleilax+studip@gmail.com> + * @version 1.0 + * @since Stud.IP 4.5 + * @license GLP2 or any later version + * @copyright 2019 Stud.IP Core Group + */ +import eventBus from "./event-bus"; + +export default class Report +{ + // Info message + static info (title: string, content: string) { + Report.#reportMessage('info', title, content); + } + + // Success message + static success (title: string, content: string) { + Report.#reportMessage('success', title, content); + } + + // Warning message + static warning (title: string, content: string) { + Report.#reportMessage('warning', title, content); + } + + // Error message + static error (title: string, content: string) { + Report.#reportMessage('error', title, content); + } + + static #reportMessage(type: string, title: string, content: string) { + eventBus.emit( + 'push-system-notification', + { + type: type, + message: title, + details: content + } + ); + } +} -- GitLab