-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: terminal | initial management terminal
- Loading branch information
Showing
6 changed files
with
224 additions
and
9 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
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,191 @@ | ||
@layout.app({ title: "Terminal List" }) | ||
@slot('main') | ||
|
||
<div class="px-6 py-2 w-full bg-white rounded-lg"> | ||
<!-- Content Head --> | ||
<div class="flex flex-row justify-between items-center mb-2"> | ||
<a href="/admin/airport" class="shadow-md py-2 px-4 inline-flex items-center gap-x-2 text-sm font-medium rounded-lg border border-transparent bg-blue-300 text-blue-800 hover:bg-blue-400 focus:outline-none focus:bg-blue-200 disabled:opacity-50 disabled:pointer-events-none">Back</a> | ||
<div class="flex flex-row gap-x-2 items-center"> | ||
<h1 class="text-xl font-bold">({{ airport.iataCode }}) {{ airport.name }} - {{ airport.City.name }}</h1> | ||
</div> | ||
@component('components/ui/modal', { | ||
title: 'Add Terminal', | ||
buttonClass: 'shadow-md py-2 px-4 inline-flex items-center gap-x-2 text-sm font-medium rounded-lg border border-transparent bg-blue-300 text-blue-800 hover:bg-blue-400 focus:outline-none focus:bg-blue-200 disabled:opacity-50 disabled:pointer-events-none', | ||
}) | ||
@slot('header') | ||
Add Terminal | ||
@end | ||
@slot('content') | ||
<form id="terminalForm" class="max-w-sm mx-auto"> | ||
<div class="mb-5"> | ||
<label for="airportId" class="block mb-2 text-sm font-medium text-gray-900">Airport</label> | ||
<input type="text" id="airportId" value="{{ airport.iataCode }}" name="airportId" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" readonly> | ||
</div> | ||
<div class="mb-5"> | ||
<label for="name" class="block mb-2 text-sm font-medium text-gray-900">Name</label> | ||
<input type="text" id="name" name="name" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"> | ||
</div> | ||
<div class="mb-5"> | ||
<label for="type" class="block mb-2 text-sm font-medium text-gray-900">Select a type</label> | ||
<select id="type" name="type" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"> | ||
<option value="" selected>Choose a Type</option> | ||
<option value="Domestik">Domestik</option> | ||
<option value="Internasional">Internasional</option> | ||
</select> | ||
</div> | ||
<button type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center">Add Airport</button> | ||
</form> | ||
@end | ||
@end | ||
</div> | ||
|
||
<div class="border-2 rounded-lg p-4 overflow-x-auto text-sm"> | ||
<table class="myTable display" style="width:100%"> | ||
<thead> | ||
<tr> | ||
<th>No</th> | ||
<th>Name</th> | ||
<th>Type</th> | ||
<th>Airport</th> | ||
<th>Action</th> | ||
</tr> | ||
</thead> | ||
<tbody class="text-center"> | ||
@each((data, index) in terminals) | ||
<tr> | ||
<td>{{ index + 1 }}</td> | ||
<td>{{ data.name }}</td> | ||
<td>{{ data.type }}</td> | ||
<td>{{ data.Airport.iataCode }}</td> | ||
<td> | ||
<div class="flex flex-row gap-x-2"> | ||
@component('components/ui/modal', { | ||
title: 'Edit Terminal', | ||
buttonClass: 'shadow-md py-2 px-4 inline-flex items-center gap-x-2 text-sm font-medium rounded-lg border border-transparent bg-yellow-300 text-yellow-800 hover:bg-yellow-400 focus:outline-none focus:bg-yellow-200 disabled:opacity-50 disabled:pointer-events-none', | ||
}) | ||
@slot('header') | ||
Edit | ||
@end | ||
@slot('content') | ||
<div class="flex flex-col gap-y-2"> | ||
<h1 class="text-sm text-gray-500">Edit Terminal</h1> | ||
{{ data.id }} | ||
|
||
<div class="flex flex-row gap-x-2"> | ||
{{-- <button type="button" onclick="editTerminal({{ data.id }})" class="shadow-md py-2 px-4 inline-flex items-center gap-x-2 text-sm font-medium rounded-lg border border-transparent bg-red-300 text-red-800 hover:bg-red-400 focus:outline-none focus:bg-red-200 disabled:opacity-50 disabled:pointer-events-none text-center w-full justify-center">Delete</button> --}} | ||
<button type="button" @click="modalOpen=false" class="shadow-md py-2 px-4 inline-flex items-center gap-x-2 text-sm font-medium rounded-lg border border-transparent bg-blue-300 text-blue-800 hover:bg-blue-400 focus:outline-none focus:bg-blue-200 disabled:opacity-50 disabled:pointer-events-none text-center w-full justify-center">Cancel</button> | ||
</div> | ||
</div> | ||
|
||
@end | ||
@end | ||
@component('components/ui/modal', { | ||
title: 'Delete Terminal', | ||
buttonClass: 'shadow-md py-2 px-4 inline-flex items-center gap-x-2 text-sm font-medium rounded-lg border border-transparent bg-red-300 text-red-800 hover:bg-red-400 focus:outline-none focus:bg-red-200 disabled:opacity-50 disabled:pointer-events-none', | ||
}) | ||
@slot('header') | ||
Delete | ||
@end | ||
@slot('content') | ||
<div class="flex flex-col gap-y-2 text-center"> | ||
<h1 class="text-sm text-red-800">Are you sure you want to delete this Terminal?</h1> | ||
<h1 class="text-sm text-gray-900 font-bold">{{ data.name }}</h1> | ||
|
||
<div class="flex flex-row gap-x-2"> | ||
<button type="button" onclick="deleteTerminal('{{ data.id }}')" class="shadow-md py-2 px-4 inline-flex items-center gap-x-2 text-sm font-medium rounded-lg border border-transparent bg-red-300 text-red-800 hover:bg-red-400 focus:outline-none focus:bg-red-200 disabled:opacity-50 disabled:pointer-events-none text-center w-full justify-center">Delete</button> | ||
<button type="button" @click="modalOpen=false" class="shadow-md py-2 px-4 inline-flex items-center gap-x-2 text-sm font-medium rounded-lg border border-transparent bg-blue-300 text-blue-800 hover:bg-blue-400 focus:outline-none focus:bg-blue-200 disabled:opacity-50 disabled:pointer-events-none text-center w-full justify-center">Cancel</button> | ||
</div> | ||
</div> | ||
|
||
@end | ||
@end | ||
</div> | ||
</td> | ||
</tr> | ||
@else | ||
<tr> | ||
<td colspan="4" class="text-center">No data available</td> | ||
</tr> | ||
@end | ||
</tbody> | ||
|
||
</table> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
const token = '{{ token }}' | ||
$(document).ready(function () { | ||
$('#terminalForm').on('submit', function (e) { | ||
e.preventDefault(); | ||
const formData = { | ||
name: $('#name').val(), | ||
type: $('#type').val(), | ||
airportId: $('#airportId').val(), | ||
}; | ||
$.ajax({ | ||
url: '{{ api }}/api/v1/terminals', | ||
method: 'POST', | ||
contentType: 'application/json', | ||
data: JSON.stringify(formData), | ||
headers: { | ||
'Authorization': `Bearer ${token}` | ||
}, | ||
success: function (response) { | ||
showToast("success", "Success", "Terminal created successfully!"); | ||
setTimeout(() => { | ||
window.location.reload(); | ||
}, 1000); | ||
}, | ||
error: function (xhr) { | ||
if (xhr.responseJSON && xhr.responseJSON.errors) { | ||
const errors = xhr.responseJSON.errors; | ||
let errorMessages = ''; | ||
errors.forEach(error => { | ||
errorMessages += `${error.field}: ${error.message}\n`; | ||
}); | ||
showToast("error", "Error", errorMessages); | ||
} else { | ||
showToast("error", "Error", "An error occurred. Please try again."); | ||
} | ||
}, | ||
}); | ||
}); | ||
}); | ||
function deleteTerminal(id) { | ||
$.ajax({ | ||
url: '{{ api }}/api/v1/terminals/' + id, | ||
method: 'DELETE', | ||
headers: { | ||
'Authorization': `Bearer ${token}` | ||
}, | ||
success: function (response) { | ||
showToast("success", "Success", "Terminal deleted successfully!"); | ||
setTimeout(() => { | ||
window.location.reload(); | ||
}, 1000); | ||
}, | ||
error: function (xhr) { | ||
if (xhr.responseJSON && xhr.responseJSON.errors) { | ||
const errors = xhr.responseJSON.errors; | ||
let errorMessages = ''; | ||
errors.forEach(error => { | ||
errorMessages += `${error.field}: ${error.message}\n`; | ||
}); | ||
showToast("error", "Error", errorMessages); | ||
} else { | ||
showToast("error", "Error", "An error occurred. Please try again."); | ||
} | ||
}, | ||
}); | ||
} | ||
</script> | ||
|
||
@endslot | ||
@end |
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