mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on Client Uploads
This commit is contained in:
parent
37e8f41bff
commit
9823df51b3
@ -55,17 +55,15 @@ class DocumentController extends Controller
|
|||||||
Storage::makeDirectory('public/' . $contact->client->client_hash, 0755);
|
Storage::makeDirectory('public/' . $contact->client->client_hash, 0755);
|
||||||
|
|
||||||
$path = Storage::putFile('public/' . $contact->client->client_hash, $request->file('file'));
|
$path = Storage::putFile('public/' . $contact->client->client_hash, $request->file('file'));
|
||||||
|
|
||||||
$url = Storage::url($path);
|
$url = Storage::url($path);
|
||||||
|
$size = $request->file('file')->getSize();
|
||||||
Log::error($path);
|
$type = $request->file('file')->getClientOriginalExtension();
|
||||||
Log::error($url);
|
|
||||||
|
|
||||||
$contact = auth()->user();
|
$contact = auth()->user();
|
||||||
|
$contact->avatar_size = $size;
|
||||||
tap($contact)->update([
|
$contact->avatar_type = $type;
|
||||||
'avatar' => $url,
|
$contact->avatar = $url;
|
||||||
]);
|
$contact->save();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
[2019-08-07 05:50:23] local.ERROR: array (
|
[2019-08-07 05:50:23] local.ERROR: array (
|
||||||
@ -82,6 +80,9 @@ class DocumentController extends Controller
|
|||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
return response()->json($contact);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -124,8 +125,22 @@ class DocumentController extends Controller
|
|||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function destroy($id)
|
public function destroy()
|
||||||
{
|
{
|
||||||
//
|
$contact = auth()->user();
|
||||||
|
|
||||||
|
$file = basename($contact->avatar);
|
||||||
|
$image_path = 'public/' . $contact->client->client_hash . '/' . $file;
|
||||||
|
|
||||||
|
Log::error($image_path);
|
||||||
|
Storage::delete($image_path);
|
||||||
|
|
||||||
|
|
||||||
|
$contact->avatar = '';
|
||||||
|
$contact->avatar_type = '';
|
||||||
|
$contact->avatar_size = '';
|
||||||
|
$contact->save();
|
||||||
|
|
||||||
|
return response()->json($contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,14 @@ class ClientContact extends Authenticatable
|
|||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'password',
|
'password',
|
||||||
'remember_token',
|
'remember_token',
|
||||||
|
'user_id',
|
||||||
|
'company_id',
|
||||||
|
'client_id',
|
||||||
|
'google_2fa_secret',
|
||||||
|
'id',
|
||||||
|
'oauth_provider_id',
|
||||||
|
'oauth_user_id',
|
||||||
|
'token',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -84,7 +92,7 @@ class ClientContact extends Authenticatable
|
|||||||
public function setAvatarAttribute($value)
|
public function setAvatarAttribute($value)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!filter_var($value, FILTER_VALIDATE_URL))
|
if(!filter_var($value, FILTER_VALIDATE_URL) && $value)
|
||||||
$this->attributes['avatar'] = url('/') . $value;
|
$this->attributes['avatar'] = url('/') . $value;
|
||||||
else
|
else
|
||||||
$this->attributes['avatar'] = $value;
|
$this->attributes['avatar'] = $value;
|
||||||
|
@ -329,9 +329,8 @@ class CreateUsersTable extends Migration
|
|||||||
$table->string('google_2fa_secret')->nullable();
|
$table->string('google_2fa_secret')->nullable();
|
||||||
$table->string('accepted_terms_version')->nullable();
|
$table->string('accepted_terms_version')->nullable();
|
||||||
$table->string('avatar', 255)->nullable();
|
$table->string('avatar', 255)->nullable();
|
||||||
$table->unsignedInteger('avatar_width')->nullable();
|
$table->string('avatar_type',255)->nullable();
|
||||||
$table->unsignedInteger('avatar_height')->nullable();
|
$table->string('avatar_size',255)->nullable();
|
||||||
$table->unsignedInteger('avatar_size')->nullable();
|
|
||||||
$table->string('password');
|
$table->string('password');
|
||||||
$table->string('token')->nullable();
|
$table->string('token')->nullable();
|
||||||
$table->boolean('is_locked')->default(false);
|
$table->boolean('is_locked')->default(false);
|
||||||
|
@ -30,6 +30,9 @@
|
|||||||
<script src="/vendors/js/dropzone.min.js"></script>
|
<script src="/vendors/js/dropzone.min.js"></script>
|
||||||
<script src="/vendors/js/sweetalert.min.js"></script>
|
<script src="/vendors/js/sweetalert.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
var contact = {!! auth()->user() !!};
|
||||||
|
|
||||||
Dropzone.autoDiscover = false;
|
Dropzone.autoDiscover = false;
|
||||||
window.countUploadingDocuments = 0;
|
window.countUploadingDocuments = 0;
|
||||||
|
|
||||||
@ -71,12 +74,38 @@
|
|||||||
|
|
||||||
if (dropzone instanceof Dropzone) {
|
if (dropzone instanceof Dropzone) {
|
||||||
|
|
||||||
//dropzone.on('addedfile', handleDocumentAdded);
|
dropzone.on('addedfile', handleDocumentAdded);
|
||||||
//dropzone.on('removedfile', handleDocumentRemoved);
|
dropzone.on('removedfile', handleDocumentRemoved);
|
||||||
//dropzone.on('success', handleDocumentUploaded);
|
dropzone.on('success', handleDocumentUploaded);
|
||||||
//dropzone.on('canceled', handleDocumentCanceled);
|
//dropzone.on('canceled', handleDocumentCanceled);
|
||||||
dropzone.on('error', handleDocumentError);
|
dropzone.on('error', handleDocumentError);
|
||||||
|
|
||||||
|
var mockFile = {
|
||||||
|
name: contact.avatar,
|
||||||
|
size: contact.avatar_size,
|
||||||
|
type: contact.avatar_type,
|
||||||
|
status: Dropzone.SUCCESS,
|
||||||
|
accepted: true,
|
||||||
|
url: contact.avatar,
|
||||||
|
mock: true
|
||||||
|
};
|
||||||
|
|
||||||
|
if(contact.avatar) {
|
||||||
|
dropzone.emit('addedfile', mockFile);
|
||||||
|
dropzone.emit('complete', mockFile);
|
||||||
|
}
|
||||||
|
var documentType = contact.avatar_type;
|
||||||
|
var previewUrl = contact.avatar;
|
||||||
|
var documentUrl = contact.avatar;
|
||||||
|
|
||||||
|
if (contact && previewUrl) {
|
||||||
|
dropzone.emit('thumbnail', mockFile, previewUrl);
|
||||||
|
} else if (documentType == 'jpeg' || documentType == 'png' || documentType == 'svg') {
|
||||||
|
dropzone.emit('thumbnail', mockFile, documentUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
dropzone.files.push(mockFile);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDocumentError(file, responseText) {
|
function handleDocumentError(file, responseText) {
|
||||||
@ -89,5 +118,66 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleDocumentAdded(file){
|
||||||
|
|
||||||
|
if (contact.avatar) {
|
||||||
|
file.previewElement.addEventListener("click", function() {
|
||||||
|
window.open(contact.avatar, '_blank');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if(file.mock)return;
|
||||||
|
if (window.addDocument) {
|
||||||
|
addDocument(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDocumentUploaded(file, response){
|
||||||
|
|
||||||
|
contact = response;
|
||||||
|
dropzone.files = [];
|
||||||
|
|
||||||
|
var mockFile = {
|
||||||
|
name: contact.avatar,
|
||||||
|
size: contact.avatar_size,
|
||||||
|
type: contact.avatar_type,
|
||||||
|
status: Dropzone.SUCCESS,
|
||||||
|
accepted: true,
|
||||||
|
url: contact.avatar,
|
||||||
|
mock: true
|
||||||
|
};
|
||||||
|
|
||||||
|
if(contact.avatar) {
|
||||||
|
dropzone.emit('complete', mockFile);
|
||||||
|
}
|
||||||
|
var documentType = contact.avatar_type;
|
||||||
|
var previewUrl = contact.avatar;
|
||||||
|
var documentUrl = contact.avatar;
|
||||||
|
|
||||||
|
if (contact && previewUrl) {
|
||||||
|
dropzone.emit('thumbnail', mockFile, previewUrl);
|
||||||
|
} else if (documentType == 'jpeg' || documentType == 'png' || documentType == 'svg') {
|
||||||
|
dropzone.emit('thumbnail', mockFile, documentUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
dropzone.files.push(mockFile);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDocumentRemoved(file){
|
||||||
|
if (window.deleteDocument) {
|
||||||
|
deleteDocument(file);
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: '{!! $url !!}',
|
||||||
|
type: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||||
|
},
|
||||||
|
success: function(result) {
|
||||||
|
// Do something with the result
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
@ -20,6 +20,7 @@ Route::group(['middleware' => ['auth:contact'], 'prefix' => 'client', 'as' => 'c
|
|||||||
Route::put('profile/{client_contact}/edit', 'ClientPortal\ProfileController@update')->name('profile.update');
|
Route::put('profile/{client_contact}/edit', 'ClientPortal\ProfileController@update')->name('profile.update');
|
||||||
|
|
||||||
Route::post('document', 'ClientPortal\DocumentController@store')->name('document.store');
|
Route::post('document', 'ClientPortal\DocumentController@store')->name('document.store');
|
||||||
|
Route::delete('document', 'ClientPortal\DocumentController@destroy')->name('document.destroy');
|
||||||
|
|
||||||
Route::get('logout', 'Auth\ContactLoginController@logout')->name('logout');
|
Route::get('logout', 'Auth\ContactLoginController@logout')->name('logout');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user