Added previous date reservation creation blocking

This commit is contained in:
Sviatoslav Tsariov Yurievich 2025-03-27 14:56:24 +03:00
parent 9fabe1a230
commit 6e6a86379b
11 changed files with 35 additions and 24 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":6411152,"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":6411808,"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 = '1743075308|11252545514';
const CACHE_VERSION = '1743076500|1018147123';
/** @type {string} */
const CACHE_PREFIX = 'Talkpal-sw-cache-';
const CACHE_NAME = CACHE_PREFIX + CACHE_VERSION;

View File

@ -203,16 +203,23 @@ func _input(event):
_block_reservation_creation = false
return
if _main.get_current_page() == Main.Pages.Board:
var time = _get_time_by_position(event.position)
_handle_reservation_creation(event)
if _time_is_before_current_time(time) and _selected_date_is_current():
return
func _handle_reservation_creation(event):
if _main.get_current_page() == Main.Pages.Board:
var date = _main.get_selected_date()
if _main.date_is_before_current_date(date):
# error
return
var creation_page = _main.load_page(Main.Pages.ReservationCreation)
creation_page.clean()
creation_page.update()
creation_page.set_start_time(time)
var time = _get_time_by_position(event.position)
if _time_is_before_current_time(time) and _selected_date_is_current():
return
var creation_page = _main.load_page(Main.Pages.ReservationCreation)
creation_page.clean()
creation_page.update()
creation_page.set_start_time(time)
func _get_time_by_position(position):
var hour_size = get_viewport_rect().size.y / 15

View File

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

View File

@ -46,5 +46,8 @@ func get_current_date() -> String:
func is_current_date_selected() -> bool:
return true
func date_is_before_current_date(date: String) -> bool:
return false
func start_date_selection() -> void:
pass

View File

@ -261,6 +261,10 @@ func get_current_date() -> String:
func is_current_date_selected() -> bool:
return get_selected_date() == get_current_date()
func date_is_before_current_date(date: String) -> bool:
var current_date = get_current_date()
return Utils._date_to_number(date) < Utils._date_to_number(current_date)
func get_selected_room() -> RoomEntity:
var room_repo = get_room_repo()
return room_repo.get_selected_room()

View File

@ -92,7 +92,7 @@ size_flags_vertical = 3
[node name="TimeLabel" type="Label" parent="Left/TimeStatusContainer"]
layout_mode = 2
theme = ExtResource("5_atujq")
text = "14:38"
text = "14:44"
horizontal_alignment = 1
[node name="StatusLabel" type="Label" parent="Left/TimeStatusContainer"]

View File

@ -202,7 +202,7 @@ func _time_is_not_entered(start_time: Dictionary, finish_time: Dictionary):
func _time_or_date_is_before_now(start_time: Dictionary):
var time_is_before_now = _time_is_before_current_time(start_time)
var date_is_before_now = _date_is_before_current_date(_date_field.get_value())
var date_is_before_now = _main.date_is_before_current_date(_date_field.get_value())
if time_is_before_now or date_is_before_now:
_error_box.set_message("Нельзя зарезервировать на прошедшее время")
@ -223,16 +223,6 @@ func _time_is_before_current_time(time) -> bool:
return time_in_minutes < current_time_in_minutes
func _date_is_before_current_date(date: String) -> bool:
var current_date = _main.get_current_date()
return _date_to_number(date) < _date_to_number(current_date)
func _date_to_number(date_str: String) -> int:
var parts = date_str.split(".")
assert(parts.size() == 3, "Некорректная дата: " + date_str)
return int(parts[2] + parts[1].lpad(2, "0") + parts[0].lpad(2, "0"))
func _start_time_is_after_finish_time(start_time: Dictionary, finish_time: Dictionary):
var start_time_is_after_finish_time = \
start_time["hours"] > finish_time["hours"] or \

View File

@ -2,7 +2,7 @@
extends AbstractRoomRepo
class_name RoomRepoHTTP
const BASE_URL = "http://localhost:5004"
const BASE_URL = "http://-localhost:5004"
signal rooms_loaded(rooms: Array[RoomEntity])
signal request_failed(error_message: String)

7
src/utils.gd Normal file
View File

@ -0,0 +1,7 @@
class_name Utils
static func _date_to_number(date_str: String) -> int:
var parts = date_str.split(".")
assert(parts.size() == 3, "Некорректная дата: " + date_str)
return int(parts[2] + parts[1].lpad(2, "0") + parts[0].lpad(2, "0"))