-
Notifications
You must be signed in to change notification settings - Fork 162
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
[WIP] Songlist webserver #911
Draft
irgendwr
wants to merge
17
commits into
UltraStar-Deluxe:master
Choose a base branch
from
irgendwr:songlist_webserver
base: master
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.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1aac5c5
Add UWebServer which serves the list of available songs on localhost,…
bohning 285ae08
Use datatables, add http routing
irgendwr 497a74b
force 100% width
irgendwr b355828
Remove un-minified js
irgendwr 0ca2831
Merge branch 'master' into songlist_webserver
irgendwr ca7dc66
add dark theme
irgendwr 189f689
adjust colors
irgendwr ae03bfc
remember page length
irgendwr 0333969
reorder head refs
irgendwr a0fa770
fix page length
irgendwr b3d58fe
add JSON API
irgendwr 3f2c400
default to 404/405
irgendwr 831e84d
add cover API
irgendwr 8792efd
stream files, refactor MIME
irgendwr f0f9cd0
add more MIME types
irgendwr 3e4688a
generic song file API
irgendwr b1d3c01
add optional json attributes
irgendwr 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,86 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Song List</title> | ||
|
||
<script src="/theme.js" fetchpriority="high" blocking="render"></script> | ||
<link rel="stylesheet" href="/style.css" /> | ||
|
||
<script src="/jquery.min.js"></script> | ||
<script src="/datatables.min.js"></script> | ||
<link rel="stylesheet" href="/datatables.min.css" /> | ||
</head> | ||
<body> | ||
<h1>Song List</h1> | ||
|
||
<div class="controls"> | ||
<div class="toggle-switch"> | ||
<label> | ||
<input type="checkbox" id="themeToggle"> | ||
<span class="slider"></span> | ||
</label> | ||
</div> | ||
</div> | ||
|
||
<table id="songTable" class="hover stripe"> | ||
<thead> | ||
<tr> | ||
<th>Artist</th> | ||
<th>Title</th> | ||
<th>Edition</th> | ||
<th>Genre</th> | ||
<th>Year</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<!--SONG_ROWS--> | ||
</tbody> | ||
</table> | ||
|
||
<script> | ||
const defaultPageLength = 25; | ||
const PAGE_LENGTH = "pageLength"; | ||
|
||
let pageLength = parseInt(localStorage.getItem(PAGE_LENGTH), 10); | ||
if (!pageLength || pageLength < 10 || pageLength > 100) { | ||
pageLength = defaultPageLength; | ||
} | ||
|
||
let table = new DataTable('#songTable', { | ||
// default entries per page | ||
pageLength: pageLength, | ||
layout: { | ||
top: { | ||
search: { | ||
text: '', | ||
placeholder: 'Search for songs…' | ||
} | ||
}, | ||
topStart: null, | ||
topEnd: null, | ||
bottomStart: [ | ||
{ | ||
pageLength: { | ||
menu: [ 10, 25, 50, 100 ] | ||
} | ||
}, | ||
], | ||
bottom2: { | ||
info: { | ||
text: 'Showing _START_ to _END_ of _TOTAL_ songs' | ||
} | ||
}, | ||
bottomEnd: { | ||
paging: { | ||
// numbers: 6 | ||
} | ||
} | ||
} | ||
}); | ||
table.on('length.dt', function (e, settings, len) { | ||
localStorage.setItem(PAGE_LENGTH, len); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,107 @@ | ||
/* Default colors */ | ||
:root { | ||
--text-color: #121212; | ||
--bkg-color: #fff; | ||
--accent-color: #add8e6; | ||
} | ||
/* Dark theme colors */ | ||
[data-theme="dark"] { | ||
--text-color: #fff; | ||
--bkg-color: #181a1b; | ||
--accent-color: rgb(27, 73, 88); | ||
} | ||
|
||
body { | ||
font-family: Arial, sans-serif; | ||
background: var(--bkg-color); | ||
color: var(--text-color); | ||
} | ||
|
||
table { | ||
width: 100% !important; | ||
} | ||
|
||
th, td { | ||
padding: 8px; | ||
text-align: left; | ||
} | ||
|
||
th { | ||
background-color: var(--accent-color); | ||
} | ||
|
||
input { | ||
margin-bottom: 12px; | ||
padding: 8px; | ||
width: 100%; | ||
} | ||
|
||
.controls { | ||
position: absolute; | ||
top: 12px; | ||
right: 10px; | ||
} | ||
|
||
|
||
/* Toggle Switch */ | ||
/* inspired by: | ||
- https://codepen.io/alvarotrigo/pen/zYPydpB | ||
- https://dribbble.com/shots/14199649-Dark-Light-Mode-Toggle-Switch-Pattern-A11y | ||
*/ | ||
|
||
:root { | ||
--switch-light: #d8dbe0; | ||
--switch-dark: #28292c; | ||
--switch-width: 60px; | ||
--switch-height: 30px; | ||
} | ||
|
||
.toggle-switch { | ||
position: relative; | ||
width: var(--switch-width); | ||
|
||
label { | ||
position: absolute; | ||
width: 100%; | ||
height: var(--switch-height); | ||
background-color: var(--switch-dark); | ||
border-radius: calc(var(--switch-height)/2); | ||
cursor: pointer; | ||
} | ||
|
||
input { | ||
position: absolute; | ||
display: none; | ||
} | ||
|
||
.slider { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
border-radius: calc(var(--switch-height)/2); | ||
transition: 0.3s; | ||
} | ||
|
||
input:checked ~ .slider { | ||
background-color: var(--switch-light); | ||
} | ||
|
||
.slider::before { | ||
content: ""; | ||
position: absolute; | ||
top: calc(var(--switch-height)*0.13); | ||
left: calc(var(--switch-height)*0.16); | ||
width: calc(var(--switch-height)*0.75); | ||
height: calc(var(--switch-height)*0.75); | ||
border-radius: 50%; | ||
box-shadow: inset calc(var(--switch-height)*0.28) -4px 0 0 var(--switch-light); | ||
background-color: var(--switch-dark); | ||
transition: 0.3s; | ||
} | ||
|
||
input:checked ~ .slider::before { | ||
transform: translateX(calc(var(--switch-height)*0.95)); | ||
background-color: var(--switch-dark); | ||
box-shadow: none; | ||
} | ||
} |
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,56 @@ | ||
const LIGHT_THEME = "light", DARK_THEME = "dark"; | ||
|
||
function isValidTheme(theme) { | ||
return theme === LIGHT_THEME || theme === DARK_THEME | ||
} | ||
|
||
function getTheme() { | ||
let theme = localStorage.getItem("theme"); | ||
if (isValidTheme(theme)) { | ||
return theme; | ||
} | ||
|
||
if (window.matchMedia("(prefers-color-scheme: dark)")) { | ||
return DARK_THEME; | ||
} | ||
|
||
return LIGHT_THEME; | ||
} | ||
|
||
function isLightTheme() { | ||
return getTheme() === LIGHT_THEME | ||
} | ||
|
||
function setTheme(theme) { | ||
if (!isValidTheme(theme)) return; | ||
|
||
document.documentElement.setAttribute("data-theme", theme); | ||
localStorage.setItem("theme", theme); | ||
} | ||
|
||
function toggleTheme() { | ||
if (isLightTheme()) { | ||
setTheme(DARK_THEME); | ||
} else { | ||
setTheme(LIGHT_THEME); | ||
} | ||
} | ||
|
||
// initialize theme | ||
setTheme(getTheme()); | ||
|
||
function updateToggle(toggle) { | ||
toggle.checked = isLightTheme() | ||
} | ||
|
||
window.onload = function() { | ||
let toggle = document.querySelector("#themeToggle"); | ||
|
||
toggle.addEventListener("change", () => { | ||
toggleTheme(); | ||
updateToggle(toggle); | ||
}); | ||
|
||
// initialize toggle | ||
updateToggle(toggle); | ||
} |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make the port configurable, but set it to strictly only listen on localhost. If people want to have it reachable over network, this forces them to put at the very least a tiny bit of effort into setting up a reverse proxy, which then hopefully has much less attack surface than the old UWebServer.