keeps example values in the example preview, fixes indent

This commit is contained in:
Godfrey M 2024-02-21 09:31:01 -08:00
parent 69317fb403
commit bee016e0be

View file

@ -6,6 +6,7 @@ use App\Models\Asset;
use App\Models\AssetModel; use App\Models\AssetModel;
use App\Models\Category; use App\Models\Category;
use App\Models\Company; use App\Models\Company;
use App\Models\CustomField;
use App\Models\Labels\Label; use App\Models\Labels\Label;
use App\Models\Location; use App\Models\Location;
use App\Models\Manufacturer; use App\Models\Manufacturer;
@ -29,47 +30,51 @@ class LabelsController extends Controller
$labelName = str_replace('/', '\\', $labelName); $labelName = str_replace('/', '\\', $labelName);
$template = Label::find($labelName); $template = Label::find($labelName);
$exampleAsset = new Asset(); $exampleAsset = new Asset();
$exampleAsset->id = 999999; $exampleAsset->id = 999999;
$exampleAsset->name = 'JEN-867-5309'; $exampleAsset->name = 'JEN-867-5309';
$exampleAsset->asset_tag = '100001'; $exampleAsset->asset_tag = '100001';
$exampleAsset->serial = 'SN9876543210'; $exampleAsset->serial = 'SN9876543210';
$exampleAsset->asset_eol_date = '2025-01-01'; $exampleAsset->asset_eol_date = '2025-01-01';
$exampleAsset->order_number = '12345'; $exampleAsset->order_number = '12345';
$exampleAsset->purchase_date = '2023-01-01'; $exampleAsset->purchase_date = '2023-01-01';
$exampleAsset->status_id = 1; $exampleAsset->status_id = 1;
$exampleAsset->company = new Company([ $exampleAsset->company = new Company([
'name' => trans('admin/labels/table.example_company'), 'name' => trans('admin/labels/table.example_company'),
'phone' => '1-555-555-5555', 'phone' => '1-555-555-5555',
'email' => 'company@example.com', 'email' => 'company@example.com',
]); ]);
$exampleAsset->setRelation('assignedTo', new User(['first_name' => 'Luke', 'last_name' => 'Skywalker'])); $exampleAsset->setRelation('assignedTo', new User(['first_name' => 'Luke', 'last_name' => 'Skywalker']));
$exampleAsset->defaultLoc = new Location(['name' => trans('admin/labels/table.example_defaultloc'), 'phone' => '1-555-555-5555']); $exampleAsset->defaultLoc = new Location(['name' => trans('admin/labels/table.example_defaultloc'), 'phone' => '1-555-555-5555']);
$exampleAsset->location = new Location(['name' => trans('admin/labels/table.example_location'), 'phone' => '1-555-555-5555']); $exampleAsset->location = new Location(['name' => trans('admin/labels/table.example_location'), 'phone' => '1-555-555-5555']);
$exampleAsset->model = new AssetModel(); $exampleAsset->model = new AssetModel();
$exampleAsset->model->id = 999999; $exampleAsset->model->id = 999999;
$exampleAsset->model->name = trans('admin/labels/table.example_model'); $exampleAsset->model->name = trans('admin/labels/table.example_model');
$exampleAsset->model->model_number = 'MDL5678'; $exampleAsset->model->model_number = 'MDL5678';
$exampleAsset->model->manufacturer = new Manufacturer(); $exampleAsset->model->manufacturer = new Manufacturer();
$exampleAsset->model->manufacturer->id = 999999; $exampleAsset->model->manufacturer->id = 999999;
$exampleAsset->model->manufacturer->name = trans('admin/labels/table.example_manufacturer'); $exampleAsset->model->manufacturer->name = trans('admin/labels/table.example_manufacturer');
$exampleAsset->model->manufacturer->support_email = 'support@test.com'; $exampleAsset->model->manufacturer->support_email = 'support@test.com';
$exampleAsset->model->manufacturer->support_phone = '1-555-555-5555'; $exampleAsset->model->manufacturer->support_phone = '1-555-555-5555';
$exampleAsset->model->manufacturer->support_url = 'https://example.com'; $exampleAsset->model->manufacturer->support_url = 'https://example.com';
$exampleAsset->supplier = new Supplier(['name' => trans('admin/labels/table.example_company')]); $exampleAsset->supplier = new Supplier(['name' => trans('admin/labels/table.example_company')]);
$exampleAsset->model->category = new Category(); $exampleAsset->model->category = new Category();
$exampleAsset->model->category->id = 999999; $exampleAsset->model->category->id = 999999;
$exampleAsset->model->category->name = trans('admin/labels/table.example_category'); $exampleAsset->model->category->name = trans('admin/labels/table.example_category');
$customFieldColumns = CustomField::all()->pluck('db_column');
collect(explode(';', Setting::getSettings()->label2_fields)) collect(explode(';', Setting::getSettings()->label2_fields))
->each(function ($item) use ($exampleAsset){ ->each(function ($item) use ($customFieldColumns, $exampleAsset) {
$pair = explode('=', $item); $pair = explode('=', $item);
$exampleAsset->{$pair[1]} = "{{$pair[0]}}"; if ($customFieldColumns->contains($pair[1])) {
$exampleAsset->{$pair[1]} = "{{$pair[0]}}";
}
}); });
$settings = Setting::getSettings(); $settings = Setting::getSettings();