Fixes #3311 - more fields for manufacturers

This commit is contained in:
snipe 2017-03-10 22:08:59 -08:00
parent 1682867d02
commit c132036f5c
13 changed files with 353 additions and 42 deletions

View file

@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
use App\Helpers\Helper;
use App\Models\Manufacturer;
use App\Http\Transformers\DatatablesTransformer;
use App\Http\Transformers\ManufacturersTransformer;
class ManufacturersController extends Controller
{
@ -20,10 +21,10 @@ class ManufacturersController extends Controller
public function index(Request $request)
{
$this->authorize('view', Manufacturer::class);
$allowed_columns = ['id','name'];
$allowed_columns = ['id','name','url','support_url','support_email','support_phone','created_at','updated_at'];
$manufacturers = Manufacturer::select(
array('id','name')
array('id','name','url','support_url','support_email','support_phone','created_at','updated_at')
)->withCount('assets')->withCount('licenses')->withCount('consumables')->withCount('accessories');
@ -39,8 +40,7 @@ class ManufacturersController extends Controller
$total = $manufacturers->count();
$manufacturers = $manufacturers->skip($offset)->take($limit)->get();
return (new DatatablesTransformer)->transformDatatables($manufacturers, $total);
return $manufacturers;
return (new ManufacturersTransformer)->transformManufacturers($manufacturers, $total);
}

View file

@ -27,13 +27,12 @@ class ManufacturersController extends Controller
* the content for the manufacturers listing, which is generated in getDatatable.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @see ManufacturersController::getDatatable() method that generates the JSON response
* @see Api\ManufacturersController::index() method that generates the JSON response
* @since [v1.0]
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
// Show the page
return View::make('manufacturers/index', compact('manufacturers'));
}
@ -42,7 +41,7 @@ class ManufacturersController extends Controller
* Returns a view that displays a form to create a new manufacturer.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @see ManufacturersController::postCreate()
* @see ManufacturersController::store()
* @since [v1.0]
* @return \Illuminate\Contracts\View\View
*/
@ -56,16 +55,23 @@ class ManufacturersController extends Controller
* Validates and stores the data for a new manufacturer.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @see ManufacturersController::postCreate()
* @see ManufacturersController::create()
* @since [v1.0]
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(Request $request)
{
$manufacturer = new Manufacturer;
$manufacturer->name = $request->input('name');
$manufacturer->user_id = Auth::id();
$manufacturer->user_id = Auth::user()->id;
$manufacturer->url = $request->input('url');
$manufacturer->support_url = $request->input('support_url');
$manufacturer->support_phone = $request->input('support_phone');
$manufacturer->support_email = $request->input('support_email');
if ($manufacturer->save()) {
return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.create.success'));
@ -77,16 +83,15 @@ class ManufacturersController extends Controller
* Returns a view that displays a form to edit a manufacturer.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @see ManufacturersController::postEdit()
* @see ManufacturersController::update()
* @param int $manufacturerId
* @since [v1.0]
* @return \Illuminate\Contracts\View\View
*/
public function edit($manufacturerId = null)
public function edit($id = null)
{
// Check if the manufacturer exists
if (is_null($item = Manufacturer::find($manufacturerId))) {
// Redirect to the manufacturer page
if (is_null($item = Manufacturer::find($id))) {
return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.does_not_exist'));
}
// Show the page
@ -114,9 +119,12 @@ class ManufacturersController extends Controller
// Save the data
$manufacturer->name = $request->input('name');
// Was it created?
$manufacturer->url = $request->input('url');
$manufacturer->support_url = $request->input('support_url');
$manufacturer->support_phone = $request->input('support_phone');
$manufacturer->support_email = $request->input('support_email');
if ($manufacturer->save()) {
// Redirect to the new manufacturer page
return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.update.success'));
}
return redirect()->back()->withInput()->withErrors($manufacturer->getErrors());

View file

@ -0,0 +1,55 @@
<?php
namespace App\Http\Transformers;
use App\Models\Manufacturer;
use Illuminate\Database\Eloquent\Collection;
use Gate;
use App\Helpers\Helper;
class ManufacturersTransformer
{
public function transformManufacturers (Collection $manufacturers, $total)
{
$array = array();
foreach ($manufacturers as $manufacturer) {
$array[] = self::transformManufacturer($manufacturer);
}
return (new DatatablesTransformer)->transformDatatables($array, $total);
}
public function transformManufacturer (Manufacturer $manufacturer = null)
{
if ($manufacturer) {
$array = [
'id' => e($manufacturer->id),
'name' => e($manufacturer->name),
'url' => e($manufacturer->url),
'support_url' => e($manufacturer->support_url),
'support_phone' => e($manufacturer->support_phone),
'support_email' => e($manufacturer->support_email),
'assets_count' => e($manufacturer->assets_count),
'licenses_count' => e($manufacturer->licenses_count),
'consumables_count' => e($manufacturer->consumables_count),
'accessories_count' => e($manufacturer->accessories_count),
'created_at' => Helper::getFormattedDateObject($manufacturer->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($manufacturer->updated_at, 'datetime'),
];
$permissions_array['available_actions'] = [
'update' => Gate::allows('update', Manufacturer::class) ? true : false,
'delete' => Gate::allows('delete', Manufacturer::class) ? true : false,
];
$array += $permissions_array;
return $array;
}
}
}

View file

@ -16,7 +16,9 @@ class Manufacturer extends SnipeModel
// Declare the rules for the form validation
protected $rules = array(
'name' => 'required|min:2|max:255|unique:manufacturers,name,NULL,deleted_at',
'user_id' => 'integer',
'url' => 'url|nullable',
'support_url' => 'url|nullable',
'support_email' => 'email|nullable'
);
protected $hidden = ['user_id','deleted_at'];
@ -38,7 +40,7 @@ class Manufacturer extends SnipeModel
*
* @var array
*/
protected $fillable = ['name'];
protected $fillable = ['name','url','support_url','support_phone','support_email'];

View file

@ -11,6 +11,130 @@ use App\Helpers\Helper;
class ManufacturerPresenter extends Presenter
{
/**
* Json Column Layout for bootstrap table
* @return string
*/
public static function dataTableLayout()
{
$layout = [
[
"field" => "id",
"searchable" => false,
"sortable" => true,
"switchable" => true,
"title" => trans('general.id'),
"visible" => false
],
[
"field" => "name",
"searchable" => true,
"sortable" => true,
"title" => trans('admin/manufacturers/table.name'),
"visible" => true,
"formatter" => "manufacturersLinkFormatter"
],
[
"field" => "url",
"searchable" => true,
"sortable" => true,
"switchable" => true,
"title" => trans('admin/manufacturers/table.url'),
"visible" => true,
"formatter" => "linkFormatter"
],
[
"field" => "support_url",
"searchable" => true,
"sortable" => true,
"switchable" => true,
"title" => trans('admin/manufacturers/table.support_url'),
"visible" => true,
"formatter" => "linkFormatter"
],
[
"field" => "support_phone",
"searchable" => true,
"sortable" => true,
"switchable" => true,
"title" => trans('admin/manufacturers/table.support_phone'),
"visible" => true
],
[
"field" => "support_email",
"searchable" => true,
"sortable" => true,
"switchable" => true,
"title" => trans('admin/manufacturers/table.support_email'),
"visible" => true,
"formatter" => "emailFormatter"
],
[
"field" => "assets_count",
"searchable" => false,
"sortable" => false,
"switchable" => true,
"title" => ' <span class="hidden-md hidden-lg">Assets</span>'
.'<span class="hidden-xs"><i class="fa fa-barcode fa-lg"></i></span>',
"visible" => true,
],
[
"field" => "licenses_count",
"searchable" => false,
"sortable" => false,
"switchable" => true,
"title" => ' <span class="hidden-md hidden-lg">Licenses</span>'
.'<span class="hidden-xs"><i class="fa fa-floppy-o fa-lg"></i></span>',
"visible" => true,
],
[
"field" => "consumables_count",
"searchable" => false,
"sortable" => false,
"switchable" => true,
"title" => ' <span class="hidden-md hidden-lg">Consumables</span>'
.'<span class="hidden-xs"><i class="fa fa-tint fa-lg"></i></span>',
"visible" => true,
],
[
"field" => "accessories_count",
"searchable" => false,
"sortable" => false,
"switchable" => true,
"title" => ' <span class="hidden-md hidden-lg">Accessories</span>'
.'<span class="hidden-xs"><i class="fa fa-keyboard-o fa-lg"></i></span>',
"visible" => true,
],
[
"field" => "created_at",
"searchable" => true,
"sortable" => true,
"switchable" => true,
"title" => trans('general.created_at'),
"visible" => false,
'formatter' => 'dateDisplayFormatter'
],
[
"field" => "actions",
"searchable" => false,
"sortable" => false,
"switchable" => false,
"title" => trans('table.actions'),
"visible" => true,
"formatter" => "manufacturersActionsFormatter",
]
];
return json_encode($layout);
}
/**
* Link to this manufacturers name

View file

@ -0,0 +1,38 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddFieldsToManufacturer extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('manufacturers', function (Blueprint $table) {
$table->string('url')->nullable()->default(null);
$table->string('support_url')->nullable()->default(null);
$table->string('support_phone')->nullable()->default(null);
$table->string('support_email')->nullable()->default(null);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('settings', function ($table) {
$table->dropColumn('url');
$table->dropColumn('support_url');
$table->dropColumn('support_phone');
$table->dropColumn('support_email');
});
}
}

View file

@ -2,11 +2,15 @@
return array(
'about_manufacturers_title' => 'About manufacturers',
'about_manufacturers_text' => 'Manufacturers make all the magic items we consume.',
'about_manufacturers_text' => 'Manufacturers are the companies that create your assets. You can store important support contact information about them here, which will be displayed on your asset detail pages.',
'asset_manufacturers' => 'Asset Manufacturers',
'create' => 'Create Manufacturer',
'id' => 'ID',
'name' => 'Manufacturer Name',
'name' => 'Name',
'support_email' => 'Support Email',
'support_phone' => 'Support Phone',
'support_url' => 'Support URL',
'update' => 'Update Manufacturer',
'url' => 'URL',
);

View file

@ -105,20 +105,37 @@
<tr>
<td>{{ trans('admin/hardware/form.manufacturer') }}</td>
<td>
@can('superuser')
@can('view', \App\Models\Manufacturer::class)
<a href="{{ route('manufacturers.show', $asset->model->manufacturer->id) }}">
{{ $asset->model->manufacturer->name }}
</a>
@else
{{ $asset->model->manufacturer->name }}
@endcan
@if ($asset->model->manufacturer->url)
<br><i class="fa fa-globe"></i> <a href="{{ $asset->model->manufacturer->url }}">{{ $asset->model->manufacturer->url }}</a>
@endif
@if ($asset->model->manufacturer->support_url)
<br><i class="fa fa-life-ring"></i> <a href="{{ $asset->model->manufacturer->support_url }}">{{ $asset->model->manufacturer->support_url }}</a>
@endif
@if ($asset->model->manufacturer->support_phone)
<br><i class="fa fa-phone"></i> {{ $asset->model->manufacturer->support_phone }}
@endif
@if ($asset->model->manufacturer->support_email)
<br><i class="fa fa-envelope"></i> <a href="mailto:{{ $asset->model->manufacturer->support_email }}">{{ $asset->model->manufacturer->support_email }}</a>
@endif
</td>
</tr>
@endif
<tr>
<td>
{{ trans('admin/hardware/form.model') }}</td>
<td>
@can('superuser')
@can('view', \App\Models\AssetModel::class)
<a href="{{ route('models.show', $asset->model->id) }}">
{{ $asset->model->name }}
</a>
@ -133,7 +150,7 @@
{{ $asset->model->model_number }}
</td>
</tr>
@endif
@if ($asset->model->fieldset)
@foreach($asset->model->fieldset->fields as $field)

View file

@ -122,10 +122,34 @@
</tr>
@endif
@if (!is_null($license->manufacturer))
@if ($license->manufacturer)
<tr>
<td>{{ trans('general.manufacturer') }}</td>
<td>{{ $license->manufacturer->name }}</td>
<td>{{ trans('admin/hardware/form.manufacturer') }}</td>
<td>
@can('view', \App\Models\Manufacturer::class)
<a href="{{ route('manufacturers.show', $license->manufacturer->id) }}">
{{ $license->manufacturer->name }}
</a>
@else
{{ $license->manufacturer->name }}
@endcan
@if ($license->manufacturer->url)
<br><i class="fa fa-globe"></i> <a href="{{ $license->manufacturer->url }}">{{ $license->manufacturer->url }}</a>
@endif
@if ($license->manufacturer->support_url)
<br><i class="fa fa-life-ring"></i> <a href="{{ $license->manufacturer->support_url }}">{{ $license->manufacturer->support_url }}</a>
@endif
@if ($license->manufacturer->support_phone)
<br><i class="fa fa-phone"></i> {{ $license->manufacturer->support_phone }}
@endif
@if ($license->manufacturer->support_email)
<br><i class="fa fa-envelope"></i> <a href="mailto:{{ $license->manufacturer->support_email }}">{{ $license->manufacturer->support_email }}</a>
@endif
</td>
</tr>
@endif

View file

@ -10,4 +10,44 @@
{{-- Page content --}}
@section('inputFields')
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/manufacturers/table.name')])
<!-- URL -->
<div class="form-group {{ $errors->has('url') ? ' has-error' : '' }}">
<label for="url" class="col-md-3 control-label">{{ trans('admin/manufacturers/table.url') }}
</label>
<div class="col-md-6">
<input class="form-control" type="text" name="url" id="url" value="{{ Input::old('url', $item->url) }}" />
{!! $errors->first('url', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>
<!-- Support URL -->
<div class="form-group {{ $errors->has('support_url') ? ' has-error' : '' }}">
<label for="support_url" class="col-md-3 control-label">{{ trans('admin/manufacturers/table.support_url') }}
</label>
<div class="col-md-6">
<input class="form-control" type="text" name="support_url" id="support_url" value="{{ Input::old('support_url', $item->support_url) }}" />
{!! $errors->first('support_url', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>
<!-- Support Phone -->
<div class="form-group {{ $errors->has('support_phone') ? ' has-error' : '' }}">
<label for="support_phone" class="col-md-3 control-label">{{ trans('admin/manufacturers/table.support_phone') }}
</label>
<div class="col-md-6">
<input class="form-control" type="text" name="support_phone" id="support_phone" value="{{ Input::old('support_phone', $item->support_phone) }}" />
{!! $errors->first('support_phone', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>
<!-- Support Email -->
<div class="form-group {{ $errors->has('support_email') ? ' has-error' : '' }}">
<label for="support_email" class="col-md-3 control-label">{{ trans('admin/manufacturers/table.support_email') }}
</label>
<div class="col-md-6">
<input class="form-control" type="email" name="support_email" id="support_email" value="{{ Input::old('support_email', $item->support_email) }}" />
{!! $errors->first('support_email', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>
@stop

View file

@ -28,18 +28,7 @@
data-cookie="true"
data-click-to-select="true"
data-cookie-id-table="manufacturersTable-{{ config('version.hash_version') }}">
<thead>
<tr>
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
<th data-sortable="true" data-field="name" data-formatter="manufacturersLinkFormatter">
{{ trans('admin/manufacturers/table.name') }}</th>
<th data-switchable="true" data-searchable="false" data-sortable="false" data-field="assets_count">{{ trans('general.assets') }}</th>
<th data-switchable="true" data-searchable="false" data-sortable="false" data-field="licenses_count">{{ trans('general.licenses') }}</th>
<th data-switchable="true" data-searchable="false" data-sortable="false" data-field="accessories_count">{{ trans('general.accessories') }}</th>
<th data-switchable="true" data-searchable="false" data-sortable="false" data-field="consumables_count">{{ trans('general.consumables') }}</th>
<th data-formatter="manufacturersActionsFormatter" data-switchable="false" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th>
</tr>
</thead>
</table>
</div>
</div><!-- /.box-body -->
@ -50,5 +39,9 @@
@stop
@section('moar_scripts')
@include ('partials.bootstrap-table', ['exportFile' => 'manufacturers-export', 'search' => true])
@include ('partials.bootstrap-table',
['exportFile' => 'manufacturers-export',
'search' => true,
'columns' => \App\Presenters\ManufacturerPresenter::dataTableLayout()
])
@stop

View file

@ -63,7 +63,7 @@
<th data-searchable="false" data-sortable="false" data-field="model" data-formatter="modelsLinkObjFormatter">{{ trans('admin/hardware/form.model') }}</th>
<th data-searchable="false" data-sortable="false" data-field="asset_tag" data-formatter="hardwareLinkFormatter">{{ trans('general.asset_tag') }}</th>
<th data-searchable="false" data-sortable="false" data-field="serial" data-formatter="hardwareLinkFormatter">{{ trans('admin/hardware/form.serial') }}</th>
<th data-searchable="false" data-sortable="false" data-field="assigned_to" data-formatter="usersLinkFormatter">{{ trans('general.user') }}</th>
<th data-searchable="false" data-sortable="false" data-field="assigned_to" data-formatter="usersLinkObjFormatter">{{ trans('general.user') }}</th>
<th data-searchable="false" data-sortable="false" data-field="change" data-switchable="false">{{ trans('admin/hardware/table.change') }}</th>
<th data-searchable="false" data-sortable="false" data-field="actions" data-switchable="false">{{ trans('table.actions') }}</th>
</tr>

View file

@ -217,6 +217,12 @@ $('.snipe-table').bootstrapTable({
}
}
function linkFormatter(value, row) {
if (value) {
return '<a href="' + value + '"> ' + value + '</a>';
}
}
function assetCompanyFilterFormatter(value, row) {
if (value) {
return '<a href="{{ url('/') }}/hardware/?company_id=' + row.id + '"> ' + value + '</a>';