Skip to content

A free open source IT asset/license management system

Added setting to choose what appears in model select list - Fixes #4879

snipe60c38a0c47d9
diff --git a/app/Http/Controllers/Api/AssetModelsController.php b/app/Http/Controllers/Api/AssetModelsController.php
index 6d2eeb54e9..a8916af45e 100644
--- a/app/Http/Controllers/Api/AssetModelsController.php
+++ b/app/Http/Controllers/Api/AssetModelsController.php
@@ -194,6 +194,7 @@ class AssetModelsController extends Controller
'models.category_id',
])->with('manufacturer','category');
+ $settings = \App\Models\Setting::getSettings();
if ($request->has('search')) {
$assetmodels = $assetmodels->SearchByManufacturerOrCat($request->input('search'));
@@ -202,8 +203,24 @@ class AssetModelsController extends Controller
$assetmodels = $assetmodels->OrderCategory('ASC')->OrderManufacturer('ASC')->orderby('models.name', 'asc')->orderby('models.model_number', 'asc')->paginate(50);
foreach ($assetmodels as $assetmodel) {
- $assetmodel->use_text = (($assetmodel->category) ? e($assetmodel->category->name) : '').': '.$assetmodel->present()->modelName;
- $assetmodel->use_image = ($assetmodel->image) ? url('/').'/uploads/models/'.$assetmodel->image : null;
+
+ $assetmodel->use_text = '';
+
+ if ($settings->modellistCheckedValue('category')) {
+ $assetmodel->use_text .= (($assetmodel->category) ? e($assetmodel->category->name).' - ' : '');
+ }
+
+ if ($settings->modellistCheckedValue('manufacturer')) {
+ $assetmodel->use_text .= (($assetmodel->manufacturer) ? e($assetmodel->manufacturer->name).' ' : '');
+ }
+
+ $assetmodel->use_text .= e($assetmodel->name);
+
+ if (($settings->modellistCheckedValue('model_number')) && ($assetmodel->model_number!='')) {
+ $assetmodel->use_text .= ' (#'.e($assetmodel->model_number).')';
+ }
+
+ $assetmodel->use_image = ($settings->modellistCheckedValue('image') && ($assetmodel->image)) ? url('/').'/uploads/models/'.$assetmodel->image : null;
}
return (new SelectlistTransformer)->transformSelectlist($assetmodels);
diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php
index a5f50e5bd8..d9caa63bc8 100755
--- a/app/Http/Controllers/SettingsController.php
+++ b/app/Http/Controllers/SettingsController.php
@@ -314,6 +314,14 @@ class SettingsController extends Controller
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
}
+ $setting->modellist_displays = '';
+
+ if (($request->has('show_in_model_list')) && (count($request->has('show_in_model_list')) > 0))
+ {
+ $setting->modellist_displays = implode(',', $request->input('show_in_model_list'));
+ }
+
+
$setting->full_multiple_companies_support = $request->input('full_multiple_companies_support', '0');
$setting->load_remote = $request->input('load_remote', '0');
$setting->show_archived_in_list = $request->input('show_archived_in_list', '0');
diff --git a/app/Models/Setting.php b/app/Models/Setting.php
index a745234b7a..7c824b9e62 100755
--- a/app/Models/Setting.php
+++ b/app/Models/Setting.php
@@ -86,6 +86,23 @@ class Setting extends Model
return null;
}
+ public function modellistCheckedValue ($element) {
+
+ // If the value is blank for some reason
+ if ($this->modellist_displays=='') {
+ return false;
+ }
+ $values = explode(',', $this->modellist_displays);
+
+ foreach ($values as $value) {
+ if ($value == $element) {
+ return true;
+ }
+ }
+ return false;
+
+ }
+
/**
* Escapes the custom CSS, and then un-escapes the greater-than symbol
* so it can work with direct descendant characters for bootstrap
diff --git a/database/migrations/2018_01_24_093426_add_modellist_preferenc.php b/database/migrations/2018_01_24_093426_add_modellist_preferenc.php
new file mode 100644
index 0000000000..d9974a2d83
--- /dev/null
+++ b/database/migrations/2018_01_24_093426_add_modellist_preferenc.php
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddModellistPreferenc extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('settings', function (Blueprint $table) {
+ $table->char('modellist_displays')->nullable()->default('image,category,manufacturer,model_number');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('settings', function (Blueprint $table) {
+ $table->dropColumn('modellist_displays');
+ });
+ }
+}
diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php
index 012cedb08a..c717910dd1 100644
--- a/resources/lang/en/admin/settings/general.php
+++ b/resources/lang/en/admin/settings/general.php
@@ -81,6 +81,7 @@ return array(
'logo' => 'Logo',
'full_multiple_companies_support_help_text' => 'Restricting users (including admins) assigned to companies to their company\'s assets.',
'full_multiple_companies_support_text' => 'Full Multiple Companies Support',
+ 'show_in_model_list' => 'Show in Model Dropdowns',
'optional' => 'optional',
'per_page' => 'Results Per Page',
'php' => 'PHP Version',
diff --git a/resources/views/settings/general.blade.php b/resources/views/settings/general.blade.php
index e547383ccb..eff72b3c2f 100644
--- a/resources/views/settings/general.blade.php
+++ b/resources/views/settings/general.blade.php
@@ -237,6 +237,21 @@
</div>
</div>
+ <!-- Model List prefs -->
+ <div class="form-group {{ $errors->has('show_in_model_list') ? 'error' : '' }}">
+ <div class="col-md-3">
+ {{ Form::label('show_in_model_list',
+ trans('admin/settings/general.show_in_model_list')) }}
+ </div>
+ <div class="col-md-9">
+ {{ Form::checkbox('show_in_model_list[]', 'image', Input::old('show_in_model_list', $snipeSettings->modellistCheckedValue('image')),array('class' => 'minimal')) }} {{ trans('general.image') }} <br>
+ {{ Form::checkbox('show_in_model_list[]', 'category', Input::old('show_in_model_list', $snipeSettings->modellistCheckedValue('category')),array('class' => 'minimal')) }} {{ trans('general.category') }} <br>
+ {{ Form::checkbox('show_in_model_list[]', 'manufacturer', Input::old('show_in_model_list', $snipeSettings->modellistCheckedValue('manufacturer')),array('class' => 'minimal')) }} {{ trans('general.manufacturer') }} <br>
+ {{ Form::checkbox('show_in_model_list[]', 'model_number', Input::old('show_in_model_list', $snipeSettings->modellistCheckedValue('model_number')),array('class' => 'minimal')) }} {{ trans('general.model_no') }}<br>
+ </div>
+ </div>
+ <!-- /.form-group -->
+
</div> <!--/.box-body-->
<div class="box-footer">
<div class="text-left col-md-6">