@@ -2,8 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace App\Http\Controllers; |
4 | 4 | |
5 | -use Illuminate\Http\Request; |
|
6 | - |
|
7 | 5 | class HomeController extends Controller |
8 | 6 | { |
9 | 7 | /** |
@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use Illuminate\Bus\Queueable; |
6 | 6 | use Illuminate\Notifications\Notification; |
7 | -use Illuminate\Contracts\Queue\ShouldQueue; |
|
8 | 7 | use Illuminate\Notifications\Messages\NexmoMessage; |
9 | 8 | |
10 | 9 | class InvoicePaid extends Notification |
@@ -2,9 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace App\Http\Controllers; |
4 | 4 | |
5 | -use Illuminate\Http\Request; |
|
6 | 5 | use Intervention\Image\Facades\Image as Image; |
7 | -use Illuminate\Support\Facades\Cache; |
|
8 | 6 | use Illuminate\Support\Facades\Storage; |
9 | 7 | |
10 | 8 | class ImageController extends Controller |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | if (Storage::disk('private')->exists('deviceimage/'.$device_id)) { |
31 | 31 | $image = Image::make(Storage::disk('private')->get('deviceimage/'.$device_id)); |
32 | 32 | } else { |
33 | - $image = Image::make(public_path() . '/img/video_not_found.jpg'); |
|
33 | + $image = Image::make(public_path().'/img/video_not_found.jpg'); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | return $image->response(); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function store($device_id, $binaryData) |
47 | 47 | { |
48 | - $storagePath = storage_path('app/private/deviceimage/') . $device_id; |
|
48 | + $storagePath = storage_path('app/private/deviceimage/').$device_id; |
|
49 | 49 | $image = Image::make($binaryData); |
50 | 50 | $image->save($storagePath, 75); |
51 | 51 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * Creates a json response for all the devices. |
16 | 16 | * |
17 | - * @return Response |
|
17 | + * @return \Illuminate\Http\JsonResponse |
|
18 | 18 | */ |
19 | 19 | public function index() |
20 | 20 | { |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * Creates a json response for a specifc device. |
26 | 26 | * |
27 | 27 | * @param Device $device |
28 | - * @return Response |
|
28 | + * @return \Illuminate\Http\JsonResponse |
|
29 | 29 | */ |
30 | 30 | public function show(Device $device) |
31 | 31 | { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * Updates the status of a device. |
37 | 37 | * |
38 | 38 | * @param Request $request |
39 | - * @return Response |
|
39 | + * @return \Illuminate\Http\JsonResponse |
|
40 | 40 | */ |
41 | 41 | public function update(Request $request) |
42 | 42 | { |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * Registers a new device. |
108 | 108 | * |
109 | 109 | * @param Request $request |
110 | - * @return Response |
|
110 | + * @return \Illuminate\Http\JsonResponse |
|
111 | 111 | */ |
112 | 112 | public function register(Request $request) |
113 | 113 | { |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * Updates the image for a device. |
165 | 165 | * |
166 | 166 | * @param Request $request |
167 | - * @return Response |
|
167 | + * @return \Illuminate\Http\JsonResponse |
|
168 | 168 | */ |
169 | 169 | public function image(Request $request) { |
170 | 170 | // Validate the request. |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | public function index() |
20 | 20 | { |
21 | - return response()->json(['data' => 'SmartSettia API - Bad request type.'], 400); |
|
21 | + return response()->json([ 'data' => 'SmartSettia API - Bad request type.' ], 400); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | // If validation fails, send the validation error back with status 400. |
64 | 64 | if ($validator->fails()) { |
65 | - return response()->json(['data' => $validator->errors()], 400); |
|
65 | + return response()->json([ 'data' => $validator->errors() ], 400); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | // Get the device record. |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | // If token doesnt match then send 401 unauthorized. |
72 | 72 | if ($request->input('token') != $device->token) { |
73 | - return response()->json(['data' => 'Bad token.'], 401); |
|
73 | + return response()->json([ 'data' => 'Bad token.' ], 401); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | // Update the device. |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | //event(new Registered(true)); |
101 | 101 | |
102 | 102 | // Return the new device info including the token. |
103 | - return response()->json(['data' => $device->toArray()], 201); |
|
103 | + return response()->json([ 'data' => $device->toArray() ], 201); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | |
120 | 120 | // If validation fails, send the validation error back with status 400. |
121 | 121 | if ($validator->fails()) { |
122 | - return response()->json(['data' => $validator->errors()], 400); |
|
122 | + return response()->json([ 'data' => $validator->errors() ], 400); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // If challenge string doesnt match then send 401 unauthorized. |
126 | 126 | if ($request->input('challenge') != env('API_CHALLENGE', 'temppass')) { |
127 | - return response()->json(['data' => 'Bad challenge.'], 401); |
|
127 | + return response()->json([ 'data' => 'Bad challenge.' ], 401); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | // If the uuid already exists then just send them the record. |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | 'uuid' => $device->uuid, |
135 | 135 | 'id' => $device->id, |
136 | 136 | 'token' => $device->token, |
137 | - ]], 200); |
|
137 | + ] ], 200); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | // Create the new device. |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | 'uuid' => $device->uuid, |
158 | 158 | 'id' => $device->id, |
159 | 159 | 'token' => $device->token, |
160 | - ]], 201); |
|
160 | + ] ], 201); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | // If validation fails, send the validation error back with status 400. |
178 | 178 | if ($validator->fails()) { |
179 | - return response()->json(['data' => $validator->errors()], 400); |
|
179 | + return response()->json([ 'data' => $validator->errors() ], 400); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // Get the device record. |
@@ -184,25 +184,25 @@ discard block |
||
184 | 184 | |
185 | 185 | // If token doesnt match then send 401 unauthorized. |
186 | 186 | if ($request->input('token') != $device->token) { |
187 | - return response()->json(['data' => 'Bad token.'], 401); |
|
187 | + return response()->json([ 'data' => 'Bad token.' ], 401); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | // Save the image to disk. |
191 | - $path = $request->file('image')->storeAs('deviceimage', $device['id'], 'private'); |
|
191 | + $path = $request->file('image')->storeAs('deviceimage', $device[ 'id' ], 'private'); |
|
192 | 192 | |
193 | 193 | // Update the url for the image. |
194 | 194 | $deviceimage = Deviceimage::updateOrCreate( |
195 | - ['device_id' => $device['id']], |
|
196 | - ['url' => $path] |
|
195 | + [ 'device_id' => $device[ 'id' ] ], |
|
196 | + [ 'url' => $path ] |
|
197 | 197 | ); |
198 | 198 | |
199 | 199 | // Force the updated_at timestamp to update as the url may not change. |
200 | 200 | $deviceimage->touch(); |
201 | 201 | |
202 | 202 | return response()->json([ 'data' => [ |
203 | - 'id' => $deviceimage['id'], |
|
203 | + 'id' => $deviceimage[ 'id' ], |
|
204 | 204 | 'url' => $path, |
205 | - ]], 201); |
|
205 | + ] ], 201); |
|
206 | 206 | } |
207 | 207 | } |
208 | 208 |
@@ -7,8 +7,6 @@ |
||
7 | 7 | use App\Device; |
8 | 8 | use App\Deviceimage; |
9 | 9 | use App\User; |
10 | -use Illuminate\Support\Facades\Cache; |
|
11 | -use Illuminate\Support\Facades\Storage; |
|
12 | 10 | |
13 | 11 | class ApiController extends Controller |
14 | 12 | { |
@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use Illuminate\Bus\Queueable; |
6 | 6 | use Illuminate\Notifications\Notification; |
7 | -use Illuminate\Contracts\Queue\ShouldQueue; |
|
8 | 7 | use Illuminate\Notifications\Messages\NexmoMessage; |
9 | 8 | |
10 | 9 | class DeviceRegister extends Notification |
@@ -3,7 +3,6 @@ |
||
3 | 3 | namespace App; |
4 | 4 | |
5 | 5 | use Illuminate\Database\Eloquent\Model; |
6 | -use Illuminate\Support\Facades\DB; |
|
7 | 6 | |
8 | 7 | class Location extends Model |
9 | 8 | { |
@@ -3,7 +3,6 @@ |
||
3 | 3 | namespace App; |
4 | 4 | |
5 | 5 | use Illuminate\Database\Eloquent\Model; |
6 | -use Illuminate\Support\Facades\DB; |
|
7 | 6 | |
8 | 7 | class Site extends Model |
9 | 8 | { |
@@ -176,7 +176,7 @@ |
||
176 | 176 | * |
177 | 177 | * @param Request $request |
178 | 178 | * @param Device $device |
179 | - * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection |
|
179 | + * @return \Illuminate\Http\JsonResponse |
|
180 | 180 | */ |
181 | 181 | public function updateCommand(Request $request, Device $device) |
182 | 182 | { |
@@ -80,27 +80,31 @@ discard block |
||
80 | 80 | //Get the given device if it is still at the same location |
81 | 81 | $device = Device::publicDashData()->where('location_id', '=', $request->location_id)->find($request->device_id); |
82 | 82 | |
83 | - if (empty($site)) //Check if the site still exists |
|
83 | + if (empty($site)) { |
|
84 | + //Check if the site still exists |
|
84 | 85 | { |
85 | 86 | //Get the first site and if no sites exist throw an error |
86 | 87 | $site = Site::select('id', 'name')->firstOrFail(); |
88 | + } |
|
87 | 89 | //Get the first location from the site |
88 | 90 | $location = $site->locations()->select('id', 'name', 'site_id')->firstOrFail(); |
89 | 91 | //Get the first device from the location |
90 | 92 | $device = $location->devices()->publicDashData()->firstOrFail(); |
91 | - } |
|
92 | - else if (empty($location)) //Check if the location still exists |
|
93 | + } else if (empty($location)) { |
|
94 | + //Check if the location still exists |
|
93 | 95 | { |
94 | 96 | //Get the first location from the given site |
95 | 97 | $location = $site->locations()->select('id', 'name', 'site_id')->firstOrFail(); |
98 | + } |
|
96 | 99 | //Get the first device from the location |
97 | 100 | $device = $location->devices()->publicDashData()->firstOrFail(); |
98 | - } |
|
99 | - else if (empty($device)) //Check if the device still exists at the given location |
|
101 | + } else if (empty($device)) { |
|
102 | + //Check if the device still exists at the given location |
|
100 | 103 | { |
101 | 104 | //Get the first device from the location |
102 | 105 | $device = $location->devices()->publicDashData()->firstOrFail(); |
103 | 106 | } |
107 | + } |
|
104 | 108 | |
105 | 109 | $data = $this->dashData($site, $location, $device); |
106 | 110 | |
@@ -185,8 +189,9 @@ discard block |
||
185 | 189 | ])->validate(); |
186 | 190 | |
187 | 191 | //Check that device isn't currently in use or has an error |
188 | - if ($device->cover_status === 'opening' || $device->cover_status === 'closing' || $device->cover_status === 'error') |
|
189 | - return response()->json("Device is currently in use.", 403); |
|
192 | + if ($device->cover_status === 'opening' || $device->cover_status === 'closing' || $device->cover_status === 'error') { |
|
193 | + return response()->json("Device is currently in use.", 403); |
|
194 | + } |
|
190 | 195 | |
191 | 196 | //1 = open, 2 = close, 3 = lock |
192 | 197 | switch($request->command) |
@@ -224,13 +229,14 @@ discard block |
||
224 | 229 | $time_now = Carbon::now(Auth::user()->timezone); |
225 | 230 | |
226 | 231 | //Check if the current time is during the open schedule or not |
227 | - if (($time_now > $open_time) && ($time_now < $close_time)) |
|
228 | - $command = 'open'; |
|
229 | - else |
|
230 | - $command = 'close'; |
|
232 | + if (($time_now > $open_time) && ($time_now < $close_time)) { |
|
233 | + $command = 'open'; |
|
234 | + } else { |
|
235 | + $command = 'close'; |
|
236 | + } |
|
237 | + } else { |
|
238 | + $command = 'lock'; |
|
231 | 239 | } |
232 | - else |
|
233 | - $command = 'lock'; |
|
234 | 240 | |
235 | 241 | return $command; |
236 | 242 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | $data = $this->dashData($site, $location, $device); |
40 | 40 | |
41 | - return view('dashboard.index', [ 'active_device' => $data[0], 'devices' => $data[1], 'locations' => $data[2], 'sites' => $data[3] ]); |
|
41 | + return view('dashboard.index', [ 'active_device' => $data[ 0 ], 'devices' => $data[ 1 ], 'locations' => $data[ 2 ], 'sites' => $data[ 3 ] ]); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | $data = $this->dashData($site, $location, $device); |
101 | 101 | |
102 | - return response()->json([ 'active_device' => $data[0], 'devices' => $data[1], 'locations' => $data[2], 'sites' => $data[3] ]); |
|
102 | + return response()->json([ 'active_device' => $data[ 0 ], 'devices' => $data[ 1 ], 'locations' => $data[ 2 ], 'sites' => $data[ 3 ] ]); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | |
120 | 120 | $data = $this->dashData($site, $location, $device); |
121 | 121 | |
122 | - return response()->json([ 'active_device' => $data[0], 'devices' => $data[1], 'locations' => $data[2], 'sites' => $data[3] ]); |
|
122 | + return response()->json([ 'active_device' => $data[ 0 ], 'devices' => $data[ 1 ], 'locations' => $data[ 2 ], 'sites' => $data[ 3 ] ]); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | $data = $this->dashData($site, $location, $device); |
141 | 141 | |
142 | - return response()->json([ 'active_device' => $data[0], 'devices' => $data[1], 'locations' => $data[2], 'sites' => $data[3] ]); |
|
142 | + return response()->json([ 'active_device' => $data[ 0 ], 'devices' => $data[ 1 ], 'locations' => $data[ 2 ], 'sites' => $data[ 3 ] ]); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | //Get all the devices that belong to the given location ordered by name |
162 | 162 | $devices = $location->devices()->publicDashData()->orderBy('name', 'ASC')->get(); |
163 | 163 | |
164 | - $active_device = collect([$device, $location, $site]); |
|
164 | + $active_device = collect([ $device, $location, $site ]); |
|
165 | 165 | |
166 | - return collect([$active_device, $devices, $locations, $sites]); |
|
166 | + return collect([ $active_device, $devices, $locations, $sites ]); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | return response()->json("Device is currently in use.", 403); |
185 | 185 | |
186 | 186 | //1 = open, 2 = close, 3 = lock |
187 | - switch($request->command) |
|
187 | + switch ($request->command) |
|
188 | 188 | { |
189 | 189 | case 1: |
190 | 190 | $device->cover_command = 'open'; |
@@ -220,12 +220,12 @@ discard block |
||
220 | 220 | |
221 | 221 | //Check if the current time is during the open schedule or not |
222 | 222 | if (($time_now > $open_time) && ($time_now < $close_time)) |
223 | - $command = 'open'; |
|
223 | + $command = 'open'; |
|
224 | 224 | else |
225 | - $command = 'close'; |
|
225 | + $command = 'close'; |
|
226 | 226 | } |
227 | 227 | else |
228 | - $command = 'lock'; |
|
228 | + $command = 'lock'; |
|
229 | 229 | |
230 | 230 | return $command; |
231 | 231 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * Get the locations with the given site id |
104 | 104 | * |
105 | 105 | * @param int $site_id |
106 | - * @return Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection |
|
106 | + * @return \Illuminate\Http\JsonResponse |
|
107 | 107 | */ |
108 | 108 | public function locations($site_id) |
109 | 109 | { |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * Get the devices details |
117 | 117 | * |
118 | 118 | * @param int $id |
119 | - * @return Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection |
|
119 | + * @return \Illuminate\Http\JsonResponse |
|
120 | 120 | */ |
121 | 121 | public function details($id) |
122 | 122 | { |
@@ -3,10 +3,8 @@ |
||
3 | 3 | namespace App\Http\Controllers; |
4 | 4 | |
5 | 5 | use App\Http\Requests\EditDevice; |
6 | -use Validator; |
|
7 | 6 | use Illuminate\Http\Request; |
8 | 7 | use App\DataTables\DevicesDataTable; |
9 | -use Illuminate\Support\Facades\Route; |
|
10 | 8 | use App\Device; |
11 | 9 | use App\Site; |
12 | 10 | use App\Location; |
@@ -84,8 +84,7 @@ discard block |
||
84 | 84 | $sites->prepend($location->site); |
85 | 85 | //Add the current location to the front of the collection of locations |
86 | 86 | $locations->prepend($location); |
87 | - } |
|
88 | - else |
|
87 | + } else |
|
89 | 88 | { |
90 | 89 | //Set locations to null since there is no site or location attached to the selected device |
91 | 90 | $locations = null; |
@@ -93,10 +92,11 @@ discard block |
||
93 | 92 | $sites = Site::all(); |
94 | 93 | } |
95 | 94 | |
96 | - if (\Request::ajax()) |
|
97 | - return response()->json([ 'device' => $device, 'locations' => $locations, 'sites' => $sites ]); |
|
98 | - else |
|
99 | - return view('device.edit', [ 'device' => $device, 'locations' => $locations, 'sites' => $sites ]); |
|
95 | + if (\Request::ajax()) { |
|
96 | + return response()->json([ 'device' => $device, 'locations' => $locations, 'sites' => $sites ]); |
|
97 | + } else { |
|
98 | + return view('device.edit', [ 'device' => $device, 'locations' => $locations, 'sites' => $sites ]); |
|
99 | + } |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -146,8 +146,7 @@ discard block |
||
146 | 146 | //Create a new site |
147 | 147 | $siteName = $request->input('new_site_name'); |
148 | 148 | $site_id = Site::createSite($siteName)->id; |
149 | - } |
|
150 | - else |
|
149 | + } else |
|
151 | 150 | { |
152 | 151 | $site_id = $request->input('site'); |
153 | 152 | } |
@@ -158,8 +157,7 @@ discard block |
||
158 | 157 | //Create a new location |
159 | 158 | $locationName = $request->input('new_location_name'); |
160 | 159 | $location_id = Location::createLocation($locationName, $site_id)->id; |
161 | - } |
|
162 | - else |
|
160 | + } else |
|
163 | 161 | { |
164 | 162 | $location_id = $request->input('location'); |
165 | 163 | } |
@@ -177,10 +175,11 @@ discard block |
||
177 | 175 | //Remove any unused sites or locations |
178 | 176 | $this->RemoveUnusedSiteLoc(); |
179 | 177 | |
180 | - if (\Request::ajax()) |
|
181 | - return response()->json("Success"); |
|
182 | - else |
|
183 | - return redirect('device'); |
|
178 | + if (\Request::ajax()) { |
|
179 | + return response()->json("Success"); |
|
180 | + } else { |
|
181 | + return redirect('device'); |
|
182 | + } |
|
184 | 183 | } |
185 | 184 | |
186 | 185 | /** |
@@ -197,8 +196,7 @@ discard block |
||
197 | 196 | { |
198 | 197 | //If the device was already deleted then permanently delete it |
199 | 198 | Device::destroy($id); |
200 | - } |
|
201 | - else |
|
199 | + } else |
|
202 | 200 | { |
203 | 201 | //Remove the location from the device |
204 | 202 | $device->location_id = null; |