@@ -42,13 +42,13 @@ discard block |
||
| 42 | 42 | $location = $device->location ?? null; |
| 43 | 43 | |
| 44 | 44 | //If the location exists then set the pagination page to be where the device is located |
| 45 | - if ($location != null) |
|
| 46 | - $request->merge([ 'page' => $device->dashPageNum(4) ]); |
|
| 45 | + if ($location != null) { |
|
| 46 | + $request->merge([ 'page' => $device->dashPageNum(4) ]); |
|
| 47 | + } |
|
| 47 | 48 | $site_id = $location->site_id ?? 0; |
| 48 | 49 | $location_id = $location->id ?? 0; |
| 49 | 50 | $device_id = $device->id ?? 0; |
| 50 | - } |
|
| 51 | - else |
|
| 51 | + } else |
|
| 52 | 52 | { |
| 53 | 53 | //Get the active site, location, and device ids |
| 54 | 54 | $site_id = $request->site_id ?? 0; |
@@ -82,8 +82,9 @@ discard block |
||
| 82 | 82 | { |
| 83 | 83 | //If the original device with the given device id was not found |
| 84 | 84 | //Then assign the the first device in the device list as the active device |
| 85 | - if ($active_device == null) |
|
| 86 | - $active_device = $devices[ 0 ]; |
|
| 85 | + if ($active_device == null) { |
|
| 86 | + $active_device = $devices[ 0 ]; |
|
| 87 | + } |
|
| 87 | 88 | |
| 88 | 89 | //Add an attribute to each device defining if it is stale |
| 89 | 90 | $devices->transform(function($item) |
@@ -97,9 +98,9 @@ discard block |
||
| 97 | 98 | { |
| 98 | 99 | $imageStaleMins = ceil(($item->image_rate * 3) / 60) + 1; |
| 99 | 100 | $item[ 'isImageStale' ] = ($item->image_updated_at <= Carbon::now()->subMinute($imageStaleMins)) ? true : false; |
| 101 | + } else { |
|
| 102 | + $item[ 'isImageStale' ] = false; |
|
| 100 | 103 | } |
| 101 | - else |
|
| 102 | - $item[ 'isImageStale' ] = false; |
|
| 103 | 104 | |
| 104 | 105 | return $item; |
| 105 | 106 | }); |
@@ -25,10 +25,11 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | public function show($device_id) |
| 27 | 27 | { |
| 28 | - if (Storage::disk('private')->exists('deviceimage/'.$device_id)) |
|
| 29 | - $image = Image::make(Storage::disk('private')->get('deviceimage/'.$device_id)); |
|
| 30 | - else |
|
| 31 | - $image = Image::make('img/video_not_found.jpg'); |
|
| 28 | + if (Storage::disk('private')->exists('deviceimage/'.$device_id)) { |
|
| 29 | + $image = Image::make(Storage::disk('private')->get('deviceimage/'.$device_id)); |
|
| 30 | + } else { |
|
| 31 | + $image = Image::make('img/video_not_found.jpg'); |
|
| 32 | + } |
|
| 32 | 33 | |
| 33 | 34 | return $image->response(); |
| 34 | 35 | } |
@@ -65,10 +65,11 @@ |
||
| 65 | 65 | { |
| 66 | 66 | $locations = $site->locations()->orderBy('name', 'ASC')->paginate(15); |
| 67 | 67 | |
| 68 | - if (\Request::ajax()) |
|
| 69 | - return response()->json(['site' => $site, 'locations' => $locations]); |
|
| 70 | - else |
|
| 71 | - return view('site.show', [ 'site' => $site, 'locations' => $locations ]); |
|
| 68 | + if (\Request::ajax()) { |
|
| 69 | + return response()->json(['site' => $site, 'locations' => $locations]); |
|
| 70 | + } else { |
|
| 71 | + return view('site.show', [ 'site' => $site, 'locations' => $locations ]); |
|
| 72 | + } |
|
| 72 | 73 | } |
| 73 | 74 | |
| 74 | 75 | /** |
@@ -117,19 +117,21 @@ |
||
| 117 | 117 | $user->email = $request->input('email'); |
| 118 | 118 | $user->role = $request->input('role'); |
| 119 | 119 | $user->phone = $request->input('phone'); |
| 120 | - if ($request->input('password') != '') |
|
| 121 | - $user->password = bcrypt($request->input('password')); |
|
| 120 | + if ($request->input('password') != '') { |
|
| 121 | + $user->password = bcrypt($request->input('password')); |
|
| 122 | + } |
|
| 123 | + } else { |
|
| 124 | + $user->preferred_device_id = $request->input('preferred_device_id'); |
|
| 122 | 125 | } |
| 123 | - else |
|
| 124 | - $user->preferred_device_id = $request->input('preferred_device_id'); |
|
| 125 | 126 | |
| 126 | 127 | $user->save(); |
| 127 | 128 | |
| 128 | - if (\Request::ajax()) |
|
| 129 | - return response()->json([ 'success' => 'Preferred device updated successfully' ]); |
|
| 130 | - else |
|
| 131 | - return redirect()->route('user.show', $user->id) |
|
| 129 | + if (\Request::ajax()) { |
|
| 130 | + return response()->json([ 'success' => 'Preferred device updated successfully' ]); |
|
| 131 | + } else { |
|
| 132 | + return redirect()->route('user.show', $user->id) |
|
| 132 | 133 | ->with('success', 'User updated successfully'); |
| 134 | + } |
|
| 133 | 135 | } |
| 134 | 136 | |
| 135 | 137 | /** |
@@ -118,53 +118,63 @@ |
||
| 118 | 118 | //Create a new location |
| 119 | 119 | $location = Location::create([ 'name' => $request->input('new_location_name'), 'site_id' => $site_id ]); |
| 120 | 120 | $location_id = $location->id; |
| 121 | - } else |
|
| 122 | - $location_id = $request->input('location_id'); |
|
| 121 | + } else { |
|
| 122 | + $location_id = $request->input('location_id'); |
|
| 123 | + } |
|
| 123 | 124 | |
| 124 | 125 | //Update the device |
| 125 | 126 | $device->location_id = $location_id; |
| 126 | 127 | } |
| 127 | 128 | |
| 128 | 129 | //Update the device |
| 129 | - if ($request->input('name') != null) |
|
| 130 | - $device->name = $request->input('name'); |
|
| 131 | - if ($request->input('open_time') != null) |
|
| 132 | - $device->open_time = $request->input('open_time'); |
|
| 133 | - if ($request->input('close_time') != null) |
|
| 134 | - $device->close_time = $request->input('close_time'); |
|
| 135 | - if ($request->input('update_rate') != null) |
|
| 136 | - $device->update_rate = $request->input('update_rate'); |
|
| 137 | - if ($request->input('image_rate') != null) |
|
| 138 | - $device->image_rate = $request->input('image_rate'); |
|
| 139 | - if ($request->input('sensor_rate') != null) |
|
| 140 | - $device->sensor_rate = $request->input('sensor_rate'); |
|
| 130 | + if ($request->input('name') != null) { |
|
| 131 | + $device->name = $request->input('name'); |
|
| 132 | + } |
|
| 133 | + if ($request->input('open_time') != null) { |
|
| 134 | + $device->open_time = $request->input('open_time'); |
|
| 135 | + } |
|
| 136 | + if ($request->input('close_time') != null) { |
|
| 137 | + $device->close_time = $request->input('close_time'); |
|
| 138 | + } |
|
| 139 | + if ($request->input('update_rate') != null) { |
|
| 140 | + $device->update_rate = $request->input('update_rate'); |
|
| 141 | + } |
|
| 142 | + if ($request->input('image_rate') != null) { |
|
| 143 | + $device->image_rate = $request->input('image_rate'); |
|
| 144 | + } |
|
| 145 | + if ($request->input('sensor_rate') != null) { |
|
| 146 | + $device->sensor_rate = $request->input('sensor_rate'); |
|
| 147 | + } |
|
| 141 | 148 | //Check if the cover_command needs to be updated |
| 142 | 149 | if ($request->input('command') != null) |
| 143 | 150 | { |
| 144 | 151 | //If device is currently opening, closing or in an error state don't update command |
| 145 | - if (!$device->isReadyForCommand()) |
|
| 146 | - return response()->json("Device is currently in use.", 403); |
|
| 152 | + if (!$device->isReadyForCommand()) { |
|
| 153 | + return response()->json("Device is currently in use.", 403); |
|
| 154 | + } |
|
| 147 | 155 | |
| 148 | 156 | $command = $request->input('command'); |
| 149 | 157 | |
| 150 | 158 | //If command is to unlock the device then check if the device should be open or closed based on the schedule |
| 151 | 159 | if ($request->command === 'unlock') |
| 152 | 160 | { |
| 153 | - if ($device->isDuringScheduleOpen()) |
|
| 154 | - $command = 'open'; |
|
| 155 | - else |
|
| 156 | - $command = 'close'; |
|
| 161 | + if ($device->isDuringScheduleOpen()) { |
|
| 162 | + $command = 'open'; |
|
| 163 | + } else { |
|
| 164 | + $command = 'close'; |
|
| 165 | + } |
|
| 157 | 166 | } |
| 158 | 167 | $device->cover_command = $command; |
| 159 | 168 | } |
| 160 | 169 | |
| 161 | 170 | $device->save(); |
| 162 | 171 | |
| 163 | - if (\Request::ajax()) |
|
| 164 | - return response()->json([ 'success' => 'Device updated successfully' ]); |
|
| 165 | - else |
|
| 166 | - return redirect()->route('device.show', $device->id) |
|
| 172 | + if (\Request::ajax()) { |
|
| 173 | + return response()->json([ 'success' => 'Device updated successfully' ]); |
|
| 174 | + } else { |
|
| 175 | + return redirect()->route('device.show', $device->id) |
|
| 167 | 176 | ->with('success', 'Device updated successfully'); |
| 177 | + } |
|
| 168 | 178 | } |
| 169 | 179 | |
| 170 | 180 | /** |