@@ -124,53 +124,63 @@ |
||
124 | 124 | //Create a new location |
125 | 125 | $location = Location::create([ 'name' => $request->input('new_location_name'), 'site_id' => $site_id ]); |
126 | 126 | $location_id = $location->id; |
127 | - } else |
|
128 | - $location_id = $request->input('location_id'); |
|
127 | + } else { |
|
128 | + $location_id = $request->input('location_id'); |
|
129 | + } |
|
129 | 130 | |
130 | 131 | //Update the device |
131 | 132 | $device->location_id = $location_id; |
132 | 133 | } |
133 | 134 | |
134 | 135 | //Update the device |
135 | - if ($request->input('name') != null) |
|
136 | - $device->name = $request->input('name'); |
|
137 | - if ($request->input('open_time') != null) |
|
138 | - $device->open_time = $request->input('open_time'); |
|
139 | - if ($request->input('close_time') != null) |
|
140 | - $device->close_time = $request->input('close_time'); |
|
141 | - if ($request->input('update_rate') != null) |
|
142 | - $device->update_rate = $request->input('update_rate'); |
|
143 | - if ($request->input('image_rate') != null) |
|
144 | - $device->image_rate = $request->input('image_rate'); |
|
145 | - if ($request->input('sensor_rate') != null) |
|
146 | - $device->sensor_rate = $request->input('sensor_rate'); |
|
136 | + if ($request->input('name') != null) { |
|
137 | + $device->name = $request->input('name'); |
|
138 | + } |
|
139 | + if ($request->input('open_time') != null) { |
|
140 | + $device->open_time = $request->input('open_time'); |
|
141 | + } |
|
142 | + if ($request->input('close_time') != null) { |
|
143 | + $device->close_time = $request->input('close_time'); |
|
144 | + } |
|
145 | + if ($request->input('update_rate') != null) { |
|
146 | + $device->update_rate = $request->input('update_rate'); |
|
147 | + } |
|
148 | + if ($request->input('image_rate') != null) { |
|
149 | + $device->image_rate = $request->input('image_rate'); |
|
150 | + } |
|
151 | + if ($request->input('sensor_rate') != null) { |
|
152 | + $device->sensor_rate = $request->input('sensor_rate'); |
|
153 | + } |
|
147 | 154 | //Check if the cover_command needs to be updated |
148 | 155 | if ($request->input('command') != null) |
149 | 156 | { |
150 | 157 | //If device is currently opening, closing or in an error state don't update command |
151 | - if (!$device->isReadyForCommand()) |
|
152 | - return response()->json("Device is currently in use.", 403); |
|
158 | + if (!$device->isReadyForCommand()) { |
|
159 | + return response()->json("Device is currently in use.", 403); |
|
160 | + } |
|
153 | 161 | |
154 | 162 | $command = $request->input('command'); |
155 | 163 | |
156 | 164 | //If command is to unlock the device then check if the device should be open or closed based on the schedule |
157 | 165 | if ($request->command === 'unlock') |
158 | 166 | { |
159 | - if ($device->isDuringScheduleOpen()) |
|
160 | - $command = 'open'; |
|
161 | - else |
|
162 | - $command = 'close'; |
|
167 | + if ($device->isDuringScheduleOpen()) { |
|
168 | + $command = 'open'; |
|
169 | + } else { |
|
170 | + $command = 'close'; |
|
171 | + } |
|
163 | 172 | } |
164 | 173 | $device->cover_command = $command; |
165 | 174 | } |
166 | 175 | |
167 | 176 | $device->save(); |
168 | 177 | |
169 | - if (\Request::ajax()) |
|
170 | - return response()->json([ 'success' => 'Device updated successfully' ]); |
|
171 | - else |
|
172 | - return redirect()->route('device.show', $id) |
|
178 | + if (\Request::ajax()) { |
|
179 | + return response()->json([ 'success' => 'Device updated successfully' ]); |
|
180 | + } else { |
|
181 | + return redirect()->route('device.show', $id) |
|
173 | 182 | ->with('success', 'Device updated successfully'); |
183 | + } |
|
174 | 184 | } |
175 | 185 | |
176 | 186 | /** |
@@ -67,7 +67,7 @@ |
||
67 | 67 | $locations = $site->locations()->orderBy('name', 'ASC')->paginate(15); |
68 | 68 | |
69 | 69 | if (\Request::ajax()) { |
70 | - return response()->json(['site' => $site, 'locations' => $locations]); |
|
70 | + return response()->json([ 'site' => $site, 'locations' => $locations ]); |
|
71 | 71 | } else { |
72 | 72 | return view('site.show', [ 'site' => $site, 'locations' => $locations ]); |
73 | 73 | } |
@@ -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 | }); |
@@ -17,31 +17,31 @@ |
||
17 | 17 | public function dataTable($query) |
18 | 18 | { |
19 | 19 | return datatables($query) |
20 | - ->editColumn('causer_id', function ($activity) { |
|
20 | + ->editColumn('causer_id', function($activity) { |
|
21 | 21 | if ($activity->causer_id && is_object($activity->causer)) { |
22 | - return '<a href="' . route($this->getRouteFromType($activity->causer_type), $activity->causer_id) . '">' . $activity->causer->name ?? '' . '</a>'; |
|
22 | + return '<a href="'.route($this->getRouteFromType($activity->causer_type), $activity->causer_id).'">'.$activity->causer->name ?? ''.'</a>'; |
|
23 | 23 | } else { |
24 | 24 | return ''; |
25 | 25 | } |
26 | 26 | }) |
27 | - ->editColumn('subject_id', function ($activity) { |
|
27 | + ->editColumn('subject_id', function($activity) { |
|
28 | 28 | if ($activity->subject_id && is_object($activity->subject)) { |
29 | - return '<a href="' . route($this->getRouteFromType($activity->subject_type), $activity->subject_id) . '">' . $activity->subject->name ?? '' . '</a>'; |
|
29 | + return '<a href="'.route($this->getRouteFromType($activity->subject_type), $activity->subject_id).'">'.$activity->subject->name ?? ''.'</a>'; |
|
30 | 30 | } else { |
31 | 31 | return ''; |
32 | 32 | } |
33 | 33 | }) |
34 | - ->editColumn('properties', function ($activity) { |
|
34 | + ->editColumn('properties', function($activity) { |
|
35 | 35 | return $activity->properties; |
36 | 36 | }) |
37 | - ->editColumn('created_at', function ($activity) { |
|
37 | + ->editColumn('created_at', function($activity) { |
|
38 | 38 | if ($activity->created_at->diffInDays() > 0) { |
39 | 39 | return $activity->created_at->setTimezone(Auth::user()->timezone)->format('M d, Y h:i a'); |
40 | 40 | } else { |
41 | 41 | return $activity->created_at->diffForHumans(); |
42 | 42 | } |
43 | 43 | }) |
44 | - ->rawColumns(['causer_id', 'subject_id', 'properties']); |
|
44 | + ->rawColumns([ 'causer_id', 'subject_id', 'properties' ]); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | public function getRouteFromType($type) { |
@@ -127,19 +127,21 @@ |
||
127 | 127 | $query->email = $request->input('email'); |
128 | 128 | $query->role = $request->input('role'); |
129 | 129 | $query->phone = $request->input('phone'); |
130 | - if ($request->input('password') != '') |
|
131 | - $query->password = bcrypt($request->input('password')); |
|
130 | + if ($request->input('password') != '') { |
|
131 | + $query->password = bcrypt($request->input('password')); |
|
132 | + } |
|
133 | + } else { |
|
134 | + $query->preferred_device_id = $request->input('preferred_device_id'); |
|
132 | 135 | } |
133 | - else |
|
134 | - $query->preferred_device_id = $request->input('preferred_device_id'); |
|
135 | 136 | |
136 | 137 | $query->save(); |
137 | 138 | |
138 | - if (\Request::ajax()) |
|
139 | - return response()->json([ 'success' => 'Preferred device updated successfully' ]); |
|
140 | - else |
|
141 | - return redirect()->route('user.show', $id) |
|
139 | + if (\Request::ajax()) { |
|
140 | + return response()->json([ 'success' => 'Preferred device updated successfully' ]); |
|
141 | + } else { |
|
142 | + return redirect()->route('user.show', $id) |
|
142 | 143 | ->with('success', 'User updated successfully'); |
144 | + } |
|
143 | 145 | } |
144 | 146 | |
145 | 147 | /** |
@@ -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 | } |