Browse Source

- Implement user/home

- Allow custom default location on map
master
Bernhard Fröhlich 1 year 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 {
6 6
   height: 500px;
7 7
 }
8 8
 
9
+.navbar-nav > li {
10
+  padding-left: 0.5rem;
11
+  padding-right: 0.5rem;
12
+}
13
+

+ 32
- 3
index.php View File

@@ -121,15 +121,27 @@ $app->post('/register', function ($request, $response) use ($session) {
121 121
 
122 122
 /* Map */
123 123
 $app->get('/map', function ($request, $response) use ($session) {
124
+    $query = '';
125
+
126
+    if ($request->getParam('lat') && $request->getParam('lng')) {
127
+        $query = sprintf('?lat=%lf&lng=%lf', $request->getParam('lat'), $request->getParam('lng'));
128
+    }
129
+
124 130
     return $this->view->render($response, 'map.html', array(
125 131
         'css' => array('/css/leaflet.css', '/css/map.css'),
126
-        'js'  => array('/js/leaflet.js', '/map.js')
132
+        'js'  => array('/js/leaflet.js', '/map.js'.$query)
127 133
     ));
128 134
 });
129 135
 
130 136
 $app->get('/map.js', function ($request, $response) use ($session) {
131 137
     $location = new Location();
132 138
     $locations = array();
139
+    $deflocation = array();
140
+
141
+    if ($request->getParam('lat') && $request->getParam('lng')) {
142
+        $deflocation['lat'] = $request->getParam('lat');
143
+        $deflocation['lng'] = $request->getParam('lng');
144
+    }
133 145
 
134 146
     foreach ($location->getAllLocations(null, 0, 999999) as $loc) {
135 147
         $popup = sprintf('<b>%s</b><br>%s', $loc->name, $loc->address);
@@ -147,8 +159,9 @@ $app->get('/map.js', function ($request, $response) use ($session) {
147 159
     }
148 160
 
149 161
     return $this->view->render($response, 'map.js', array(
150
-        'locations' => $locations,
151
-        'links'     => array()
162
+        'deflocation' => $deflocation,
163
+        'locations'   => $locations,
164
+        'links'       => array()
152 165
     ))->withHeader('Content-Type', 'application/javascript; charset=utf-8');
153 166
 });
154 167
 
@@ -300,4 +313,20 @@ $app->post('/location/{locationid}/add', function ($request, $response, $args) u
300 313
     ));
301 314
 });
302 315
 
316
+/* User Area */
317
+$app->get('/user/home', function ($request, $response) use ($session) {
318
+    if (!$session->isAuthenticated()) {
319
+        $this->flash->addMessage('error', 'Please login first');
320
+
321
+        return $response->withStatus(302)->withHeader('Location', '/');
322
+    }
323
+
324
+    $loc = new Location();
325
+
326
+    return $this->view->render($response, 'user/home.html', array(
327
+        'user'      => $session->getUser(),
328
+        'locations' => $loc->getAllLocations($session->getUser()->userid, 0, 999999)
329
+    ));
330
+});
331
+
303 332
 $app->run();

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

@@ -148,7 +148,17 @@ class Location
148 148
         return $stmt->fetch(\PDO::FETCH_BOTH)[0];
149 149
     }
150 150
 
151
-    public function getAllNodes()
151
+    public function countNodes()
152
+    {
153
+        $stmt = $this->_handle->prepare('SELECT count(*) FROM nodes WHERE location = ?');
154
+        if (!$stmt->execute(array($this->location))) {
155
+            return false;
156
+        }
157
+
158
+        return $stmt->fetch(\PDO::FETCH_BOTH)[0];
159
+    }
160
+
161
+    public function getNodes()
152 162
     {
153 163
         $data = array();
154 164
 

+ 6
- 4
templates/_header.html View File

@@ -38,15 +38,17 @@
38 38
           <li class="nav-item active">
39 39
             <a class="nav-link" href="/register">Register</a>
40 40
           </li>
41
-          {% else %}
42
-          <li class="nav-item active">
43
-            <a class="nav-link" href="/location/add">Add Location</a>
44
-          </li>
45 41
           {% endif %}
46 42
         </ul>
47 43
 
48 44
         {% if session.isAuthenticated() %}
49 45
         <ul class="navbar-nav float-right">
46
+          <li class="nav-item active">
47
+            <a class="nav-link btn btn-outline-primary" href="/user/home">
48
+              <span class="oi oi-person" title="icon person" aria-hidden="true"></span>
49
+              My Locations
50
+            </a>
51
+          </li>
50 52
           <li class="nav-item">
51 53
             <a class="btn btn-outline-success" href="/logout">Logout</a>
52 54
           </li>

+ 12
- 8
templates/locations.html View File

@@ -5,15 +5,19 @@
5 5
       <h1>Locations</h1>
6 6
 
7 7
       <table class="table table-striped">
8
-      <thead><tr><th>Name</th><th style="width: 60%">Address</th><th>Status</th></tr></thead>
8
+        <thead><tr><th>Name</th><th style="width: 60%">Address</th><th>Status</th><th></th></tr></thead>
9 9
 
10
-      {% for loc in locations %}
11
-        <tr>
12
-          <td><a href="/location/{{ loc.locationid }}/">{{ loc.name }}</a></td>
13
-          <td>{{ loc.address }}</td>
14
-          <td><img src="/css/images/tower-{{ loc.status }}.svg" style="height: 2em" alt="{{ loc.status }}"></td>
15
-        </tr>
16
-      {% endfor %}
10
+        {% for loc in locations %}
11
+          <tr>
12
+            <td><a href="/location/{{ loc.locationid }}/">{{ loc.name }}</a></td>
13
+            <td>{{ loc.address }} <a href="/map?lat={{ loc.latitude }}&lng={{ loc.longitude }}" class="btn btn-outline-primary btn-sm">
14
+              <span class="oi oi-map-marker" title="icon map-marker" aria-hidden="true"></span>
15
+              </a>
16
+            </td>
17
+            <td><img src="/css/images/tower-{{ loc.status }}.svg" style="height: 2em" alt="{{ loc.status }}"></td>
18
+            <td><a href="/location/{{ loc.locationid }}" class="btn btn-primary btn-sm">Show</a></td>
19
+          </tr>
20
+        {% endfor %}
17 21
 
18 22
       </table>
19 23
 

+ 8
- 0
templates/map.js View File

@@ -1,6 +1,10 @@
1 1
 var map;
2 2
 
3
+{% if deflocation %}
4
+var deflocation = [{{ deflocation.lat }}, {{ deflocation.lng }}];
5
+{% else %}
3 6
 var deflocation = [47.0707, 15.4395];
7
+{% endif %}
4 8
 var defzoom = 13;
5 9
 
6 10
 function initmap() {
@@ -33,6 +37,10 @@ function initmap() {
33 37
 
34 38
    L.control.layers({ "Karte": basemap, "Satellit": orthomap, "Terrain": topomap }).addTo(map);
35 39
 
40
+   {% if deflocation %}
41
+   L.marker([{{ deflocation.lat }}, {{ deflocation.lng }}]).addTo(map);
42
+   {% endif %}
43
+
36 44
    // custom icons
37 45
    var TowerIcon = L.Icon.extend({
38 46
       options: {

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

@@ -0,0 +1,75 @@
1
+{% include('_header.html') %}
2
+
3
+    <div class="container">
4
+
5
+      <div class="row">
6
+        <div class="col-sm-6">
7
+          <div class="card">
8
+            <div class="card-header"><h5>User Details</h5></div>
9
+            <div class="card-body">
10
+              <div class="row">
11
+                <div class="col-3"><b>E-Mail:</b></div>
12
+                <div class="col">{{ user.email }}</div>
13
+              </div>
14
+              <div class="row">
15
+                <div class="col-3"><b>Name:</b></div>
16
+                <div class="col">{{ user.firstname }} {{ user.lastname }}</div>
17
+              </div>
18
+              <div class="row">
19
+                <div class="col-3"><b>Phone:</b></div>
20
+                <div class="col">{{ user.phone }}</div>
21
+              </div>
22
+              <div class="row text-right">
23
+                <div class="col">
24
+                  <a href="/user/edit" class="btn btn-primary">Edit userdata</a>
25
+                  <a href="/user/changepwd" class="btn btn-primary">Change password</a>
26
+                </div>
27
+              </div>
28
+            </div>
29
+          </div>
30
+        </div>
31
+        <div class="col-sm-6">
32
+          <div class="card">
33
+            <div class="card-header"><h5>Locations</h5></div>
34
+            <div class="card-body">
35
+              <div class="row">
36
+                <div class="col">
37
+                  <a href="/location/add" class="btn btn-primary">Add Location</a>
38
+                </div>
39
+              </div>
40
+            </div>
41
+          </div>
42
+        </div>
43
+      </div>
44
+
45
+      <br />
46
+
47
+      <h2>Your Locations</h2>
48
+
49
+      <table class="table table-striped">
50
+        <thead><tr><th>Name</th><th style="width: 60%">Address</th><th>Status</th><th></th></tr></thead>
51
+        <tbody>
52
+
53
+        {% for loc in locations %}
54
+          <tr>
55
+            <td><a href="/location/{{ loc.locationid }}/">{{ loc.name }}</a></td>
56
+            <td>{{ loc.address }} <a href="/map?lat={{ loc.latitude }}&lng={{ loc.longitude }}" class="btn btn-outline-primary btn-sm">
57
+              <span class="oi oi-map-marker" title="icon map-marker" aria-hidden="true"></span>
58
+              </a>
59
+            </td>
60
+            <td><img src="/css/images/tower-{{ loc.status }}.svg" style="height: 2em" alt="{{ loc.status }}"></td>
61
+            <td>
62
+              <a href="/location/{{ loc.locationid }}" class="btn btn-primary btn-sm">Show</a>
63
+              <a href="/location/{{ loc.locationid }}/edit" class="btn btn-primary btn-sm">
64
+                <span class="oi oi-wrench" title="icon wrench" aria-hidden="true"></span>
65
+              </a>
66
+            </td>
67
+          </tr>
68
+        {% endfor %}
69
+
70
+        </tbody>
71
+      </table>
72
+
73
+    </div>
74
+
75
+{% include('_footer.html') %}

Loading…
Cancel
Save