@@ -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 | /** |
@@ -66,7 +66,7 @@ |
||
66 | 66 | $locations = $site->locations()->orderBy('name', 'ASC')->paginate(15); |
67 | 67 | |
68 | 68 | if (\Request::ajax()) |
69 | - return response()->json(['site' => $site, 'locations' => $locations]); |
|
69 | + return response()->json([ 'site' => $site, 'locations' => $locations ]); |
|
70 | 70 | else |
71 | 71 | return view('site.show', [ 'site' => $site, 'locations' => $locations ]); |
72 | 72 | } |
@@ -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) { |
@@ -28,10 +28,11 @@ |
||
28 | 28 | { |
29 | 29 | $this->authorize('show', Deviceimage::class); |
30 | 30 | |
31 | - if (Storage::disk('private')->exists('deviceimage/'.$device_id)) |
|
32 | - $image = Image::make(Storage::disk('private')->get('deviceimage/'.$device_id)); |
|
33 | - else |
|
34 | - $image = Image::make('img/video_not_found.jpg'); |
|
31 | + if (Storage::disk('private')->exists('deviceimage/'.$device_id)) { |
|
32 | + $image = Image::make(Storage::disk('private')->get('deviceimage/'.$device_id)); |
|
33 | + } else { |
|
34 | + $image = Image::make('img/video_not_found.jpg'); |
|
35 | + } |
|
35 | 36 | |
36 | 37 | return $image->response(); |
37 | 38 | } |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | //Create a new site |
112 | 112 | $site = Site::create([ 'name' => $request->input('new_site_name') ]); |
113 | 113 | $site_id = $site->id; |
114 | + } else { |
|
115 | + $site_id = $request->input('site_id'); |
|
114 | 116 | } |
115 | - else |
|
116 | - $site_id = $request->input('site_id'); |
|
117 | 117 | |
118 | 118 | //Get the location id of the old or newly created location |
119 | 119 | if (!empty($request->input('new_location_name'))) |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | //Create a new location |
122 | 122 | $location = Location::create([ 'name' => $request->input('new_location_name'), 'site_id' => $site_id ]); |
123 | 123 | $location_id = $location->id; |
124 | + } else { |
|
125 | + $location_id = $request->input('location_id'); |
|
124 | 126 | } |
125 | - else |
|
126 | - $location_id = $request->input('location_id'); |
|
127 | 127 | |
128 | 128 | //Update the device |
129 | 129 | $device->location_id = $location_id; |
@@ -141,29 +141,32 @@ discard block |
||
141 | 141 | { |
142 | 142 | $this->authorize('updateCommand', Device::class); |
143 | 143 | //If device is currently opening, closing or in an error state don't update command |
144 | - if (!$device->isReadyForCommand()) |
|
145 | - return response()->json("Device is currently in use.", 503); |
|
144 | + if (!$device->isReadyForCommand()) { |
|
145 | + return response()->json("Device is currently in use.", 503); |
|
146 | + } |
|
146 | 147 | |
147 | 148 | $command = $request->input('command'); |
148 | 149 | |
149 | 150 | //If command is to unlock the device then check if the device should be open or closed based on the schedule |
150 | 151 | if ($request->command === 'unlock') |
151 | 152 | { |
152 | - if ($device->isDuringScheduleOpen()) |
|
153 | - $command = 'open'; |
|
154 | - else |
|
155 | - $command = 'close'; |
|
153 | + if ($device->isDuringScheduleOpen()) { |
|
154 | + $command = 'open'; |
|
155 | + } else { |
|
156 | + $command = 'close'; |
|
157 | + } |
|
156 | 158 | } |
157 | 159 | $device->cover_command = $command; |
158 | 160 | } |
159 | 161 | |
160 | 162 | $device->save(); |
161 | 163 | |
162 | - if (\Request::ajax()) |
|
163 | - return response()->json([ 'success' => 'Device updated successfully' ]); |
|
164 | - else |
|
165 | - return redirect()->route('device.show', $device->id) |
|
164 | + if (\Request::ajax()) { |
|
165 | + return response()->json([ 'success' => 'Device updated successfully' ]); |
|
166 | + } else { |
|
167 | + return redirect()->route('device.show', $device->id) |
|
166 | 168 | ->with('success', 'Device updated successfully'); |
169 | + } |
|
167 | 170 | } |
168 | 171 | |
169 | 172 | /** |
@@ -61,7 +61,7 @@ |
||
61 | 61 | 'email' => $request->input('email'), |
62 | 62 | 'password' => bcrypt($request->input('password')), |
63 | 63 | 'phone' => $request->input('phone'), |
64 | - 'role' => $request->input('role'),]); |
|
64 | + 'role' => $request->input('role'), ]); |
|
65 | 65 | |
66 | 66 | return redirect()->route('user.show', $user->id) |
67 | 67 | ->with('success', 'User created successfully'); |
@@ -133,21 +133,24 @@ |
||
133 | 133 | $user->name = $request->input('name'); |
134 | 134 | $user->email = $request->input('email'); |
135 | 135 | $user->phone = $request->input('phone'); |
136 | - if ($request->input('password') != '') |
|
137 | - $user->password = bcrypt($request->input('password')); |
|
138 | - if (Auth::user()->can('updateRole', $user)) |
|
139 | - $user->role = $request->input('role'); |
|
136 | + if ($request->input('password') != '') { |
|
137 | + $user->password = bcrypt($request->input('password')); |
|
138 | + } |
|
139 | + if (Auth::user()->can('updateRole', $user)) { |
|
140 | + $user->role = $request->input('role'); |
|
141 | + } |
|
142 | + } else { |
|
143 | + $user->preferred_device_id = $request->input('preferred_device_id'); |
|
140 | 144 | } |
141 | - else |
|
142 | - $user->preferred_device_id = $request->input('preferred_device_id'); |
|
143 | 145 | |
144 | 146 | $user->save(); |
145 | 147 | |
146 | - if (\Request::ajax()) |
|
147 | - return response()->json([ 'success' => 'Preferred device updated successfully' ]); |
|
148 | - else |
|
149 | - return redirect()->route('user.show', $user->id) |
|
148 | + if (\Request::ajax()) { |
|
149 | + return response()->json([ 'success' => 'Preferred device updated successfully' ]); |
|
150 | + } else { |
|
151 | + return redirect()->route('user.show', $user->id) |
|
150 | 152 | ->with('success', 'User updated successfully'); |
153 | + } |
|
151 | 154 | } |
152 | 155 | |
153 | 156 | /** |
@@ -51,10 +51,11 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function show(User $user, User $user2) |
53 | 53 | { |
54 | - if ($user->isAdmin()) |
|
55 | - return true; |
|
56 | - else |
|
57 | - return $user->id === $user2->id; |
|
54 | + if ($user->isAdmin()) { |
|
55 | + return true; |
|
56 | + } else { |
|
57 | + return $user->id === $user2->id; |
|
58 | + } |
|
58 | 59 | } |
59 | 60 | |
60 | 61 | /** |
@@ -69,9 +70,9 @@ discard block |
||
69 | 70 | if ($user->role > $user2->role) |
70 | 71 | { |
71 | 72 | return $user->isAdmin(); |
73 | + } else { |
|
74 | + return $user->id === $user2->id; |
|
72 | 75 | } |
73 | - else |
|
74 | - return $user->id === $user2->id; |
|
75 | 76 | } |
76 | 77 | |
77 | 78 | /** |
@@ -86,9 +87,9 @@ discard block |
||
86 | 87 | if ($user->role > $user2->role) |
87 | 88 | { |
88 | 89 | return $user->isAdmin(); |
90 | + } else { |
|
91 | + return $user->id === $user2->id; |
|
89 | 92 | } |
90 | - else |
|
91 | - return $user->id === $user2->id; |
|
92 | 93 | } |
93 | 94 | |
94 | 95 | /** |
@@ -103,9 +104,9 @@ discard block |
||
103 | 104 | if ($user->role > $user2->role) |
104 | 105 | { |
105 | 106 | return $user->isAdmin(); |
107 | + } else { |
|
108 | + return false; |
|
106 | 109 | } |
107 | - else |
|
108 | - return false; |
|
109 | 110 | } |
110 | 111 | |
111 | 112 | /** |
@@ -120,9 +121,9 @@ discard block |
||
120 | 121 | if ($user->role > $user2->role) |
121 | 122 | { |
122 | 123 | return $user->isAdmin(); |
124 | + } else { |
|
125 | + return false; |
|
123 | 126 | } |
124 | - else |
|
125 | - return false; |
|
126 | 127 | } |
127 | 128 | |
128 | 129 | /** |
@@ -45,10 +45,10 @@ |
||
45 | 45 | { |
46 | 46 | $this->registerPolicies(); |
47 | 47 | |
48 | - Gate::define('index-dashboard', function ($user) { |
|
48 | + Gate::define('index-dashboard', function($user) { |
|
49 | 49 | return $user->isUser(); |
50 | 50 | }); |
51 | - Gate::define('index-activitylog', function ($user) { |
|
51 | + Gate::define('index-activitylog', function($user) { |
|
52 | 52 | return $user->isManager(); |
53 | 53 | }); |
54 | 54 | } |
@@ -28,10 +28,11 @@ |
||
28 | 28 | */ |
29 | 29 | public function index(ActivityLogDataTable $dataTable) |
30 | 30 | { |
31 | - if (Gate::denies('index-activitylog')) |
|
32 | - throw new AuthorizationException("This action is unauthorized."); |
|
33 | - else |
|
34 | - return $dataTable->render('activitylog.index'); |
|
31 | + if (Gate::denies('index-activitylog')) { |
|
32 | + throw new AuthorizationException("This action is unauthorized."); |
|
33 | + } else { |
|
34 | + return $dataTable->render('activitylog.index'); |
|
35 | + } |
|
35 | 36 | } |
36 | 37 | |
37 | 38 | } |