summaryrefslogtreecommitdiff
path: root/web/index.html
blob: db313c48e515f79ce9da5b536b2722d912f37418 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="common.css">
<script>

setInterval(function() {
	status = fetch("/api/v1/status").then(response => {
		response.json().then(data => {
			if (data.playing) {
				document.getElementById('playing').innerHTML = "Playing";
			} else {
				document.getElementById('playing').innerHTML = "Stopped";
			}
			document.getElementById('dcp_name').innerHTML = data.dcp_name;
			document.getElementById('position').innerHTML = data.position;
		});
	});
}, 250);
function play() {
	fetch("/api/v1/play", { method: "POST" });
}
function stop() {
	fetch("/api/v1/stop", { method: "POST" });
}

function selectedPlaylistId()
{
	var children = document.getElementById("content-and-playlists-inner").children;
	for (var i = 0; i < children.length; i++) {
		if (children[i].classList.contains("selected")) {
			return children[i].uuid;
		}
	}

	return null;
}


function setSelectedPlaylist(uuid)
{
	var children = document.getElementById("content-and-playlists-inner").children;
	for (var i = 0; i < children.length; i++) {
		var child = children[i];
		if (child.uuid == uuid) {
			child.classList.add("selected");
		} else {
			child.classList.remove("selected");
		}
	}
};

	
// Fetch all playlists and put them in the shared content/playlists div
function showPlaylists()
{
	var div = document.getElementById('content-and-playlists-inner');
	if (div) {
		div.innerHTML = "";
	}

	fetch("/api/v1/playlists").then(response => {
		response.json().then(data => {
			data.forEach(playlist => {
				var li = document.createElement("li");
				li.classList.add("playlist");
				li.appendChild(document.createTextNode(playlist.name));
				li.uuid = playlist['uuid'];
				li.onclick = function() {
					setSelectedPlaylist(playlist['uuid']);
				};
				document.getElementById('content-and-playlists-inner').appendChild(li);
			});

			document.getElementById('playlists-tab').classList.add('selected');
			document.getElementById('content-tab').classList.remove('selected');
		});
	});
}

function showContent()
{
	var div = document.getElementById('content-and-playlists-inner');
	if (div) {
		div.innerHTML = "";
	}

	fetch("/api/v1/content").then(response => {
		response.json().then(data => {
			data.forEach(content => {
				var li = document.createElement("li");
				li.classList.add("playlist");
				li.appendChild(document.createTextNode(content.name));
				document.getElementById('content-and-playlists-inner').appendChild(li);

				document.getElementById('content-tab').classList.add('selected');
				document.getElementById('playlists-tab').classList.remove('selected');
			});
		});
	})
}

showPlaylists();
</script>

<style>
table {
	border-collapse: collapse;
	margin: 25px 0;
	font-size: 0.9em;
	box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
	border: 2px solid black;
}

tr {
	text-align: left;
	border: 1px solid black;
}

td {
	padding: 4px 16px;
	text-align: left;
	border: 1px solid black;
}

div.tab {
	padding: 6px;
	border: 0.5px solid black;
	background-color: #eeeeee;
	width: fit-content;
	display: inline-block;
	cursor: pointer;
	margin: 2px;
}

div.tab.selected {
	background-color: #cccccc;
}

li.playlist {
	border: 1px solid black;
	background-color: #a7bad9;
	padding: 3px;
	list-style-type: none;
	cursor: pointer;
}

li.playlist.selected {
	background-color: #d343e0;
	cursor: pointer;
}

</style>

<title>TITLE</title>

</head>
<body>

SIDEBAR

<div id="controls" style="float: left; width: 20%;">
	<button name="play" value="play" onclick="play()">Play</button>
	<button name="stop" value="stop" onclick="stop()">Stop</button>
	<table>
		<tr><td>DCP</td><td><p id="dcp_name"></td></tr>
		<tr><td>State</td><td><p id="playing"></td></tr>
		<tr><td>Position</td><td><p id="position"></td></tr>
	</table>
</div>

<div id="current-playlist" style="float: left; width: 20%;">
Current playlist:
</div>

<div id="content-and-playlists" style="float: left; width: 20%;">
<div id="playlists-tab" onclick="showPlaylists();" class="tab selected">Playlists</div>
<div id="content-tab" onclick="showContent();" class="tab">Content</div>
<div id="content-and-playlists-inner" style="margin-top: 5pt; margin-bottom: 5pt;"></div>
</div>
</body>
</html>