-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
1,094 additions
and
315 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
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
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
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,80 @@ | ||
<script setup> | ||
import { h, onMounted } from 'vue' | ||
import { useNotification } from 'naive-ui' | ||
import { localStorageWrapper } from '../shared/local-storage-wrapper' | ||
import { JSONWrapper } from '../shared/json-wrapper' | ||
import { STATUS_STORAGE_KEY, generateStatusTestId } from '../shared/status-common' | ||
const getDismissedStatuses = () => { | ||
const jsonString = localStorageWrapper.getItem(STATUS_STORAGE_KEY) | ||
const jsonValue = JSONWrapper.parse(jsonString, []) | ||
if(Array.isArray(jsonValue)) { | ||
return jsonValue | ||
} | ||
return [] | ||
} | ||
const dismissStatus = (id) => { | ||
const dissmissed = [id, ...getDismissedStatuses()] | ||
localStorageWrapper.setItem(STATUS_STORAGE_KEY, JSONWrapper.stringify(dissmissed)) | ||
return true | ||
} | ||
let notificationInstances = {} // keyed by status.id | ||
let notification | ||
const pollStatusAPI = () => { | ||
fetch('/status/latest.json') | ||
.then(resp => resp.json()) | ||
.then(status => { | ||
if(status === null || status.hasMessage === false) { | ||
console.debug("No status message") | ||
return | ||
} | ||
const dismissedStatuses = getDismissedStatuses() | ||
if(dismissedStatuses.includes(status.id)) { | ||
console.debug(`Not showing site status ${status.id} because it was already dismissed. Dismissed Ids:`, dismissedStatuses) | ||
return | ||
} | ||
const isSameStatusPage = Boolean(document.querySelector(`[data-status-id="${status.id}"]`)) | ||
if(isSameStatusPage) { | ||
console.debug(`Not showing site status ${status.id} because we're on the target page`) | ||
return | ||
} | ||
if(notificationInstances[status.id]) { | ||
console.debug(`Not showing site status ${status.id} because it's already been displayed`) | ||
return | ||
} | ||
notificationInstances[status.id] = notification.create({ | ||
title: status.title, | ||
content: status.body, | ||
meta: `${status.date}`, | ||
action: () => | ||
h( | ||
'a', | ||
{ | ||
'data-testid': generateStatusTestId(status.id), | ||
href: status.url, | ||
'aria-label': `Read more about ${status.title}` | ||
}, | ||
"Read more" | ||
), | ||
onClose: () => { | ||
return dismissStatus(status.id) | ||
} | ||
}) | ||
}) | ||
.catch(e => { | ||
console.error(e) | ||
}) | ||
} | ||
onMounted(() => { | ||
notification = useNotification() | ||
pollStatusAPI(notification) | ||
}) | ||
</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
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,20 @@ | ||
export const JSONWrapper = { | ||
parse(jsonString, defaultValue) { | ||
if(typeof jsonString !== "string") { | ||
return defaultValue | ||
} | ||
try { | ||
return JSON.parse(jsonString); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
return defaultValue | ||
}, | ||
stringify(data) { | ||
try { | ||
return JSON.stringify(data); | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
}, | ||
} |
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,42 @@ | ||
|
||
/* | ||
* DEVELOPER NOTE | ||
* | ||
* Some browsers can block storage (localStorage, sessionStorage) | ||
* access for privacy reasons, and all browsers can have storage | ||
* that's full, and then they throw exceptions. | ||
* | ||
* See https://michalzalecki.com/why-using-localStorage-directly-is-a-bad-idea/ | ||
* | ||
* Exceptions can even be thrown when testing if localStorage | ||
* even exists. This can throw: | ||
* | ||
* if (window.localStorage) | ||
* | ||
* Also localStorage/sessionStorage can be enabled after DOMContentLoaded | ||
* so we handle it gracefully. | ||
* | ||
* 1) we need to wrap all usage in try/catch | ||
* 2) we need to defer actual usage of these until | ||
* necessary, | ||
* | ||
*/ | ||
|
||
export const localStorageWrapper = { | ||
getItem: (key) => { | ||
try { | ||
return localStorage.getItem(key) | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
return null; | ||
}, | ||
setItem: (key, value) => { | ||
try { | ||
return localStorage.setItem(key, value) | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
return; | ||
}, | ||
} |
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,5 @@ | ||
// Used in Playwright Status and components | ||
|
||
export const STATUS_STORAGE_KEY = "status-dismissed" | ||
|
||
export const generateStatusTestId = (id) => `status-${id}` |
Empty file.
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,6 @@ | ||
# Copyright The IETF Trust 2024, All Rights Reserved | ||
from django.contrib.admin import apps as admin_apps | ||
|
||
|
||
class AdminConfig(admin_apps.AdminConfig): | ||
default_site = "ietf.admin.sites.AdminSite" |
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,15 @@ | ||
# Copyright The IETF Trust 2024, All Rights Reserved | ||
from django.contrib.admin import AdminSite as _AdminSite | ||
from django.conf import settings | ||
from django.utils.safestring import mark_safe | ||
|
||
|
||
class AdminSite(_AdminSite): | ||
site_title = "Datatracker admin" | ||
|
||
@staticmethod | ||
def site_header(): | ||
if settings.SERVER_MODE == "production": | ||
return "Datatracker administration" | ||
else: | ||
return mark_safe('Datatracker administration <span class="text-danger">δ</span>') |
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
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,15 @@ | ||
from django.apps import AppConfig | ||
from . import populate_api_list | ||
|
||
|
||
class ApiConfig(AppConfig): | ||
name = "ietf.api" | ||
|
||
def ready(self): | ||
"""Hook to do init after the app registry is fully populated | ||
Importing models or accessing the app registry is ok here, but do not | ||
interact with the database. See | ||
https://docs.djangoproject.com/en/4.2/ref/applications/#django.apps.AppConfig.ready | ||
""" | ||
populate_api_list() |
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
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
Oops, something went wrong.