initialize supervisor...still has bugs

This commit is contained in:
hayano
2024-10-28 02:20:28 +00:00
parent 051916f9f6
commit 2913a435c1
10 changed files with 842 additions and 16 deletions

View File

@ -51,7 +51,9 @@ RUN pip install gunicorn
#RUN ["chmod", "+x", "wait-for.sh"] #RUN ["chmod", "+x", "wait-for.sh"]
RUN pip install -r requirements.txt # xlsxwriterを追加
RUN pip install -r requirements.txt \
&& pip install xlsxwriter gunicorn
COPY . /app COPY . /app

26
Dockerfile.supervisor Normal file
View File

@ -0,0 +1,26 @@
FROM nginx:alpine
# Create necessary directories and set permissions
RUN mkdir -p /usr/share/nginx/html \
&& mkdir -p /var/log/nginx \
&& mkdir -p /var/cache/nginx \
&& chown -R nginx:nginx /usr/share/nginx/html \
&& chown -R nginx:nginx /var/log/nginx \
&& chown -R nginx:nginx /var/cache/nginx \
&& chmod -R 755 /usr/share/nginx/html
# Copy files - notice the change in the source path
COPY supervisor/html/* /usr/share/nginx/html/
COPY supervisor/nginx/default.conf /etc/nginx/conf.d/default.conf
# Set final permissions
RUN chown -R nginx:nginx /usr/share/nginx/html \
&& chmod -R 755 /usr/share/nginx/html \
&& touch /var/log/nginx/access.log \
&& touch /var/log/nginx/error.log \
&& chown -R nginx:nginx /var/log/nginx \
&& chown -R nginx:nginx /etc/nginx/conf.d
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@ -37,6 +37,34 @@ services:
#entrypoint: ["/app/wait-for.sh", "postgres-db:5432", "--", ""] #entrypoint: ["/app/wait-for.sh", "postgres-db:5432", "--", ""]
#command: python3 manage.py runserver 0.0.0.0:8100 #command: python3 manage.py runserver 0.0.0.0:8100
supervisor-web:
build:
context: .
dockerfile: Dockerfile.supervisor
volumes:
- type: bind
source: ./supervisor/html
target: /usr/share/nginx/html
read_only: true
- type: bind
source: ./supervisor/nginx/default.conf
target: /etc/nginx/conf.d/default.conf
read_only: true
- type: volume
source: static_volume
target: /app/static
read_only: true
- type: volume
source: nginx_logs
target: /var/log/nginx
ports:
- "80:80"
depends_on:
- api
networks:
- rog-api
restart: always
networks: networks:
rog-api: rog-api:
@ -45,3 +73,5 @@ networks:
volumes: volumes:
postgres_data: postgres_data:
geoserver-data: geoserver-data:
static_volume:
nginx_logs:

View File

@ -29,17 +29,21 @@ http {
listen 80; listen 80;
server_name localhost; server_name localhost;
# 静的ファイルの提供
location /static/ { location /static/ {
alias /app/static/; alias /app/static/;
} }
location /media/ { # スーパーバイザー Web アプリケーション
alias /app/media/; location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
} }
# Django API プロキシ
location / { location /api/ {
proxy_pass http://app:8000; proxy_pass http://api:8000;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

View File

@ -1,7 +1,8 @@
from sys import prefix from sys import prefix
from rest_framework import urlpatterns from rest_framework import urlpatterns
from rest_framework.routers import DefaultRouter from rest_framework.routers import DefaultRouter
from .views import LocationViewSet, Location_lineViewSet, Location_polygonViewSet, Jpn_Main_PerfViewSet, LocationsInPerf, ExtentForSubPerf, SubPerfInMainPerf, ExtentForMainPerf, LocationsInSubPerf, CatView, RegistrationAPI, LoginAPI, UserAPI, UserActionViewset, UserMakeActionViewset, UserDestinations, UpdateOrder, LocationInBound, DeleteDestination, CustomAreaLocations, GetAllGifuAreas, CustomAreaNames, userDetials, UserTracksViewSet, CatByCity, ChangePasswordView, GoalImageViewSet, CheckinImageViewSet, ExtentForLocations, DeleteAccount, PrivacyView, RegistrationView, TeamViewSet,MemberViewSet,EntryViewSet,RegisterView, VerifyEmailView, NewEventListView,NewEvent2ListView,NewCategoryListView,CategoryListView, MemberUserDetailView, TeamMembersWithUserView,MemberAddView,UserActivationView,RegistrationView,TempUserRegistrationView,ResendInvitationEmailView,update_user_info,update_user_detail,ActivateMemberView, ActivateNewMemberView, PasswordResetRequestView, PasswordResetConfirmView, NewCategoryViewSet,LocationInBound2,UserLastGoalTimeView,TeamEntriesView,update_entry_status from .views import LocationViewSet, Location_lineViewSet, Location_polygonViewSet, Jpn_Main_PerfViewSet, LocationsInPerf, ExtentForSubPerf, SubPerfInMainPerf, ExtentForMainPerf, LocationsInSubPerf, CatView, RegistrationAPI, LoginAPI, UserAPI, UserActionViewset, UserMakeActionViewset, UserDestinations, UpdateOrder, LocationInBound, DeleteDestination, CustomAreaLocations, GetAllGifuAreas, CustomAreaNames, userDetials, UserTracksViewSet, CatByCity, ChangePasswordView, GoalImageViewSet, CheckinImageViewSet, ExtentForLocations, DeleteAccount, PrivacyView, RegistrationView, TeamViewSet,MemberViewSet,EntryViewSet,RegisterView, VerifyEmailView, NewEventListView,NewEvent2ListView,NewCategoryListView,CategoryListView, MemberUserDetailView, TeamMembersWithUserView,MemberAddView,UserActivationView,RegistrationView,TempUserRegistrationView,ResendInvitationEmailView,update_user_info,update_user_detail,ActivateMemberView, ActivateNewMemberView, PasswordResetRequestView, PasswordResetConfirmView, NewCategoryViewSet,LocationInBound2,UserLastGoalTimeView,TeamEntriesView,update_entry_status,get_events,get_zekken_numbers,get_team_info,get_checkins,update_checkins,export_excel
from django.urls import path, include from django.urls import path, include
from knox import views as knox_views from knox import views as knox_views
@ -110,4 +111,13 @@ urlpatterns += [
path('entries/<int:entry_id>/update-status/', update_entry_status, name='update-entry-status'), path('entries/<int:entry_id>/update-status/', update_entry_status, name='update-entry-status'),
# for Supervisor Web app
path('api/events/', get_events, name='get_events'),
path('api/zekken_numbers/<str:event_code>/', get_zekken_numbers, name='get_zekken_numbers'),
path('api/team_info/<int:zekken_number>/', get_team_info, name='get_team_info'),
path('api/checkins/<int:zekken_number>/', get_checkins, name='get_checkins'),
path('api/update_checkins/', update_checkins, name='update_checkins'),
path('api/export_excel/<int:zekken_number>/', export_excel, name='export_excel'),
# for Supervisor Web app
] ]

View File

@ -85,6 +85,9 @@ from django.conf import settings
from django.db import transaction from django.db import transaction
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
import xlsxwriter
from io import BytesIO
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@api_view(['PATCH']) @api_view(['PATCH'])
@ -2309,3 +2312,110 @@ class UserLastGoalTimeView(APIView):
'message': 'User not found' 'message': 'User not found'
}, status=status.HTTP_404_NOT_FOUND) }, status=status.HTTP_404_NOT_FOUND)
# ----- for Supervisor -----
@api_view(['GET'])
def get_events(request):
events = NewEvent2.objects.filter(public=True)
return Response([{
'code': event.event_name,
'name': event.event_name
} for event in events])
@api_view(['GET'])
def get_zekken_numbers(request, event_code):
entries = Entry.objects.filter(
event__event_name=event_code,
is_active=True
).order_by('zekken_number')
return Response([entry.zekken_number for entry in entries])
@api_view(['GET'])
def get_team_info(request, zekken_number):
entry = Entry.objects.select_related('team').get(zekken_number=zekken_number)
members = Member.objects.filter(team=entry.team)
return Response({
'team_name': entry.team.team_name,
'members': ', '.join([f"{m.lastname} {m.firstname}" for m in members]),
'start_time': entry.start_time.strftime('%Y-%m-%d %H:%M:%S') if entry.start_time else None,
'goal_time': entry.goal_time.strftime('%Y-%m-%d %H:%M:%S') if entry.goal_time else None,
'late_points': entry.late_point or 0
})
@api_view(['GET'])
def get_checkins(request, zekken_number):
checkins = GpsCheckin.objects.filter(
zekken_number=zekken_number
).order_by('path_order')
return Response([{
'id': c.id,
'path_order': c.path_order,
'cp_number': c.cp_number,
'create_at': c.create_at,
'validate_location': c.validate_location,
'points': c.points,
'buy_flag': c.buy_flag
} for c in checkins])
@api_view(['POST'])
def update_checkins(request):
with transaction.atomic():
for update in request.data:
checkin = GpsCheckin.objects.get(id=update['id'])
checkin.path_order = update['path_order']
checkin.validate_location = update['validate_location']
checkin.save()
return Response({'status': 'success'})
@api_view(['GET'])
def export_excel(request, zekken_number):
# エントリー情報の取得
entry = Entry.objects.select_related('team').get(zekken_number=zekken_number)
checkins = GpsCheckin.objects.filter(zekken_number=zekken_number).order_by('path_order')
# Excelファイルの生成
output = BytesIO()
workbook = xlsxwriter.Workbook(output)
worksheet = workbook.add_worksheet('通過証明書')
# スタイルの定義
header_format = workbook.add_format({
'bold': True,
'bg_color': '#CCCCCC',
'border': 1
})
# ヘッダー情報の書き込み
worksheet.write('A1', 'チーム名', header_format)
worksheet.write('B1', entry.team.team_name)
worksheet.write('A2', 'ゼッケン番号', header_format)
worksheet.write('B2', zekken_number)
# チェックインデータの書き込み
headers = ['順序', 'CP番号', 'チェックイン時刻', '検証', 'ポイント']
for col, header in enumerate(headers):
worksheet.write(3, col, header, header_format)
for row, checkin in enumerate(checkins, start=4):
worksheet.write(row, 0, checkin.path_order)
worksheet.write(row, 1, checkin.cp_number)
worksheet.write(row, 2, checkin.create_at.strftime('%Y-%m-%d %H:%M:%S'))
worksheet.write(row, 3, '' if checkin.validate_location else '')
worksheet.write(row, 4, checkin.points)
workbook.close()
# レスポンスの生成
output.seek(0)
response = HttpResponse(
output.read(),
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)
response['Content-Disposition'] = f'attachment; filename=通過証明書_{zekken_number}.xlsx'
return response
# ----- for Supervisor -----

274
supervisor-html.html Normal file
View File

@ -0,0 +1,274 @@
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>スーパーバイザーパネル</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.15.0/Sortable.min.js"></script>
</head>
<body class="bg-gray-50">
<div class="container mx-auto p-4">
<div class="bg-white rounded-lg shadow-lg p-6 mb-6">
<h1 class="text-2xl font-bold mb-6">スーパーバイザーパネル</h1>
<!-- 選択フォーム -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">イベントコード</label>
<select id="eventCode" class="w-full border border-gray-300 rounded-md px-3 py-2">
<option value="">イベントを選択してください</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">ゼッケン番号</label>
<select id="zekkenNumber" class="w-full border border-gray-300 rounded-md px-3 py-2">
<option value="">ゼッケン番号を選択してください</option>
</select>
</div>
</div>
<!-- チーム情報サマリー -->
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">チーム名</div>
<div id="teamName" class="font-semibold"></div>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">メンバー</div>
<div id="members" class="font-semibold"></div>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">スタート時刻</div>
<div id="startTime" class="font-semibold"></div>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">ゴール時刻</div>
<div id="goalTime" class="font-semibold"></div>
</div>
</div>
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">チェックインポイント合計</div>
<div id="totalPoints" class="font-semibold"></div>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">買い物ポイント合計</div>
<div id="buyPoints" class="font-semibold"></div>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">遅刻減点</div>
<div id="latePoints" class="font-semibold text-red-600"></div>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">総合計ポイント</div>
<div id="finalPoints" class="font-semibold text-blue-600"></div>
</div>
</div>
<!-- チェックインデータテーブル -->
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">順序</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">CP番号</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">チェックイン時刻</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">検証</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">ポイント</th>
</tr>
</thead>
<tbody id="checkinList" class="bg-white divide-y divide-gray-200">
<!-- JavaScript で動的に生成 -->
</tbody>
</table>
</div>
<!-- アクションボタン -->
<div class="mt-6 flex justify-end space-x-4">
<button id="saveButton" class="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700">
保存
</button>
<button id="exportButton" class="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700">
通過証明書出力
</button>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Sortable初期化
const checkinList = document.getElementById('checkinList');
new Sortable(checkinList, {
animation: 150,
onEnd: function(evt) {
updatePathOrders();
}
});
// イベントコード変更時の処理
document.getElementById('eventCode').addEventListener('change', function(e) {
loadZekkenNumbers(e.target.value);
});
// ゼッケン番号変更時の処理
document.getElementById('zekkenNumber').addEventListener('change', function(e) {
loadTeamData(e.target.value);
});
// チェックボックス変更時の処理
checkinList.addEventListener('change', function(e) {
if (e.target.type === 'checkbox') {
updateValidation(e.target);
}
});
// 保存ボタンの処理
document.getElementById('saveButton').addEventListener('click', saveChanges);
// Excel出力ボタンの処理
document.getElementById('exportButton').addEventListener('click', exportExcel);
// 初期データ読み込み
loadEventCodes();
});
function loadEventCodes() {
// APIからイベントコードを取得して選択肢を設定
fetch('/api/events')
.then(response => response.json())
.then(data => {
const select = document.getElementById('eventCode');
data.forEach(event => {
const option = document.createElement('option');
option.value = event.code;
option.textContent = event.name;
select.appendChild(option);
});
});
}
function loadZekkenNumbers(eventCode) {
// APIからゼッケン番号を取得して選択肢を設定
fetch(`/api/zekken-numbers/${eventCode}`)
.then(response => response.json())
.then(data => {
const select = document.getElementById('zekkenNumber');
select.innerHTML = '<option value="">ゼッケン番号を選択してください</option>';
data.forEach(number => {
const option = document.createElement('option');
option.value = number;
option.textContent = number;
select.appendChild(option);
});
});
}
function loadTeamData(zekkenNumber) {
// チーム情報とチェックインデータを取得
Promise.all([
fetch(`/api/team-info/${zekkenNumber}`),
fetch(`/api/checkins/${zekkenNumber}`)
]).then(responses => Promise.all(responses.map(r => r.json())))
.then(([teamInfo, checkins]) => {
updateTeamInfo(teamInfo);
updateCheckinList(checkins);
calculatePoints();
});
}
function updateTeamInfo(teamInfo) {
document.getElementById('teamName').textContent = teamInfo.team_name;
document.getElementById('members').textContent = teamInfo.members;
document.getElementById('startTime').textContent = teamInfo.start_time;
document.getElementById('goalTime').textContent = teamInfo.goal_time;
document.getElementById('latePoints').textContent = teamInfo.late_points;
}
function updateCheckinList(checkins) {
const tbody = document.getElementById('checkinList');
tbody.innerHTML = '';
checkins.forEach((checkin, index) => {
const tr = document.createElement('tr');
tr.dataset.id = checkin.id;
tr.innerHTML = `
<td class="px-6 py-4">${index + 1}</td>
<td class="px-6 py-4">${checkin.cp_number}</td>
<td class="px-6 py-4">${formatDateTime(checkin.create_at)}</td>
<td class="px-6 py-4">
<input type="checkbox" ${checkin.validate_location ? 'checked' : ''}
class="h-4 w-4 text-blue-600 rounded validate-checkbox">
</td>
<td class="px-6 py-4">${checkin.points}</td>
`;
tbody.appendChild(tr);
});
}
function updatePathOrders() {
const rows = Array.from(document.getElementById('checkinList').children);
rows.forEach((row, index) => {
row.children[0].textContent = index + 1;
});
}
function calculatePoints() {
const rows = Array.from(document.getElementById('checkinList').children);
let totalPoints = 0;
let buyPoints = 0;
rows.forEach(row => {
const points = parseInt(row.children[4].textContent);
if (!isNaN(points)) {
totalPoints += points;
if (row.dataset.buyFlag === 'true') {
buyPoints += points;
}
}
});
const latePoints = parseInt(document.getElementById('latePoints').textContent) || 0;
const finalPoints = totalPoints + buyPoints - latePoints;
document.getElementById('totalPoints').textContent = totalPoints;
document.getElementById('buyPoints').textContent = buyPoints;
document.getElementById('finalPoints').textContent = finalPoints;
}
function formatDateTime(dateString) {
return new Date(dateString).toLocaleString('ja-JP');
}
function saveChanges() {
const rows = Array.from(document.getElementById('checkinList').children);
const updates = rows.map((row, index) => ({
id: row.dataset.id,
path_order: index + 1,
validate_location: row.querySelector('.validate-checkbox').checked
}));
fetch('/api/update-checkins', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(updates)
}).then(response => {
if (response.ok) {
alert('保存しました');
} else {
alert('保存に失敗しました');
}
});
}
function exportExcel() {
const zekkenNumber = document.getElementById('zekkenNumber').value;
window.location.href = `/api/export-excel/${zekkenNumber}`;
}
</script>
</body>
</html>

274
supervisor/html/index.html Executable file
View File

@ -0,0 +1,274 @@
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>スーパーバイザーパネル</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.15.0/Sortable.min.js"></script>
</head>
<body class="bg-gray-50">
<div class="container mx-auto p-4">
<div class="bg-white rounded-lg shadow-lg p-6 mb-6">
<h1 class="text-2xl font-bold mb-6">スーパーバイザーパネル</h1>
<!-- 選択フォーム -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">イベントコード</label>
<select id="eventCode" class="w-full border border-gray-300 rounded-md px-3 py-2">
<option value="">イベントを選択してください</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">ゼッケン番号</label>
<select id="zekkenNumber" class="w-full border border-gray-300 rounded-md px-3 py-2">
<option value="">ゼッケン番号を選択してください</option>
</select>
</div>
</div>
<!-- チーム情報サマリー -->
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">チーム名</div>
<div id="teamName" class="font-semibold"></div>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">メンバー</div>
<div id="members" class="font-semibold"></div>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">スタート時刻</div>
<div id="startTime" class="font-semibold"></div>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">ゴール時刻</div>
<div id="goalTime" class="font-semibold"></div>
</div>
</div>
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">チェックインポイント合計</div>
<div id="totalPoints" class="font-semibold"></div>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">買い物ポイント合計</div>
<div id="buyPoints" class="font-semibold"></div>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">遅刻減点</div>
<div id="latePoints" class="font-semibold text-red-600"></div>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<div class="text-sm text-gray-500">総合計ポイント</div>
<div id="finalPoints" class="font-semibold text-blue-600"></div>
</div>
</div>
<!-- チェックインデータテーブル -->
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">順序</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">CP番号</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">チェックイン時刻</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">検証</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">ポイント</th>
</tr>
</thead>
<tbody id="checkinList" class="bg-white divide-y divide-gray-200">
<!-- JavaScript で動的に生成 -->
</tbody>
</table>
</div>
<!-- アクションボタン -->
<div class="mt-6 flex justify-end space-x-4">
<button id="saveButton" class="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700">
保存
</button>
<button id="exportButton" class="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700">
通過証明書出力
</button>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Sortable初期化
const checkinList = document.getElementById('checkinList');
new Sortable(checkinList, {
animation: 150,
onEnd: function(evt) {
updatePathOrders();
}
});
// イベントコード変更時の処理
document.getElementById('eventCode').addEventListener('change', function(e) {
loadZekkenNumbers(e.target.value);
});
// ゼッケン番号変更時の処理
document.getElementById('zekkenNumber').addEventListener('change', function(e) {
loadTeamData(e.target.value);
});
// チェックボックス変更時の処理
checkinList.addEventListener('change', function(e) {
if (e.target.type === 'checkbox') {
updateValidation(e.target);
}
});
// 保存ボタンの処理
document.getElementById('saveButton').addEventListener('click', saveChanges);
// Excel出力ボタンの処理
document.getElementById('exportButton').addEventListener('click', exportExcel);
// 初期データ読み込み
loadEventCodes();
});
function loadEventCodes() {
// APIからイベントコードを取得して選択肢を設定
fetch('/api/events')
.then(response => response.json())
.then(data => {
const select = document.getElementById('eventCode');
data.forEach(event => {
const option = document.createElement('option');
option.value = event.code;
option.textContent = event.name;
select.appendChild(option);
});
});
}
function loadZekkenNumbers(eventCode) {
// APIからゼッケン番号を取得して選択肢を設定
fetch(`/api/zekken-numbers/${eventCode}`)
.then(response => response.json())
.then(data => {
const select = document.getElementById('zekkenNumber');
select.innerHTML = '<option value="">ゼッケン番号を選択してください</option>';
data.forEach(number => {
const option = document.createElement('option');
option.value = number;
option.textContent = number;
select.appendChild(option);
});
});
}
function loadTeamData(zekkenNumber) {
// チーム情報とチェックインデータを取得
Promise.all([
fetch(`/api/team-info/${zekkenNumber}`),
fetch(`/api/checkins/${zekkenNumber}`)
]).then(responses => Promise.all(responses.map(r => r.json())))
.then(([teamInfo, checkins]) => {
updateTeamInfo(teamInfo);
updateCheckinList(checkins);
calculatePoints();
});
}
function updateTeamInfo(teamInfo) {
document.getElementById('teamName').textContent = teamInfo.team_name;
document.getElementById('members').textContent = teamInfo.members;
document.getElementById('startTime').textContent = teamInfo.start_time;
document.getElementById('goalTime').textContent = teamInfo.goal_time;
document.getElementById('latePoints').textContent = teamInfo.late_points;
}
function updateCheckinList(checkins) {
const tbody = document.getElementById('checkinList');
tbody.innerHTML = '';
checkins.forEach((checkin, index) => {
const tr = document.createElement('tr');
tr.dataset.id = checkin.id;
tr.innerHTML = `
<td class="px-6 py-4">${index + 1}</td>
<td class="px-6 py-4">${checkin.cp_number}</td>
<td class="px-6 py-4">${formatDateTime(checkin.create_at)}</td>
<td class="px-6 py-4">
<input type="checkbox" ${checkin.validate_location ? 'checked' : ''}
class="h-4 w-4 text-blue-600 rounded validate-checkbox">
</td>
<td class="px-6 py-4">${checkin.points}</td>
`;
tbody.appendChild(tr);
});
}
function updatePathOrders() {
const rows = Array.from(document.getElementById('checkinList').children);
rows.forEach((row, index) => {
row.children[0].textContent = index + 1;
});
}
function calculatePoints() {
const rows = Array.from(document.getElementById('checkinList').children);
let totalPoints = 0;
let buyPoints = 0;
rows.forEach(row => {
const points = parseInt(row.children[4].textContent);
if (!isNaN(points)) {
totalPoints += points;
if (row.dataset.buyFlag === 'true') {
buyPoints += points;
}
}
});
const latePoints = parseInt(document.getElementById('latePoints').textContent) || 0;
const finalPoints = totalPoints + buyPoints - latePoints;
document.getElementById('totalPoints').textContent = totalPoints;
document.getElementById('buyPoints').textContent = buyPoints;
document.getElementById('finalPoints').textContent = finalPoints;
}
function formatDateTime(dateString) {
return new Date(dateString).toLocaleString('ja-JP');
}
function saveChanges() {
const rows = Array.from(document.getElementById('checkinList').children);
const updates = rows.map((row, index) => ({
id: row.dataset.id,
path_order: index + 1,
validate_location: row.querySelector('.validate-checkbox').checked
}));
fetch('/api/update-checkins', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(updates)
}).then(response => {
if (response.ok) {
alert('保存しました');
} else {
alert('保存に失敗しました');
}
});
}
function exportExcel() {
const zekkenNumber = document.getElementById('zekkenNumber').value;
window.location.href = `/api/export-excel/${zekkenNumber}`;
}
</script>
</body>
</html>

View File

@ -0,0 +1,45 @@
# HTTPS server
server {
listen 80;
listen [::]:80;
server_name rogaining.sumasen.net;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log debug;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization';
}
location /api/ {
proxy_pass http://api:8100;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
}
location /static/ {
alias /app/static/;
expires 1h;
add_header Cache-Control "public, no-transform";
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

View File

@ -0,0 +1,51 @@
# HTTP to HTTPS redirect
server {
listen 80;
server_name rogaining.sumasen.net;
return 301 https://$server_name$request_uri;
}
# HTTPS server
server {
listen 443 ssl;
listen [::]:80;
server_name rogaining.sumasen.net;
ssl_certificate /etc/letsencrypt/live/rogaining.sumasen.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/rogaining.sumasen.net/privkey.pem;
# SSL configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log debug;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://api:8100;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /static/ {
alias /app/static/;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}