-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
namespace Coyote\Http\Controllers\Adm; | ||
|
||
use Coyote\Domain\Icon\FontAwesomePro; | ||
use Illuminate\Database\Connection; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Support\Facades\Session; | ||
use Illuminate\View\View; | ||
|
||
class IconsController extends BaseController | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->breadcrumb->push('Ikony', route('adm.icons')); | ||
} | ||
|
||
public function index(FontAwesomePro $icons, Connection $connection): View | ||
{ | ||
return $this->view('adm.icons', [ | ||
'editorIcons' => $this->editorIcons(\array_filter($icons->icons()), $connection), | ||
]); | ||
} | ||
|
||
private function editorIcons(array $icons, Connection $connection): array | ||
{ | ||
$record = $connection->table('settings_key_value')->where('key', 'currentIcons')->first(); | ||
if ($record) { | ||
$sessionIcons = \json_decode($record->value, true); | ||
} else { | ||
$sessionIcons = []; | ||
} | ||
$editorIcons = []; | ||
foreach ($icons as $iconName => $defaultIcon) { | ||
$editorIcons[$iconName] = [$defaultIcon, $sessionIcons[$iconName] ?? '']; | ||
} | ||
return $editorIcons; | ||
} | ||
|
||
public function save(Connection $connection): RedirectResponse | ||
{ | ||
$currentIcons = $this->request->get('icons'); | ||
Session::put('icons', $currentIcons); | ||
$connection->table('settings_key_value')->insert([ | ||
'key' => date('Y-m-d H:i:s'), | ||
'value' => json_encode($currentIcons), | ||
]); | ||
$connection->table('settings_key_value')->updateOrInsert( | ||
['key' => 'currentIcons'], | ||
['value' => json_encode($currentIcons)]); | ||
return response()->redirectToRoute('adm.icons'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{% extends 'adm.base' %} | ||
{% block title %}Ikony {{ parent() }}{% endblock %} | ||
|
||
{% block card %} | ||
{{ form_open({url: route('adm.icons.save'), method: 'post', id: 'app'}) }} | ||
<div class="d-flex justify-content-end"> | ||
<p> | ||
<input type="submit" value="Zapisz" class="btn btn-primary" data-submit-state="Zapisywanie..."> | ||
</p> | ||
</div> | ||
<table class="table table-striped"> | ||
<tr> | ||
<th>umiejscowienie</th> | ||
<th>ikona FontAwesome</th> | ||
<th></th> | ||
</tr> | ||
<tr v-for="(icon, index) in icons"> | ||
<td> | ||
<input :value="icon.location" class="form-control" disabled> | ||
</td> | ||
<td> | ||
<input | ||
:name="'icons[' + icon.location + ']'" | ||
:value="icon.currentIcon" | ||
:placeholder="icon.defaultIcon" | ||
class="form-control" | ||
></td> | ||
<td> | ||
<button | ||
type="button" | ||
@click="reset" | ||
class="btn btn-sm" | ||
> | ||
<i class="fa-solid fa-arrow-rotate-left"></i> | ||
</button> | ||
</td> | ||
</tr> | ||
</table> | ||
{{ form_close() }} | ||
{% endblock %} | ||
|
||
{% block body %} | ||
{{ parent() }} | ||
<script | ||
src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.14/vue.min.js" | ||
integrity="sha512-XdUZ5nrNkVySQBnnM5vzDqHai823Spoq1W3pJoQwomQja+o4Nw0Ew1ppxo5bhF2vMug6sfibhKWcNJsG8Vj9tg==" | ||
crossorigin="anonymous" | ||
referrerpolicy="no-referrer"> | ||
</script> | ||
<script> | ||
const editorIcons = {{ editorIcons|json_encode|raw }}; | ||
new Vue({ | ||
name: 'Icons', | ||
el: '#app', | ||
delimiters: ['${', '}'], | ||
data() { | ||
return { | ||
editorIcons, | ||
}; | ||
}, | ||
computed: { | ||
icons() { | ||
return Object.entries(this.$data.editorIcons).map(([location, [defaultIcon, currentIcon]]) => { | ||
return {location, defaultIcon, currentIcon}; | ||
}); | ||
}, | ||
}, | ||
methods: { | ||
reset(event) { | ||
event.currentTarget.parentElement.parentElement.querySelector('input[name]').value = ''; | ||
}, | ||
}, | ||
}); | ||
</script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters