diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.php index ddff771961..950094bc45 100755 --- a/app/Http/Controllers/LabelsController.php +++ b/app/Http/Controllers/LabelsController.php @@ -7,8 +7,10 @@ use App\Models\AssetModel; use App\Models\Category; use App\Models\Company; use App\Models\Labels\Label; +use App\Models\Location; use App\Models\Manufacturer; use App\Models\Setting; +use App\Models\Supplier; use App\Models\User; use App\View\Label as LabelView; use Illuminate\Support\Facades\Storage; @@ -33,18 +35,20 @@ class LabelsController extends Controller $exampleAsset->name = 'JEN-867-5309'; $exampleAsset->asset_tag = '100001'; $exampleAsset->serial = 'SN9876543210'; + $exampleAsset->asset_eol_date = '2025-01-01'; + $exampleAsset->order_number = '12345'; + $exampleAsset->purchase_date = '2023-01-01'; + $exampleAsset->status_id = 1; - $exampleAsset->company = new Company(); - $exampleAsset->company->id = 999999; - $exampleAsset->company->name = 'Test Company Limited'; - $exampleAsset->company->image = 'company-image-test.png'; + $exampleAsset->company = new Company([ + 'name' => 'Test Company Limited', + 'phone' => '1-555-555-5555', + 'email' => 'company@example.com', + ]); - $exampleAsset->assignedto = new User(); - $exampleAsset->assignedto->id = 999999; - $exampleAsset->assignedto->first_name = 'Test'; - $exampleAsset->assignedto->last_name = 'Person'; - $exampleAsset->assignedto->username = 'Test.Person'; - $exampleAsset->assignedto->employee_num = '0123456789'; + $exampleAsset->setRelation('assignedTo', new User(['first_name' => 'Luke', 'last_name' => 'Skywalker'])); + $exampleAsset->defaultLoc = new Location(['name' => 'Building 1', 'phone' => '1-555-555-5555']); + $exampleAsset->location = new Location(['name' => 'Building 2', 'phone' => '1-555-555-5555']); $exampleAsset->model = new AssetModel(); $exampleAsset->model->id = 999999; @@ -53,6 +57,10 @@ class LabelsController extends Controller $exampleAsset->model->manufacturer = new Manufacturer(); $exampleAsset->model->manufacturer->id = 999999; $exampleAsset->model->manufacturer->name = 'Test Manufacturing Inc.'; + $exampleAsset->model->manufacturer->support_email = 'support@test.com'; + $exampleAsset->model->manufacturer->support_phone = '1-555-555-5555'; + $exampleAsset->model->manufacturer->support_url = 'https://example.com'; + $exampleAsset->supplier = new Supplier(['name' => 'Test Company Limited']); $exampleAsset->model->category = new Category(); $exampleAsset->model->category->id = 999999; $exampleAsset->model->category->name = 'Test Category'; diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index b4acc4c5a0..989fe8c494 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -7,6 +7,7 @@ use App\Helpers\StorageHelper; use App\Http\Requests\ImageUploadRequest; use App\Http\Requests\SettingsSamlRequest; use App\Http\Requests\SetupUserRequest; +use App\Models\CustomField; use App\Models\Group; use App\Models\Setting; use App\Models\Asset; @@ -809,9 +810,10 @@ class SettingsController extends Controller */ public function getLabels() { - $setting = Setting::getSettings(); - - return view('settings.labels', compact('setting')); + return view('settings.labels', [ + 'setting' => Setting::getSettings(), + 'customFields' => CustomField::all(), + ]); } /** diff --git a/app/Models/Labels/FieldOption.php b/app/Models/Labels/FieldOption.php index 76427accaf..7e45cc0ce7 100644 --- a/app/Models/Labels/FieldOption.php +++ b/app/Models/Labels/FieldOption.php @@ -14,6 +14,14 @@ class FieldOption { public function getValue(Asset $asset) { $dataPath = collect(explode('.', $this->dataSource)); + + // assignedTo directly on the asset is a special case where + // we want to avoid returning the property directly + // and instead return the entity's presented name. + if ($dataPath[0] === 'assignedTo'){ + return $asset->assignedTo ? $asset->assignedTo->present()->fullName() : null; + } + return $dataPath->reduce(function ($myValue, $path) { try { return $myValue ? $myValue->{$path} : ${$myValue}; } catch (\Exception $e) { return $myValue; } @@ -46,4 +54,4 @@ class FieldOption { return $option; } } -} \ No newline at end of file +} diff --git a/resources/views/partials/label2-field-definitions.blade.php b/resources/views/partials/label2-field-definitions.blade.php index 6522b951d8..21aa7a0cf9 100644 --- a/resources/views/partials/label2-field-definitions.blade.php +++ b/resources/views/partials/label2-field-definitions.blade.php @@ -304,7 +304,54 @@ - + @@ -331,4 +378,4 @@ > - \ No newline at end of file + diff --git a/resources/views/settings/labels.blade.php b/resources/views/settings/labels.blade.php index 46ce4fe610..a6edd29154 100644 --- a/resources/views/settings/labels.blade.php +++ b/resources/views/settings/labels.blade.php @@ -216,7 +216,7 @@ {{ Form::label('label2_fields', trans('admin/settings/general.label2_fields')) }}
- @include('partials.label2-field-definitions', [ 'name' => 'label2_fields', 'value' => old('label2_fields', $setting->label2_fields) ]) + @include('partials.label2-field-definitions', [ 'name' => 'label2_fields', 'value' => old('label2_fields', $setting->label2_fields), 'customFields' => $customFields ]) {!! $errors->first('label2_fields', '') !!}

{{ trans('admin/settings/general.label2_fields_help') }}