Skip to content

Commit

Permalink
feat: terminal | initial management terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
MRoyhanF committed Dec 22, 2024
1 parent e116f6c commit ac9ee82
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 9 deletions.
8 changes: 4 additions & 4 deletions public/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -1039,14 +1039,14 @@ video {
border-radius: 0.375rem;
}

.rounded-xl {
border-radius: 0.75rem;
}

.rounded-sm {
border-radius: 0.125rem;
}

.rounded-xl {
border-radius: 0.75rem;
}

.rounded-r-xl {
border-top-right-radius: 0.75rem;
border-bottom-right-radius: 0.75rem;
Expand Down
24 changes: 24 additions & 0 deletions src/modules/airport/aiport.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,27 @@ export const index = async (req, res, next) => {
next(error);
}
};

export const terminal = async (req, res, next) => {
try {
const api = process.env.API_URL;
const { code } = req.params;
const { token } = req;

const detailAirportResponse = await axios.get(`${api}/api/v1/airports/${code}`);
const terminalsResponse = await axios.get(`${api}/api/v1/terminals`);

const data = {
api: api,
code: code,
token: token,
airport: detailAirportResponse.data.data,
terminals: terminalsResponse.data.data || [],
};


res.edge("pages/airport/terminal", data);
} catch (error) {
next(error);
}
};
1 change: 1 addition & 0 deletions src/modules/airport/airport.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import {validateCookies} from '../../middlewares/auth.js';
export default (router) => {
const prefix = "/airport";
router.get(prefix + "/", validateCookies, airportController.index);
router.get(prefix + "/:code/terminal", validateCookies, airportController.terminal);
};
2 changes: 1 addition & 1 deletion src/resources/views/pages/airport/index.edge
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<tr>
<td>{{ index + 1 }}</td>
<td>{{ airport.iataCode }}</td>
<td>{{ airport.name }}</td>
<td><a href="/admin/airport/{{ airport.iataCode }}/terminal" class="text-blue-500 hover:text-blue-700 hover:underline">{{ airport.name }}</a></td>
<td>{{ airport.type }}</td>
<td>{{ airport.City ? airport.City.name : '-' }}</td>
<td>{{ airport.City ? airport.City.country : '-' }}</td>
Expand Down
191 changes: 191 additions & 0 deletions src/resources/views/pages/airport/terminal.edge
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
7 changes: 3 additions & 4 deletions src/resources/views/pages/ticket/create.edge
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
<h1 class="font-bold">{{ route.ArrivalAirport.City.name }}</h1>
</div>
</div>
</div>

</div>

{{-- Selected Flights Display --}}
<div id="selectedFlights" class="flex flex-col gap-2 w-full justify-center items-center hidden rounded-lg border-2 border-gray-300 px-4 py-2 shadow-md">
Expand Down Expand Up @@ -115,7 +114,7 @@
<span class="bg-blue-300 rounded-full text-sm px-2 py-1 shadow-md">{{ data.class }}</span>
@elseif(data.class == 'Business')
<span class="bg-red-300 rounded-full text-sm px-2 py-1 shadow-md">{{ data.class }}</span>
@elseif(data.class == 'First Class')
@elseif(data.class == 'First_Class')
<span class="bg-purple-300 rounded-full text-sm px-2 py-1 shadow-md">{{ data.class }}</span>
@endif
</div>
Expand Down Expand Up @@ -162,7 +161,7 @@
<span class="bg-blue-300 rounded-full text-sm px-2 py-1 shadow-md">{{ data.class }}</span>
@elseif(data.class == 'Business')
<span class="bg-red-300 rounded-full text-sm px-2 py-1 shadow-md">{{ data.class }}</span>
@elseif(data.class == 'First Class')
@elseif(data.class == 'First_Class')
<span class="bg-purple-300 rounded-full text-sm px-2 py-1 shadow-md">{{ data.class }}</span>
@endif
</div>
Expand Down

0 comments on commit ac9ee82

Please sign in to comment.