@@ -23,7 +23,7 @@ |
||
23 | 23 | /** |
24 | 24 | * Display index page and process dataTable ajax request. |
25 | 25 | * |
26 | - * @param \App\DataTables\UsersDataTable $dataTable |
|
26 | + * @param ActivityLogDataTable $dataTable |
|
27 | 27 | * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View |
28 | 28 | */ |
29 | 29 | public function index(ActivityLogDataTable $dataTable) |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * Creates a json response for all the devices. |
19 | 19 | * |
20 | - * @return Response |
|
20 | + * @return \Illuminate\Http\JsonResponse |
|
21 | 21 | */ |
22 | 22 | public function index() |
23 | 23 | { |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * Creates a json response for a specifc device. |
29 | 29 | * |
30 | 30 | * @param Device $device |
31 | - * @return Response |
|
31 | + * @return \Illuminate\Http\JsonResponse |
|
32 | 32 | */ |
33 | 33 | public function show(Device $device) |
34 | 34 | { |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * Updates the status of a device. |
40 | 40 | * |
41 | 41 | * @param Request $request |
42 | - * @return Response |
|
42 | + * @return \Illuminate\Http\JsonResponse |
|
43 | 43 | */ |
44 | 44 | public function update(Request $request) |
45 | 45 | { |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * Updates the sensors of a device. |
108 | 108 | * |
109 | 109 | * @param Request $request |
110 | - * @return Response |
|
110 | + * @return \Illuminate\Http\JsonResponse |
|
111 | 111 | */ |
112 | 112 | public function sensor(Request $request) |
113 | 113 | { |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * Registers a new device. |
171 | 171 | * |
172 | 172 | * @param Request $request |
173 | - * @return Response |
|
173 | + * @return \Illuminate\Http\JsonResponse |
|
174 | 174 | */ |
175 | 175 | public function register(Request $request) |
176 | 176 | { |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * Updates the image for a device. |
229 | 229 | * |
230 | 230 | * @param Request $request |
231 | - * @return Response |
|
231 | + * @return \Illuminate\Http\JsonResponse |
|
232 | 232 | */ |
233 | 233 | public function image(Request $request) { |
234 | 234 | // Validate the request. |
@@ -68,8 +68,9 @@ |
||
68 | 68 | $device->mac_address = $request->input('mac_address'); |
69 | 69 | $device->time = $request->input('time'); |
70 | 70 | $device->cover_status = $request->input('cover_status'); |
71 | - if ($request->input('cover_command') != null) |
|
72 | - $device->cover_command = $request->input('cover_command'); |
|
71 | + if ($request->input('cover_command') != null) { |
|
72 | + $device->cover_command = $request->input('cover_command'); |
|
73 | + } |
|
73 | 74 | $device->error_msg = $request->input('error_msg'); |
74 | 75 | $device->last_network_update_at = Carbon::now(); |
75 | 76 |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * Store a newly created resource in storage. |
45 | 45 | * |
46 | 46 | * @param Request $request |
47 | - * @return Response |
|
47 | + * @return \Illuminate\Http\RedirectResponse |
|
48 | 48 | */ |
49 | 49 | public function store(Request $request) |
50 | 50 | { |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @param Request $request |
97 | 97 | * @param int $id |
98 | - * @return Response |
|
98 | + * @return \Illuminate\Http\RedirectResponse |
|
99 | 99 | */ |
100 | 100 | public function update(Request $request, $id) |
101 | 101 | { |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * Remove the specified resource from storage. |
114 | 114 | * |
115 | 115 | * @param int $id |
116 | - * @return Response |
|
116 | + * @return \Illuminate\Http\RedirectResponse |
|
117 | 117 | */ |
118 | 118 | public function destroy($id) |
119 | 119 | { |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * Store a newly created resource in storage. |
44 | 44 | * |
45 | 45 | * @param Request $request |
46 | - * @return Response |
|
46 | + * @return \Illuminate\Http\RedirectResponse |
|
47 | 47 | */ |
48 | 48 | public function store(Request $request) |
49 | 49 | { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * Update the specified resource in storage. |
90 | 90 | * |
91 | 91 | * @param int $id |
92 | - * @return Response |
|
92 | + * @return \Illuminate\Http\RedirectResponse |
|
93 | 93 | */ |
94 | 94 | public function update($id) |
95 | 95 | { |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * Remove the specified resource from storage. |
107 | 107 | * |
108 | 108 | * @param int $id |
109 | - * @return Response |
|
109 | + * @return \Illuminate\Http\RedirectResponse |
|
110 | 110 | */ |
111 | 111 | public function destroy($id) |
112 | 112 | { |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * Store a newly created resource in storage. |
45 | 45 | * |
46 | 46 | * @param EditLocation $request |
47 | - * @return \Illuminate\Http\Response |
|
47 | + * @return \Illuminate\Http\RedirectResponse |
|
48 | 48 | */ |
49 | 49 | public function store(EditLocation $request) |
50 | 50 | { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @param EditLocation $request |
99 | 99 | * @param int $id |
100 | - * @return \Illuminate\Http\Response |
|
100 | + * @return \Illuminate\Http\RedirectResponse |
|
101 | 101 | */ |
102 | 102 | public function update(EditLocation $request, $id) |
103 | 103 | { |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * Remove the specified resource from storage. |
123 | 123 | * |
124 | 124 | * @param int $id |
125 | - * @return \Illuminate\Http\Response |
|
125 | + * @return \Illuminate\Http\RedirectResponse |
|
126 | 126 | */ |
127 | 127 | public function destroy($id) |
128 | 128 | { |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | //Create a new site |
55 | 55 | $site = Site::create(['name' => $request->input('new_site_name')]); |
56 | 56 | $site_id = $site->id; |
57 | + } else { |
|
58 | + $site_id = $request->input('site'); |
|
57 | 59 | } |
58 | - else |
|
59 | - $site_id = $request->input('site'); |
|
60 | 60 | |
61 | 61 | $location = Location::create(['name' => $request->input('name'), 'site_id' => $site_id]); |
62 | 62 | |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | //Create a new site |
108 | 108 | $site = Site::create(['name' => $request->input('new_site_name')]); |
109 | 109 | $site_id = $site->id; |
110 | + } else { |
|
111 | + $site_id = $request->input('site'); |
|
110 | 112 | } |
111 | - else |
|
112 | - $site_id = $request->input('site'); |
|
113 | 113 | |
114 | 114 | //Update the location with the supplied name and the site |
115 | 115 | Location::findOrFail($id)->update(['name' => $request->input('name'), 'site_id' => $site_id]); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * Store a newly created resource in storage. |
42 | 42 | * |
43 | 43 | * @param \Illuminate\Http\Request $request |
44 | - * @return \Illuminate\Http\Response |
|
44 | + * @return \Illuminate\Http\RedirectResponse |
|
45 | 45 | */ |
46 | 46 | public function store(Request $request) |
47 | 47 | { |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * |
88 | 88 | * @param \Illuminate\Http\Request $request |
89 | 89 | * @param Site $site |
90 | - * @return \Illuminate\Http\Response |
|
90 | + * @return \Illuminate\Http\RedirectResponse |
|
91 | 91 | */ |
92 | 92 | public function update(Request $request, Site $site) |
93 | 93 | { |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * Remove the specified resource from storage. |
106 | 106 | * |
107 | 107 | * @param int $id |
108 | - * @return \Illuminate\Http\Response |
|
108 | + * @return \Illuminate\Http\RedirectResponse |
|
109 | 109 | */ |
110 | 110 | public function destroy($id) |
111 | 111 | { |
@@ -66,10 +66,11 @@ |
||
66 | 66 | $site = Site::findOrFail($id); |
67 | 67 | $locations = $site->locations()->orderBy('name', 'ASC')->paginate(15); |
68 | 68 | |
69 | - if (\Request::ajax()) |
|
70 | - return response()->json(['site' => $site, 'locations' => $locations]); |
|
71 | - else |
|
72 | - return view('site.show', [ 'site' => $site, 'locations' => $locations ]); |
|
69 | + if (\Request::ajax()) { |
|
70 | + return response()->json(['site' => $site, 'locations' => $locations]); |
|
71 | + } else { |
|
72 | + return view('site.show', [ 'site' => $site, 'locations' => $locations ]); |
|
73 | + } |
|
73 | 74 | } |
74 | 75 | |
75 | 76 | /** |
@@ -330,7 +330,7 @@ |
||
330 | 330 | * Get the page number of the device for the dashboard device table pagination |
331 | 331 | * |
332 | 332 | * @param int $limit |
333 | - * @return int |
|
333 | + * @return double |
|
334 | 334 | */ |
335 | 335 | public function dashPageNum($limit) |
336 | 336 | { |
@@ -105,8 +105,9 @@ discard block |
||
105 | 105 | $time = new Carbon($value, 'UTC'); |
106 | 106 | |
107 | 107 | //If the user is logged in then use there preferred timezone |
108 | - if (Auth::check()) |
|
109 | - $time = $time->setTimezone(Auth::user()->timezone); |
|
108 | + if (Auth::check()) { |
|
109 | + $time = $time->setTimezone(Auth::user()->timezone); |
|
110 | + } |
|
110 | 111 | |
111 | 112 | return $time->format('H:i'); |
112 | 113 | } |
@@ -124,8 +125,9 @@ discard block |
||
124 | 125 | $time = new Carbon($value, 'UTC'); |
125 | 126 | |
126 | 127 | //If the user is logged in then use there preferred timezone |
127 | - if (Auth::check()) |
|
128 | - $time = $time->setTimezone(Auth::user()->timezone); |
|
128 | + if (Auth::check()) { |
|
129 | + $time = $time->setTimezone(Auth::user()->timezone); |
|
130 | + } |
|
129 | 131 | |
130 | 132 | return $time->format('H:i'); |
131 | 133 | } |
@@ -145,9 +147,9 @@ discard block |
||
145 | 147 | { |
146 | 148 | $time = new Carbon($value, Auth::user()->timezone); |
147 | 149 | $time = $time->setTimezone('UTC'); |
150 | + } else { |
|
151 | + $time = new Carbon($value, 'UTC'); |
|
148 | 152 | } |
149 | - else |
|
150 | - $time = new Carbon($value, 'UTC'); |
|
151 | 153 | |
152 | 154 | $this->attributes['open_time'] = $time->format('H:i:s'); |
153 | 155 | } |
@@ -167,9 +169,9 @@ discard block |
||
167 | 169 | { |
168 | 170 | $time = new Carbon($value, Auth::user()->timezone); |
169 | 171 | $time = $time->setTimezone('UTC'); |
172 | + } else { |
|
173 | + $time = new Carbon($value, 'UTC'); |
|
170 | 174 | } |
171 | - else |
|
172 | - $time = new Carbon($value, 'UTC'); |
|
173 | 175 | |
174 | 176 | $this->attributes['close_time'] = $time->format('H:i:s'); |
175 | 177 | } |
@@ -293,10 +295,11 @@ discard block |
||
293 | 295 | $time_now = Carbon::now($timezone); |
294 | 296 | |
295 | 297 | //Check if the current time is during the open schedule or not |
296 | - if ($time_now->gt($open_time) && $time_now->lt($close_time)) |
|
297 | - return true; |
|
298 | - else |
|
299 | - return false; |
|
298 | + if ($time_now->gt($open_time) && $time_now->lt($close_time)) { |
|
299 | + return true; |
|
300 | + } else { |
|
301 | + return false; |
|
302 | + } |
|
300 | 303 | } |
301 | 304 | |
302 | 305 | /** |
@@ -314,20 +317,22 @@ discard block |
||
314 | 317 | switch ($this['cover_command']) |
315 | 318 | { |
316 | 319 | case 'open': |
317 | - if ($isOpen) |
|
318 | - $status = 'open'; |
|
319 | - else if ($isLocked) |
|
320 | - $status = 'unlocking'; |
|
321 | - else |
|
322 | - $status = 'opening'; |
|
320 | + if ($isOpen) { |
|
321 | + $status = 'open'; |
|
322 | + } else if ($isLocked) { |
|
323 | + $status = 'unlocking'; |
|
324 | + } else { |
|
325 | + $status = 'opening'; |
|
326 | + } |
|
323 | 327 | break; |
324 | 328 | case 'close': |
325 | - if ($isClosed) |
|
326 | - $status = 'closed'; |
|
327 | - else if ($isLocked) |
|
328 | - $status = 'unlocking'; |
|
329 | - else |
|
330 | - $status = 'closing'; |
|
329 | + if ($isClosed) { |
|
330 | + $status = 'closed'; |
|
331 | + } else if ($isLocked) { |
|
332 | + $status = 'unlocking'; |
|
333 | + } else { |
|
334 | + $status = 'closing'; |
|
335 | + } |
|
331 | 336 | break; |
332 | 337 | case 'lock': |
333 | 338 | $status = 'locked'; |
@@ -336,8 +341,9 @@ discard block |
||
336 | 341 | $status = 'error'; |
337 | 342 | } |
338 | 343 | |
339 | - if ($this->cover_status === 'error') |
|
340 | - $status = 'error'; |
|
344 | + if ($this->cover_status === 'error') { |
|
345 | + $status = 'error'; |
|
346 | + } |
|
341 | 347 | |
342 | 348 | return $status; |
343 | 349 | } |
@@ -43,13 +43,13 @@ discard block |
||
43 | 43 | $location = $device->location ?? null; |
44 | 44 | |
45 | 45 | //If the location exists then set the pagination page to be where the device is located |
46 | - if ($location != null) |
|
47 | - $request->merge(['page' => $device->dashPageNum(4)]); |
|
46 | + if ($location != null) { |
|
47 | + $request->merge(['page' => $device->dashPageNum(4)]); |
|
48 | + } |
|
48 | 49 | $site_id = $location->site_id ?? 0; |
49 | 50 | $location_id = $location->id ?? 0; |
50 | 51 | $device_id = $device->id ?? 0; |
51 | - } |
|
52 | - else |
|
52 | + } else |
|
53 | 53 | { |
54 | 54 | //Get the active site, location, and device ids |
55 | 55 | $site_id = $request->site_id ?? 0; |
@@ -83,8 +83,9 @@ discard block |
||
83 | 83 | { |
84 | 84 | //If the original device with the given device id was not found |
85 | 85 | //Then assign the the first device in the device list as the active device |
86 | - if ($active_device == null) |
|
87 | - $active_device = $devices[0]; |
|
86 | + if ($active_device == null) { |
|
87 | + $active_device = $devices[0]; |
|
88 | + } |
|
88 | 89 | |
89 | 90 | //Add an attribute to each device defining if it is stale |
90 | 91 | $devices->transform(function ($item) |
@@ -98,9 +99,9 @@ discard block |
||
98 | 99 | { |
99 | 100 | $imageStaleMins = ceil(($item->image_rate * 3) / 60) + 1; |
100 | 101 | $item['isImageStale'] = ($item->image_updated_at <= Carbon::now()->subMinute($imageStaleMins)) ? true : false; |
102 | + } else { |
|
103 | + $item['isImageStale'] = false; |
|
101 | 104 | } |
102 | - else |
|
103 | - $item['isImageStale'] = false; |
|
104 | 105 | |
105 | 106 | return $item; |
106 | 107 | }); |
@@ -112,12 +113,13 @@ discard block |
||
112 | 113 | //Use the device_list.blade.php to generate the device table html |
113 | 114 | $html_device_table = view('dashboard.device_list', ['devices' => $devices, 'active_data' => $active_data])->render(); |
114 | 115 | |
115 | - if (\Request::ajax()) |
|
116 | - return response()->json([ 'active_data' => $active_data, 'devices' => $devices, 'locations' => $locations, |
|
116 | + if (\Request::ajax()) { |
|
117 | + return response()->json([ 'active_data' => $active_data, 'devices' => $devices, 'locations' => $locations, |
|
117 | 118 | 'sites' => $sites, 'html_device_table' => $html_device_table ]); |
118 | - else |
|
119 | - return view('dashboard.index', [ 'active_data' => $active_data, 'devices' => $devices, |
|
119 | + } else { |
|
120 | + return view('dashboard.index', [ 'active_data' => $active_data, 'devices' => $devices, |
|
120 | 121 | 'locations' => $locations, 'sites' => $sites ]); |
122 | + } |
|
121 | 123 | } |
122 | 124 | |
123 | 125 | /** |
@@ -116,8 +116,9 @@ discard block |
||
116 | 116 | //Create a new site |
117 | 117 | $site = Site::create(['name' => $request->input('new_site_name')]); |
118 | 118 | $site_id = $site->id; |
119 | - } else |
|
120 | - $site_id = $request->input('site_id'); |
|
119 | + } else { |
|
120 | + $site_id = $request->input('site_id'); |
|
121 | + } |
|
121 | 122 | |
122 | 123 | //Get the location id of the old or newly created location |
123 | 124 | if (!empty($request->input('new_location_name'))) |
@@ -125,53 +126,63 @@ discard block |
||
125 | 126 | //Create a new location |
126 | 127 | $location = Location::create(['name' => $request->input('new_location_name'), 'site_id' => $site_id]); |
127 | 128 | $location_id = $location->id; |
128 | - } else |
|
129 | - $location_id = $request->input('location_id'); |
|
129 | + } else { |
|
130 | + $location_id = $request->input('location_id'); |
|
131 | + } |
|
130 | 132 | |
131 | 133 | //Update the device |
132 | 134 | $device->location_id = $location_id; |
133 | 135 | } |
134 | 136 | |
135 | 137 | //Update the device |
136 | - if ($request->input('name') != null) |
|
137 | - $device->name = $request->input('name'); |
|
138 | - if ($request->input('open_time') != null) |
|
139 | - $device->open_time = $request->input('open_time'); |
|
140 | - if ($request->input('close_time') != null) |
|
141 | - $device->close_time = $request->input('close_time'); |
|
142 | - if ($request->input('update_rate') != null) |
|
143 | - $device->update_rate = $request->input('update_rate'); |
|
144 | - if ($request->input('image_rate') != null) |
|
145 | - $device->image_rate = $request->input('image_rate'); |
|
146 | - if ($request->input('sensor_rate') != null) |
|
147 | - $device->sensor_rate = $request->input('sensor_rate'); |
|
138 | + if ($request->input('name') != null) { |
|
139 | + $device->name = $request->input('name'); |
|
140 | + } |
|
141 | + if ($request->input('open_time') != null) { |
|
142 | + $device->open_time = $request->input('open_time'); |
|
143 | + } |
|
144 | + if ($request->input('close_time') != null) { |
|
145 | + $device->close_time = $request->input('close_time'); |
|
146 | + } |
|
147 | + if ($request->input('update_rate') != null) { |
|
148 | + $device->update_rate = $request->input('update_rate'); |
|
149 | + } |
|
150 | + if ($request->input('image_rate') != null) { |
|
151 | + $device->image_rate = $request->input('image_rate'); |
|
152 | + } |
|
153 | + if ($request->input('sensor_rate') != null) { |
|
154 | + $device->sensor_rate = $request->input('sensor_rate'); |
|
155 | + } |
|
148 | 156 | //Check if the cover_command needs to be updated |
149 | 157 | if ($request->input('command') != null) |
150 | 158 | { |
151 | 159 | //If device is currently opening, closing or in an error state don't update command |
152 | - if (!$device->isReadyForCommand()) |
|
153 | - return response()->json("Device is currently in use.", 403); |
|
160 | + if (!$device->isReadyForCommand()) { |
|
161 | + return response()->json("Device is currently in use.", 403); |
|
162 | + } |
|
154 | 163 | |
155 | 164 | $command = $request->input('command'); |
156 | 165 | |
157 | 166 | //If command is to unlock the device then check if the device should be open or closed based on the schedule |
158 | 167 | if ($request->command === 'unlock') |
159 | 168 | { |
160 | - if ($device->isDuringScheduleOpen()) |
|
161 | - $command = 'open'; |
|
162 | - else |
|
163 | - $command = 'close'; |
|
169 | + if ($device->isDuringScheduleOpen()) { |
|
170 | + $command = 'open'; |
|
171 | + } else { |
|
172 | + $command = 'close'; |
|
173 | + } |
|
164 | 174 | } |
165 | 175 | $device->cover_command = $command; |
166 | 176 | } |
167 | 177 | |
168 | 178 | $device->save(); |
169 | 179 | |
170 | - if (\Request::ajax()) |
|
171 | - return response()->json(['success' => 'Device updated successfully']); |
|
172 | - else |
|
173 | - return redirect()->route('device.show', $id) |
|
180 | + if (\Request::ajax()) { |
|
181 | + return response()->json(['success' => 'Device updated successfully']); |
|
182 | + } else { |
|
183 | + return redirect()->route('device.show', $id) |
|
174 | 184 | ->with('success', 'Device updated successfully'); |
185 | + } |
|
175 | 186 | } |
176 | 187 | |
177 | 188 | /** |
@@ -188,8 +199,7 @@ discard block |
||
188 | 199 | { |
189 | 200 | //If the device was already deleted then permanently delete it |
190 | 201 | $device->forceDelete($device->id); |
191 | - } |
|
192 | - else |
|
202 | + } else |
|
193 | 203 | { |
194 | 204 | //Remove the location from the device |
195 | 205 | $device->location_id = null; |