Skip to content

Commit

Permalink
Merge pull request #13680 from marcusmoore/feature/sc-23769
Browse files Browse the repository at this point in the history
Changed data source input to select in new label engine
  • Loading branch information
snipe authored Nov 13, 2023
2 parents 9dc9834 + eb2edb7 commit 4546e87
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 17 deletions.
28 changes: 18 additions & 10 deletions app/Http/Controllers/LabelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
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;
Expand All @@ -33,18 +35,20 @@ public function show(string $labelName)
$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' => '[email protected]',
]);

$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;
Expand All @@ -53,6 +57,10 @@ public function show(string $labelName)
$exampleAsset->model->manufacturer = new Manufacturer();
$exampleAsset->model->manufacturer->id = 999999;
$exampleAsset->model->manufacturer->name = 'Test Manufacturing Inc.';
$exampleAsset->model->manufacturer->support_email = '[email protected]';
$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';
Expand Down
8 changes: 5 additions & 3 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -809,9 +810,10 @@ public function getPhpInfo()
*/
public function getLabels()
{
$setting = Setting::getSettings();

return view('settings.labels', compact('setting'));
return view('settings.labels', [
'setting' => Setting::getSettings(),
'customFields' => CustomField::all(),
]);
}

/**
Expand Down
10 changes: 9 additions & 1 deletion app/Models/Labels/FieldOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public function getDataSource() { return $this->dataSource; }

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; }
Expand Down Expand Up @@ -46,4 +54,4 @@ public static function fromString(string $theString) {
return $option;
}
}
}
}
51 changes: 49 additions & 2 deletions resources/views/partials/label2-field-definitions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,54 @@
<label style="grid-area: label-title">Label</label>
<input style="grid-area: label-field" x-model="option.label" />
<label style="grid-area: source-title">DataSource</label>
<input style="grid-area: source-field" x-model="option.datasource" />
<select style="grid-area: source-field" x-model="option.datasource">
<optgroup label="Asset">
<option value="asset_tag">Asset Tag</option>
<option value="name">Asset Name</option>
<option value="serial">Asset Serial</option>
<option value="asset_eol_date">Asset EOL Date</option>
<option value="order_number">Asset Order Number</option>
<option value="purchase_date">Asset Purchase Date</option>
<option value="assignedTo">Assigned To</option>
</optgroup>
<optgroup label="Asset Model">
<option value="model.name">Asset Model Name</option>
<option value="model.model_number">Asset Model Number</option>
</optgroup>
<optgroup label="Manufacturer">
<option value="model.manufacturer.name">Manufacturer Name</option>
<option value="model.manufacturer.support_email">Manufacturer Support Email</option>
<option value="model.manufacturer.support_phone">Manufacturer Support Phone</option>
<option value="model.manufacturer.support_url">Manufacturer Support URL</option>
</optgroup>
<optgroup label="Category">
<option value="model.category.name">Category Name</option>
</optgroup>
<optgroup label="Status">
<option value="assetstatus.name">Status</option>
</optgroup>
<optgroup label="Supplier">
<option value="supplier.name">Supplier Name</option>
</optgroup>
<optgroup label="Default Location">
<option value="defaultLoc.name">Default Location Name</option>
<option value="defaultLoc.phone">Default Location Phone</option>
</optgroup>
<optgroup label="Location">
<option value="location.name">Location Name</option>
<option value="location.phone">Location Phone</option>
</optgroup>
<optgroup label="Company">
<option value="company.email">Company Email</option>
<option value="company.name">Company Name</option>
<option value="company.phone">Company Phone</option>
</optgroup>
<optgroup label="Custom Fields">
@foreach($customFields as $customField)
<option value="{{ $customField->db_column }}">{{ $customField->name }}</option>
@endforeach
</optgroup>
</select>
</div>
</template>
</template>
Expand All @@ -331,4 +378,4 @@
><i class="fa-solid fa-trash"></i></button>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion resources/views/settings/labels.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class="table table-striped snipe-table"
{{ Form::label('label2_fields', trans('admin/settings/general.label2_fields')) }}
</div>
<div class="col-md-9">
@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', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
<p class="help-block">{{ trans('admin/settings/general.label2_fields_help') }}</p>
</div>
Expand Down

0 comments on commit 4546e87

Please sign in to comment.