Merge pull request #1554 from snipe/final_custom_fields_tweaks
Final custom fields tweaks
This commit is contained in:
@@ -8,6 +8,7 @@ use Validator;
|
||||
use Redirect;
|
||||
use Model;
|
||||
use Lang;
|
||||
use Sentry;
|
||||
|
||||
class CustomFieldsController extends \BaseController {
|
||||
|
||||
@@ -19,7 +20,11 @@ class CustomFieldsController extends \BaseController {
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
return View::make("backend.custom_fields.index")->with("custom_fieldsets",CustomFieldset::all())->with("custom_fields",CustomField::all());
|
||||
$fieldsets=CustomFieldset::with("fields","models")->get();
|
||||
//$fieldsets=CustomFieldset::all();
|
||||
$fields=CustomField::with("fieldset")->get();
|
||||
//$fields=CustomField::all();
|
||||
return View::make("backend.custom_fields.index")->with("custom_fieldsets",$fieldsets)->with("custom_fields",$fields);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +48,7 @@ class CustomFieldsController extends \BaseController {
|
||||
public function store()
|
||||
{
|
||||
//
|
||||
$cfset=new CustomFieldset(["name" => Input::get("name")]);
|
||||
$cfset=new CustomFieldset(["name" => Input::get("name"),"user_id" => Sentry::getUser()->id]);
|
||||
$validator=Validator::make(Input::all(),$cfset->rules);
|
||||
if($validator->passes()) {
|
||||
$cfset->save();
|
||||
@@ -76,7 +81,7 @@ class CustomFieldsController extends \BaseController {
|
||||
|
||||
public function storeField()
|
||||
{
|
||||
$field=new CustomField(["name" => Input::get("name"),"element" => Input::get("element")]);
|
||||
$field=new CustomField(["name" => Input::get("name"),"element" => Input::get("element"),"user_id" => Sentry::getUser()->id]);
|
||||
if(!in_array(Input::get('format'),["ALPHA","NUMERIC","MAC","IP"])) {
|
||||
$field->format=Input::get("custom_format");
|
||||
} else {
|
||||
|
||||
@@ -15,6 +15,7 @@ class MigrateMacAddress extends Migration {
|
||||
DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
|
||||
|
||||
$f2=new CustomFieldset(['name' => "Asset with MAC Address"]);
|
||||
$f2->timestamps=false; //when this model was first created, it had no timestamps. But later on it gets them.
|
||||
if(!$f2->save()) {
|
||||
throw new Exception("couldn't save customfieldset");
|
||||
}
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddTimestampAndUserIdToCustomFields extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('custom_fields', function(Blueprint $table)
|
||||
{
|
||||
$table->integer("user_id")->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('custom_fields', function(Blueprint $table)
|
||||
{
|
||||
$table->dropColumn("user_id");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddTimestampAndUserIdToCustomFieldsets extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
Schema::table('custom_fieldsets', function(Blueprint $table)
|
||||
{
|
||||
$table->timestamps();
|
||||
$table->integer("user_id")->nullable();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('custom_fieldsets', function(Blueprint $table)
|
||||
{
|
||||
$table->dropTimestamps();
|
||||
$table->dropColumn("user_id");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -71,6 +71,10 @@ class CustomField extends Elegant
|
||||
public function fieldset() {
|
||||
return $this->belongsToMany('CustomFieldset'); //?!?!?!?!?!?
|
||||
}
|
||||
|
||||
public function user() {
|
||||
return $this->belongsTo('User');
|
||||
}
|
||||
|
||||
//public function
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
class CustomFieldset extends Elegant
|
||||
{
|
||||
protected $guarded=["id"];
|
||||
public $timestamps=false;
|
||||
|
||||
public $rules=[
|
||||
"name" => "required|unique:custom_fieldsets"
|
||||
@@ -16,6 +15,10 @@ class CustomFieldset extends Elegant
|
||||
return $this->hasMany('Model',"fieldset_id");
|
||||
}
|
||||
|
||||
public function user() {
|
||||
return $this->belongsTo('User'); //WARNING - not all CustomFieldsets have a User!!
|
||||
}
|
||||
|
||||
public function validation_rules()
|
||||
{
|
||||
$rules=[];
|
||||
|
||||
Reference in New Issue
Block a user