@@ -127,12 +127,12 @@ discard block |
||
127 | 127 | private function modalUrl($type) |
128 | 128 | { |
129 | 129 | switch ($type) { |
130 | - case 'edit': |
|
131 | - $action = 'update'; |
|
132 | - break; |
|
133 | - default: |
|
134 | - $action = $type; |
|
135 | - break; |
|
130 | + case 'edit': |
|
131 | + $action = 'update'; |
|
132 | + break; |
|
133 | + default: |
|
134 | + $action = $type; |
|
135 | + break; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | return route('crudapi.'.$action.'.item', $this->model); |
@@ -153,116 +153,116 @@ discard block |
||
153 | 153 | $output = ''; |
154 | 154 | |
155 | 155 | switch ($type) { |
156 | - case 'form-create': |
|
157 | - foreach ($fields as $f) { |
|
158 | - $ucF = ucfirst($f); |
|
156 | + case 'form-create': |
|
157 | + foreach ($fields as $f) { |
|
158 | + $ucF = ucfirst($f); |
|
159 | 159 | |
160 | - $input_attr = [ |
|
161 | - 'class' => 'form-control', |
|
162 | - 'id' => 'createItem'.$f, |
|
163 | - 'name' => $f, |
|
164 | - ]; |
|
160 | + $input_attr = [ |
|
161 | + 'class' => 'form-control', |
|
162 | + 'id' => 'createItem'.$f, |
|
163 | + 'name' => $f, |
|
164 | + ]; |
|
165 | 165 | |
166 | - $output .= '<fieldset class="form-group">'; |
|
166 | + $output .= '<fieldset class="form-group">'; |
|
167 | 167 | |
168 | - $output .= '<label for="'.$input_attr['id'].'">'.$ucF.'</label>'; |
|
168 | + $output .= '<label for="'.$input_attr['id'].'">'.$ucF.'</label>'; |
|
169 | 169 | |
170 | - if ($this->fieldHelper->isIdField($f)) { |
|
171 | - $input_attr['type'] = 'select'; |
|
170 | + if ($this->fieldHelper->isIdField($f)) { |
|
171 | + $input_attr['type'] = 'select'; |
|
172 | 172 | |
173 | - $output .= '<select '; |
|
174 | - foreach ($input_attr as $attr => $value) { |
|
175 | - $output .= "{$attr}='{$value}'"; |
|
176 | - } |
|
173 | + $output .= '<select '; |
|
174 | + foreach ($input_attr as $attr => $value) { |
|
175 | + $output .= "{$attr}='{$value}'"; |
|
176 | + } |
|
177 | 177 | |
178 | - $relation = $this->getRelatedModel($f); |
|
179 | - $output .= '>'; |
|
178 | + $relation = $this->getRelatedModel($f); |
|
179 | + $output .= '>'; |
|
180 | 180 | |
181 | - $output .= $this->getRelatedOptions($relation); |
|
181 | + $output .= $this->getRelatedOptions($relation); |
|
182 | 182 | |
183 | - $output .= '</select>'; |
|
184 | - } else { |
|
185 | - $input_attr['type'] = 'text'; |
|
183 | + $output .= '</select>'; |
|
184 | + } else { |
|
185 | + $input_attr['type'] = 'text'; |
|
186 | 186 | |
187 | - $output .= '<input '; |
|
188 | - foreach ($input_attr as $attr => $value) { |
|
189 | - $output .= "{$attr}='{$value}'"; |
|
187 | + $output .= '<input '; |
|
188 | + foreach ($input_attr as $attr => $value) { |
|
189 | + $output .= "{$attr}='{$value}'"; |
|
190 | + } |
|
191 | + $output .= '>'; |
|
190 | 192 | } |
191 | - $output .= '>'; |
|
193 | + |
|
194 | + $output .= '</fieldset>'; |
|
192 | 195 | } |
196 | + break; |
|
197 | + case 'form-edit': |
|
198 | + foreach ($fields as $f) { |
|
199 | + $ucF = ucfirst($f); |
|
193 | 200 | |
194 | - $output .= '</fieldset>'; |
|
195 | - } |
|
196 | - break; |
|
197 | - case 'form-edit': |
|
198 | - foreach ($fields as $f) { |
|
199 | - $ucF = ucfirst($f); |
|
201 | + $input_attr = [ |
|
202 | + 'class' => 'form-control', |
|
203 | + 'id' => 'editItem'.$ucF, |
|
204 | + 'name' => $f, |
|
205 | + ]; |
|
200 | 206 | |
201 | - $input_attr = [ |
|
202 | - 'class' => 'form-control', |
|
203 | - 'id' => 'editItem'.$ucF, |
|
204 | - 'name' => $f, |
|
205 | - ]; |
|
207 | + $output .= '<fieldset class="form-group">'; |
|
206 | 208 | |
207 | - $output .= '<fieldset class="form-group">'; |
|
209 | + $output .= '<label for="'.$input_attr['id'].'">'.$ucF.'</label>'; |
|
208 | 210 | |
209 | - $output .= '<label for="'.$input_attr['id'].'">'.$ucF.'</label>'; |
|
211 | + if ($this->fieldHelper->isIdField($f)) { |
|
212 | + $input_attr['type'] = 'select'; |
|
210 | 213 | |
211 | - if ($this->fieldHelper->isIdField($f)) { |
|
212 | - $input_attr['type'] = 'select'; |
|
214 | + $output .= '<select '; |
|
215 | + foreach ($input_attr as $attr => $value) { |
|
216 | + $output .= "{$attr}='{$value}'"; |
|
217 | + } |
|
213 | 218 | |
214 | - $output .= '<select '; |
|
215 | - foreach ($input_attr as $attr => $value) { |
|
216 | - $output .= "{$attr}='{$value}'"; |
|
217 | - } |
|
219 | + $relation = $this->getRelatedModel($f); |
|
220 | + $output .= '>'; |
|
218 | 221 | |
219 | - $relation = $this->getRelatedModel($f); |
|
220 | - $output .= '>'; |
|
222 | + $output .= $this->getRelatedOptions($relation); |
|
223 | + $output .= '</select>'; |
|
224 | + } else { |
|
225 | + $input_attr['type'] = 'text'; |
|
221 | 226 | |
222 | - $output .= $this->getRelatedOptions($relation); |
|
223 | - $output .= '</select>'; |
|
224 | - } else { |
|
225 | - $input_attr['type'] = 'text'; |
|
227 | + $output .= '<input '; |
|
228 | + foreach ($input_attr as $attr => $value) { |
|
229 | + $output .= "{$attr}='{$value}'"; |
|
230 | + } |
|
231 | + $output .= '>'; |
|
232 | + } |
|
226 | 233 | |
227 | - $output .= '<input '; |
|
228 | - foreach ($input_attr as $attr => $value) { |
|
229 | - $output .= "{$attr}='{$value}'"; |
|
234 | + $output .= '</fieldset>'; |
|
235 | + } |
|
236 | + break; |
|
237 | + case 'table-headings': |
|
238 | + foreach ($fields as $f) { |
|
239 | + $output .= '<th>'.ucfirst($f).'</th>'; |
|
240 | + } |
|
241 | + break; |
|
242 | + case 'table-content': |
|
243 | + foreach ($fields as $f) { |
|
244 | + if ($this->fieldHelper->isIdField($f)) { |
|
245 | + $display = $this->getRelatedDisplay($f); |
|
246 | + $output .= '<td>'.$display.'</td>'; |
|
247 | + } else { |
|
248 | + $output .= '<td>'.$this->instance->$f.'</td>'; |
|
230 | 249 | } |
231 | - $output .= '>'; |
|
232 | 250 | } |
233 | - |
|
234 | - $output .= '</fieldset>'; |
|
235 | - } |
|
236 | - break; |
|
237 | - case 'table-headings': |
|
238 | - foreach ($fields as $f) { |
|
239 | - $output .= '<th>'.ucfirst($f).'</th>'; |
|
240 | - } |
|
241 | - break; |
|
242 | - case 'table-content': |
|
243 | - foreach ($fields as $f) { |
|
244 | - if ($this->fieldHelper->isIdField($f)) { |
|
245 | - $display = $this->getRelatedDisplay($f); |
|
246 | - $output .= '<td>'.$display.'</td>'; |
|
247 | - } else { |
|
248 | - $output .= '<td>'.$this->instance->$f.'</td>'; |
|
251 | + break; |
|
252 | + // JavaScript Variables |
|
253 | + case 'js-var': |
|
254 | + foreach ($fields as $f) { |
|
255 | + $output .= 'var '.$f.' = '.$this->instance->$f.'; '; |
|
249 | 256 | } |
250 | - } |
|
251 | - break; |
|
252 | - // JavaScript Variables |
|
253 | - case 'js-var': |
|
254 | - foreach ($fields as $f) { |
|
255 | - $output .= 'var '.$f.' = '.$this->instance->$f.'; '; |
|
256 | - } |
|
257 | - break; |
|
258 | - case 'js-modal-create': |
|
259 | - foreach ($fields as $f) { |
|
260 | - $output .= '"'.$f.'": $(\'#createItem'.$f.'\').val(), '; |
|
261 | - } |
|
262 | - break; |
|
263 | - default: |
|
264 | - return; |
|
265 | 257 | break; |
258 | + case 'js-modal-create': |
|
259 | + foreach ($fields as $f) { |
|
260 | + $output .= '"'.$f.'": $(\'#createItem'.$f.'\').val(), '; |
|
261 | + } |
|
262 | + break; |
|
263 | + default: |
|
264 | + return; |
|
265 | + break; |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | echo $output; |
@@ -330,17 +330,17 @@ discard block |
||
330 | 330 | $class = get_class($field); |
331 | 331 | |
332 | 332 | switch ($class) { |
333 | - case 'App\\Helpers\\CrudApi': |
|
334 | - break; |
|
335 | - case 'App\\Indicator': |
|
336 | - return $field->indicator; |
|
337 | - break; |
|
338 | - case 'Taskforcedev\\CrudApi\\Helpers\\CrudApi': |
|
339 | - return false; |
|
340 | - break; |
|
341 | - default: |
|
342 | - return $field->name; |
|
333 | + case 'App\\Helpers\\CrudApi': |
|
343 | 334 | break; |
335 | + case 'App\\Indicator': |
|
336 | + return $field->indicator; |
|
337 | + break; |
|
338 | + case 'Taskforcedev\\CrudApi\\Helpers\\CrudApi': |
|
339 | + return false; |
|
340 | + break; |
|
341 | + default: |
|
342 | + return $field->name; |
|
343 | + break; |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | Route::group( |
4 | - ['namespace' => 'Taskforcedev\CrudApi\Http\Controllers'], function () { |
|
4 | + ['namespace' => 'Taskforcedev\CrudApi\Http\Controllers'], function() { |
|
5 | 5 | Route::group( |
6 | - ['middleware' => ['web'], 'prefix' => 'admin/'], function () { |
|
7 | - Route::post('create/{model}', ['as' => 'crudapi.create.item', 'uses' => 'AdminController@store']); |
|
8 | - Route::patch('update/{model}', ['as' => 'crudapi.update.item', 'uses' => 'AdminController@update']); |
|
6 | + ['middleware' => ['web'], 'prefix' => 'admin/'], function() { |
|
7 | + Route::post('create/{model}', ['as' => 'crudapi.create.item', 'uses' => 'AdminController@store']); |
|
8 | + Route::patch('update/{model}', ['as' => 'crudapi.update.item', 'uses' => 'AdminController@update']); |
|
9 | 9 | Route::delete('delete/{model}', ['as' => 'crudapi.delete.item', 'uses' => 'AdminController@delete']); |
10 | - Route::get('{model}', ['as' => 'crudapi.admin.model', 'uses' => 'AdminController@index']); |
|
10 | + Route::get('{model}', ['as' => 'crudapi.admin.model', 'uses' => 'AdminController@index']); |
|
11 | 11 | } |
12 | 12 | ); |
13 | 13 | } |
@@ -2,6 +2,6 @@ |
||
2 | 2 | if (!isset($uiframework) || $uiframework == 'bs3') { |
3 | 3 | $uiframework = 'bs4'; |
4 | 4 | } |
5 | -$adminIndex = 'crudapi::admin.' . $uiframework . '.index'; |
|
5 | +$adminIndex = 'crudapi::admin.'.$uiframework.'.index'; |
|
6 | 6 | ?> |
7 | 7 | @include($adminIndex) |
8 | 8 | \ No newline at end of file |
@@ -43,13 +43,13 @@ |
||
43 | 43 | var id = button.data('id'); |
44 | 44 | <?php |
45 | 45 | foreach ($fields as $field) { |
46 | - echo 'var ' . $field . ' = button.data(\'' . $field . '\');' . "\n"; |
|
46 | + echo 'var '.$field.' = button.data(\''.$field.'\');'."\n"; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | foreach ($fields as $field) { |
50 | 50 | $ucfield = ucfirst($field); |
51 | 51 | if ($apiHelper->fieldHelper->isIdField($field)) { |
52 | - echo "$('#editItem{$ucfield} option[value=' +{$field} +']').attr('selected', 'selected'); " . "\n"; |
|
52 | + echo "$('#editItem{$ucfield} option[value=' +{$field} +']').attr('selected', 'selected'); "."\n"; |
|
53 | 53 | } else { |
54 | 54 | echo "$('#editItem{$ucfield}').val({$field});\n"; |
55 | 55 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | data-id="{{ $r->id }}" |
7 | 7 | <?php |
8 | 8 | foreach ($fields as $f) { |
9 | - echo "data-{$f}=\"" . $r->$f . "\" "; |
|
9 | + echo "data-{$f}=\"".$r->$f."\" "; |
|
10 | 10 | } |
11 | 11 | ?> |
12 | 12 | data-target="#edit{{$trimmed_item}}Modal">Edit</button> |
13 | 13 | \ No newline at end of file |
@@ -11,7 +11,7 @@ |
||
11 | 11 | <table class="table"> |
12 | 12 | <?php |
13 | 13 | foreach ($fields as $field) { |
14 | - echo "<tr><td>{$field}</td><td><span id=\"deletedItem" . ucfirst($field) . "\"></span></td></tr>"; |
|
14 | + echo "<tr><td>{$field}</td><td><span id=\"deletedItem".ucfirst($field)."\"></span></td></tr>"; |
|
15 | 15 | } |
16 | 16 | ?> |
17 | 17 | </table> |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | "_token": "{{ csrf_token() }}" |
25 | 25 | } |
26 | 26 | |
27 | - $('#<?php echo $modal_id;?>').modal('hide'); |
|
27 | + $('#<?php echo $modal_id; ?>').modal('hide'); |
|
28 | 28 | |
29 | 29 | /* Send the post request */ |
30 | 30 | @if(isset($done)) |
@@ -40,13 +40,13 @@ discard block |
||
40 | 40 | } |
41 | 41 | </script> |
42 | 42 | <script> |
43 | - $('#<?php echo $modal_id;?>').on('show.bs.modal', function (event) { |
|
43 | + $('#<?php echo $modal_id; ?>').on('show.bs.modal', function (event) { |
|
44 | 44 | var button = $(event.relatedTarget) // Button that triggered the modal |
45 | 45 | |
46 | 46 | var id = button.data('id'); |
47 | 47 | <?php |
48 | 48 | foreach ($fields as $field) { |
49 | - echo 'var ' . $field . ' = button.data(\'' . $field . '\')' . "\n"; |
|
49 | + echo 'var '.$field.' = button.data(\''.$field.'\')'."\n"; |
|
50 | 50 | } ?> |
51 | 51 | |
52 | 52 | //var recipient = button.data('whatever') // Extract info from data-* attributes |
@@ -6,7 +6,7 @@ |
||
6 | 6 | data-id="{{ $r->id }}" |
7 | 7 | <?php |
8 | 8 | foreach ($fields as $f) { |
9 | - echo "data-{$f}=\"" . $r->$f . "\" "; |
|
9 | + echo "data-{$f}=\"".$r->$f."\" "; |
|
10 | 10 | } |
11 | 11 | ?> |
12 | 12 | data-target="#delete{{$trimmed_item}}Modal">Delete</button> |
13 | 13 | \ No newline at end of file |
@@ -27,7 +27,7 @@ |
||
27 | 27 | |
28 | 28 | $fqModel = $crudApi->getModel(); |
29 | 29 | |
30 | - $this->assertEquals($namespace . 'User', $fqModel); |
|
30 | + $this->assertEquals($namespace.'User', $fqModel); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | public function testUserGetModelCanBeInstantiated() |