-
Notifications
You must be signed in to change notification settings - Fork 17
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
14 changed files
with
342 additions
and
4 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,145 @@ | ||
const locationModal = new bootstrap.Modal('#locationModal', {keyboard: false}) | ||
|
||
const table = document.getElementById('locationsTable'); | ||
const rows = table.getElementsByTagName('tr'); | ||
|
||
reloadTable() | ||
|
||
async function reloadTable() { | ||
table.getElementsByTagName('tbody')[0].innerHTML = '' | ||
document.getElementById('locationsTableLoadingSpinner').classList.remove('d-none') | ||
|
||
const response = await fetch('/settings/locations'); | ||
|
||
console.log(response.status) | ||
if (response.status !== 200) { | ||
setLocationsAlert('Could not load locations', 'danger') | ||
document.getElementById('locationsTableLoadingSpinner').classList.add('d-none') | ||
|
||
return | ||
} | ||
|
||
const locations = await response.json(); | ||
|
||
document.getElementById('locationsTableLoadingSpinner').classList.add('d-none') | ||
|
||
locations.forEach((location) => { | ||
let row = document.createElement('tr'); | ||
row.innerHTML = '<td>' + location.id + '</td>'; | ||
row.innerHTML += '<td>' + location.name + '</td>'; | ||
row.style.cursor = 'pointer' | ||
|
||
table.getElementsByTagName('tbody')[0].appendChild(row); | ||
}) | ||
|
||
registerTableRowClickEvent() | ||
} | ||
|
||
function setLocationsAlert(message, type = 'success') { | ||
const locationManagementAlerts = document.getElementById('locationAlerts'); | ||
locationManagementAlerts.classList.remove('d-none') | ||
locationManagementAlerts.innerHTML = '' | ||
locationManagementAlerts.innerHTML = '<div class="alert alert-' + type + ' alert-dismissible" role="alert">' + message + '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>' | ||
locationManagementAlerts.style.textAlign = 'center' | ||
} | ||
|
||
function registerTableRowClickEvent() { | ||
for (let i = 0; i < rows.length; i++) { | ||
if (i === 0) continue | ||
|
||
rows[i].onclick = function () { | ||
prepareEditLocationsModal( | ||
this.cells[0].innerHTML, | ||
this.cells[1].innerHTML, | ||
this.cells[2].innerHTML, | ||
this.cells[3].innerHTML === '1' | ||
) | ||
|
||
locationModal.show() | ||
}; | ||
} | ||
} | ||
|
||
function prepareEditLocationsModal(id, name) { | ||
document.getElementById('locationModalHeaderTitle').innerHTML = 'Edit User' | ||
|
||
document.getElementById('locationModalFooterCreateButton').classList.add('d-none') | ||
document.getElementById('locationModalFooterButtons').classList.remove('d-none') | ||
|
||
document.getElementById('locationModalNameInput').value = name | ||
|
||
document.getElementById('locationModalAlerts').innerHTML = '' | ||
|
||
// Remove class invalid-input from all (input) elements | ||
Array.from(document.querySelectorAll('.invalid-input')).forEach((el) => el.classList.remove('invalid-input')); | ||
} | ||
|
||
function showCreateLocationModal() { | ||
prepareCreateLocationModal() | ||
locationModal.show() | ||
} | ||
|
||
function prepareCreateLocationModal(name) { | ||
document.getElementById('locationModalHeaderTitle').innerHTML = 'Create Location' | ||
|
||
document.getElementById('locationModalFooterCreateButton').classList.remove('d-none') | ||
document.getElementById('locationModalFooterButtons').classList.add('d-none') | ||
|
||
document.getElementById('locationModalIdInput').value = '' | ||
document.getElementById('locationModalNameInput').value = '' | ||
|
||
document.getElementById('locationModalAlerts').innerHTML = '' | ||
|
||
// Remove class invalid-input from all (input) elements | ||
Array.from(document.querySelectorAll('.invalid-input')).forEach((el) => el.classList.remove('invalid-input')); | ||
} | ||
|
||
document.getElementById('createLocationButton').addEventListener('click', async () => { | ||
if (validateCreateLocationInput() === true) { | ||
return; | ||
} | ||
|
||
const response = await fetch('/settings/locations', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
'name': document.getElementById('locationModalNameInput').value, | ||
}) | ||
}) | ||
|
||
if (response.status !== 200) { | ||
setLocationModalAlertServerError(await response.text()) | ||
return | ||
} | ||
|
||
setLocationsAlert('Location was created: ' + document.getElementById('locationModalNameInput').value) | ||
|
||
reloadTable() | ||
locationModal.hide() | ||
}) | ||
|
||
function setLocationModalAlertServerError(message = "Server error, please try again.") { | ||
document.getElementById('locationModalAlerts').innerHTML = '<div class="alert alert-danger alert-dismissible" role="alert">' + message + '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>' | ||
} | ||
|
||
|
||
function validateCreateLocationInput() { | ||
let error = false | ||
|
||
const nameInput = document.getElementById('locationModalNameInput'); | ||
|
||
let mustNotBeEmptyInputs = [nameInput] | ||
|
||
mustNotBeEmptyInputs.forEach((input) => { | ||
input.classList.remove('invalid-input'); | ||
if (input.value.toString() === '') { | ||
input.classList.add('invalid-input'); | ||
|
||
error = true | ||
} | ||
}) | ||
|
||
return error | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/Domain/Movie/History/Location/MovieHistoryLocationApi.php
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,15 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Movary\Domain\Movie\History\Location; | ||
|
||
class MovieHistoryLocationApi | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
|
||
public function findLocationsByUserId(int $userId) : MovieHistoryLocationEntityList | ||
{ | ||
return MovieHistoryLocationEntityList::create(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Domain/Movie/History/Location/MovieHistoryLocationEntity.php
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,29 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Movary\Domain\Movie\History\Location; | ||
|
||
use Movary\ValueObject\DateTime; | ||
|
||
class MovieHistoryLocationEntity | ||
{ | ||
private function __construct( | ||
private readonly int $id, | ||
private readonly int $userId, | ||
private readonly string $name, | ||
private readonly DateTime $createdAt, | ||
private readonly DateTime $updatedAt, | ||
) { | ||
} | ||
|
||
public static function createFromArray(array $data) : self | ||
{ | ||
return new self( | ||
(int)$data['id'], | ||
(int)$data['user_id'], | ||
(string)$data['name'], | ||
DateTime::createFromString((string)$data['created_at']), | ||
DateTime::createFromString((string)$data['updated_at']), | ||
); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/Domain/Movie/History/Location/MovieHistoryLocationEntityList.php
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,33 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Movary\Domain\Movie\History\Location; | ||
|
||
use Movary\ValueObject\AbstractList; | ||
|
||
/** | ||
* @method MovieHistoryLocationEntity[] getIterator() | ||
* @psalm-suppress ImplementedReturnTypeMismatch | ||
*/ | ||
class MovieHistoryLocationEntityList extends AbstractList | ||
{ | ||
public static function create() : self | ||
{ | ||
return new self(); | ||
} | ||
|
||
public static function createFromArray(array $data) : self | ||
{ | ||
$list = new self(); | ||
|
||
foreach ($data as $historyEntry) { | ||
$list->add(MovieHistoryLocationEntity::createFromArray($historyEntry)); | ||
} | ||
|
||
return $list; | ||
} | ||
|
||
private function add(MovieHistoryLocationEntity $dto) : void | ||
{ | ||
$this->data[] = $dto; | ||
} | ||
} |
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,30 @@ | ||
<div class="modal fade" id="locationModal" tabindex="-1" aria-labelledby="locationModal" aria-hidden="true" data-bs-keyboard="false"> | ||
<div class="modal-dialog modal-dialog-centered"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h1 class="modal-title fs-5" id="locationModalHeaderTitle"></h1> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | ||
</div> | ||
<div class="modal-body" style="padding-bottom: 0!important;"> | ||
<form> | ||
<input type="hidden" id="locationModalIdInput"> | ||
|
||
<div class="mb-3"> | ||
<label for="locationModalNameInput" class="form-label">Name <span class="text-danger">*</span></label> | ||
<input type="text" class="form-control" id="locationModalNameInput" required> | ||
</div> | ||
</form> | ||
<div id="locationModalAlerts"></div> | ||
</div> | ||
<div class="modal-footer"> | ||
<div class="d-none" id="locationModalFooterCreateButton"> | ||
<button type="submit" form="locationCreateModal" class="btn btn-primary" id="createLocationButton">Create</button> | ||
</div> | ||
<div class="d-none" id="locationModalFooterButtons"> | ||
<button type="button" class="btn btn-danger" id="deleteLocationButton">Delete</button> | ||
<button type="button" class="btn btn-primary" id="updateLocationButton">Save</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
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
Oops, something went wrong.