Passed
Push — dev5a ( 8099d5...bf034e )
by Ron
07:35
created

EquipmentInformationController::getFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Domains\Equipment\GetEquipDataFields;
6
use App\Domains\Equipment\SetEquipmentDataFields;
7
use App\Http\Controllers\Controller;
8
use App\Http\Requests\Equipment\EditFieldRequest;
9
use App\Http\Requests\Equipment\NewFieldRequest;
10
use Illuminate\Http\Request;
11
12
use Illuminate\Support\Facades\Auth;
13
use Illuminate\Support\Facades\Log;
14
15
class EquipmentInformationController extends Controller
16
{
17 2
    public function index()
18
    {
19 2
        return view('admin.equipment.equipmentInformation', [
20 2
            'fields' => (new GetEquipDataFields)->getAllFieldsWithStats(),
21
        ]);
22
    }
23
24
    public function getFields($sysID)
25
    {
26
        return (new GetEquipDataFields)->getFieldsForEquip($sysID);
27
    }
28
29 2
    public function newField(NewFieldRequest $request)
30
    {
31 2
        (new SetEquipmentDataFields)->processNewField($request->name, $request->hidden);
32 2
        return response()->json(['success' => true]);
33
    }
34
35 2
    public function submitFieldName(EditFieldRequest $request)
36
    {
37 2
        (new SetEquipmentDataFields)->editExistingField($request->data_type_id, $request->name, $request->hidden);
38 2
        Log::info('Data Field Type ID '.$request->data_type_id.' was updated by '.Auth::user()->full_name.'.  Data - ', $request->toArray());
39 2
        return response()->json(['success' => true]);
40
    }
41
42 2
    public function deleteField($id)
43
    {
44 2
        (new SetEquipmentDataFields)->deleteField($id);
45 2
        Log::notice('Data Field Type ID - '.$id.' was deleted by '.Auth::user()->full_name);
46 2
        return response()->json(['success' => true]);
47
    }
48
}
49