mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Everything's all wired up; just need to clean up all the FIXME's and stuff
This commit is contained in:
parent
53db266b69
commit
2f94bf96ff
|
@ -8,8 +8,10 @@ X - (fixed somehow?!) The Livewire.first() thing is still dumb (but Id o'nt know
|
|||
|
||||
X - Deletes need to work (I got this working before using $.ajax; it's not even hard)
|
||||
|
||||
Then mapping and so on.
|
||||
X - Then mapping and so on.
|
||||
|
||||
Can we potentially delete whatever that this.$http thing? Or is that some side-effect of Vue.js that we don't get for free? (yes, it was that)
|
||||
X - Can we potentially delete whatever that this.$http thing? Or is that some side-effect of Vue.js that we don't get for free? (yes, it was that)
|
||||
|
||||
I suspect the Alert section is not yet wired up - but should be. Doesn't seem too hard?
|
||||
X - I suspect the Alert section is not yet wired up - but should be. Doesn't seem too hard?
|
||||
|
||||
???? translations on the main import screen seem donked for some inexplicable reason? PRobably we newly-tranlsated them?
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Transformers\ImportsTransformer;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Import;
|
||||
|
||||
class ImportsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('import');
|
||||
// $imports = (new ImportsTransformer)->transformImports(Import::latest()->get());
|
||||
|
||||
return view('importer/import'); //->with('imports', $imports);
|
||||
}
|
||||
}
|
|
@ -30,10 +30,11 @@ class Importer extends Component
|
|||
'files.*.filesize' => 'required|integer'
|
||||
];
|
||||
|
||||
protected $listeners = ['hideDetails' => 'hideDetails', 'importError' => 'importError'];
|
||||
protected $listeners = ['hideDetails' => 'hideDetails', 'importError' => 'importError', 'alert' => 'alert'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
//$this->authorize('import'); // FIXME - gotta do this somewhere!!!!!
|
||||
//$this->files = Import::all(); // this *SHOULD* be how it works, but...it doesn't? (note orderBy/get, below)
|
||||
//$this->forcerefresh = 0;
|
||||
$this->progress = -1; // '-1' means 'don't show the progressbar'
|
||||
|
@ -52,6 +53,13 @@ class Importer extends Component
|
|||
$this->import_errors = $errors;
|
||||
}
|
||||
|
||||
public function alert($obj)
|
||||
{
|
||||
\Log::info("Alert object received: ".print_r($obj,true));
|
||||
$this->message = $obj;
|
||||
$this->message_type = "danger"; // FIXME - when does this get reset? Only when you click the 'x'?
|
||||
}
|
||||
|
||||
public function toggleEvent($id)
|
||||
{
|
||||
Log::error("toggled on: ".$id);
|
||||
|
@ -84,6 +92,12 @@ class Importer extends Component
|
|||
public function render()
|
||||
{
|
||||
$this->files = Import::orderBy('id','desc')->get(); //HACK - slows down renders.
|
||||
return view('livewire.importer');
|
||||
return view('livewire.importer')
|
||||
->extends('layouts.default')
|
||||
->section('content')
|
||||
->layoutData(['title', trans('general.import')]); /* return view('livewire.show-posts')
|
||||
4 ->layout('layouts.base', ['title' => 'Show Posts'])
|
||||
->section('body') // or whatever?
|
||||
5 */
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,78 +171,6 @@ class ImporterFile extends Component
|
|||
$this->statusType = 'pending';
|
||||
$this->statusText = "Processing...";
|
||||
|
||||
axios.post('{{ route('api.imports.importFile', $activeFile->id) }}', {
|
||||
'import-update': !!@this.update,
|
||||
'send-welcome': !!@this.send_welcome,
|
||||
'import-type': @this.activeFile.import_type,
|
||||
'run-backup': !!@this.run_backup,
|
||||
'column-mappings': mappings // FIXME - terrible name
|
||||
}).then( (body) => {
|
||||
Log::warn("success!!!")
|
||||
// Success
|
||||
$this->statusType = "success";
|
||||
$this->statusText = "Success... Redirecting.";
|
||||
// FIXME - can we 'flash' an update here?
|
||||
window.location.href = body.data.messages.redirect_url; // definite fixme here!
|
||||
}, (body) => {
|
||||
// Failure
|
||||
console.warn("failure!!!!")
|
||||
if(body.response.data.status == 'import-errors') {
|
||||
//window.eventHub.$emit('importErrors', body.messages);
|
||||
console.warn("import error")
|
||||
console.dir(body)
|
||||
@this.set('statusType','error');
|
||||
@this.emit('importError', body.response.data.messages)
|
||||
//@this.set('statusText', "Error: "+body.response.data.messages.join("<br>"));
|
||||
} else {
|
||||
console.warn("not import-errors, just regular errors")
|
||||
console.dir(body)
|
||||
@this.set('statusType','error');
|
||||
@this.emit('importError',body.response.data.messages ? body.response.data.messages : {'import-type': ['Unknown error']})
|
||||
@this.set('statusText',body.response.data.messages ? body.response.data.messages : 'Unknown error');
|
||||
}
|
||||
// @this.emit('hideDetails');
|
||||
});
|
||||
}
|
||||
$(function () {
|
||||
$('#import').on('click',function () {
|
||||
console.warn("okay, click handler firing!!!")
|
||||
postSave()
|
||||
})
|
||||
console.warn("JS click handler loaded!")
|
||||
})
|
||||
window.setTimeout(function() {
|
||||
var what = @this.dinglefarts
|
||||
console.warn("What is this: ",what)
|
||||
},1000)
|
||||
|
||||
$class = title_case($this->option('item-type'));
|
||||
$classString = "App\\Importer\\{$class}Importer";
|
||||
$importer = new $classString($filename);
|
||||
$importer->setCallbacks([$this, 'log'], [$this, 'progress'], [$this, 'errorCallback'])
|
||||
->setUserId($this->option('user_id'))
|
||||
->setUpdating($this->option('update'))
|
||||
->setShouldNotify($this->option('send-welcome'))
|
||||
->setUsernameFormat($this->option('username_format'));
|
||||
|
||||
// This $logFile/useFiles() bit is currently broken, so commenting it out for now
|
||||
// $logFile = $this->option('logfile');
|
||||
// \Log::useFiles($logFile);
|
||||
$this->comment('======= Importing Items from '.$filename.' =========');
|
||||
$importer->import();
|
||||
|
||||
$this->bar = null;
|
||||
|
||||
if (! empty($this->errors)) {
|
||||
$this->comment('The following Errors were encountered.');
|
||||
foreach ($this->errors as $asset => $error) {
|
||||
$this->comment('Error: Item: '.$asset.' failed validation: '.json_encode($error));
|
||||
}
|
||||
} else {
|
||||
$this->comment('All Items imported successfully!');
|
||||
}
|
||||
$this->comment('');
|
||||
|
||||
}
|
||||
|
||||
public function changeTypes() // UNUSED?
|
||||
|
|
|
@ -39,7 +39,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||
{
|
||||
Route::group([
|
||||
'middleware' => 'web',
|
||||
'namespace' => $this->namespace,
|
||||
// 'namespace' => $this->namespace, //okay, I don't know what this means, but somehow this might be a problem for us?
|
||||
], function ($router) {
|
||||
require base_path('routes/web/hardware.php');
|
||||
require base_path('routes/web/models.php');
|
||||
|
@ -65,7 +65,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||
{
|
||||
Route::group([
|
||||
'middleware' => 'auth:api',
|
||||
'namespace' => $this->namespace,
|
||||
// 'namespace' => $this->namespace, // this might also be a problem? I don't really know :/
|
||||
'prefix' => 'api',
|
||||
], function ($router) {
|
||||
require base_path('routes/api.php');
|
||||
|
|
|
@ -127,6 +127,9 @@
|
|||
"sort-packages": true,
|
||||
"optimize-autoloader": true,
|
||||
"discard-changes": true,
|
||||
"process-timeout": 3000
|
||||
"process-timeout": 3000,
|
||||
"allow-plugins": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
@extends('layouts/default')
|
||||
|
||||
{{-- Page title --}}
|
||||
@section('title')
|
||||
{{ trans('general.import') }}
|
||||
@parent
|
||||
@stop
|
||||
|
||||
{{-- Page content --}}
|
||||
@section('content')
|
||||
{{-- Hide importer until vue has rendered it, if we continue using vue for other things we should move this higher in the style --}}
|
||||
{{-- <style>
|
||||
[v-cloak] {
|
||||
display:none;
|
||||
}
|
||||
|
||||
THIS IS VUE STUFF ISNT IT?
|
||||
</style> --}}
|
||||
|
||||
{{-- YET ANOTHER FIXME! argh. This file shouldn't exist. --}}
|
||||
|
||||
@livewire('importer') {{-- Yes, this is stupid - we should be able to route straight over and not have this, but Livewire doesn't work in this app that way :/ --}}
|
||||
@stop
|
||||
|
||||
@section('moar_scripts')
|
||||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
||||
|
||||
|
||||
{{-- <script nonce="{{ csrf_token() }}">
|
||||
new Vue({
|
||||
el: '#app'
|
||||
});
|
||||
</script> --}}
|
||||
@endsection
|
|
@ -94,7 +94,7 @@
|
|||
<div class="row">
|
||||
<div class="col-md-6 col-md-offset-2 text-right" style="padding-top: 20px;">
|
||||
<button type="button" class="btn btn-sm btn-default" wire:click="$emit('hideDetails')">Cancel</button>
|
||||
<button type="submit" class="btn btn-sm btn-primary" id="import" wire:click="postSave">Import</button>
|
||||
<button type="submit" class="btn btn-sm btn-primary" id="import">Import</button>
|
||||
<br><br>
|
||||
</div>
|
||||
</div><!-- /div row -->
|
||||
|
@ -114,6 +114,56 @@
|
|||
</tr>
|
||||
{{-- </template> --}}
|
||||
<script>
|
||||
$('#import').on('click', function () {
|
||||
console.log('saving');
|
||||
console.log(@this.activeFile.import_type);
|
||||
if(!@this.activeFile.import_type) {
|
||||
@this.statusType='error';
|
||||
@this.statusText= "An import type is required... ";
|
||||
return;
|
||||
}
|
||||
@this.statusType='pending';
|
||||
@this.statusText = "Processing...";
|
||||
@this.getDinglefartsProperty().then(function (mappings_raw) {
|
||||
var mappings = JSON.parse(mappings_raw)
|
||||
console.warn("Here is the mappings:")
|
||||
console.dir(mappings)
|
||||
$.post({
|
||||
url: "{{ route('api.imports.importFile', $activeFile->id) }}",
|
||||
data: {
|
||||
'import-update': !!@this.update,
|
||||
'send-welcome': !!@this.send_welcome,
|
||||
'import-type': @this.activeFile.import_type,
|
||||
'run-backup': !!@this.run_backup,
|
||||
'column-mappings': mappings // THE HARD PART.
|
||||
},
|
||||
headers: {
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
|
||||
}
|
||||
}).done( function (body) {
|
||||
// Success
|
||||
@this.statusType="success";
|
||||
@this.statusText = "Success... Redirecting.";
|
||||
console.dir(body)
|
||||
window.location.href = body.messages.redirect_url;
|
||||
}).fail( function (jqXHR, textStatus, error) {
|
||||
// Failure
|
||||
var body = jqXHR.responseJSON
|
||||
if(body.status == 'import-errors') {
|
||||
@this.emit('importError', body.messages);
|
||||
@this.statusType='error';
|
||||
@this.statusText = "Error";
|
||||
} else {
|
||||
console.warn("Not import-errors, just regular errors")
|
||||
console.dir(body)
|
||||
@this.emit('alert', body.error)
|
||||
}
|
||||
@this.emit('hideDetails') // emit something ?
|
||||
});
|
||||
})
|
||||
return false;
|
||||
});
|
||||
|
||||
$(function () {
|
||||
console.warn("Setting iCheck callbacks!")
|
||||
$('.iCheck').on('ifToggled', function (event) {
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
@section('title')
|
||||
{{ trans('general.import') }}
|
||||
@parent
|
||||
@stop
|
||||
<div id="not-app">
|
||||
{{-- <importer inline-template v-cloak> --}} {{-- like, this, here, that's a literal Vue directive --}}
|
||||
<div class="row">
|
||||
|
@ -22,7 +26,7 @@
|
|||
<div class="box">
|
||||
<div class="box-body">
|
||||
<div class="alert alert-warning">
|
||||
<strong>Warning</strong> Some Errors occured while importing
|
||||
<strong>Warning</strong> Some Errors occurred while importing {{-- FIXME: hardcoded string --}}
|
||||
</div>
|
||||
|
||||
<div class="errors-table">
|
||||
|
|
|
@ -699,7 +699,7 @@ $(document).ready(function() {
|
|||
data: {},
|
||||
headers: {
|
||||
"X-Requested-With": 'XMLHttpRequest',
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content') // TODO` - we should do this in ajaxSetup
|
||||
},
|
||||
dataType: 'json',
|
||||
|
||||
|
|
|
@ -222,11 +222,16 @@ Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'authorize:superuser
|
|||
|
|
||||
|
|
||||
*/
|
||||
Route::group(['prefix' => 'import', 'middleware' => ['auth']], function () {
|
||||
Route::get('/',
|
||||
[ImportsController::class, 'index']
|
||||
)->name('imports.index');
|
||||
});
|
||||
|
||||
//Route::group(['prefix' => 'import', 'middleware' => ['auth']], function () {
|
||||
// Route::get('/',
|
||||
// [ImportsController::class, 'index']
|
||||
// )->name('imports.index');
|
||||
//});
|
||||
|
||||
Route::get('/import',
|
||||
\App\Http\Livewire\Importer::class
|
||||
)->middleware('auth')->name('imports.index');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue