From 95d136284d46196e22c98f336a7877507d23fe5b Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 28 Oct 2024 22:02:48 +0000 Subject: [PATCH] Few more fixes Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 14 +++--- .../Api/StatuslabelsController.php | 3 +- app/Http/Controllers/ModalController.php | 2 +- .../Controllers/StatuslabelsController.php | 23 ++-------- app/Models/Asset.php | 12 ++--- app/Presenters/StatusLabelPresenter.php | 6 +-- ...10_24_180042_add_type_to_status_labels.php | 45 +++++++++++-------- database/seeders/SettingsSeeder.php | 1 + database/seeders/StatuslabelSeeder.php | 3 ++ resources/views/statuslabels/edit.blade.php | 6 +-- 10 files changed, 56 insertions(+), 59 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 67b32d053a..d1f6feaa86 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -61,7 +61,7 @@ class AssetsController extends Controller if ($action == 'audit') { $action = 'audits'; } - $filter_non_deprecable_assets = false; + $filter_non_depreciable_assets = false; /** * This looks MAD janky (and it is), but the AssetsController@index does a LOT of heavy lifting throughout the @@ -75,7 +75,7 @@ class AssetsController extends Controller * which would have been far worse of a mess. *sad face* - snipe (Sept 1, 2021) */ if (Route::currentRouteName()=='api.depreciation-report.index') { - $filter_non_deprecable_assets = true; + $filter_non_depreciable_assets = true; $transformer = 'App\Http\Transformers\DepreciationReportTransformer'; $this->authorize('reports.view'); } else { @@ -130,9 +130,9 @@ class AssetsController extends Controller 'model.category', 'model.manufacturer', 'model.fieldset','supplier'); //it might be tempting to add 'assetlog' here, but don't. It blows up update-heavy users. - if ($filter_non_deprecable_assets) { - $non_deprecable_models = AssetModel::select('id')->whereNotNull('depreciation_id')->get(); - $assets->InModelList($non_deprecable_models->toArray()); + if ($filter_non_depreciable_assets) { + $non_depreciable_models = AssetModel::select('id')->whereNotNull('depreciation_id')->get(); + $assets->InModelList($non_depreciable_models->toArray()); } @@ -231,7 +231,6 @@ class AssetsController extends Controller $join->on('status_alias.id', '=', 'assets.status_id') ->where('status_alias.status_type', '=', 'deployable'); }); - break; case 'Deployed': // more sad, horrible workarounds for laravel bugs when doing full text searches @@ -248,7 +247,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.status_type', '=', 'archived'); + ->where('status_alias.status_type', '!=', 'archived'); }); // If there is a status ID, don't take show_archived_in_list into consideration @@ -257,6 +256,7 @@ class AssetsController extends Controller $join->on('status_alias.id', '=', 'assets.status_id'); }); } + break; } diff --git a/app/Http/Controllers/Api/StatuslabelsController.php b/app/Http/Controllers/Api/StatuslabelsController.php index 4e521ae9a4..f1c7315c30 100644 --- a/app/Http/Controllers/Api/StatuslabelsController.php +++ b/app/Http/Controllers/Api/StatuslabelsController.php @@ -32,7 +32,8 @@ class StatuslabelsController extends Controller 'assets_count', 'color', 'notes', - 'default_label' + 'default_label', + 'status_type', ]; $statuslabels = Statuslabel::with('adminuser')->withCount('assets as assets_count'); diff --git a/app/Http/Controllers/ModalController.php b/app/Http/Controllers/ModalController.php index fab491a5f4..0a9ae7d1ca 100644 --- a/app/Http/Controllers/ModalController.php +++ b/app/Http/Controllers/ModalController.php @@ -40,7 +40,7 @@ class ModalController extends Controller $view = view("modals.${type}"); if ($type == "statuslabel") { - $view->with('statuslabel_types', Helper::statusTypeList()); + $view->with('status_types', Helper::statusTypeList()); } if (in_array($type, ['kit-model', 'kit-license', 'kit-consumable', 'kit-accessory'])) { $view->with('kitId', $itemId); diff --git a/app/Http/Controllers/StatuslabelsController.php b/app/Http/Controllers/StatuslabelsController.php index c282d94f4e..c4ab1907d8 100755 --- a/app/Http/Controllers/StatuslabelsController.php +++ b/app/Http/Controllers/StatuslabelsController.php @@ -47,7 +47,7 @@ class StatuslabelsController extends Controller return view('statuslabels/edit') ->with('item', new Statuslabel) - ->with('statuslabel_types', Helper::statusTypeList()); + ->with('status_types', Helper::statusTypeList()); } /** @@ -61,12 +61,6 @@ class StatuslabelsController extends Controller // create a new model instance $statusLabel = new Statuslabel(); - if ($request->missing('statuslabel_types')) { - return redirect()->back()->withInput()->withErrors(['statuslabel_types' => trans('validation.statuslabel_type')]); - } - - $statusType = Statuslabel::getStatuslabelTypesForDB($request->input('statuslabel_types')); - // Save the Statuslabel data $statusLabel->name = $request->input('name'); $statusLabel->created_by = auth()->id(); @@ -98,11 +92,7 @@ class StatuslabelsController extends Controller return redirect()->route('statuslabels.index')->with('error', trans('admin/statuslabels/message.does_not_exist')); } - $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')]; - - return view('statuslabels/edit', compact('item', 'statuslabel_types'))->with('use_statuslabel_type', $use_statuslabel_type); + return view('statuslabels/edit', compact('item'))->with('status_types', Helper::statusTypeList());; } /** @@ -119,17 +109,10 @@ class StatuslabelsController extends Controller return redirect()->route('statuslabels.index')->with('error', trans('admin/statuslabels/message.does_not_exist')); } - if (! $request->filled('statuslabel_types')) { - return redirect()->back()->withInput()->withErrors(['statuslabel_types' => trans('validation.statuslabel_type')]); - } - // Update the Statuslabel data - $statustype = Statuslabel::getStatuslabelTypesForDB($request->input('statuslabel_types')); $statuslabel->name = $request->input('name'); $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); diff --git a/app/Models/Asset.php b/app/Models/Asset.php index d2bcbc710b..d151b0760e 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -301,9 +301,9 @@ class Asset extends Depreciable // This asset is not currently assigned to anyone and is not deleted... if ((! $this->assigned_to) && (! $this->deleted_at)) { - // The asset status is not archived and is deployable - if (($this->assetstatus) && ($this->assetstatus->archived == '0') - && ($this->assetstatus->deployable == '1')) + // The asset is not archived and the status is deployable + if (($this->assetstatus) && ($this->archived == '0') + && ($this->assetstatus->status_type == 'deployable')) { return true; @@ -1208,7 +1208,7 @@ class Asset extends Depreciable public function scopeUndeployable($query) { return $query->whereHas('assetstatus', function ($query) { - $query->whereNot('status_type', 'deployable'); + $query->where('status_type', '!=', 'deployable'); }); } @@ -1223,7 +1223,7 @@ class Asset extends Depreciable public function scopeNotArchived($query) { return $query->whereHas('assetstatus', function ($query) { - $query->whereNot('status_label', 'archived'); + $query->where('status_label', '!=', 'archived'); }); } @@ -1432,7 +1432,7 @@ class Asset extends Depreciable return Company::scopeCompanyables($query->where($table.'.requestable', '=', 1)) ->whereHas('assetstatus', function ($query) { $query->where(function ($query) { - $query->whereNot('status_type', 'archived'); // you definitely can't request something that's archived + $query->where('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/Presenters/StatusLabelPresenter.php b/app/Presenters/StatusLabelPresenter.php index 2e43400041..fef8d9f28a 100644 --- a/app/Presenters/StatusLabelPresenter.php +++ b/app/Presenters/StatusLabelPresenter.php @@ -30,9 +30,9 @@ class StatusLabelPresenter extends Presenter 'visible' => true, 'formatter' => 'statuslabelsAssetLinkFormatter', ],[ - 'field' => 'type', - 'searchable' => false, - 'sortable' => false, + 'field' => 'status_type', + 'searchable' => true, + 'sortable' => true, 'switchable' => false, 'title' => trans('admin/statuslabels/table.status_type'), 'visible' => true, 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 index 07953ca3b4..17ed155807 100644 --- 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 @@ -13,25 +13,30 @@ return new class extends Migration */ public function up(): void { - Schema::table('status_labels', function (Blueprint $table) { - $table->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']); + if (!Schema::hasColumn('status_labels', 'status_type')) { - Schema::table('status_labels', function (Blueprint $table) { - $table->renameColumn('deployable', 'legacy_deployable'); - }); + Schema::table('status_labels', function (Blueprint $table) { + $table->string('status_type')->after('name')->default('deployable'); + }); - Schema::table('status_labels', function (Blueprint $table) { - $table->renameColumn('pending', 'legacy_pending'); - }); + 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'); + }); + } - Schema::table('status_labels', function (Blueprint $table) { - $table->renameColumn('archived', 'legacy_archived'); - }); } @@ -41,8 +46,12 @@ return new class extends Migration */ public function down(): void { - Schema::table('status_labels', function (Blueprint $table) { - $table->dropColumn('status_type'); + + if (Schema::hasColumn('status_labels', 'status_type')) { + + Schema::table('status_labels', function (Blueprint $table) { + $table->dropColumn('status_type'); + }); Schema::table('status_labels', function (Blueprint $table) { $table->renameColumn('legacy_deployable', 'deployable'); @@ -55,8 +64,8 @@ return new class extends Migration Schema::table('status_labels', function (Blueprint $table) { $table->renameColumn('legacy_archived', 'archived'); }); + } - }); } }; diff --git a/database/seeders/SettingsSeeder.php b/database/seeders/SettingsSeeder.php index b913caf6a4..b335c58777 100644 --- a/database/seeders/SettingsSeeder.php +++ b/database/seeders/SettingsSeeder.php @@ -37,6 +37,7 @@ class SettingsSeeder extends Seeder $settings->support_footer = 'on'; $settings->pwd_secure_min = '8'; $settings->default_avatar = 'default.png'; + $settings->show_archived_in_list = 0; $settings->save(); if ($user = User::where('username', '=', 'admin')->first()) { diff --git a/database/seeders/StatuslabelSeeder.php b/database/seeders/StatuslabelSeeder.php index b15294b57b..575fad4340 100755 --- a/database/seeders/StatuslabelSeeder.php +++ b/database/seeders/StatuslabelSeeder.php @@ -18,18 +18,21 @@ class StatuslabelSeeder extends Seeder 'name' => 'Ready to Deploy', 'created_by' => $admin->id, 'status_type' => 'deployable', + 'legacy_deployable' => 1, ]); Statuslabel::factory()->pending()->create([ 'name' => 'Pending', 'created_by' => $admin->id, 'status_type' => 'pending', + 'legacy_pending' => 1, ]); Statuslabel::factory()->archived()->create([ 'name' => 'Archived', 'created_by' => $admin->id, 'status_type' => 'archived', + 'legacy_archived' => 1, ]); Statuslabel::factory()->outForDiagnostics()->pending()->create(['created_by' => $admin->id]); diff --git a/resources/views/statuslabels/edit.blade.php b/resources/views/statuslabels/edit.blade.php index a6a44bdbbb..f51bd53cfa 100755 --- a/resources/views/statuslabels/edit.blade.php +++ b/resources/views/statuslabels/edit.blade.php @@ -22,13 +22,13 @@ @include ('partials.forms.edit.name', ['translated_name' => trans('general.name')]) -
+
- {{ 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', '') !!} + {{ Form::select('status_type', $status_types, $item->status_type, array('class'=>'select2', 'style'=>'width: 100%; min-width:400px', 'aria-label'=>'status_type')) }} + {!! $errors->first('status_type', '') !!}