Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add change skin card to profile #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions resources/views/cards/changeskin.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

@push('styles')
<style>
#skinPreview {
width: 250px;
image-rendering: crisp-edges; /* Firefox */
image-rendering: pixelated; /* Chrome and Safari */
}
</style>
@endpush


@push('footer-scripts')
<script>
const skinInput = document.getElementById('skin');

skinInput.addEventListener('change', function () {
if (!skinInput.files || !skinInput.files[0]) {
return;
}

const file = skinInput.files[0];

if (file.name !== undefined && file.name !== '') {
document.getElementById('skinLabel').innerText = file.name;
}

const reader = new FileReader();

reader.onload = function (e) {
const preview = document.getElementById('skinPreview');
preview.src = e.currentTarget.result;
preview.classList.remove('d-none');
};

reader.readAsDataURL(skinInput.files[0]);
});
</script>
@endpush


<form action="{{ route('skin-api.update') }}" method="POST" enctype="multipart/form-data">
@csrf

<div class="mb-3">
<label for="skin"></label>
<img src="{{ route('skin-api.api.show', auth()->user()->name) }}" alt="{{ trans('skin-api::messages.skin') }}" id="skinPreview" class="mt-3 img-fluid mx-auto d-block">
</div>

<div class="mb-3">
<div class="custom-file">
<label class="form-label" for="skin" data-browse="{{ trans('messages.actions.browse') }}" id="skinLabel">
{{ trans('messages.actions.choose_file') }}
</label>
<input type="file" class="form-control @error('skin') is-invalid @enderror" id="skin" name="skin" accept=".png" required>

@error('skin')
<span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
@enderror
</div>
</div>

<button type="submit" class="btn btn-primary">
{{ trans('messages.actions.save') }}
</button>

</form>
1 change: 0 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@

Route::middleware('auth')->group(function () {
Route::get('/', 'SkinApiController@index')->name('home');

Route::post('/update', 'SkinApiController@update')->name('update');
});
27 changes: 27 additions & 0 deletions src/Cards/ChangeSkinViewCard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Azuriom\Plugin\SkinApi\Cards;

use Azuriom\Extensions\Plugin\UserProfileCardComposer;

class ChangeSkinViewCard extends UserProfileCardComposer
{
/**
* * Get the cards to add to the user profile.
* * Each card should contains:
* * - 'name' : The name of the card
* * - 'view' : The view (Ex: shop::giftcards.index).
* */

public function getCards(): array
{
$skinUrl = "";
return [
[
'name' => trans('skin-api::messages.change'),
'view' => 'skin-api::cards.changeskin',
],
];
}
}

1 change: 1 addition & 0 deletions src/Controllers/SkinApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ public function update(Request $request)

return redirect()->back()->with('success', trans('skin-api::messages.updated'));
}

}
4 changes: 4 additions & 0 deletions src/Providers/SkinApiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use Azuriom\Models\Permission;
use Azuriom\Models\User;
use Azuriom\Plugin\SkinApi\SkinAPI;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Storage;
use Azuriom\Plugin\SkinApi\Cards\ChangeSkinViewCard;

class SkinApiServiceProvider extends BasePluginServiceProvider
{
Expand Down Expand Up @@ -61,6 +63,8 @@ public function boot()
$this->registerAdminNavigation();

$this->registerUserNavigation();

View::composer('profile.index', ChangeSkinViewCard::class);
}

/**
Expand Down