From f5aea7b0d5b0292f97367c7bdff1a62c72c04b00 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 28 Oct 2024 11:37:17 +0000 Subject: [PATCH] Changed status label to use `status_type` instead of booleans Signed-off-by: snipe --- app/Helpers/Helper.php | 6 +- app/Http/Controllers/Api/AssetsController.php | 22 ++--- .../Api/StatuslabelsController.php | 44 +++------ .../Controllers/Assets/AssetsController.php | 2 +- .../Controllers/StatuslabelsController.php | 6 +- .../AssetMaintenancesTransformer.php | 2 +- app/Http/Transformers/AssetsTransformer.php | 5 +- .../Transformers/StatuslabelsTransformer.php | 3 +- app/Importer/AssetImporter.php | 4 +- app/Models/Asset.php | 23 ++--- app/Models/Location.php | 4 +- app/Models/Statuslabel.php | 91 ++----------------- app/Presenters/AssetPresenter.php | 13 --- .../DepreciationReportPresenter.php | 2 +- ...annotBeCheckedOutToNondeployableStatus.php | 2 +- database/factories/AssetFactory.php | 3 +- database/factories/StatuslabelFactory.php | 14 +-- ...10_24_180042_add_type_to_status_labels.php | 62 +++++++++++++ database/seeders/StatuslabelSeeder.php | 11 ++- resources/views/statuslabels/edit.blade.php | 2 +- tests/Feature/Assets/Api/AssetIndexTest.php | 19 +++- 21 files changed, 146 insertions(+), 194 deletions(-) create mode 100644 database/migrations/2024_10_24_180042_add_type_to_status_labels.php diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 6c43fec05a..0027b68a33 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -553,7 +553,7 @@ class Helper */ public static function statusLabelList() { - $statuslabel_list = ['' => trans('general.select_statuslabel')] + Statuslabel::orderBy('default_label', 'desc')->orderBy('name', 'asc')->orderBy('deployable', 'desc') + $statuslabel_list = ['' => trans('general.select_statuslabel')] + Statuslabel::orderBy('default_label', 'desc')->orderBy('name', 'asc')->orderBy('status_type', 'desc') ->pluck('name', 'id')->toArray(); return $statuslabel_list; @@ -572,9 +572,9 @@ class Helper */ public static function deployableStatusLabelList() { - $statuslabel_list = Statuslabel::where('deployable', '=', '1')->orderBy('default_label', 'desc') + $statuslabel_list = Statuslabel::where('status_type', 'deployable')->orderBy('default_label', 'desc') ->orderBy('name', 'asc') - ->orderBy('deployable', 'desc') + ->orderBy('status_type', 'desc') ->pluck('name', 'id')->toArray(); return $statuslabel_list; diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index d4a103be37..67b32d053a 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -206,18 +206,14 @@ class AssetsController extends Controller case 'Pending': $assets->join('status_labels AS status_alias', function ($join) { $join->on('status_alias.id', '=', 'assets.status_id') - ->where('status_alias.deployable', '=', 0) - ->where('status_alias.pending', '=', 1) - ->where('status_alias.archived', '=', 0); + ->where('status_alias.status_type', '=', 'pending'); }); break; case 'RTD': $assets->whereNull('assets.assigned_to') ->join('status_labels AS status_alias', function ($join) { $join->on('status_alias.id', '=', 'assets.status_id') - ->where('status_alias.deployable', '=', 1) - ->where('status_alias.pending', '=', 0) - ->where('status_alias.archived', '=', 0); + ->where('status_alias.status_type', '=', 'deployable'); }); break; case 'Undeployable': @@ -226,18 +222,14 @@ class AssetsController extends Controller case 'Archived': $assets->join('status_labels AS status_alias', function ($join) { $join->on('status_alias.id', '=', 'assets.status_id') - ->where('status_alias.deployable', '=', 0) - ->where('status_alias.pending', '=', 0) - ->where('status_alias.archived', '=', 1); + ->where('status_alias.status_type', '=', 'archived'); }); break; case 'Requestable': $assets->where('assets.requestable', '=', 1) ->join('status_labels AS status_alias', function ($join) { $join->on('status_alias.id', '=', 'assets.status_id') - ->where('status_alias.deployable', '=', 1) - ->where('status_alias.pending', '=', 0) - ->where('status_alias.archived', '=', 0); + ->where('status_alias.status_type', '=', 'deployable'); }); break; @@ -256,7 +248,7 @@ class AssetsController extends Controller // terrible workaround for complex-query Laravel bug in fulltext $assets->join('status_labels AS status_alias', function ($join) { $join->on('status_alias.id', '=', 'assets.status_id') - ->where('status_alias.archived', '=', 0); + ->where('status_alias.status_type', '=', 'archived'); }); // If there is a status ID, don't take show_archived_in_list into consideration @@ -574,8 +566,8 @@ class AssetsController extends Controller } - if ($asset->assetstatus->getStatuslabelType() == 'pending') { - $asset->use_text .= '('.$asset->assetstatus->getStatuslabelType().')'; + if ($asset->assetstatus->status_label == 'pending') { + $asset->use_text .= '('.$asset->assetstatus->status_label.')'; } $asset->use_image = ($asset->getImageUrl()) ? $asset->getImageUrl() : null; diff --git a/app/Http/Controllers/Api/StatuslabelsController.php b/app/Http/Controllers/Api/StatuslabelsController.php index 7e4851ff5a..4e521ae9a4 100644 --- a/app/Http/Controllers/Api/StatuslabelsController.php +++ b/app/Http/Controllers/Api/StatuslabelsController.php @@ -49,13 +49,12 @@ class StatuslabelsController extends Controller // if a status_type is passed, filter by that if ($request->filled('status_type')) { if (strtolower($request->input('status_type')) == 'pending') { - $statuslabels = $statuslabels->Pending(); - } elseif (strtolower($request->input('status_type')) == 'archived') { - $statuslabels = $statuslabels->Archived(); - } elseif (strtolower($request->input('status_type')) == 'deployable') { - $statuslabels = $statuslabels->Deployable(); + $statuslabels->where('status_type', '=', 'pending'); + } elseif (strtolower($request->input('status_type')) == 'archived') $statuslabels->where('status_type', '=', 'archived'); + elseif (strtolower($request->input('status_type')) == 'deployable') { + $statuslabels->where('status_type', '=', 'deployable'); } elseif (strtolower($request->input('status_type')) == 'undeployable') { - $statuslabels = $statuslabels->Undeployable(); + $statuslabels->whereNot('status_type', 'deployable'); } } @@ -92,20 +91,11 @@ class StatuslabelsController extends Controller public function store(Request $request) : JsonResponse { $this->authorize('create', Statuslabel::class); - $request->except('deployable', 'pending', 'archived'); - if (! $request->filled('type')) { - - return response()->json(Helper::formatStandardApiResponse('error', null, ['type' => ['Status label type is required.']])); - } $statuslabel = new Statuslabel; $statuslabel->fill($request->all()); - - $statusType = Statuslabel::getStatuslabelTypesForDB($request->input('type')); - $statuslabel->deployable = $statusType['deployable']; - $statuslabel->pending = $statusType['pending']; - $statuslabel->archived = $statusType['archived']; + $statuslabel->status_type = $request->input('status_type'); $statuslabel->color = $request->input('color'); $statuslabel->show_in_nav = $request->input('show_in_nav', 0); $statuslabel->default_label = $request->input('default_label', 0); @@ -146,20 +136,12 @@ class StatuslabelsController extends Controller { $this->authorize('update', Statuslabel::class); $statuslabel = Statuslabel::findOrFail($id); - - $request->except('deployable', 'pending', 'archived'); - if (! $request->filled('type')) { - return response()->json(Helper::formatStandardApiResponse('error', null, 'Status label type is required.')); - } - $statuslabel->fill($request->all()); $statusType = Statuslabel::getStatuslabelTypesForDB($request->input('type')); - $statuslabel->deployable = $statusType['deployable']; - $statuslabel->pending = $statusType['pending']; - $statuslabel->archived = $statusType['archived']; + $statuslabel->status_type = $request->input('status_type'); $statuslabel->color = $request->input('color'); $statuslabel->show_in_nav = $request->input('show_in_nav', 0); $statuslabel->default_label = $request->input('default_label', 0); @@ -207,7 +189,7 @@ class StatuslabelsController extends Controller $this->authorize('view', Statuslabel::class); if (Setting::getSettings()->show_archived_in_list == 0 ) { - $statuslabels = Statuslabel::withCount('assets')->where('archived','0')->get(); + $statuslabels = Statuslabel::withCount('assets')->whereNot('status_type','archived')->get(); } else { $statuslabels = Statuslabel::withCount('assets')->get(); } @@ -301,7 +283,7 @@ class StatuslabelsController extends Controller public function checkIfDeployable($id) : string { $statuslabel = Statuslabel::findOrFail($id); - if ($statuslabel->getStatuslabelType() == 'deployable') { + if ($statuslabel->status_type == 'deployable') { return '1'; } @@ -319,22 +301,22 @@ class StatuslabelsController extends Controller { $this->authorize('view.selectlists'); - $statuslabels = Statuslabel::orderBy('default_label', 'desc')->orderBy('name', 'asc')->orderBy('deployable', 'desc'); + $statuslabels = Statuslabel::orderBy('default_label', 'desc')->orderBy('name', 'asc')->orderBy('status_type', 'desc'); if ($request->filled('search')) { $statuslabels = $statuslabels->where('name', 'LIKE', '%'.$request->get('search').'%'); } if ($request->filled('deployable')) { - $statuslabels = $statuslabels->where('deployable', '=', '1'); + $statuslabels = $statuslabels->where('status_type', '=', 'deployable'); } if ($request->filled('pending')) { - $statuslabels = $statuslabels->where('pending', '=', '1'); + $statuslabels = $statuslabels->where('status_type', '=', 'pending'); } if ($request->filled('archived')) { - $statuslabels = $statuslabels->where('archived', '=', '1'); + $statuslabels = $statuslabels->where('status_type', '=', 'archived'); } $statuslabels = $statuslabels->orderBy('name', 'ASC')->paginate(50); diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 52eb751a89..edb566c895 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -352,7 +352,7 @@ class AssetsController extends Controller $status = Statuslabel::find($request->input('status_id')); // This is a non-deployable status label - we should check the asset back in. - if (($status && $status->getStatuslabelType() != 'deployable') && ($target = $asset->assignedTo)) { + if (($status && $status->status_type != 'deployable') && ($target = $asset->assignedTo)) { $originalValues = $asset->getRawOriginal(); $asset->assigned_to = null; diff --git a/app/Http/Controllers/StatuslabelsController.php b/app/Http/Controllers/StatuslabelsController.php index 21a7c798b9..c282d94f4e 100755 --- a/app/Http/Controllers/StatuslabelsController.php +++ b/app/Http/Controllers/StatuslabelsController.php @@ -71,9 +71,7 @@ class StatuslabelsController extends Controller $statusLabel->name = $request->input('name'); $statusLabel->created_by = auth()->id(); $statusLabel->notes = $request->input('notes'); - $statusLabel->deployable = $statusType['deployable']; - $statusLabel->pending = $statusType['pending']; - $statusLabel->archived = $statusType['archived']; + $statusLabel->status_type = $request->input('status_type'); $statusLabel->color = $request->input('color'); $statusLabel->show_in_nav = $request->input('show_in_nav', 0); $statusLabel->default_label = $request->input('default_label', 0); @@ -100,7 +98,7 @@ class StatuslabelsController extends Controller return redirect()->route('statuslabels.index')->with('error', trans('admin/statuslabels/message.does_not_exist')); } - $use_statuslabel_type = $item->getStatuslabelType(); + $use_statuslabel_type = $item->status_type; $statuslabel_types = ['' => trans('admin/hardware/form.select_statustype')] + ['undeployable' => trans('admin/hardware/general.undeployable')] + ['pending' => trans('admin/hardware/general.pending')] + ['archived' => trans('admin/hardware/general.archived')] + ['deployable' => trans('admin/hardware/general.deployable')]; diff --git a/app/Http/Transformers/AssetMaintenancesTransformer.php b/app/Http/Transformers/AssetMaintenancesTransformer.php index 81b4a9eabb..7523b11509 100644 --- a/app/Http/Transformers/AssetMaintenancesTransformer.php +++ b/app/Http/Transformers/AssetMaintenancesTransformer.php @@ -39,7 +39,7 @@ class AssetMaintenancesTransformer 'status_label' => ($assetmaintenance->asset->assetstatus) ? [ 'id' => (int) $assetmaintenance->asset->assetstatus->id, 'name'=> e($assetmaintenance->asset->assetstatus->name), - 'status_type'=> e($assetmaintenance->asset->assetstatus->getStatuslabelType()), + 'status_type'=> e($assetmaintenance->asset->assetstatus->status_type), 'status_meta' => e($assetmaintenance->asset->present()->statusMeta), ] : null, 'company' => (($assetmaintenance->asset) && ($assetmaintenance->asset->company)) ? [ diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index d7ee423249..b1405f3db9 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -8,7 +8,6 @@ use App\Models\Setting; use Illuminate\Support\Facades\Gate; use Illuminate\Database\Eloquent\Collection; use Carbon\Carbon; -use Illuminate\Support\Facades\Auth; class AssetsTransformer { @@ -45,8 +44,8 @@ class AssetsTransformer 'status_label' => ($asset->assetstatus) ? [ 'id' => (int) $asset->assetstatus->id, 'name'=> e($asset->assetstatus->name), - 'status_type'=> e($asset->assetstatus->getStatuslabelType()), - 'status_meta' => e($asset->present()->statusMeta), + 'status_type'=> e($asset->assetstatus->status_type), + 'status_meta' => e($asset->assetstatus->status_type), ] : null, 'category' => (($asset->model) && ($asset->model->category)) ? [ 'id' => (int) $asset->model->category->id, diff --git a/app/Http/Transformers/StatuslabelsTransformer.php b/app/Http/Transformers/StatuslabelsTransformer.php index 751edb7016..ea9fa510ce 100644 --- a/app/Http/Transformers/StatuslabelsTransformer.php +++ b/app/Http/Transformers/StatuslabelsTransformer.php @@ -24,7 +24,8 @@ class StatuslabelsTransformer $array = [ 'id' => (int) $statuslabel->id, 'name' => e($statuslabel->name), - 'type' => $statuslabel->getStatuslabelType(), + 'type' => $statuslabel->status_type, // legacy - to be removed in later versions + 'status_type' => $statuslabel->status_type, 'color' => ($statuslabel->color) ? e($statuslabel->color) : null, 'show_in_nav' => ($statuslabel->show_in_nav == '1') ? true : false, 'default_label' => ($statuslabel->default_label == '1') ? true : false, diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index 1112a04e35..97a26781d4 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -18,8 +18,8 @@ class AssetImporter extends ItemImporter $this->defaultStatusLabelId = Statuslabel::first()->id; - if (!is_null(Statuslabel::deployable()->first())) { - $this->defaultStatusLabelId = Statuslabel::deployable()->first()->id; + if (!is_null(Statuslabel::where('status_type', 'deployable')->first())) { + $this->defaultStatusLabelId = Statuslabel::where('status_type', 'deployable')->first()->id; } } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index ce8b870eb2..d2bcbc710b 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1146,9 +1146,7 @@ class Asset extends Depreciable public function scopePending($query) { return $query->whereHas('assetstatus', function ($query) { - $query->where('deployable', '=', 0) - ->where('pending', '=', 1) - ->where('archived', '=', 0); + $query->where('status_label', '=', 'deployable'); }); } @@ -1195,9 +1193,7 @@ class Asset extends Depreciable { return $query->whereNull('assets.assigned_to') ->whereHas('assetstatus', function ($query) { - $query->where('deployable', '=', 1) - ->where('pending', '=', 0) - ->where('archived', '=', 0); + $query->where('status_type', '=', 'deployable'); }); } @@ -1212,9 +1208,7 @@ class Asset extends Depreciable public function scopeUndeployable($query) { return $query->whereHas('assetstatus', function ($query) { - $query->where('deployable', '=', 0) - ->where('pending', '=', 0) - ->where('archived', '=', 0); + $query->whereNot('status_type', 'deployable'); }); } @@ -1229,7 +1223,7 @@ class Asset extends Depreciable public function scopeNotArchived($query) { return $query->whereHas('assetstatus', function ($query) { - $query->where('archived', '=', 0); + $query->whereNot('status_label', 'archived'); }); } @@ -1406,9 +1400,7 @@ class Asset extends Depreciable public function scopeArchived($query) { return $query->whereHas('assetstatus', function ($query) { - $query->where('deployable', '=', 0) - ->where('pending', '=', 0) - ->where('archived', '=', 1); + $query->where('status_type', '=', 'archived'); }); } @@ -1440,9 +1432,8 @@ class Asset extends Depreciable return Company::scopeCompanyables($query->where($table.'.requestable', '=', 1)) ->whereHas('assetstatus', function ($query) { $query->where(function ($query) { - $query->where('deployable', '=', 1) - ->where('archived', '=', 0); // you definitely can't request something that's archived - })->orWhere('pending', '=', 1); // we've decided that even though an asset may be 'pending', you can still request it + $query->whereNot('status_type', 'archived'); // you definitely can't request something that's archived + }); // we've decided that even though an asset may be 'pending', you can still request it }); } diff --git a/app/Models/Location.php b/app/Models/Location.php index 014db3053e..b0cf402d3a 100755 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -138,9 +138,7 @@ class Location extends SnipeModel { return $this->hasMany(\App\Models\Asset::class, 'location_id') ->whereHas('assetstatus', function ($query) { - $query->where('status_labels.deployable', '=', 1) - ->orWhere('status_labels.pending', '=', 1) - ->orWhere('status_labels.archived', '=', 0); + $query->whereNot('status_labels.status_type', '=', 'archived'); }); } diff --git a/app/Models/Statuslabel.php b/app/Models/Statuslabel.php index c1bcc3042d..8be90a521c 100755 --- a/app/Models/Statuslabel.php +++ b/app/Models/Statuslabel.php @@ -23,17 +23,16 @@ class Statuslabel extends SnipeModel protected $rules = [ 'name' => 'required|string|unique_undeleted', 'notes' => 'string|nullable', - 'deployable' => 'required', - 'pending' => 'required', - 'archived' => 'required', + 'status_type' => 'required|in:deployable,pending,archived', ]; protected $fillable = [ - 'archived', - 'deployable', + 'status_type', 'name', 'notes', - 'pending', + 'color', + 'show_in_nav', + 'default_label', ]; use Searchable; @@ -76,54 +75,6 @@ class Statuslabel extends SnipeModel * @since [v1.0] * @return string */ - public function getStatuslabelType() - { - if (($this->pending == '1') && ($this->archived == '0') && ($this->deployable == '0')) { - return 'pending'; - } elseif (($this->pending == '0') && ($this->archived == '1') && ($this->deployable == '0')) { - return 'archived'; - } elseif (($this->pending == '0') && ($this->archived == '0') && ($this->deployable == '0')) { - return 'undeployable'; - } - - return 'deployable'; - } - - /** - * Query builder scope to for pending status types - * - * @return \Illuminate\Database\Query\Builder Modified query builder - */ - public function scopePending() - { - return $this->where('pending', '=', 1) - ->where('archived', '=', 0) - ->where('deployable', '=', 0); - } - - /** - * Query builder scope for archived status types - * - * @return \Illuminate\Database\Query\Builder Modified query builder - */ - public function scopeArchived() - { - return $this->where('pending', '=', 0) - ->where('archived', '=', 1) - ->where('deployable', '=', 0); - } - - /** - * Query builder scope for deployable status types - * - * @return \Illuminate\Database\Query\Builder Modified query builder - */ - public function scopeDeployable() - { - return $this->where('pending', '=', 0) - ->where('archived', '=', 0) - ->where('deployable', '=', 1); - } /** * Query builder scope for undeployable status types @@ -132,40 +83,10 @@ class Statuslabel extends SnipeModel */ public function scopeUndeployable() { - return $this->where('pending', '=', 0) - ->where('archived', '=', 0) - ->where('deployable', '=', 0); + return $this->whereNot('status_type', '=', 'deployable'); } - /** - * Helper function to determine type attributes - * - * @author A. Gianotto - * @since [v1.0] - * @return string - */ - public static function getStatuslabelTypesForDB($type) - { - $statustype['pending'] = 0; - $statustype['deployable'] = 0; - $statustype['archived'] = 0; - if ($type == 'pending') { - $statustype['pending'] = 1; - $statustype['deployable'] = 0; - $statustype['archived'] = 0; - } elseif ($type == 'deployable') { - $statustype['pending'] = 0; - $statustype['deployable'] = 1; - $statustype['archived'] = 0; - } elseif ($type == 'archived') { - $statustype['pending'] = 0; - $statustype['deployable'] = 0; - $statustype['archived'] = 1; - } - - return $statustype; - } public function scopeOrderByCreatedBy($query, $order) { diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.php index 19bd2985e7..fbaa7c9117 100644 --- a/app/Presenters/AssetPresenter.php +++ b/app/Presenters/AssetPresenter.php @@ -479,19 +479,6 @@ class AssetPresenter extends Presenter return $interval; } - /** - * @return string - * This handles the status label "meta" status of "deployed" if - * it's assigned. Should maybe deprecate. - */ - public function statusMeta() - { - if ($this->model->assigned) { - return 'deployed'; - } - - return $this->model->assetstatus->getStatuslabelType(); - } /** * @return string diff --git a/app/Presenters/DepreciationReportPresenter.php b/app/Presenters/DepreciationReportPresenter.php index 1d4c459614..ed295fa4e2 100644 --- a/app/Presenters/DepreciationReportPresenter.php +++ b/app/Presenters/DepreciationReportPresenter.php @@ -311,7 +311,7 @@ class DepreciationReportPresenter extends Presenter if ($this->model->assigned) { return 'deployed'; } - return $this->model->assetstatus->getStatuslabelType(); + return $this->model->assetstatus->status_type; } /** diff --git a/app/Rules/AssetCannotBeCheckedOutToNondeployableStatus.php b/app/Rules/AssetCannotBeCheckedOutToNondeployableStatus.php index c2c451b82b..6c31c0f6fc 100644 --- a/app/Rules/AssetCannotBeCheckedOutToNondeployableStatus.php +++ b/app/Rules/AssetCannotBeCheckedOutToNondeployableStatus.php @@ -40,7 +40,7 @@ class AssetCannotBeCheckedOutToNondeployableStatus implements DataAwareRule, Val // Check to see if any of the assign-ish fields are set if ((isset($this->data['assigned_to'])) || (isset($this->data['assigned_user'])) || (isset($this->data['assigned_location'])) || (isset($this->data['assigned_asset'])) || (isset($this->data['assigned_type']))) { - if (($value) && ($label = Statuslabel::find($value)) && ($label->getStatuslabelType()!='deployable')) { + if (($value) && ($label = Statuslabel::find($value)) && ($label->status_type!='deployable')) { $fail(trans('admin/hardware/form.asset_not_deployable')); } diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index 4d6d20651c..54529983e7 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -34,7 +34,8 @@ class AssetFactory extends Factory 'rtd_location_id' => Location::factory(), 'serial' => $this->faker->uuid(), 'status_id' => function () { - return Statuslabel::where('name', 'Ready to Deploy')->first() ?? Statuslabel::factory()->rtd()->create(['name' => 'Ready to Deploy']); + // $status = Statuslabel::factory()->create(); dd($status) ; + return Statuslabel::where('status_type', 'deployable')->first() ?? Statuslabel::factory()->create(['name' => 'Ready to Deploy', 'status_type' => 'deployable'])->id; }, 'created_by' => User::factory()->superuser(), 'asset_tag' => $this->faker->unixTime('now'), diff --git a/database/factories/StatuslabelFactory.php b/database/factories/StatuslabelFactory.php index 1f04f4564e..49dae110f0 100644 --- a/database/factories/StatuslabelFactory.php +++ b/database/factories/StatuslabelFactory.php @@ -28,9 +28,7 @@ class StatuslabelFactory extends Factory 'updated_at' => $this->faker->dateTime(), 'created_by' => User::factory()->superuser(), 'deleted_at' => null, - 'deployable' => 0, - 'pending' => 0, - 'archived' => 0, + 'status_type' => 'deployable', 'notes' => '', ]; } @@ -40,7 +38,7 @@ class StatuslabelFactory extends Factory return $this->state(function () { return [ 'notes' => $this->faker->sentence(), - 'deployable' => 1, + 'status_type' => 'deployable', 'default_label' => 1, ]; }); @@ -56,7 +54,7 @@ class StatuslabelFactory extends Factory return $this->state(function () { return [ 'notes' => $this->faker->sentence(), - 'pending' => 1, + 'status_type' => 'pending', 'default_label' => 1, ]; }); @@ -67,8 +65,8 @@ class StatuslabelFactory extends Factory return $this->state(function () { return [ 'notes' => 'These assets are permanently undeployable', - 'archived' => 1, 'default_label' => 0, + 'status_type' => 'archived', ]; }); } @@ -79,6 +77,7 @@ class StatuslabelFactory extends Factory return [ 'name' => 'Out for Diagnostics', 'default_label' => 0, + 'status_type' => 'pending', ]; }); } @@ -89,6 +88,7 @@ class StatuslabelFactory extends Factory return [ 'name' => 'Out for Repair', 'default_label' => 0, + 'status_type' => 'pending', ]; }); } @@ -99,6 +99,7 @@ class StatuslabelFactory extends Factory return [ 'name' => 'Broken - Not Fixable', 'default_label' => 0, + 'status_type' => 'archived', ]; }); } @@ -109,6 +110,7 @@ class StatuslabelFactory extends Factory return [ 'name' => 'Lost/Stolen', 'default_label' => 0, + 'status_type' => 'archived', ]; }); } diff --git a/database/migrations/2024_10_24_180042_add_type_to_status_labels.php b/database/migrations/2024_10_24_180042_add_type_to_status_labels.php new file mode 100644 index 0000000000..07953ca3b4 --- /dev/null +++ b/database/migrations/2024_10_24_180042_add_type_to_status_labels.php @@ -0,0 +1,62 @@ +string('status_type')->after('name')->nullable()->default('deployable'); + }); + + DB::table('status_labels')->where('pending', 1)->update(['status_type' => 'pending']); + DB::table('status_labels')->where('archived', 1)->update(['status_type' => 'archived']); + DB::table('status_labels')->where('deployable', 1)->update(['status_type' => 'deployable']); + + Schema::table('status_labels', function (Blueprint $table) { + $table->renameColumn('deployable', 'legacy_deployable'); + }); + + Schema::table('status_labels', function (Blueprint $table) { + $table->renameColumn('pending', 'legacy_pending'); + }); + + Schema::table('status_labels', function (Blueprint $table) { + $table->renameColumn('archived', 'legacy_archived'); + }); + + + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('status_labels', function (Blueprint $table) { + $table->dropColumn('status_type'); + + Schema::table('status_labels', function (Blueprint $table) { + $table->renameColumn('legacy_deployable', 'deployable'); + }); + + Schema::table('status_labels', function (Blueprint $table) { + $table->renameColumn('legacy_pending', 'pending'); + }); + + Schema::table('status_labels', function (Blueprint $table) { + $table->renameColumn('legacy_archived', 'archived'); + }); + + + }); + } +}; diff --git a/database/seeders/StatuslabelSeeder.php b/database/seeders/StatuslabelSeeder.php index be36e7790d..b15294b57b 100755 --- a/database/seeders/StatuslabelSeeder.php +++ b/database/seeders/StatuslabelSeeder.php @@ -17,21 +17,24 @@ class StatuslabelSeeder extends Seeder Statuslabel::factory()->rtd()->create([ 'name' => 'Ready to Deploy', 'created_by' => $admin->id, + 'status_type' => 'deployable', ]); Statuslabel::factory()->pending()->create([ 'name' => 'Pending', 'created_by' => $admin->id, + 'status_type' => 'pending', ]); Statuslabel::factory()->archived()->create([ 'name' => 'Archived', 'created_by' => $admin->id, + 'status_type' => 'archived', ]); - Statuslabel::factory()->outForDiagnostics()->create(['created_by' => $admin->id]); - Statuslabel::factory()->outForRepair()->create(['created_by' => $admin->id]); - Statuslabel::factory()->broken()->create(['created_by' => $admin->id]); - Statuslabel::factory()->lost()->create(['created_by' => $admin->id]); + Statuslabel::factory()->outForDiagnostics()->pending()->create(['created_by' => $admin->id]); + Statuslabel::factory()->outForRepair()->pending()->create(['created_by' => $admin->id]); + Statuslabel::factory()->broken()->archived()->create(['created_by' => $admin->id]); + Statuslabel::factory()->lost()->archived()->create(['created_by' => $admin->id]); } } diff --git a/resources/views/statuslabels/edit.blade.php b/resources/views/statuslabels/edit.blade.php index af69f35de8..a6a44bdbbb 100755 --- a/resources/views/statuslabels/edit.blade.php +++ b/resources/views/statuslabels/edit.blade.php @@ -27,7 +27,7 @@ {{ trans('admin/statuslabels/table.status_type') }}
- {{ Form::select('statuslabel_types', $statuslabel_types, $item->getStatuslabelType(), array('class'=>'select2', 'style'=>'width: 100%; min-width:400px', 'aria-label'=>'statuslabel_types')) }} + {{ Form::select('statuslabel_types', $statuslabel_types, $item->status_type, array('class'=>'select2', 'style'=>'width: 100%; min-width:400px', 'aria-label'=>'statuslabel_types')) }} {!! $errors->first('statuslabel_types', '') !!}
diff --git a/tests/Feature/Assets/Api/AssetIndexTest.php b/tests/Feature/Assets/Api/AssetIndexTest.php index c4a362d28b..9ebcc5701c 100644 --- a/tests/Feature/Assets/Api/AssetIndexTest.php +++ b/tests/Feature/Assets/Api/AssetIndexTest.php @@ -13,9 +13,23 @@ class AssetIndexTest extends TestCase { public function testAssetApiIndexReturnsExpectedAssets() { - Asset::factory()->count(3)->create(); + $this->withoutExceptionHandling(); - $this->actingAsForApi(User::factory()->superuser()->create()) + if ($assets = Asset::factory()->count(3)->make()) { + //dd($assets); + + foreach ($assets as $asset) { + \Log::error($asset->asset_tag); + \Log::error($asset->assetstatus->name); + \Log::error($asset->assetstatus->status_type); + } + } else { + \Log::error('No created'); + } + + + + $response = $this->actingAsForApi(User::factory()->superuser()->create()) ->getJson( route('api.assets.index', [ 'sort' => 'name', @@ -29,6 +43,7 @@ class AssetIndexTest extends TestCase 'rows', ]) ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); + \Log::error($response); } public function testAssetApiIndexReturnsDisplayUpcomingAuditsDue()