Starter asset import routes
This commit is contained in:
@@ -619,6 +619,57 @@ class AssetsController extends AdminController
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getImport() {
|
||||
|
||||
$path = app_path().'/private_uploads/imports/assets';
|
||||
$files = array();
|
||||
|
||||
if ($handle = opendir($path)) {
|
||||
|
||||
/* This is the correct way to loop over the directory. */
|
||||
while (false !== ($entry = readdir($handle))) {
|
||||
clearstatcache();
|
||||
if (substr(strrchr($entry,'.'),1)=='csv') {
|
||||
$files[] = array(
|
||||
'filename' => $entry,
|
||||
'filesize' => Setting::fileSizeConvert(filesize($path.'/'.$entry)),
|
||||
'modified' => filemtime($path.'/'.$entry)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
closedir($handle);
|
||||
$files = array_reverse($files);
|
||||
}
|
||||
|
||||
return View::make('backend/hardware/import')->with('files',$files);
|
||||
}
|
||||
|
||||
public function apiPostImport() {
|
||||
|
||||
$files = Input::file('files');
|
||||
$path = app_path().'/private_uploads/imports/assets';
|
||||
$results = array();
|
||||
|
||||
foreach ($files as $file) {
|
||||
$file->move($path, $file->getClientOriginalName());
|
||||
$name = $file->getClientOriginalName();
|
||||
$results[] = compact('name');
|
||||
}
|
||||
|
||||
return array(
|
||||
'files' => $results
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function getProcessFile() {
|
||||
// php artisan asset-import:csv path/to/your/file.csv --domain=yourdomain.com --email_format=firstname.lastname
|
||||
|
||||
Artisan::call('asset-import:csv', ['path/to/your/file.csv']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asset clone.
|
||||
*
|
||||
|
||||
+17
-6
@@ -10,6 +10,8 @@
|
||||
Route::group( [ 'prefix' => 'hardware' ], function () {
|
||||
|
||||
Route::get( 'list/{status?}', [ 'as' => 'api.hardware.list', 'uses' => 'AssetsController@getDatatable' ] );
|
||||
|
||||
Route::post('import', 'AssetsController@apiPostImport' );
|
||||
} );
|
||||
|
||||
/*---Status Label API---*/
|
||||
@@ -118,12 +120,6 @@
|
||||
Route::group( [ 'prefix' => 'hardware', 'namespace' => 'Controllers\Admin', 'before' => 'admin-auth' ],
|
||||
function () {
|
||||
|
||||
Route::get( '/', [
|
||||
'as' => 'hardware',
|
||||
'uses' => 'AssetsController@getIndex'
|
||||
]
|
||||
);
|
||||
|
||||
Route::get( 'create/{model?}', [
|
||||
'as' => 'create/hardware',
|
||||
'uses' => 'AssetsController@getCreate'
|
||||
@@ -160,6 +156,15 @@
|
||||
[ 'as' => 'delete/assetfile', 'uses' => 'AssetsController@getDeleteFile' ] );
|
||||
Route::get( '{assetId}/showfile/{fileId}',
|
||||
[ 'as' => 'show/assetfile', 'uses' => 'AssetsController@displayFile' ] );
|
||||
|
||||
Route::get('import', 'AssetsController@getImport' );
|
||||
|
||||
Route::get( 'import/delete-import/{filename}',
|
||||
[ 'as' => 'assets/import/delete-file', 'uses' => 'AssetsController@getDeleteImportFile' ] );
|
||||
|
||||
Route::get( 'import/process/{filename}',
|
||||
[ 'as' => 'assets/import/process-file', 'uses' => 'AssetsController@getProcessImport' ] );
|
||||
|
||||
Route::post( '{assetId}/edit', 'AssetsController@postEdit' );
|
||||
|
||||
Route::post( 'bulkedit',
|
||||
@@ -188,6 +193,12 @@
|
||||
Route::get( '{modelID}/restore', [ 'as' => 'restore/model', 'uses' => 'ModelsController@getRestore' ] );
|
||||
} );
|
||||
|
||||
Route::get( '/', [
|
||||
'as' => 'hardware',
|
||||
'uses' => 'AssetsController@getIndex'
|
||||
]
|
||||
);
|
||||
|
||||
} );
|
||||
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
@extends('backend/layouts/default')
|
||||
|
||||
{{-- Page title --}}
|
||||
@section('title')
|
||||
@lang('general.import') ::
|
||||
@parent
|
||||
@stop
|
||||
|
||||
{{-- Page content --}}
|
||||
@section('content')
|
||||
|
||||
<div class="row header">
|
||||
<div class="col-md-12">
|
||||
<a href="{{ URL::previous() }}" class="btn-flat gray pull-right"><i class="fa fa-arrow-left icon-white"></i> @lang('general.back')</a>
|
||||
<h3> @lang('general.import')</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row form-wrapper">
|
||||
|
||||
<!-- left column -->
|
||||
<div class="col-md-12 column">
|
||||
|
||||
<div class="col-md-3">
|
||||
<!-- The fileinput-button span is used to style the file input field as button -->
|
||||
<span class="btn btn-info fileinput-button">
|
||||
<i class="glyphicon glyphicon-plus"></i>
|
||||
<span>Select Import File...</span>
|
||||
<!-- The file input field used as target for the file upload widget -->
|
||||
<input id="fileupload" type="file" name="files[]" accept="text/csv" data-url="../api/hardware/import">
|
||||
</span>
|
||||
</div>
|
||||
<div class="col-md-9" id="progress-container" style="visibility: hidden; padding-bottom: 20px;">
|
||||
<!-- The global progress bar -->
|
||||
<div class="col-md-11">
|
||||
<div id="progress" class="progress" style="margin-top: 10px;">
|
||||
<div class="progress-bar progress-bar-success"></div>
|
||||
<div class="progress-bar-text"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-1">
|
||||
<div class="pull-right progress-checkmark" style="display: none;">
|
||||
<i class="fa fa-check fa-3x icon-white" style="color: green"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="{{ asset('assets/js/jquery.ui.widget.js') }}"></script>
|
||||
<script src="{{ asset('assets/js/jquery.iframe-transport.js') }}"></script>
|
||||
<script src="{{ asset('assets/js/jquery.fileupload.js') }}"></script>
|
||||
<link rel="stylesheet" type="text/css" href="{{ asset('assets/css/lib/jquery.fileupload.css') }}">
|
||||
<link rel="stylesheet" type="text/css" href="{{ asset('assets/css/lib/jquery.fileupload-ui.css') }}">
|
||||
|
||||
|
||||
<script>
|
||||
$(function () {
|
||||
//binds to onchange event of your input field
|
||||
var uploadedFileSize = 0;
|
||||
$('#fileupload').bind('change', function() {
|
||||
uploadedFileSize = this.files[0].size;
|
||||
$('#progress-container').css('visibility', 'visible');
|
||||
});
|
||||
|
||||
$('#fileupload').fileupload({
|
||||
//maxChunkSize: 100000,
|
||||
dataType: 'json',
|
||||
|
||||
progress: function (e, data) {
|
||||
var progress = parseInt((data.loaded / uploadedFileSize) * 100, 10);
|
||||
$('.progress-bar-success').css('width',progress + '%');
|
||||
$('.progress-bar-text').html(progress + '%');
|
||||
|
||||
if (data.error != 0) {
|
||||
$('.progress-bar-success').css('color','red');
|
||||
}
|
||||
|
||||
if (progress == 100) {
|
||||
$('.progress-checkmark').fadeIn('slow');
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<th>File</th>
|
||||
<th>Created</th>
|
||||
<th>Size</th>
|
||||
<th></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($files as $file)
|
||||
<tr>
|
||||
<td><a href="assets/import/download/{{{ $file['filename'] }}}">{{{ $file['filename'] }}}</a></td>
|
||||
<td>{{{ date("M d, Y g:i A", $file['modified']) }}} </td>
|
||||
<td>{{{ $file['filesize'] }}}</td>
|
||||
<td><a class="btn btn-info btn-sm" href="">Process</a></td>
|
||||
<td>
|
||||
<a data-html="false"
|
||||
class="btn delete-asset btn-danger btn-sm {{ (Config::get('app.lock_passwords')) ? ' disabled': '' }}" data-toggle="modal" href=" {{ route('assets/import/delete-file', $file['filename']) }}" data-content="@lang('admin/settings/message.backup.delete_confirm')" data-title="{{ Lang::get('general.delete') }} {{ htmlspecialchars($file['filename']) }} ?" onClick="return false;">
|
||||
<i class="fa fa-trash icon-white"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@stop
|
||||
Reference in New Issue
Block a user