diff --git a/app/routes/users.py b/app/routes/users.py index 8cbe3cf..d883135 100644 --- a/app/routes/users.py +++ b/app/routes/users.py @@ -254,11 +254,17 @@ def view_user(user_id): def profile(): """View the current user's profile.""" contracts = None + coach_availability = [] if isinstance(current_user, Player): contracts = Contract.query.filter_by( player_id=current_user.id, ).order_by(Contract.uploaded_at.desc()).all() - return render_template('pages/profile.html', user=current_user, contracts=contracts) + elif isinstance(current_user, Coach): + coach_availability = CoachAvailability.query.filter_by( + coach_id=current_user.id, + ).all() + return render_template('pages/profile.html', user=current_user, contracts=contracts, + coach_availability=coach_availability) @users_bp.route('/profile/edit', methods=['GET', 'POST']) @@ -974,12 +980,8 @@ def manage_coach_availability(): db.session.commit() return jsonify({'success': True}) - existing_availability = CoachAvailability.query.filter_by( - coach_id=current_user.id, - ).all() - - return render_template('pages/coach_availability.html', - existing_availability=existing_availability) + # GET requests redirect to profile page where availability is now managed + return redirect(url_for('users.profile')) @users_bp.route('/coach-availability/clear', methods=['POST']) diff --git a/app/templates/layouts/base.html b/app/templates/layouts/base.html index 22676c3..8961f03 100644 --- a/app/templates/layouts/base.html +++ b/app/templates/layouts/base.html @@ -85,12 +85,6 @@ {% endif %} {% if current_user.role == 'coach' %} -
  • - - - Availability - -
  • diff --git a/app/templates/pages/edit_profile.html b/app/templates/pages/edit_profile.html index 5c95c29..5560a39 100644 --- a/app/templates/pages/edit_profile.html +++ b/app/templates/pages/edit_profile.html @@ -104,25 +104,6 @@ - {% if user.role == 'player' %} -
    -

    My Disponibilities

    -

    Select your available time blocks for matches (5pm to 12am). Green = selected, Gray = available to select.

    - -
    -

    Loading...

    -
    - -
    - - -
    - {% endif %} -
    Cancel @@ -165,177 +146,6 @@ document.addEventListener('DOMContentLoaded', function() { // Show gamertag inputs for already selected games toggleGamertagInputs(); - - {% if user.role == 'player' %} - renderDisponibilityGrid(); - {% endif %} }); - -{% if user.role == 'player' %} -// Generate time slots from 5pm (17:00) to 12am (24:00) -var TIME_SLOTS = []; -for (var h = 17; h <= 24; h++) { - for (var m = 0; m < 60; m += 30) { - if (h === 24 && m > 0) continue; - var displayHour; - var displayAmpm; - if (h === 24) { - displayHour = 12; - displayAmpm = 'AM'; - } else if (h > 12) { - displayHour = h - 12; - displayAmpm = 'PM'; - } else { - displayHour = h; - displayAmpm = 'PM'; - } - var timeStr = (h < 10 ? '0' : '') + h + ':' + (m < 10 ? '0' : '') + m; - var displayTime = displayHour + ':' + (m < 10 ? '0' : '') + m + ' ' + displayAmpm; - TIME_SLOTS.push({ time: timeStr, display: displayTime }); - } -} - -var DAYS = [ - { value: 0, name: 'Monday' }, - { value: 1, name: 'Tuesday' }, - { value: 2, name: 'Wednesday' }, - { value: 3, name: 'Thursday' }, - { value: 4, name: 'Friday' }, - { value: 5, name: 'Saturday' }, - { value: 6, name: 'Sunday' } -]; - -// Store selected slots: {day: [time, time, ...]} -var selectedSlots = {}; - -function renderDisponibilityGrid() { - var grid = document.getElementById('disponibilities-grid'); - grid.innerHTML = '
    Click time blocks to select your available hours
    '; - - var container = document.createElement('div'); - container.className = 'disponibility-grid'; - - DAYS.forEach(function(day) { - var dayRow = document.createElement('div'); - dayRow.className = 'disponibility-day-row'; - - var dayLabel = document.createElement('div'); - dayLabel.className = 'disponibility-day-label'; - dayLabel.textContent = day.name; - dayRow.appendChild(dayLabel); - - var timeBlocks = document.createElement('div'); - timeBlocks.className = 'disponibility-time-blocks'; - - TIME_SLOTS.forEach(function(slot) { - var block = document.createElement('div'); - block.className = 'disponibility-time-block'; - block.dataset.day = day.value; - block.dataset.time = slot.time; - block.textContent = slot.display; - block.onclick = function() { - toggleSlot(day.value, slot.time, block); - }; - timeBlocks.appendChild(block); - }); - - dayRow.appendChild(timeBlocks); - container.appendChild(dayRow); - }); - - grid.appendChild(container); - loadMyDisponibilities(); -} - -function toggleSlot(day, time, element) { - if (!selectedSlots[day]) selectedSlots[day] = []; - - var index = selectedSlots[day].indexOf(time); - if (index > -1) { - selectedSlots[day].splice(index, 1); - element.classList.remove('selected'); - } else { - selectedSlots[day].push(time); - element.classList.add('selected'); - } -} - -function loadMyDisponibilities() { - fetch('{{ url_for("users.get_my_disponibilities") }}') - .then(function(response) { return response.json(); }) - .then(function(data) { - selectedSlots = {}; - - for (var day in data) { - var slots = data[day]; - slots.forEach(function(slot) { - selectedSlots[day] = selectedSlots[day] || []; - selectedSlots[day].push(slot.start_time); - }); - } - - document.querySelectorAll('.disponibility-time-block').forEach(function(block) { - var day = block.dataset.day; - var time = block.dataset.time; - if (selectedSlots[day] && selectedSlots[day].indexOf(time) > -1) { - block.classList.add('selected'); - } else { - block.classList.remove('selected'); - } - }); - }) - .catch(function(error) { - console.error('Error loading disponibilities:', error); - }); -} - -function saveDisponibilities() { - var slots = []; - for (var day in selectedSlots) { - selectedSlots[day].forEach(function(time) { - slots.push({ day_of_week: parseInt(day), start_time: time }); - }); - } - - fetch('{{ url_for("users.add_disponibilities_bulk") }}', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ slots: slots }) - }) - .then(function(response) { return response.json(); }) - .then(function(data) { - if (data.success) { - var msg = document.createElement('div'); - msg.className = 'alert alert-success'; - msg.style.marginTop = '10px'; - msg.innerHTML = ' Disponibilities saved successfully!'; - document.getElementById('disponibilities-grid').appendChild(msg); - setTimeout(function() { msg.remove(); }, 3000); - } - }) - .catch(function(error) { - console.error('Error saving disponibilities:', error); - }); -} - -function clearDisponibilities() { - if (!confirm('Are you sure you want to clear all your disponibilities?')) return; - - fetch('{{ url_for("users.clear_disponibilities") }}', { - method: 'POST' - }) - .then(function(response) { return response.json(); }) - .then(function(data) { - if (data.success) { - selectedSlots = {}; - document.querySelectorAll('.disponibility-time-block').forEach(function(block) { - block.classList.remove('selected'); - }); - } - }); -} -{% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/templates/pages/profile.html b/app/templates/pages/profile.html index 46f4e63..fc51f64 100644 --- a/app/templates/pages/profile.html +++ b/app/templates/pages/profile.html @@ -145,6 +145,49 @@
    + + {% if user.role == 'player' %} +
    +
    +

    My Disponibilities

    +

    Your available time blocks for matches (5pm to 12am). Green = selected, Gray = available to select.

    +
    +
    +
    +

    Loading...

    +
    +
    + + +
    +
    +
    + {% endif %} + + + {% if user.role == 'coach' %} +
    +
    +

    My Availability

    +

    Select time slots when you're available for One on One sessions (8am to 10pm).

    +
    +
    +
    +

    Loading availability grid...

    +
    +
    + +
    +
    +
    + {% endif %} + {% if user.role == 'player' %}
    @@ -182,3 +225,366 @@ {% endif %}
    {% endblock %} + +{% block scripts %} +{% if user.role == 'player' %} + +{% endif %} + +{% if user.role == 'coach' %} + + +{% endif %} +{% endblock %}