Skip to content

Commit

Permalink
Fixes #509 - added MAC address as model option
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Feb 12, 2015
1 parent 89dce89 commit fbf03b2
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 16 deletions.
5 changes: 3 additions & 2 deletions app/controllers/admin/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function postCreate()
$asset->order_number = e(Input::get('order_number'));
$asset->notes = e(Input::get('notes'));
$asset->asset_tag = e(Input::get('asset_tag'));

$asset->mac_address = e(Input::get('mac_address'));
$asset->user_id = Sentry::getId();
$asset->archived = '0';
$asset->physical = '1';
Expand Down Expand Up @@ -322,10 +322,11 @@ public function postEdit($assetId = null)
$asset->name = e(Input::get('name'));
$asset->serial = e(Input::get('serial'));
$asset->model_id = e(Input::get('model_id'));
$asset->order_number = e(Input::get('order_number'));
$asset->order_number = e(Input::get('order_number'));
$asset->asset_tag = e(Input::get('asset_tag'));
$asset->notes = e(Input::get('notes'));
$asset->physical = '1';
$asset->mac_address = e(Input::get('mac_address'));

// Was the asset updated?
if($asset->save()) {
Expand Down
29 changes: 15 additions & 14 deletions app/controllers/admin/ModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public function postCreate()

// attempt validation
if ($model->validate($new)) {

if ( e(Input::get('depreciation_id')) == '') {
$model->depreciation_id = 0;
} else {
$model->depreciation_id = e(Input::get('depreciation_id'));
}

if ( e(Input::get('eol')) == '') {
$model->eol = 0;
} else {
Expand All @@ -83,11 +83,11 @@ public function postCreate()
// Save the model data
$model->name = e(Input::get('name'));
$model->modelno = e(Input::get('modelno'));
//$model->depreciation_id = e(Input::get('depreciation_id'));
$model->manufacturer_id = e(Input::get('manufacturer_id'));
$model->category_id = e(Input::get('category_id'));
$model->user_id = Sentry::getId();
//$model->eol = e(Input::get('eol'));
$model->show_mac_address = e(Input::get('show_mac_address', '0'));


if (Input::file('image')) {
$image = Input::file('image');
Expand Down Expand Up @@ -160,18 +160,18 @@ public function postEdit($modelId = null)

if ($validator->fails())
{
// The given data did not pass validation
// The given data did not pass validation
return Redirect::back()->withInput()->withErrors($validator->messages());
}
// attempt validation
else {

if ( e(Input::get('depreciation_id')) == '') {
$model->depreciation_id = 0;
} else {
$model->depreciation_id = e(Input::get('depreciation_id'));
}

if ( e(Input::get('eol')) == '') {
$model->eol = 0;
} else {
Expand All @@ -180,9 +180,10 @@ public function postEdit($modelId = null)

// Update the model data
$model->name = e(Input::get('name'));
$model->modelno = e(Input::get('modelno'));
$model->modelno = e(Input::get('modelno'));
$model->manufacturer_id = e(Input::get('manufacturer_id'));
$model->category_id = e(Input::get('category_id'));
$model->show_mac_address = e(Input::get('show_mac_address', '0'));

if (Input::file('image')) {
$image = Input::file('image');
Expand All @@ -198,13 +199,13 @@ public function postEdit($modelId = null)
if (Input::get('image_delete') == 1 && Input::file('image') == "") {
$model->image = NULL;
}

// Was it created?
if($model->save()) {
// Redirect to the new model page
return Redirect::to("hardware/models")->with('success', Lang::get('admin/models/message.update.success'));
}
}
}

// Redirect to the model create page
return Redirect::to("hardware/models/$modelId/edit")->with('error', Lang::get('admin/models/message.update.error'));
Expand Down Expand Up @@ -261,18 +262,18 @@ public function getView($modelId = null)


}

public function getClone($modelId = null)
{
// Check if the model exists
if (is_null($model_to_clone = Model::find($modelId))) {
// Redirect to the model management page
return Redirect::to('assets/models')->with('error', Lang::get('admin/models/message.does_not_exist'));
}

$model = clone $model_to_clone;
$model->id = null;

// Show the page
$depreciation_list = array('' => 'Do Not Depreciate') + Depreciation::lists('name', 'id');
$manufacturer_list = array('' => 'Select One') + Manufacturer::lists('name', 'id');
Expand All @@ -284,7 +285,7 @@ public function getClone($modelId = null)
$view->with('model',$model);
$view->with('clone_model',$model_to_clone);
return $view;

}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddMacAddressToAsset extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::table('assets', function ($table) {
$table->string('mac_address')->nullable()->default(NULL);
});

Schema::table('models', function ($table) {
$table->boolean('show_mac_address')->default(0);
});

}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::table('assets', function ($table) {
$table->dropColumn('mac_address');
});

Schema::table('models', function ($table) {
$table->dropColumn('show_mac_address');
});
}

}
1 change: 1 addition & 0 deletions app/lang/en/admin/hardware/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'expires' => 'Expires',
'fully_depreciated' => 'Fully Depreciated',
'help_checkout' => 'If you wish to assign this asset immediately, you should select "Ready to Deploy" from the status list above, or unexpected things may happen. ',
'mac_address' => 'MAC Address',
'manufacturer' => 'Manufacturer',
'model' => 'Model',
'months' => 'months',
Expand Down
7 changes: 7 additions & 0 deletions app/lang/en/admin/models/general.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(

'show_mac_address' => 'Show MAC address field in assets in this model',

);
11 changes: 11 additions & 0 deletions app/views/backend/hardware/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@
</div>
</div>

@if ($asset->model->show_mac_address != 0)

This comment has been minimized.

Copy link
@splaer

splaer Feb 12, 2015

This line is blowing up on my latest pull. Throws a npe when trying to create a new asset. This logic only is valid when editing an asset associated to a model correct? Creating a new asset will not have a model and the property will be invalid which is the error I am seeing.

Based on other logic the below seems more accurate since we need to confirm whether its an existing asset or a new

@if ($asset->id)
@if ($asset->model->show_mac_address != 0)

This comment has been minimized.

Copy link
@snipe

snipe Feb 12, 2015

Author Owner

If it's new, there is still an asset object passed, by way of the controller, but there wouldn't be a model associated with it yet, you're right. I'll push a fix.

<!-- MAC Address -->
<div class="form-group {{ $errors->has('mac_address') ? ' has-error' : '' }}">
<label for="mac_address" class="col-md-2 control-label">@lang('admin/hardware/form.mac_address')</label>
<div class="col-md-7">
<input class="form-control" type="text" name="mac_address" id="mac_address" value="{{{ Input::old('mac_address', $asset->mac_address) }}}" />
{{ $errors->first('mac_address', '<span class="alert-msg"><i class="icon-remove-sign"></i> :message</span>') }}
</div>
</div>
@endif

<!-- Purchase Date -->
<div class="form-group {{ $errors->has('purchase_date') ? ' has-error' : '' }}">
<label for="purchase_date" class="col-md-2 control-label">@lang('admin/hardware/form.date')</label>
Expand Down
9 changes: 9 additions & 0 deletions app/views/backend/models/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@
</div>
</div>

<div class="form-group {{ $errors->has('eol') ? ' has-error' : '' }}">
<div class="checkbox col-md-offset-2">
<label>
{{ Form::checkbox('show_mac_address', '1', Input::old('show_mac_address', $model->show_mac_address)) }}
@lang('admin/models/general.show_mac_address')
</label>
</div>
</div>

<!-- Image -->
@if ($model->image)
<div class="form-group {{ $errors->has('image_delete') ? 'has-error' : '' }}">
Expand Down

0 comments on commit fbf03b2

Please sign in to comment.