-
Notifications
You must be signed in to change notification settings - Fork 14
[OGUI-1854] Notify user via native browser notification when a new run has started #3258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hehoon
wants to merge
23
commits into
dev
Choose a base branch
from
feature/QCG/OGUI-1854/notify-user-when-a-new-run-has-started
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
fa667bc
Notify user via native browser notification when a new run has started
hehoon 033aeb8
Fix failing tests
hehoon ac82b0e
Add `getPageTargetModel` to `FilterModel` and rewrite `filterSpecific…
hehoon 591fb80
on notification click, the runmode for that runnumber should be enabled
hehoon 4abdbfa
Backend tests
hehoon caf1e3f
Add tests
hehoon 22d4ca0
Notify user via native browser notification when a new run has started
hehoon 669f350
Fix failing tests
hehoon 05d4d6a
Add `getPageTargetModel` to `FilterModel` and rewrite `filterSpecific…
hehoon f0ff74b
on notification click, the runmode for that runnumber should be enabled
hehoon 34331ae
Backend tests
hehoon db1b8f2
Add tests
hehoon f2475f2
Merge branch 'dev' into feature/QCG/OGUI-1854/notify-user-when-a-new-…
hehoon 89d648b
Merge branch 'feature/QCG/OGUI-1854/notify-user-when-a-new-run-has-st…
hehoon af57099
Use the `BrowserNotificationPermission` enum in `header.js`
hehoon 03d1080
Merge branch 'dev' into feature/QCG/OGUI-1854/notify-user-when-a-new-…
hehoon 3ba3362
Do not show filters when editing the layout on the layout show page
hehoon c1655dc
Merge branch 'dev' into feature/QCG/OGUI-1854/notify-user-when-a-new-…
hehoon 3f6a5f9
Update test queries
hehoon 286b31c
Address PR feedback
hehoon 5d82e3d
Remove unnecessary `async` from `getBrowserNotificationSetting`
hehoon d1f0aa2
Fix eslint errors
hehoon 6076a27
Fix docs after attribute name change
hehoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
102 changes: 102 additions & 0 deletions
102
QualityControl/public/common/notifications/model/NotificationRunStartModel.js
This file contains hidden or 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,102 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
| * See http://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
| * All rights not expressly granted are reserved. | ||
| * | ||
| * This software is distributed under the terms of the GNU General Public | ||
| * License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
| * | ||
| * In applying this license CERN does not waive the privileges and immunities | ||
| * granted to it by virtue of its status as an Intergovernmental Organization | ||
| * or submit itself to any jurisdiction. | ||
| */ | ||
|
|
||
| import { Observable, BrowserStorage, showNativeBrowserNotification, | ||
| areBrowserNotificationsGranted } from '/js/src/index.js'; | ||
| import { EmitterKeys } from '../../../../library/enums/emitterKeys.enum.js'; | ||
| import { StorageKeysEnum } from '../../enums/storageKeys.enum.js'; | ||
|
|
||
| /** | ||
| * Model responsible for handling browser notifications when a new run starts. | ||
| */ | ||
| export default class NotificationRunStartModel extends Observable { | ||
| /** | ||
| * Initialize with empty values | ||
| * @param {Model} model - root model of the application | ||
| */ | ||
| constructor(model) { | ||
| super(); | ||
|
|
||
| this.model = model; | ||
| this._browserNotificationStorage = new BrowserStorage(StorageKeysEnum.NOTIFICATION_START_RUN_SETTING); | ||
|
|
||
| this.model.ws.addListener('command', (message) => { | ||
| if (message.command === EmitterKeys.RUN_TRACK) { | ||
| this._handleWSRunTrack.bind(this, message.payload); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether browser notifications for run start events | ||
| * are enabled for the current user. | ||
| * @returns {boolean} `true` if notifications are enabled, `false` otherwise. | ||
| */ | ||
| getBrowserNotificationSetting() { | ||
| try { | ||
| if (this._browserNotificationStorage.getLocalItem(this.model.session.personid.toString())) { | ||
| return areBrowserNotificationsGranted(); | ||
| } | ||
| return false; | ||
| } catch { | ||
| this._browserNotificationStorage.removeLocalItem(this.model.session.personid.toString()); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Persists the browser notification preference for the current user | ||
| * and notifies all observers. | ||
| * @param {boolean} enabled - Whether notifications should be enabled. | ||
| * @returns {undefined} | ||
| */ | ||
| setBrowserNotificationSetting(enabled) { | ||
| this._browserNotificationStorage.setLocalItem(this.model.session.personid.toString(), enabled); | ||
| this.notify(); | ||
| } | ||
|
|
||
| /** | ||
| * Handles {@link EmitterKeys.RUN_TRACK} WebSocket events. | ||
| * A native browser notification is displayed only when: | ||
| * - The transition is {@link Transition.START_ACTIVITY} | ||
| * - The user has enabled notifications | ||
| * @param {object} payload - WebSocket payload. | ||
| * @param {number} payload.runNumber - Run number that started. | ||
| * @returns {undefined} | ||
| */ | ||
| async _handleWSRunTrack({ runNumber }) { | ||
| if (!this.getBrowserNotificationSetting()) { | ||
| return; | ||
| } | ||
|
|
||
| showNativeBrowserNotification({ | ||
| title: `RUN ${runNumber ?? 'unknown'} has started`, | ||
| onclick: () => { | ||
| // On notification click we always navigate to the `objectTree` page. | ||
| // Additionally, we view the run using the given `runNumber`. | ||
| this.model.router.go(`?page=objectTree&RunNumber=${runNumber}`); | ||
|
|
||
| // If RunMode is not activated, we should enable it | ||
| const { isRunModeActivated } = this.model.filterModel; | ||
| if (!isRunModeActivated) { | ||
| this.model.filterModel.activateRunsMode(this.model.filterModel.getPageTargetModel()); | ||
| } | ||
|
|
||
| // We select the given `runNumber` in RunMode. | ||
| // We do not have to set the parameter in the URL, as this is already achieved on navigation. | ||
| this.model.filterModel.setFilterValue('RunNumber', runNumber?.toString()); | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.