Browse Source

- Implement user/home

- Allow custom default location on map
master
Bernhard Fröhlich 2 years ago
parent
commit
a296984dbe
7 changed files with 149 additions and 16 deletions
  1. 5
    0
      css/custom.css
  2. 32
    3
      index.php
  3. 11
    1
      lib/FunkFeuer/Nodeman/Location.php
  4. 6
    4
      templates/_header.html
  5. 12
    8
      templates/locations.html
  6. 8
    0
      templates/map.js
  7. 75
    0
      templates/user/home.html

+ 5
- 0
css/custom.css View File

@@ -6,3 +6,8 @@ body {
height: 500px;
}

.navbar-nav > li {
padding-left: 0.5rem;
padding-right: 0.5rem;
}


+ 32
- 3
index.php View File

@@ -121,15 +121,27 @@ $app->post('/register', function ($request, $response) use ($session) {

/* Map */
$app->get('/map', function ($request, $response) use ($session) {
$query = '';

if ($request->getParam('lat') && $request->getParam('lng')) {
$query = sprintf('?lat=%lf&lng=%lf', $request->getParam('lat'), $request->getParam('lng'));
}

return $this->view->render($response, 'map.html', array(
'css' => array('/css/leaflet.css', '/css/map.css'),
'js' => array('/js/leaflet.js', '/map.js')
'js' => array('/js/leaflet.js', '/map.js'.$query)
));
});

$app->get('/map.js', function ($request, $response) use ($session) {
$location = new Location();
$locations = array();
$deflocation = array();

if ($request->getParam('lat') && $request->getParam('lng')) {
$deflocation['lat'] = $request->getParam('lat');
$deflocation['lng'] = $request->getParam('lng');
}

foreach ($location->getAllLocations(null, 0, 999999) as $loc) {
$popup = sprintf('<b>%s</b><br>%s', $loc->name, $loc->address);
@@ -147,8 +159,9 @@ $app->get('/map.js', function ($request, $response) use ($session) {
}

return $this->view->render($response, 'map.js', array(
'locations' => $locations,
'links' => array()
'deflocation' => $deflocation,
'locations' => $locations,
'links' => array()
))->withHeader('Content-Type', 'application/javascript; charset=utf-8');
});

@@ -300,4 +313,20 @@ $app->post('/location/{locationid}/add', function ($request, $response, $args) u
));
});

/* User Area */
$app->get('/user/home', function ($request, $response) use ($session) {
if (!$session->isAuthenticated()) {
$this->flash->addMessage('error', 'Please login first');

return $response->withStatus(302)->withHeader('Location', '/');
}

$loc = new Location();

return $this->view->render($response, 'user/home.html', array(
'user' => $session->getUser(),
'locations' => $loc->getAllLocations($session->getUser()->userid, 0, 999999)
));
});

$app->run();

+ 11
- 1
lib/FunkFeuer/Nodeman/Location.php View File

@@ -148,7 +148,17 @@ class Location
return $stmt->fetch(\PDO::FETCH_BOTH)[0];
}

public function getAllNodes()
public function countNodes()
{
$stmt = $this->_handle->prepare('SELECT count(*) FROM nodes WHERE location = ?');
if (!$stmt->execute(array($this->location))) {
return false;
}

return $stmt->fetch(\PDO::FETCH_BOTH)[0];
}

public function getNodes()
{
$data = array();


+ 6
- 4
templates/_header.html View File

@@ -38,15 +38,17 @@
<li class="nav-item active">
<a class="nav-link" href="/register">Register</a>
</li>
{% else %}
<li class="nav-item active">
<a class="nav-link" href="/location/add">Add Location</a>
</li>
{% endif %}
</ul>

{% if session.isAuthenticated() %}
<ul class="navbar-nav float-right">
<li class="nav-item active">
<a class="nav-link btn btn-outline-primary" href="/user/home">
<span class="oi oi-person" title="icon person" aria-hidden="true"></span>
My Locations
</a>
</li>
<li class="nav-item">
<a class="btn btn-outline-success" href="/logout">Logout</a>
</li>

+ 12
- 8
templates/locations.html View File

@@ -5,15 +5,19 @@
<h1>Locations</h1>

<table class="table table-striped">
<thead><tr><th>Name</th><th style="width: 60%">Address</th><th>Status</th></tr></thead>
<thead><tr><th>Name</th><th style="width: 60%">Address</th><th>Status</th><th></th></tr></thead>

{% for loc in locations %}
<tr>
<td><a href="/location/{{ loc.locationid }}/">{{ loc.name }}</a></td>
<td>{{ loc.address }}</td>
<td><img src="/css/images/tower-{{ loc.status }}.svg" style="height: 2em" alt="{{ loc.status }}"></td>
</tr>
{% endfor %}
{% for loc in locations %}
<tr>
<td><a href="/location/{{ loc.locationid }}/">{{ loc.name }}</a></td>
<td>{{ loc.address }} <a href="/map?lat={{ loc.latitude }}&lng={{ loc.longitude }}" class="btn btn-outline-primary btn-sm">
<span class="oi oi-map-marker" title="icon map-marker" aria-hidden="true"></span>
</a>
</td>
<td><img src="/css/images/tower-{{ loc.status }}.svg" style="height: 2em" alt="{{ loc.status }}"></td>
<td><a href="/location/{{ loc.locationid }}" class="btn btn-primary btn-sm">Show</a></td>
</tr>
{% endfor %}

</table>


+ 8
- 0
templates/map.js View File

@@ -1,6 +1,10 @@
var map;

{% if deflocation %}
var deflocation = [{{ deflocation.lat }}, {{ deflocation.lng }}];
{% else %}
var deflocation = [47.0707, 15.4395];
{% endif %}
var defzoom = 13;

function initmap() {
@@ -33,6 +37,10 @@ function initmap() {

L.control.layers({ "Karte": basemap, "Satellit": orthomap, "Terrain": topomap }).addTo(map);

{% if deflocation %}
L.marker([{{ deflocation.lat }}, {{ deflocation.lng }}]).addTo(map);
{% endif %}

// custom icons
var TowerIcon = L.Icon.extend({
options: {

+ 75
- 0
templates/user/home.html View File

@@ -0,0 +1,75 @@
{% include('_header.html') %}

<div class="container">

<div class="row">
<div class="col-sm-6">
<div class="card">
<div class="card-header"><h5>User Details</h5></div>
<div class="card-body">
<div class="row">
<div class="col-3"><b>E-Mail:</b></div>
<div class="col">{{ user.email }}</div>
</div>
<div class="row">
<div class="col-3"><b>Name:</b></div>
<div class="col">{{ user.firstname }} {{ user.lastname }}</div>
</div>
<div class="row">
<div class="col-3"><b>Phone:</b></div>
<div class="col">{{ user.phone }}</div>
</div>
<div class="row text-right">
<div class="col">
<a href="/user/edit" class="btn btn-primary">Edit userdata</a>
<a href="/user/changepwd" class="btn btn-primary">Change password</a>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card">
<div class="card-header"><h5>Locations</h5></div>
<div class="card-body">
<div class="row">
<div class="col">
<a href="/location/add" class="btn btn-primary">Add Location</a>
</div>
</div>
</div>
</div>
</div>
</div>

<br />

<h2>Your Locations</h2>

<table class="table table-striped">
<thead><tr><th>Name</th><th style="width: 60%">Address</th><th>Status</th><th></th></tr></thead>
<tbody>

{% for loc in locations %}
<tr>
<td><a href="/location/{{ loc.locationid }}/">{{ loc.name }}</a></td>
<td>{{ loc.address }} <a href="/map?lat={{ loc.latitude }}&lng={{ loc.longitude }}" class="btn btn-outline-primary btn-sm">
<span class="oi oi-map-marker" title="icon map-marker" aria-hidden="true"></span>
</a>
</td>
<td><img src="/css/images/tower-{{ loc.status }}.svg" style="height: 2em" alt="{{ loc.status }}"></td>
<td>
<a href="/location/{{ loc.locationid }}" class="btn btn-primary btn-sm">Show</a>
<a href="/location/{{ loc.locationid }}/edit" class="btn btn-primary btn-sm">
<span class="oi oi-wrench" title="icon wrench" aria-hidden="true"></span>
</a>
</td>
</tr>
{% endfor %}

</tbody>
</table>

</div>

{% include('_footer.html') %}

Loading…
Cancel
Save