-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddms-docks-admin.php
394 lines (315 loc) · 13.8 KB
/
ddms-docks-admin.php
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?php
require_once '../../../wp-load.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<title>Dock test</title>
<style>
:root {
--blrt-color-red: #D31145;
--blrt-color-red-50: #D3114550;
--blrt-color-blue: #0B2265;
}
body {
background-color: white;
font-family: "Open Sans", sans-serif;
}
h3 a {
color: var(--blrt-color-blue);
}
.docks-list {
display: flex;
flex-wrap: wrap;
}
.imagemap {
width: 45%;
height: auto;
margin: 0 auto;
min-width: 600px;
}
.admin__dock-page .imagemap {
width: 100%;
min-width: unset;
display: flex;
}
.admin__dock-page .imagemap svg {
width: auto;
height: 100%;
margin: 0 auto;
}
g[id*="-areas"] path{
stroke-width: 1px;
fill: rgba(255, 255, 255, 0.01);
}
g[id*="-areas"] path.active_area {
stroke-width: 2px;
fill: var(--blrt-color-red-50);
stroke: var(--blrt-color-red) !important;
}
.admin__dock-page g[id*="-areas"] path:hover {
stroke-width: 2px;
fill: rgba(182, 255, 175, 0.5);
stroke: #04C900 !important;
}
.admin__dock-page g[id*="-areas"] path.active_area {
cursor: pointer;
}
.admin__dock-page {
width: 80%;
margin: 0 auto;
}
.admin__dock-page h1 {
text-align: center;
}
.admin__dock-page table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
border: 1px solid #ddd;
}
.admin__dock-page th, .admin__dock-page td {
text-align: left;
padding: 8px;
}
.admin__dock-page tr:nth-child(even){background-color: #f2f2f2}
.admin__dock-page .jobs {
overflow-x:auto;
}
.dock-page__section {
margin-bottom: 50px;
}
.admin__dock-page span[class*="-area_stat"] {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
color: white;
background-color: var(--blrt-color-red);
border-radius: 50%;
height: 25px;
width: 25px;
cursor: default;
pointer-events: none;
}
.ddms-button.button {
display: inline-block;
padding: 10px 30px;
margin: 10px 0 20px 0;
color: white;
font-size: 18px;
background-color: var(--blrt-color-blue);
text-decoration: none;
border-radius: 10px;
border: 2px solid var(--blrt-color-blue);
box-shadow: 2px 4px 10px #a9a9a9;
transition: 0.5s background, color;
}
.ddms-button.button:hover {
color: var(--blrt-color-blue);
background-color: white;
border: 2px solid var(--blrt-color-blue);
}
</style>
</head>
<body>
<?php
$dock_post_id = (int) htmlspecialchars( $_GET["dock_id"] );
if ( ! empty ( $dock_post_id ) ):
/**
*
* Single Dock Template
*/
$dock_data = [];
// Getting dock data
try {
$dock_data = \DDMS\Entities\Dock::getById($dock_post_id);
} catch (\Throwable $th) {
// error_log( $th );
die("No dock found with dock_id: $dock_post_id");
}
if ( !empty( $dock_data ) ):
$dock_active_jobs = \DDMS\Entities\Job::getAllActiveByDockId($dock_data->id);
// var_dump($dock_active_jobs);
$status = ( $dock_data->connection ) ? "<span style='color:green;'>online</span>" : "<span style='color:var(--blrt-color-red);'>offline</span>"; ?>
<div class='admin__dock-page'>
<div class="dock-header">
<p><a target="_parent" href="/wp-admin/admin.php?page=ddms-admin"> < Back to docks </a></p>
<?php echo "<h1>$dock_data->name | $status | active jobs: " . count($dock_active_jobs) ."</h1>"; ?>
</div>
<div id="<?= $dock_data->slug ?>-map" class="imagemap">
<?php
if ( !empty ( $dock_data->svg_imagemap ) ) {
echo $dock_data->svg_imagemap;
} else {
echo "<p> no imagemap provided </p>";
}
?>
<?php $area_stats = []; ?>
<?php if ( ! empty ( $dock_active_jobs ) ): ?>
<?php $job_table_rows = ""; ?>
<?php foreach ($dock_active_jobs as $job): ?>
<?php
// collecting job count for each active area. used for stats lables
( empty( $area_stats[$job->dock_area] ) ) ? $area_stats[$job->dock_area] = 1 : $area_stats[$job->dock_area]++;
?>
<?php $area = \DDMS\Entities\Area::getById($job->dock_area); ?>
<?php // Rendering dock's active areas ?>
<script>
window.addEventListener('load', (event) => {
jQuery("#a-<?= $job->dock_area ?>").addClass("active_area a-<?= $job->dock_area ?>-mark");
jQuery("#a-<?= $job->dock_area ?>").click(function () {
alert(
"Job ID: <?= $job->id ?>\r\n" +
"Job Name: <?= $job->title ?>\r\n" +
"\r\n" +
"Dock: <?= $dock_data->slug ?>\r\n" +
"Area ID: <?= $area->id ?>\r\n" +
"Area Name: <?= $area->title ?>"
);
});
});
</script>
<?php
// Rendering job's table rows
ob_start();
?>
<tr>
<td><?= $job->id ?></td>
<td><?= $job->date_created ?></td>
<td><?= $job->title ?></td>
<td><?= $job->description ?></td>
<td><?= $job->pin ?></td>
<td><?= $job->person ?></td>
<td><?= $job->company ?></td>
<td><?= $area->title ?></td>
<td><?= $job->status ?></td>
</tr>
<?php
$job_table_rows .= ob_get_clean();
?>
<?php endforeach; ?>
<?php endif; ?>
</div>
<div class='dock-page__section'>
<h2>Active Jobs</h2>
<a target="_parent" href="/wp-admin/post-new.php?post_type=job" class="ddms-button button">+ New Job</a>
<div class="jobs active_jobs">
<table>
<tr>
<th>Id</th>
<th>Created</th>
<th>Title</th>
<th>Description</th>
<th>Pin</th>
<th>Person</th>
<th>Company</th>
<th>Area</th>
<th>Status</th>
</tr>
<?= $job_table_rows ?>
</table>
</div>
</div>
</div>
<script>
window.addEventListener('load', (event) => {
// let paths = Array.from(document.getElementsByTagName('path'))
let paths = Array.from(document.querySelectorAll('g[id*="-areas"] path:not(.active_area)'))
let rects = Array.from(document.querySelectorAll('g[id*="-areas"] rect:not(.active_area)'))
let shapes = [...paths, ...rects];
shapes.forEach(shape => {
if (shape.className.baseVal !== 'active_area') {
shape.addEventListener('click', (e) => {
alert("Area: " + e.target.id);
console.log(e.target.id);
})
}
})
<?php //generating job count stat for each active area ?>
<?php if ( ! empty ( $area_stats ) ): ?>
let areaPos;
let statPosOffset = 8;
//
// experiments with svg text
// $("#a-56").after("<text id='sv-text' x=25 y=25 fill='green' style='font: bold 30px sans-serif;'>55</text>");
// $(".imagemap").after("<text id='sv-text' x=25 y=25 fill='green' style='font: bold 30px sans-serif;'>55</text>");
// console.log( $("text") )
// console.log( $("text").position() )
// $("text").css({
// 'transform' : 'translate(' + 200 +', ' + 300 + ')'
// })
// console.log( $("text").position() )
<?php foreach ($area_stats as $a => $s): ?>
areaPos = $('#a-<?= $a ?>').position();
$(".imagemap").after("<span class='a-<?= $a ?>-area_stat stat a-<?= $a ?>-mark'><?= $s ?></span>");
$(".a-<?= $a ?>-area_stat").css({
top : areaPos.top + statPosOffset,
left : areaPos.left + statPosOffset
});
<?php endforeach; ?>
<?php // re-rendering area's stats position on window resize ?>
$( window ).resize(function() {
let activeAreas = Array.from( $('.active_area') );
activeAreas.forEach(a => {
let aNewPos = $(a).position();
let aMark = a.className.baseVal.split(' ')[1];
$(".stat." + aMark).css({
top : aNewPos.top + statPosOffset,
left : aNewPos.left + statPosOffset
});
});
});
<?php endif; ?>
});
</script>
<?php
endif;
else: ?>
<p><!-- DDMS admin page style: <?= get_template_directory_uri() . 'ddms-admin-style.css' ?> --></p>
<div class="docks-list">
<?php
$all_docks = \DDMS\Entities\Dock::getAll();
if ( !empty( $all_docks ) ) {
foreach ($all_docks as $dock) {
$dock_active_jobs = \DDMS\Entities\Job::getAllActiveByDockId($dock->id);
// var_dump($dock_active_jobs);
$status = ( $dock->connection ) ? "<span style='color:green;'>online</span>" : "<span style='color:var(--blrt-color-red);'>offline</span>"; ?>
<div id="<?= $dock->slug ?>-map" class="imagemap">
<div class="dock-header">
<h3><a href="?dock_id=<?= $dock->id ?>"><?= $dock->name ?></a> <?= $status ?></h3>
<h5>Active jobs: <?= count($dock_active_jobs) ?></h5>
<?php if ( ! empty ( $dock_active_jobs ) ): ?>
<?php foreach ($dock_active_jobs as $job): ?>
<?php $area = \DDMS\Entities\Area::getById($job->dock_area); ?>
<script>
window.addEventListener('load', (event) => {
jQuery("#a-<?= $job->dock_area ?>").addClass("active_area");
// jQuery("#a-<?= $job->dock_area ?>").click(function () {
// alert( "Job ID: <?= $job->id ?>\r\n" + "Job Name: <?= $job->title ?>\r\n" + "\r\nDock: <?= $dock->slug ?>\r\n" + "Area ID: <?= $area->id ?>\r\n" + "Area Name: <?= $area->title ?>" );
// });
});
</script>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php
if ( !empty ( $dock->svg_imagemap ) ) {
echo $dock->svg_imagemap;
} else {
echo "<p> no imagemap provided </p>";
}
?>
</div>
<?php
}
}
?>
</div>
<?php endif; ?>
</body>
</html>