@@ -15,15 +15,15 @@ |
||
15 | 15 | public function dataTable($query) |
16 | 16 | { |
17 | 17 | return datatables($query) |
18 | - ->editColumn('name', function ($location) { |
|
19 | - return '<a href="' . route('location.show', $location->id) . '">'. $location->name . '</a>'; |
|
18 | + ->editColumn('name', function($location) { |
|
19 | + return '<a href="'.route('location.show', $location->id).'">'.$location->name.'</a>'; |
|
20 | 20 | }) |
21 | - ->editColumn('site_id', function ($location) { |
|
22 | - return '<a href="' . route('site.show', $location->site_id) . '">'. ($location->site->name ?? '') . '</a>'; |
|
21 | + ->editColumn('site_id', function($location) { |
|
22 | + return '<a href="'.route('site.show', $location->site_id).'">'.($location->site->name ?? '').'</a>'; |
|
23 | 23 | }) |
24 | 24 | ->addColumn('action', 'location.action') |
25 | 25 | ->blacklist([ 'action' ]) |
26 | - ->rawColumns(['site_id', 'name', 'action']); |
|
26 | + ->rawColumns([ 'site_id', 'name', 'action' ]); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -15,12 +15,12 @@ |
||
15 | 15 | public function dataTable($query) |
16 | 16 | { |
17 | 17 | return datatables($query) |
18 | - ->editColumn('name', function ($site) { |
|
19 | - return '<a href="' . route('site.show', $site->id) . '">'. $site->name . '</a>'; |
|
18 | + ->editColumn('name', function($site) { |
|
19 | + return '<a href="'.route('site.show', $site->id).'">'.$site->name.'</a>'; |
|
20 | 20 | }) |
21 | 21 | ->addColumn('action', 'site.action') |
22 | 22 | ->blacklist([ 'action' ]) |
23 | - ->rawColumns(['name', 'action']); |
|
23 | + ->rawColumns([ 'name', 'action' ]); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -69,7 +69,7 @@ |
||
69 | 69 | */ |
70 | 70 | public function getLatestDataAttribute() |
71 | 71 | { |
72 | - return $this->hasOne('App\SensorData')->latest()->first() ?? (object)[]; |
|
72 | + return $this->hasOne('App\SensorData')->latest()->first() ?? (object) [ ]; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -3,7 +3,6 @@ |
||
3 | 3 | namespace App\Http\Requests; |
4 | 4 | |
5 | 5 | use Illuminate\Foundation\Http\FormRequest; |
6 | -use App\Http\Requests\Request; |
|
7 | 6 | use Illuminate\Support\Facades\Auth; |
8 | 7 | |
9 | 8 | class EditDevice extends FormRequest |
@@ -46,19 +46,19 @@ |
||
46 | 46 | { |
47 | 47 | $validator = parent::getValidatorInstance(); |
48 | 48 | |
49 | - $validator->sometimes('site_id', 'bail|integer|digits_between:1,10|exists:sites,id', function ($input) { |
|
49 | + $validator->sometimes('site_id', 'bail|integer|digits_between:1,10|exists:sites,id', function($input) { |
|
50 | 50 | return !$input->new_site_name && $input->site_id; |
51 | 51 | }); |
52 | 52 | |
53 | - $validator->sometimes('location_id', 'bail|integer|digits_between:1,10|exists:locations,id', function ($input) { |
|
53 | + $validator->sometimes('location_id', 'bail|integer|digits_between:1,10|exists:locations,id', function($input) { |
|
54 | 54 | return !$input->new_location_name && $input->location_id; |
55 | 55 | }); |
56 | 56 | |
57 | - $validator->sometimes('new_site_name', 'bail|min:2|max:75|name|unique:sites,name', function ($input) { |
|
57 | + $validator->sometimes('new_site_name', 'bail|min:2|max:75|name|unique:sites,name', function($input) { |
|
58 | 58 | return !$input->site_id && $input->name; |
59 | 59 | }); |
60 | 60 | |
61 | - $validator->sometimes('new_location_name', 'bail|min:2|max:75|name|unique:locations,name', function ($input) { |
|
61 | + $validator->sometimes('new_location_name', 'bail|min:2|max:75|name|unique:locations,name', function($input) { |
|
62 | 62 | return !$input->location_id && $input->name; |
63 | 63 | }); |
64 | 64 |
@@ -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 | { |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @var array |
31 | 31 | */ |
32 | - protected $hidden = ['token']; |
|
32 | + protected $hidden = [ 'token' ]; |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * The attributes that are mass assignable. |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @var array |
50 | 50 | */ |
51 | - protected static $ignoreChangedAttributes = ['updated_at']; |
|
51 | + protected static $ignoreChangedAttributes = [ 'updated_at' ]; |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * The attributes to log in the Activity Log |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function getSiteAttribute() |
91 | 91 | { |
92 | - return $this->location->site ?? (object)[]; |
|
92 | + return $this->location->site ?? (object) [ ]; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | else |
150 | 150 | $time = new Carbon($value, 'UTC'); |
151 | 151 | |
152 | - $this->attributes['open_time'] = $time->format('H:i:s'); |
|
152 | + $this->attributes[ 'open_time' ] = $time->format('H:i:s'); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | else |
172 | 172 | $time = new Carbon($value, 'UTC'); |
173 | 173 | |
174 | - $this->attributes['close_time'] = $time->format('H:i:s'); |
|
174 | + $this->attributes[ 'close_time' ] = $time->format('H:i:s'); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | $isClosed = $this->cover_status === 'closed'; |
312 | 312 | $isLocked = $this->cover_status === 'locked'; |
313 | 313 | |
314 | - switch ($this['cover_command']) |
|
314 | + switch ($this[ 'cover_command' ]) |
|
315 | 315 | { |
316 | 316 | case 'open': |
317 | 317 | if ($isOpen) |
@@ -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 | } |
@@ -143,7 +143,7 @@ |
||
143 | 143 | public function roleString() |
144 | 144 | { |
145 | 145 | $role_en = array(0 => "Registered", 1 => "User", 2 => "Manager", 3 => "Admin"); |
146 | - return $role_en[ $this->role ] . ' (' . $this->role . ')'; |
|
146 | + return $role_en[ $this->role ].' ('.$this->role.')'; |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use Illuminate\Support\Facades\Auth; |
6 | 6 | use Illuminate\Http\Request; |
7 | -use Validator; |
|
8 | 7 | use App\Device; |
9 | 8 | use App\Site; |
10 | 9 | use App\Location; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | |
45 | 45 | //If the location exists then set the pagination page to be where the device is located |
46 | 46 | if ($location != null) |
47 | - $request->merge(['page' => $device->dashPageNum(4)]); |
|
47 | + $request->merge([ 'page' => $device->dashPageNum(4) ]); |
|
48 | 48 | $site_id = $location->site_id ?? 0; |
49 | 49 | $location_id = $location->id ?? 0; |
50 | 50 | $device_id = $device->id ?? 0; |
@@ -64,14 +64,14 @@ discard block |
||
64 | 64 | ->get(); |
65 | 65 | //Get all locations for the selected site with the selected location first |
66 | 66 | $locations = Location::select('id', 'name', 'site_id') |
67 | - ->where('site_id', '=', $sites[0]->id ?? 0) |
|
67 | + ->where('site_id', '=', $sites[ 0 ]->id ?? 0) |
|
68 | 68 | ->orderByRaw("id = ? DESC", $location_id) |
69 | 69 | ->orderBy('name', 'ASC') |
70 | 70 | ->get(); |
71 | 71 | //Get all devices for the selected location |
72 | 72 | $devices = Device::publicDashData() |
73 | 73 | ->leftJoin('deviceimages as image', 'devices.id', '=', 'image.device_id') |
74 | - ->where('location_id', '=', $locations[0]->id ?? 0) |
|
74 | + ->where('location_id', '=', $locations[ 0 ]->id ?? 0) |
|
75 | 75 | ->orderBy('name', 'ASC') |
76 | 76 | ->paginate(4); |
77 | 77 | |
@@ -84,33 +84,33 @@ discard block |
||
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 | 86 | if ($active_device == null) |
87 | - $active_device = $devices[0]; |
|
87 | + $active_device = $devices[ 0 ]; |
|
88 | 88 | |
89 | 89 | //Add an attribute to each device defining if it is stale |
90 | - $devices->transform(function ($item) |
|
90 | + $devices->transform(function($item) |
|
91 | 91 | { |
92 | 92 | //Mark the device as stale if the device has missed three updates plus a minute |
93 | 93 | $deviceStaleMins = ceil(($item->update_rate * 3) / 60) + 1; |
94 | - $item['isDeviceStale'] = ($item->last_network_update_at <= Carbon::now()->subMinute($deviceStaleMins)) ? true : false; |
|
94 | + $item[ 'isDeviceStale' ] = ($item->last_network_update_at <= Carbon::now()->subMinute($deviceStaleMins)) ? true : false; |
|
95 | 95 | |
96 | 96 | //Mark the device image as stale if the device has missed three image updates plus a minute |
97 | 97 | if ($item->image_updated_at != null) |
98 | 98 | { |
99 | 99 | $imageStaleMins = ceil(($item->image_rate * 3) / 60) + 1; |
100 | - $item['isImageStale'] = ($item->image_updated_at <= Carbon::now()->subMinute($imageStaleMins)) ? true : false; |
|
100 | + $item[ 'isImageStale' ] = ($item->image_updated_at <= Carbon::now()->subMinute($imageStaleMins)) ? true : false; |
|
101 | 101 | } |
102 | 102 | else |
103 | - $item['isImageStale'] = false; |
|
103 | + $item[ 'isImageStale' ] = false; |
|
104 | 104 | |
105 | 105 | return $item; |
106 | 106 | }); |
107 | 107 | } |
108 | 108 | |
109 | 109 | //Store the active site, location, and device in a collection |
110 | - $active_data = collect(['device' => $active_device, 'location' => $locations[0] ?? null, 'site' => $sites[0] ?? null]); |
|
110 | + $active_data = collect([ 'device' => $active_device, 'location' => $locations[ 0 ] ?? null, 'site' => $sites[ 0 ] ?? null ]); |
|
111 | 111 | |
112 | 112 | //Use the device_list.blade.php to generate the device table html |
113 | - $html_device_table = view('dashboard.device_list', ['devices' => $devices, 'active_data' => $active_data])->render(); |
|
113 | + $html_device_table = view('dashboard.device_list', [ 'devices' => $devices, 'active_data' => $active_data ])->render(); |
|
114 | 114 | |
115 | 115 | if (\Request::ajax()) |
116 | 116 | return response()->json([ 'active_data' => $active_data, 'devices' => $devices, 'locations' => $locations, |
@@ -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 | /** |
@@ -38,11 +38,11 @@ |
||
38 | 38 | { |
39 | 39 | $validator = parent::getValidatorInstance(); |
40 | 40 | |
41 | - $validator->sometimes('site', 'integer|digits_between:1,10|exists:sites,id', function ($input) { |
|
41 | + $validator->sometimes('site', 'integer|digits_between:1,10|exists:sites,id', function($input) { |
|
42 | 42 | return !$input->new_site_name; |
43 | 43 | }); |
44 | 44 | |
45 | - $validator->sometimes('new_site_name', 'bail|min:2|max:75|name|unique:sites,name', function ($input) { |
|
45 | + $validator->sometimes('new_site_name', 'bail|min:2|max:75|name|unique:sites,name', function($input) { |
|
46 | 46 | return !$input->site; |
47 | 47 | }); |
48 | 48 |