mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
WIP import mapper #3639
@dmeltzer, I’m not sure how much extra work this will be to integrate.
This commit is contained in:
parent
c2494fe0e5
commit
ad816264e9
|
@ -687,6 +687,34 @@ class AssetsController extends Controller
|
|||
return View::make('hardware/import');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Map the fields for import
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @return View
|
||||
*/
|
||||
public function getImportMap()
|
||||
{
|
||||
|
||||
$this->authorize('create', Asset::class);
|
||||
|
||||
// This is currently hardcoded for testing - should use a post variable or something to dynamically select the correct file.
|
||||
$file = storage_path().'/private_uploads/imports/2017-06-08-072329-sample-assets.csv';
|
||||
$reader = Reader::createFromPath($file);
|
||||
$header_rows = $reader->fetchOne(0);
|
||||
|
||||
// Grab the first row to display via ajax as the user picks fields
|
||||
$first_row = $reader->fetchOne(1);
|
||||
|
||||
// Grab all of the custom fields to we can map those too.
|
||||
$custom_fields = CustomField::all();
|
||||
|
||||
return View::make('importer/fieldmapper')->with('header_rows', $header_rows)->with('first_row',$first_row)->with('custom_fields',$custom_fields);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the uploaded file
|
||||
*
|
||||
|
|
|
@ -518,3 +518,22 @@ Form::macro('customfield_elements', function ($name = "customfield_elements", $s
|
|||
return $select;
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
Form::macro('header_list', function ($headers = null, $name = "header_list", $selected = null, $class = null) {
|
||||
|
||||
|
||||
$select = '<select name="'.$name.'" class="'.$class.'" style="width: 100%">';
|
||||
$select .= '<option value="">Do Not Import</option>';
|
||||
|
||||
foreach ($headers as $header => $label) {
|
||||
$select .= '<option value="'.str_slug($label).'"'.($selected == str_slug($label) ? ' selected="selected"' : '').'>'.e($label).'</option> '."\n";
|
||||
}
|
||||
|
||||
$select .= '</select>';
|
||||
|
||||
return $select;
|
||||
|
||||
});
|
||||
|
|
233
resources/views/importer/fieldmapper.blade.php
Normal file
233
resources/views/importer/fieldmapper.blade.php
Normal file
|
@ -0,0 +1,233 @@
|
|||
@extends('layouts.default')
|
||||
|
||||
{{-- Page title --}}
|
||||
@section('title')
|
||||
Map Import Fields
|
||||
@parent
|
||||
@stop
|
||||
|
||||
@section('header_right')
|
||||
<a href="{{ URL::previous() }}" class="btn btn-primary pull-right">
|
||||
{{ trans('general.back') }}</a>
|
||||
@stop
|
||||
|
||||
|
||||
|
||||
{{-- Page content --}}
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8 col-md-offset-2">
|
||||
<div class="box box-default">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">
|
||||
|
||||
</h3>
|
||||
@if (isset($helpText))
|
||||
<div class="box-tools pull-right">
|
||||
<button class="slideout-menu-toggle btn btn-box-tool btn-box-tool-lg" data-toggle="tooltip" title="Help"><i class="fa fa-question"></i></button>
|
||||
</div>
|
||||
@endif
|
||||
</div><!-- /.box-header -->
|
||||
|
||||
<div class="box-body">
|
||||
<form id="create-form" class="form-horizontal" method="post" action="{{ (isset($formAction)) ? $formAction : \Request::url() }}" autocomplete="off" role="form" enctype="multipart/form-data">
|
||||
|
||||
<!-- CSRF Token -->
|
||||
{{ csrf_field() }}
|
||||
|
||||
<pre>
|
||||
@php
|
||||
print_r($first_row);
|
||||
@endphp
|
||||
</pre>
|
||||
|
||||
<div class="col-md-8 col-md-offset-2">
|
||||
<h3>Standard Fields</h3>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Check out to User (First Last)
|
||||
</label>
|
||||
<div class="col-md-4 required">
|
||||
{!! Form::header_list($header_rows, 'user_name_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Username
|
||||
</label>
|
||||
<div class="col-md-4 required">
|
||||
{!! Form::header_list($header_rows, 'username_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Email
|
||||
</label>
|
||||
<div class="col-md-4 required">
|
||||
{!! Form::header_list($header_rows, 'email_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Item Name
|
||||
</label>
|
||||
<div class="col-md-4 required">
|
||||
{!! Form::header_list($header_rows, 'item_name_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Asset Tag
|
||||
</label>
|
||||
<div class="col-md-4 required">
|
||||
{!! Form::header_list($header_rows, 'asset_tag_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Serial Number
|
||||
</label>
|
||||
<div class="col-md-4 required">
|
||||
{!! Form::header_list($header_rows, 'serial_number_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Model name
|
||||
</label>
|
||||
<div class="col-md-4 required">
|
||||
{!! Form::header_list($header_rows, 'model_name_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Model Number
|
||||
</label>
|
||||
<div class="col-md-4">
|
||||
{!! Form::header_list($header_rows, 'model_number_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Category
|
||||
</label>
|
||||
<div class="col-md-4 required">
|
||||
{!! Form::header_list($header_rows, 'category_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Manufacturer
|
||||
</label>
|
||||
<div class="col-md-4 required">
|
||||
{!! Form::header_list($header_rows, 'manufacturer_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Company
|
||||
</label>
|
||||
<div class="col-md-4">
|
||||
{!! Form::header_list($header_rows, 'company_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Location
|
||||
</label>
|
||||
<div class="col-md-4">
|
||||
{!! Form::header_list($header_rows, 'location_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Purchase Date
|
||||
</label>
|
||||
<div class="col-md-4">
|
||||
{!! Form::header_list($header_rows, 'purchase_date_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Purchase Cost
|
||||
</label>
|
||||
<div class="col-md-4">
|
||||
{!! Form::header_list($header_rows, 'purchase_cost_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Status
|
||||
</label>
|
||||
<div class="col-md-4">
|
||||
{!! Form::header_list($header_rows, 'status_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Notes
|
||||
</label>
|
||||
<div class="col-md-4">
|
||||
{!! Form::header_list($header_rows, 'notes_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">Image Filename
|
||||
</label>
|
||||
<div class="col-md-4">
|
||||
{!! Form::header_list($header_rows, 'image_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if ($custom_fields->count() > 0)
|
||||
<div class="col-md-8 col-md-offset-2">
|
||||
<h3>Custom Fields</h3>
|
||||
<hr>
|
||||
</div>
|
||||
@foreach ($custom_fields as $custom_field)
|
||||
<div class="form-group">
|
||||
<label for="url" class="col-md-3 control-label">{{ $custom_field->name }}
|
||||
</label>
|
||||
<div class="col-md-4">
|
||||
{!! Form::header_list($header_rows, 'image_header', Input::old('header_row'), 'select2') !!}
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
@endif
|
||||
|
||||
|
||||
|
||||
<div class="box-footer text-right">
|
||||
<a class="btn btn-link" href="{{ URL::previous() }}">{{ trans('button.cancel') }}</a>
|
||||
<button type="submit" class="btn btn-success"><i class="fa fa-check icon-white"></i> {{ trans('general.process') }}</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if ((isset($helpText)) && (isset($helpTitle)))
|
||||
<div class="slideout-menu">
|
||||
<a href="#" class="slideout-menu-toggle pull-right">×</a>
|
||||
<h3>
|
||||
{{ $helpTitle}}
|
||||
</h3>
|
||||
<p>{{ $helpText }} </p>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@stop
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
@extends('layouts/default')
|
||||
two@extends('layouts/default')
|
||||
|
||||
{{-- Page title --}}
|
||||
@section('title')
|
||||
|
|
|
@ -87,6 +87,11 @@ Route::group(
|
|||
'uses' => 'AssetsController@getDeleteImportFile'
|
||||
]);
|
||||
|
||||
Route::get('import/map',[
|
||||
'as' => 'import.map',
|
||||
'uses' => 'AssetsController@getImportMap'
|
||||
]);
|
||||
|
||||
Route::get('import',[
|
||||
'as' => 'assets/import',
|
||||
'uses' => 'AssetsController@getImportUpload'
|
||||
|
|
Loading…
Reference in a new issue