Completed
Push — master ( 21e9de...3c7ef4 )
by
unknown
03:55 queued 03:35
created
app/Http/Controllers/DeviceController.php 1 patch
Braces   +34 added lines, -24 removed lines patch added patch discarded remove patch
@@ -124,53 +124,63 @@
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.
app/Http/Controllers/DashboardController.php 1 patch
Braces   +9 added lines, -8 removed lines patch added patch discarded remove patch
@@ -42,13 +42,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
             });
Please login to merge, or discard this patch.