From fbf03b225d732e12821bfc83b9bae7fb7b4b8be8 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 11 Feb 2015 16:37:24 -0800 Subject: [PATCH] Fixes #509 - added MAC address as model option --- app/controllers/admin/AssetsController.php | 5 ++- app/controllers/admin/ModelsController.php | 29 +++++++------ ..._02_12_001312_add_mac_address_to_asset.php | 43 +++++++++++++++++++ app/lang/en/admin/hardware/form.php | 1 + app/lang/en/admin/models/general.php | 7 +++ app/views/backend/hardware/edit.blade.php | 11 +++++ app/views/backend/models/edit.blade.php | 9 ++++ 7 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 app/database/migrations/2015_02_12_001312_add_mac_address_to_asset.php create mode 100644 app/lang/en/admin/models/general.php diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index d76b42a4d195..005d0c593a90 100755 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -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'; @@ -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()) { diff --git a/app/controllers/admin/ModelsController.php b/app/controllers/admin/ModelsController.php index 320491ed92f9..910e9011756c 100755 --- a/app/controllers/admin/ModelsController.php +++ b/app/controllers/admin/ModelsController.php @@ -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 { @@ -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'); @@ -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 { @@ -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'); @@ -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')); @@ -261,7 +262,7 @@ public function getView($modelId = null) } - + public function getClone($modelId = null) { // Check if the model exists @@ -269,10 +270,10 @@ public function getClone($modelId = null) // 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'); @@ -284,7 +285,7 @@ public function getClone($modelId = null) $view->with('model',$model); $view->with('clone_model',$model_to_clone); return $view; - + } diff --git a/app/database/migrations/2015_02_12_001312_add_mac_address_to_asset.php b/app/database/migrations/2015_02_12_001312_add_mac_address_to_asset.php new file mode 100644 index 000000000000..eb658a53ae0a --- /dev/null +++ b/app/database/migrations/2015_02_12_001312_add_mac_address_to_asset.php @@ -0,0 +1,43 @@ +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'); + }); + } + +} diff --git a/app/lang/en/admin/hardware/form.php b/app/lang/en/admin/hardware/form.php index aef375bd0a24..bcd86a4ef611 100755 --- a/app/lang/en/admin/hardware/form.php +++ b/app/lang/en/admin/hardware/form.php @@ -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', diff --git a/app/lang/en/admin/models/general.php b/app/lang/en/admin/models/general.php new file mode 100644 index 000000000000..5e7a6870db5a --- /dev/null +++ b/app/lang/en/admin/models/general.php @@ -0,0 +1,7 @@ + 'Show MAC address field in assets in this model', + +); diff --git a/app/views/backend/hardware/edit.blade.php b/app/views/backend/hardware/edit.blade.php index 30a99586ab49..a83e12ba8517 100755 --- a/app/views/backend/hardware/edit.blade.php +++ b/app/views/backend/hardware/edit.blade.php @@ -90,6 +90,17 @@ + @if ($asset->model->show_mac_address != 0) + +
+ +
+ + {{ $errors->first('mac_address', ' :message') }} +
+
+ @endif +
diff --git a/app/views/backend/models/edit.blade.php b/app/views/backend/models/edit.blade.php index 5163c350836b..020f39d638f7 100755 --- a/app/views/backend/models/edit.blade.php +++ b/app/views/backend/models/edit.blade.php @@ -107,6 +107,15 @@
+
+
+ +
+
+ @if ($model->image)