Merge branch 'features/cusom_field_types' into develop

This commit is contained in:
snipe 2016-08-25 16:36:21 -07:00
commit 98eb26a2bd
19 changed files with 238 additions and 56 deletions

View file

@ -30,7 +30,7 @@ MAIL_USERNAME=YOURUSERNAME
MAIL_PASSWORD=YOURPASSWORD
MAIL_ENCRYPTION=null
MAIL_FROM_ADDR=you@example.com
MAIL_FROM_NAME=Snipe-IT
MAIL_FROM_NAME='Snipe-IT'
# --------------------------------------------

View file

@ -237,7 +237,7 @@ class Helper
{
$keys=array_keys(CustomField::$PredefinedFormats);
$stuff=array_combine($keys, $keys);
return $stuff+["" => "Custom Format..."];
return $stuff+["" => trans('admin/custom_fields/general.custom_format')];
}
public static function barcodeDimensions($barcode_type = 'QRCODE')

View file

@ -1588,7 +1588,7 @@ class AssetsController extends Controller
* @since [v2.0]
* @return String JSON
*/
public function getDatatable($status = null)
public function getDatatable(Request $request, $status = null, $status_id = null)
{
@ -1640,6 +1640,12 @@ class AssetsController extends Controller
}
if ($request->has('status_id')) {
$assets->where('status_id','=', e($request->get('status_id')));
}
$allowed_columns = [
'id',
'name',

View file

@ -32,7 +32,7 @@ class DashboardController extends Controller
$recent_activity = Actionlog::orderBy('created_at', 'DESC')
->with('accessorylog', 'consumablelog', 'licenselog', 'assetlog', 'adminlog', 'userlog', 'componentlog')
->take(30)
->take(20)
->get();

View file

@ -120,6 +120,7 @@ class StatuslabelsController extends Controller
$statuslabel->pending = $statustype['pending'];
$statuslabel->archived = $statustype['archived'];
$statuslabel->color = e(Input::get('color'));
$statuslabel->show_in_nav = e(Input::get('show_in_nav'),0);
// Was the asset created?
@ -208,6 +209,7 @@ class StatuslabelsController extends Controller
$statuslabel->pending = $statustype['pending'];
$statuslabel->archived = $statustype['archived'];
$statuslabel->color = e(Input::get('color'));
$statuslabel->show_in_nav = e(Input::get('show_in_nav'),0);
// Was the asset created?
@ -258,7 +260,7 @@ class StatuslabelsController extends Controller
public function getDatatable()
{
$statuslabels = Statuslabel::select(array('id','name','deployable','pending','archived','color'))
$statuslabels = Statuslabel::select(array('id','name','deployable','pending','archived','color','show_in_nav'))
->whereNull('deleted_at');
if (Input::has('search')) {
@ -314,6 +316,7 @@ class StatuslabelsController extends Controller
'type' => e($label_type),
'name' => e($statuslabel->name),
'color' => $color,
'show_in_nav' => ($statuslabel->show_in_nav=='1') ? trans('general.yes') : trans('general.no'),
'actions' => $actions
);
}

View file

@ -18,7 +18,7 @@ class CustomField extends Model
"URL" => "url",
"NUMERIC" => "numeric",
"MAC" => "regex:/^[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}$/",
"IP" => "ip"
"IP" => "ip",
];
public $rules=[

View file

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddNewFieldsToCustomFields extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('custom_fields', function (Blueprint $table) {
//
$table->string('field_values')->nullable()->default(null);
$table->boolean('field_encrypted')->default(0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('custom_fields', function (Blueprint $table) {
//
$table->dropColumn('field_values', 'field_encrypted');
});
}
}

View file

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddShowInNavToStatusLabels extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('status_labels', function (Blueprint $table) {
$table->boolean('show_in_nav')->default(0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('status_labels', function (Blueprint $table) {
$table->dropColumn('show_in_nav', 'field_encrypted');
});
}
}

View file

@ -18,6 +18,7 @@ DB_DATABASE=${MYSQL_DATABASE}
DB_USERNAME=${MYSQL_USER}
DB_PASSWORD=${MYSQL_PASSWORD}
DB_PREFIX=null
DB_DUMP_PATH='/usr/bin'
# --------------------------------------------

View file

@ -5,11 +5,17 @@ return array(
'field' => 'Field',
'about_fieldsets_title' => 'About Fieldsets',
'about_fieldsets_text' => 'Fieldsets allow you to create groups of custom fields that are frequently re-used used for specific asset model types.',
'custom_format' => 'Custom format...',
'encrypt_field' => 'Encrypt field in database',
'encrypt_field_help' => 'WARNING: Encrypting a field makes it unsearchable.',
'fieldset' => 'Fieldset',
'qty_fields' => 'Qty Fields',
'fieldsets' => 'Fieldsets',
'fieldset_name' => 'Fieldset Name',
'field_name' => 'Field Name',
'field_values' => 'Field Values',
'field_values_help' => 'Add selectable options, one per line. Blank lines other than the first line will be ignored.',
'field_element' => 'Form Element',
'field_element_short' => 'Element',
'field_format' => 'Format',

View file

@ -10,6 +10,7 @@ return array(
'name' => 'Status Name',
'pending' => 'Pending',
'status_type' => 'Status Type',
'show_in_nav' => 'Show in side nav',
'title' => 'Status Labels',
'undeployable' => 'Undeployable',
'update' => 'Update Status Label',

View file

@ -472,3 +472,24 @@ Form::macro('username_format', function ($name = "username_format", $selected =
return $select;
});
Form::macro('customfield_elements', function ($name = "customfield_elements", $selected = null, $class = null) {
$formats = array(
'text' => 'Text Box',
'listbox' => 'List Box',
'checkbox' => 'Checkbox',
'radio' => 'Radio Buttons',
);
$select = '<select name="'.$name.'" class="'.$class.'" style="width: 100%">';
foreach ($formats as $format => $label) {
$select .= '<option value="'.$format.'"'.($selected == $format ? ' selected="selected"' : '').'>'.$label.'</option> '."\n";
}
$select .= '</select>';
return $select;
});

View file

@ -28,67 +28,133 @@
<!-- Name -->
<div class="form-group {{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">{{ trans('admin/custom_fields/general.field_name') }}
<i class='fa fa-asterisk'></i></label>
<label for="name" class="col-md-4 control-label">{{ trans('admin/custom_fields/general.field_name') }} </label>
</label>
<div class="col-md-6">
<div class="col-md-6 required">
<input class="form-control" type="text" name="name" id="name" value="{{ Input::old('name') }}" />
{!! $errors->first('name', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>
<!-- Type -->
<!-- Element Type -->
<div class="form-group {{ $errors->has('element') ? ' has-error' : '' }}">
<label for="element" class="col-md-4 control-label">{{ trans('admin/custom_fields/general.field_element') }}
<i class='fa fa-asterisk'></i></label>
<label for="element" class="col-md-4 control-label">{{ trans('admin/custom_fields/general.field_element') }}</label>
</label>
<div class="col-md-6">
<div class="col-md-6 required">
{{ Form::select("element",["text" => "Text Box"],"text", array('class'=>'select2 form-control')) }}
{!! Form::customfield_elements('customfield_element', Input::old('customfield_element'), 'field_element select2 form-control') !!}
{!! $errors->first('customfield_element', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
{!! $errors->first('element', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>
<!-- Element values -->
<div class="form-group {{ $errors->has('element') ? ' has-error' : '' }}" id="field_values_text" style="display:none;">
<label for="field_values" class="col-md-4 control-label">{{ trans('admin/custom_fields/general.field_values') }}</label>
</label>
<div class="col-md-6 required">
{!! Form::textarea('field_values', Input::old('field_values'), ['style' => 'width: 100%', 'rows' => 4, 'class' => 'form-control']) !!}
{!! $errors->first('field_values', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
<p class="help-block">{{ trans('admin/custom_fields/general.field_values_help') }}</p>
</div>
</div>
<!-- Format -->
<div class="form-group {{ $errors->has('format') ? ' has-error' : '' }}">
<label for="format" class="col-md-4 control-label">{{ trans('admin/custom_fields/general.field_format') }}
<i class='fa fa-asterisk'></i></label>
<label for="format" class="col-md-4 control-label">{{ trans('admin/custom_fields/general.field_format') }}</label>
</label>
<div class="col-md-6">
{{ Form::select("format",\App\Helpers\Helper::predefined_formats(),"ANY", array('class'=>'select2 form-control')) }}
<div class="col-md-6 required">
{{ Form::select("format",\App\Helpers\Helper::predefined_formats(),"ANY", array('class'=>'format select2 form-control')) }}
{!! $errors->first('format', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>
<!-- Custom Format -->
<div class="form-group {{ $errors->has('custom_format') ? ' has-error' : '' }}">
<div class="form-group {{ $errors->has('custom_format') ? ' has-error' : '' }}" id="custom_regex" style="display:none;">
<label for="custom_format" class="col-md-4 control-label">{{ trans('admin/custom_fields/general.field_custom_format') }}
</label>
</label>
<div class="col-md-6">
<div class="col-md-6 required">
<input class="form-control" type="text" name="custom_format" id="custom_format" value="{{ Input::old('custom_format') }}" />
{!! $errors->first('custom_format', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>
<!-- Encrypted -->
<div class="form-group {{ $errors->has('custom_format') ? ' has-error' : '' }}">
<div class="col-md-8 col-md-offset-4">
<label for="field_encrypted">
<input type="checkbox" value="1" name="field_encrypted" id="field_encrypted" class="minimal"
{{ Input::old('field_encrypted') ? ' checked="checked"' : '' }}> {{ trans('admin/custom_fields/general.encrypt_field') }}
</label>
</div>
<div class="col-md-6 col-md-offset-4" id="encrypt_warning" style="display:none;">
<div class="callout callout-danger">
<p><i class="fa fa-warning"></i> {{ trans('admin/custom_fields/general.encrypt_field_help') }}</p>
</div>
<!-- Form actions -->
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-7">
<a class="btn btn-link" href="{{ route('admin.custom_fields.index') }}">{{ trans('button.cancel') }}</a>
<button type="submit" class="btn btn-success"><i class="fa fa-check icon-white"></i> {{ trans('general.save') }}</button>
</div>
</div>
</div>
<div class="box-footer text-right">
<button type="submit" class="btn btn-success"> {{ trans('general.save') }}</button>
</div>
</div>
</div>
{{ Form::close() }}
</div>
</div>
</div>
<div class="col-md-3">
<h4>About Custom Fields</h4>
<p>Custom fields allow you to add arbitrary attributes to assets.</p>
</div>
@section('moar_scripts')
<script>
$(document).ready(function(){
// Only display the custom format field if it's a custom format validation type
$(".format").change(function(){
$(this).find("option:selected").each(function(){
//console.warn($(this).attr("value"));
if (($(this).attr("value")=="") && $('.format').prop("selectedIndex") != 0) {
$("#custom_regex").show();
} else{
$("#custom_regex").hide();
}
});
}).change();
// Only display the field element if the type is not text
$(".field_element").change(function(){
$(this).find("option:selected").each(function(){
//console.warn($(this).attr("value"));
if($(this).attr("value")!="text"){
$("#field_values_text").show();
} else{
$("#field_values_text").hide();
}
});
}).change();
});
// Checkbox handling
$('div.icheckbox_minimal-blue').on('ifChecked', function(event){
$("#encrypt_warning").show();
});
$('div.icheckbox_minimal-blue').on('ifUnchecked', function(event){
$("#encrypt_warning").hide();
});
</script>
@stop
@stop

View file

@ -65,7 +65,7 @@
data-toolbar="#toolbar"
class="table table-striped"
id="table"
data-url="{{route('api.hardware.list', array(''=>e(Input::get('status')),'order_number'=>e(Input::get('order_number'))))}}"
data-url="{{route('api.hardware.list', array(''=>e(Input::get('status')),'order_number'=>e(Input::get('order_number')), 'status_id'=>e(Input::get('status_id'))))}}"
data-cookie="true"
data-click-to-select="true"
data-cookie-id-table="{{ e(Input::get('status')) }}assetTable-{{ config('version.hash_version') }}">

View file

@ -269,13 +269,13 @@
<div class="col-md-4">
@if ($asset->image)
<img src="{{ Config::get('app.url') }}/uploads/assets/{{{ $asset->image }}}" class="assetimg">
<img src="{{ config('app.url') }}/uploads/assets/{{{ $asset->image }}}" class="assetimg">
@elseif ($asset->model->image!='')
<img src="{{ Config::get('app.url') }}/uploads/models/{{{ $asset->model->image }}}" class="assetimg">
<img src="{{ config('app.url') }}/uploads/models/{{{ $asset->model->image }}}" class="assetimg">
@endif
@if (App\Models\Setting::getSettings()->qr_code=='1')
<img src="{{ config('get.url') }}/hardware/{{ $asset->id }}/qr_code" class="img-thumbnail pull-right" style="height: 100px; width: 100px; margin-right: 10px;">
<img src="{{ config('app.url') }}/hardware/{{ $asset->id }}/qr_code" class="img-thumbnail pull-right" style="height: 100px; width: 100px; margin-right: 10px;">
@endif
@if (($asset->assigneduser) && ($asset->assigned_to > 0) && ($asset->deleted_at==''))

View file

@ -405,6 +405,16 @@
<li>
<a href="{{ URL::to('hardware') }}">@lang('general.list_all')</a>
</li>
<?php $status_navs = \App\Models\Statuslabel::where('show_in_nav','=',1)->get(); ?>
@if (count($status_navs) > 0)
<li class="divider">&nbsp;</li>
@foreach ($status_navs as $status_nav)
<li><a href="{{ URL::to('hardware?status_id='.$status_nav->id) }}"}> {{ $status_nav->name }}</a></li>
@endforeach
@endif
<li{!! (Request::query('status') == 'Deployed' ? ' class="active"' : '') !!}>
<a href="{{ URL::to('hardware?status=Deployed') }}">@lang('general.deployed')
</a>
@ -490,7 +500,6 @@
<li><a href="{{ URL::to('reports/unaccepted_assets') }}" {{ (Request::is('reports/unaccepted_assets') ? ' class="active"' : '') }} >@lang('general.unaccepted_asset_report')</a></li>
<li><a href="{{ URL::to('reports/accessories') }}" {{ (Request::is('reports/accessories') ? ' class="active"' : '') }} >@lang('general.accessory_report')</a></li>
<li><a href="{{ URL::to('reports/custom') }}" {{ (Request::is('reports/custom') ? ' class="active"' : '') }}>@lang('general.custom_report')</a></li>
</ul>
</li>
@endcan

View file

@ -40,7 +40,6 @@
<!-- Asset Title -->
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name" class="col-md-3 control-label">{{ trans('general.name') }}</label>
</label>
<div class="col-md-7 required">
<input class="form-control" type="text" name="name" id="name" value="{{ Input::old('name', $statuslabel->name) }}" />
{!! $errors->first('name', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
@ -49,8 +48,7 @@
<!-- Label type -->
<div class="form-group{{ $errors->has('statuslabel_types') ? ' has-error' : '' }}">
<label for="statuslabel_types" class="col-md-3 control-label">{{ trans('admin/statuslabels/table.status_type') }}
</label>
<label for="statuslabel_types" class="col-md-3 control-label">{{ trans('admin/statuslabels/table.status_type') }} </label>
<div class="col-md-7 required">
{{ Form::select('statuslabel_types', $statuslabel_types, $statuslabel->getStatuslabelType(), array('class'=>'select2', 'style'=>'min-width:400px')) }}
{!! $errors->first('statuslabel_types', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
@ -65,8 +63,6 @@
{{ Form::text('color', Input::old('color', $statuslabel->color), array('class' => 'form-control', 'style' => 'width: 100px;', 'maxlength'=>'10')) }}
<div class="input-group-addon"><i></i></div>
</div><!-- /.input group -->
{!! $errors->first('header_color', '<span class="alert-msg">:message</span>') !!}
</div>
</div>
@ -80,6 +76,15 @@
</div>
</div>
<!-- Show in Nav -->
<div class="form-group{{ $errors->has('notes') ? ' has-error' : '' }}">
<label class="col-md-offset-3" style="padding-left: 15px;">
<input type="checkbox" value="1" name="show_in_nav" id="show_in_nav" class="minimal" {{ Input::old('show_in_nav', $statuslabel->show_in_nav) == '1' ? ' checked="checked"' : '' }}> {{ trans('admin/statuslabels/table.show_in_nav') }}
</label>
</div>

View file

@ -32,6 +32,7 @@
<th data-sortable="true" data-field="name">{{ trans('admin/statuslabels/table.name') }}</th>
<th data-sortable="false" data-field="type">{{ trans('admin/statuslabels/table.status_type') }}</th>
<th data-sortable="false" data-field="color">{{ trans('admin/statuslabels/table.color') }}</th>
<th data-sortable="true" data-field="show_in_nav">{{ trans('admin/statuslabels/table.show_in_nav') }}</th>
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th>
</tr>
</thead>

View file

@ -406,8 +406,6 @@ $(document).ready(function(){
}
});
console.dir($('.superuser'));
$('#genPassword').pGenerator({
'bind': 'click',
'passwordElement': '#password',