Added rooms menu

Redone reservation design
This commit is contained in:
Sviatoslav Tsariov Yurievich 2025-03-17 23:13:40 +03:00
parent 2707d80723
commit ffa96152f0
15 changed files with 353 additions and 29 deletions

View File

@ -98,7 +98,7 @@ body {
<script src="Talkpal.js"></script>
<script>
const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"ensureCrossOriginIsolationHeaders":true,"executable":"Talkpal","experimentalVK":true,"fileSizes":{"Talkpal.pck":6372256,"Talkpal.wasm":43016933},"focusCanvas":true,"gdextensionLibs":[],"serviceWorker":"Talkpal.service.worker.js"};
const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"ensureCrossOriginIsolationHeaders":true,"executable":"Talkpal","experimentalVK":true,"fileSizes":{"Talkpal.pck":6385104,"Talkpal.wasm":43016933},"focusCanvas":true,"gdextensionLibs":[],"serviceWorker":"Talkpal.service.worker.js"};
const GODOT_THREADS_ENABLED = false;
const engine = new Engine(GODOT_CONFIG);

Binary file not shown.

View File

@ -4,7 +4,7 @@
// Incrementing CACHE_VERSION will kick off the install event and force
// previously cached resources to be updated from the network.
/** @type {string} */
const CACHE_VERSION = '1741733523|6678384895';
const CACHE_VERSION = '1742239479|2606992692';
/** @type {string} */
const CACHE_PREFIX = 'Talkpal-sw-cache-';
const CACHE_NAME = CACHE_PREFIX + CACHE_VERSION;

View File

@ -9,7 +9,8 @@ const WorkingDayEnd = 20
const MinimalMinutesToShowTitle = 30
const MinimalMinutesForBigSize = 60
const DateUpdateInterval := 1.0
const DateUpdateInterval := 60.0
const ScheduleUpdateInterval := 1.0 # 5.0
@onready var _main: Main = get_tree().get_current_scene()
@onready var _timeline = $Panel/Timeline
@ -17,7 +18,11 @@ const DateUpdateInterval := 1.0
@onready var _date = $TopBar/DateButton
@onready var _room = $TopBar/RoomButton
var _date_update_timer = 0.0
@onready var _rooms_menu = $RoomsMenu
var _date_update_timer := 0.0
var _schedule_update_timer := 0.0
var _block_reservation_creation := false
func _process(delta):
_process_hour_size()
@ -49,6 +54,13 @@ func _process_font_size(obj, k):
if font_size != new_font_size:
obj.add_theme_font_size_override("font_size", new_font_size)
func _process_schedule(delta):
if _schedule_update_timer >= ScheduleUpdateInterval:
_schedule_update_timer = 0.0
_update_schedule()
_schedule_update_timer += delta
func _ready():
_connect_signals()
@ -62,6 +74,9 @@ func _connect_signals():
var event_handler = _main.get_event_handler()
event_handler.reservations_updated.connect(_on_reservations_updated)
_room.pressed.connect(_on_room_button_pressed)
_rooms_menu.item_clicked.connect(_on_room_selected)
func _remove_time_slots():
for time_slot in _timeline.get_children():
time_slot.queue_free()
@ -123,8 +138,16 @@ func _input(event):
if _clicked_on_timeline(event.position):
await get_tree().create_timer(0.01, false).timeout
if _block_reservation_creation:
_block_reservation_creation = false
return
if _main.get_current_page() == Main.Pages.Board:
var time = _get_time_by_position(event.position)
if _time_is_before_current_time(time):
return
var creation_page = _main.load_page(Main.Pages.ReservationCreation)
creation_page.set_start_time(time)
@ -148,8 +171,24 @@ func _clicked_on_timeline(pos: Vector2):
pos.y < _timeline.size.y + timeline_position.y
)
func _time_is_before_current_time(time):
var current_time = Time.get_time_dict_from_system()
var time_in_minutes = time.hours*60 + time.minutes
var current_time_in_minutes = current_time.hour*60 + current_time.minute
return time_in_minutes < current_time_in_minutes
func _on_room_button_pressed():
print("emit change room signal")
if _rooms_menu.visible:
_rooms_menu.hide()
else:
_rooms_menu.position = _date.position
_rooms_menu.show()
func _on_room_selected(idx, text):
_block_reservation_creation = true
_room.text = text
_rooms_menu.hide()
func _on_date_button_pressed():
print("emit change date signal")

View File

@ -1,10 +1,11 @@
[gd_scene load_steps=6 format=3 uid="uid://c431r28ef5edp"]
[gd_scene load_steps=7 format=3 uid="uid://c431r28ef5edp"]
[ext_resource type="Script" path="res://scenes/board/board.gd" id="1_2wgc4"]
[ext_resource type="Theme" uid="uid://cmhwbyqu6nh38" path="res://assets/themes/big.tres" id="1_na0ey"]
[ext_resource type="PackedScene" uid="uid://cnr23ry08ntv4" path="res://scenes/board/time_slot.tscn" id="2_kklmx"]
[ext_resource type="PackedScene" uid="uid://dpi5ft4r8sfwb" path="res://scenes/board/reservation.tscn" id="4_o5rhy"]
[ext_resource type="Script" path="res://scenes/board/current_time.gd" id="6_8jgig"]
[ext_resource type="PackedScene" uid="uid://bt3h3m10qx1jr" path="res://scenes/board/rooms_menu.tscn" id="6_ofefh"]
[node name="Board" type="VBoxContainer"]
anchors_preset = 10
@ -55,11 +56,23 @@ layout_mode = 2
[node name="TimeSlot2" parent="Panel/Timeline" instance=ExtResource("2_kklmx")]
layout_mode = 2
[node name="Reservations" type="Control" parent="Panel"]
layout_mode = 2
anchors_preset = 0
offset_top = 50.0
offset_right = 1036.0
offset_bottom = 117.0
grow_horizontal = 2
[node name="Reservation" parent="Panel/Reservations" instance=ExtResource("4_o5rhy")]
layout_mode = 2
offset_right = 1036.0
[node name="CurrentTime" type="VBoxContainer" parent="Panel"]
custom_minimum_size = Vector2(1036, 0)
layout_mode = 2
offset_top = 50.0
offset_right = 1036.0
offset_right = 1041.0
offset_bottom = 318.0
grow_horizontal = 2
script = ExtResource("6_8jgig")
@ -74,6 +87,7 @@ color = Color(0, 0, 0, 0.470588)
layout_mode = 2
[node name="Indent" type="Label" parent="Panel/CurrentTime/HBoxContainer"]
visible = false
layout_mode = 2
theme = ExtResource("1_na0ey")
theme_override_colors/font_color = Color(0, 0, 0, 0)
@ -86,17 +100,6 @@ size_flags_horizontal = 3
size_flags_vertical = 0
color = Color(1, 1, 0, 0.556863)
[node name="Reservations" type="Control" parent="Panel"]
layout_mode = 2
anchors_preset = 0
offset_top = 50.0
offset_right = 1036.0
offset_bottom = 117.0
grow_horizontal = 2
[node name="Reservation" parent="Panel/Reservations" instance=ExtResource("4_o5rhy")]
layout_mode = 2
offset_right = 1036.0
[node name="Control" type="Control" parent="."]
[node name="RoomsMenu" parent="." instance=ExtResource("6_ofefh")]
visible = false
layout_mode = 2

View File

@ -0,0 +1,27 @@
extends Control
@onready var _items = $Items
signal item_clicked(idx, text)
func _process(delta):
_process_items_font_size()
func _process_items_font_size():
var font_size = _items.get_theme_default_font_size()
var new_font_size = get_viewport_rect().size.y/35
if font_size != new_font_size:
_items.add_theme_font_size_override("font_size", new_font_size)
func _ready():
_connect_signals()
func _connect_signals():
_items.item_clicked.connect(_on_item_clicked)
func set_items(items: Array):
pass
func _on_item_clicked(index, at_position, mouse_button_index):
var text = _items.get_item_text(index)
item_clicked.emit(index, text)

View File

@ -0,0 +1,21 @@
[gd_scene load_steps=3 format=3 uid="uid://bt3h3m10qx1jr"]
[ext_resource type="Script" path="res://scenes/board/rooms_menu.gd" id="1_5p83j"]
[ext_resource type="Theme" uid="uid://cmhwbyqu6nh38" path="res://assets/themes/big.tres" id="1_yypwp"]
[node name="RoomsMenu" type="Control"]
layout_mode = 3
anchors_preset = 0
script = ExtResource("1_5p83j")
[node name="Items" type="ItemList" parent="."]
layout_mode = 0
offset_right = 500.0
offset_bottom = 280.0
theme = ExtResource("1_yypwp")
auto_height = true
item_count = 4
item_0/text = "Маркетинг"
item_1/text = "Green"
item_2/text = "Конференц-зал"
item_3/text = "Dipal"

View File

@ -14,7 +14,7 @@ script = ExtResource("1_2wxyg")
[node name="TimeEdit" type="LineEdit" parent="."]
visible = false
layout_mode = 2
text = "14:35 "
text = "21:41 "
placeholder_text = "hh:mm (a/p)m"
script = ExtResource("2_7d4ae")
current_time = true

View File

@ -9,7 +9,7 @@ const BgColors = {
"temporarily_free": Color("3a2c00")
}
const MinutesForTemporarilyFree := 15
const StatusCheckPeriod := 5.0
const StatusCheckInterval := 1.0 # 5.0
enum Status {
FREE,
@ -47,7 +47,7 @@ enum Status {
var _current_page := Pages.Board
var _previous_page : Pages
var _status : Status
var _time_after_status_check := 0.0
var _status_check_timer := 0.0
func _ready():
initialize_signals()
@ -90,11 +90,11 @@ func _process_available_time(time):
_will_be_available_label.text = ""
func _process_status(delta):
if _time_after_status_check >= StatusCheckPeriod:
_time_after_status_check = 0.0
if _status_check_timer >= StatusCheckInterval:
_status_check_timer = 0.0
_update_status()
_time_after_status_check += delta
_status_check_timer += delta
func _update_status(reservations=null):
var time = Time.get_time_dict_from_system()

View File

@ -80,7 +80,7 @@ size_flags_vertical = 3
[node name="TimeLabel" type="Label" parent="Left/TimeStatusContainer"]
layout_mode = 2
theme = ExtResource("5_atujq")
text = "15:09"
text = "11:31"
horizontal_alignment = 1
[node name="StatusLabel" type="Label" parent="Left/TimeStatusContainer"]

View File

@ -0,0 +1,9 @@
@tool
extends Node
class_name AbstractRoomRepo
signal connected
signal not_connected
func list_rooms():
pass

View File

@ -1,7 +1,7 @@
class_name EventHandlerWS
extends EventHandler
const BACKEND_URL = "http://192.168.1.178:5000/socket.io"
const BACKEND_URL = "http://192.168.0.147:5000/socket.io"
var _room_id: String = ""
var _jwt_token: String = ""
var _client: SocketIOClient

View File

@ -2,7 +2,7 @@
extends AbstractReservationRepo
class_name ReservationRepoHTTP
const BASE_URL = "http://192.168.1.178:5000"
const BASE_URL = "http://192.168.0.147:5000"
const RESERVATION_ENDPOINT = "/reservation/"
const HEALTH_ENDPOINT = "/health/"

View File

@ -0,0 +1,209 @@
@tool
extends AbstractRoomRepo
class_name RoomRepoHTTP
const BASE_URL = "http://192.168.1.178:5000"
const RESERVATION_ENDPOINT = "/reservation/"
const HEALTH_ENDPOINT = "/health/"
signal request_failed(error_message: String)
var _jwt_token: String = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTc0MDA0MDQzNywianRpIjoiOTM4NTUyMjMtMjhiNC00OWVhLWI3ZjUtZmYxMTg4YzI1Mjg2IiwidHlwZSI6ImFjY2VzcyIsInN1YiI6InRlc3RfdXNlciIsIm5iZiI6MTc0MDA0MDQzNywiY3NyZiI6ImMwYzI2MTU0LTdkNjItNGYyZi04ZjBhLWI0MjA0ODJlMmEzZCIsImV4cCI6MTc0MDA0MTMzN30.esPRTXNxrtziuOc2dUsc9XqbedErjcyvPlL3aUZIaaA"
var _timed_out := false
func _ready():
if await _backend_is_accessible():
connected.emit()
else:
not_connected.emit()
func _backend_is_accessible():
var result = await _make_request(HEALTH_ENDPOINT, HTTPClient.METHOD_GET)
if not result:
push_error("Server initialization failed")
return false
if result.has("error"):
push_error("Server initialization failed: " + result.error)
return false
return true
#region Public Methods
func create_reservation(dto: CreateReservationDTO) -> void:
_make_request(RESERVATION_ENDPOINT, HTTPClient.METHOD_POST, _dto_to_json(dto))
func cancel_reservation(reservation_id: String) -> void:
_make_request(RESERVATION_ENDPOINT + "%s" % reservation_id, HTTPClient.METHOD_DELETE)
func change_reservation(reservation_id: String, dto: UpdateReservationDTO) -> void:
_make_request(RESERVATION_ENDPOINT + "%s" % reservation_id, HTTPClient.METHOD_PUT, _dto_to_json(dto))
func get_reservation(reservation_id: String) -> ReservationEntity:
var result = await _make_request(RESERVATION_ENDPOINT + "%s" % reservation_id, HTTPClient.METHOD_GET)
return _parse_reservation_entity(result) if result is Dictionary else null
func list_reservations(filters: Dictionary = {}) -> Array:
var query = "?"
for key in filters:
query += "%s=%s&" % [key, filters[key]]
query = query.rstrip("&") if filters else ""
var endpoint = RESERVATION_ENDPOINT + query
var result = await _make_request(endpoint, HTTPClient.METHOD_GET)
var reservations = _parse_reservation_list(result) if result is Array else []
_set_current_reservation_id_from_reservations(reservations)
return reservations
func _set_current_reservation_id_from_reservations(reservations):
var time = Time.get_time_dict_from_system()
var current_time_in_minutes = time.hour*60 + time.minute
for reservation in reservations:
var start_time_in_minutes = reservation.start_time.hours*60 + reservation.start_time.minutes
var finish_time_in_minutes = reservation.finish_time.hours*60 + reservation.finish_time.minutes
if current_time_in_minutes >= start_time_in_minutes \
and current_time_in_minutes < finish_time_in_minutes:
_current_reservation = reservation
return
_current_reservation = null
func set_selected_reservation_id(value):
_selected_reservation_id = value
func get_selected_reservation_id():
return _selected_reservation_id
func set_jwt_token(token: String):
_jwt_token = token
#endregion
#region Private Methods
func _get_headers() -> PackedStringArray:
return PackedStringArray([
"Content-Type: application/json",
"Authorization: Bearer %s" % _jwt_token
])
func _dto_to_json(dto) -> String:
var dict = {}
match typeof(dto):
TYPE_OBJECT when dto is CreateReservationDTO:
dict = {
"title": dto.title,
"description": dto.description,
"room_id": dto.room_id,
"date": dto.date,
"start_time": dto.start_time,
"finish_time": dto.finish_time,
"color": dto.color
}
TYPE_OBJECT when dto is UpdateReservationDTO:
if dto.title: dict["title"] = dto.title
if dto.description: dict["description"] = dto.description
if dto.room_id: dict["room_id"] = dto.room_id
if dto.date: dict["date"] = dto.date
if dto.start_time: dict["start_time"] = dto.start_time
if dto.finish_time: dict["finish_time"] = dto.finish_time
if dto.color: dict["color"] = dto.color
return JSON.stringify(dict)
func _time_dto_to_dict(time_dto: TimeDTO) -> Dictionary:
return {"hours": time_dto.hours, "minutes": time_dto.minutes}
func _make_request(endpoint: String, method: int, body: String = "") -> Variant:
var request = HTTPRequest.new()
add_child(request)
var url = BASE_URL + endpoint
var error = request.request(url, _get_headers(), method, body)
if error != OK:
request.queue_free()
emit_signal("request_failed", "Request creation failed: %d" % error)
return null
var response = await _wait_for_request_or_timeout(request)
request.queue_free()
var result = response[0]
var response_code = response[1]
var response_body = response[3]
if result != HTTPRequest.RESULT_SUCCESS:
emit_signal("request_failed", "HTTP request failed: %d" % result)
return null
var json = JSON.new()
var parse_error = json.parse(response_body.get_string_from_utf8())
if parse_error != OK:
emit_signal("request_failed", "JSON parse error: %d" % parse_error)
return null
var response_data = json.get_data()
if response_code >= 400:
emit_signal("request_failed", response_data.get("error", "Unknown error"))
return null
return response_data
func _wait_for_request_or_timeout(request: HTTPRequest) -> Array:
var timer = Timer.new()
add_child(timer)
timer.wait_time = 5.0
timer.one_shot = true
timer.timeout.connect(func():
_timed_out = true
if request.get_http_client_status() != HTTPClient.STATUS_DISCONNECTED:
request.cancel_request()
)
timer.start()
while true:
if _timed_out:
_timed_out = false
timer.queue_free()
return [HTTPRequest.RESULT_REQUEST_FAILED, 408, [], PackedByteArray()]
if request.get_http_client_status() == HTTPClient.STATUS_REQUESTING:
break
await get_tree().process_frame
timer.queue_free()
return await request.request_completed
func _parse_reservation_entity(data: Dictionary) -> ReservationEntity:
var entity = ReservationEntity.new()
entity.id = data.get("id", "")
entity.title = data.get("title", "")
entity.description = data.get("description", "")
entity.room_id = data.get("room_id", "")
entity.creator = data.get("creator", "")
entity.date = data.get("date", "")
entity.color = data.get("color", 0)
entity.start_time = data.get("start_time", {})
entity.finish_time = data.get("finish_time", {})
return entity
func _parse_reservation_list(data: Array) -> Array[ReservationEntity]:
var entities: Array[ReservationEntity] = []
for item in data:
entities.append(_parse_reservation_entity(item))
entities.sort_custom(_compare_reservations_by_start_time)
return entities
func _compare_reservations_by_start_time(a: ReservationEntity, b: ReservationEntity) -> int:
var time_a = a.start_time.get("hours", 0) * 60 + a.start_time.get("minutes", 0)
var time_b = b.start_time.get("hours", 0) * 60 + b.start_time.get("minutes", 0)
return time_a < time_b
#endregion

View File

@ -0,0 +1,16 @@
@tool
extends AbstractRoomRepo
class_name LocalRoomRepo
var _rooms = [
{"id": "67d28e7004bda1d7130c9825", "title": "Маркетинг"},
{"id": "67d28e7004bda1d7130c9826", "title": "Green"},
{"id": "67d28e7004bda1d7130c9827", "title": "Конференц-зал"},
{"id": "67d28e7004bda1d7130c9828", "title": "Dipal"}
]
func _ready():
connected.emit()
func list_rooms():
return _rooms