105 lines
3.7 KiB
GDScript
105 lines
3.7 KiB
GDScript
class_name BugReportForm
|
|
extends ColorRect
|
|
|
|
signal closed
|
|
|
|
@onready var __version_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/VersionButton
|
|
@onready var __hardware_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/HardwareButton
|
|
@onready var __os_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/OSButton
|
|
@onready var __component_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/ComponentButton
|
|
@onready var __severity_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/SeverityButton
|
|
|
|
@onready var __summary_text : LineEdit = $Form/VBoxContainerRight/GridContainer/SummaryText
|
|
@onready var __description_text : TextEdit = $Form/VBoxContainerRight/GridContainer/DescriptionText
|
|
|
|
var __label_groups : Array
|
|
var __stored_mouse_mode : int
|
|
var __server_api : BugbotServerAPI
|
|
|
|
const __button_disabled_message : StringName = &"Not available"
|
|
|
|
|
|
func _enter_tree():
|
|
__stored_mouse_mode = Input.mouse_mode
|
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
|
|
|
__server_api = BugbotServerAPI._create_new_server_api()
|
|
|
|
func _exit_tree():
|
|
Input.mouse_mode = __stored_mouse_mode
|
|
|
|
|
|
func fill_tags(tag_list:Array):
|
|
__label_groups.resize(BugbotServerAPI.BugbotTagArray.MAX)
|
|
__label_groups = tag_list
|
|
|
|
__fill_item_list(__version_button, BugbotServerAPI.BugbotTagArray.VERSION)
|
|
__fill_item_list(__hardware_button, BugbotServerAPI.BugbotTagArray.HARDWARE)
|
|
__fill_item_list(__os_button, BugbotServerAPI.BugbotTagArray.OS)
|
|
__fill_item_list(__component_button, BugbotServerAPI.BugbotTagArray.COMPONENT)
|
|
__fill_item_list(__severity_button, BugbotServerAPI.BugbotTagArray.SEVERITY)
|
|
|
|
func __fill_item_list(menu_button:MenuButton, label_group:int):
|
|
var menu_options : Array = __label_groups[label_group]
|
|
if menu_options.is_empty():
|
|
menu_button.text = __button_disabled_message
|
|
menu_button.disabled = true
|
|
else:
|
|
var menu : PopupMenu = menu_button.get_popup()
|
|
for i in menu_options.size():
|
|
menu.add_item(menu_options[i]["name"], i)
|
|
menu.id_pressed.connect(func(id:int): menu_button.text = menu_options[id]["name"])
|
|
|
|
|
|
func _on_submit_button_pressed() -> void:
|
|
var error_detected : bool = false
|
|
|
|
var summary_text : String = __summary_text.text
|
|
var description_text : String = __description_text.text
|
|
if summary_text.is_empty():
|
|
printerr("You must fill in a summary.")
|
|
error_detected = true
|
|
if description_text.is_empty():
|
|
printerr("You must fill in a description.")
|
|
error_detected = true
|
|
|
|
var labels_to_be_added : Array
|
|
# Check severity first, since this is a requirement.
|
|
__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.SEVERITY)
|
|
if labels_to_be_added.is_empty():
|
|
printerr("You must select a severity level.")
|
|
error_detected = true
|
|
|
|
if error_detected: return
|
|
|
|
__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.VERSION)
|
|
__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.HARDWARE)
|
|
__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.OS)
|
|
__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.COMPONENT)
|
|
|
|
var bug_report_form_data : Dictionary = {
|
|
"title": summary_text,
|
|
"body": description_text,
|
|
"labels": labels_to_be_added,
|
|
}
|
|
|
|
__server_api._send_form_data(bug_report_form_data, __form_data_response)
|
|
|
|
func __form_data_response(response:Variant):
|
|
print(response)
|
|
|
|
func __get_label_ids_for_submission_data(label_array:Array, label_group_id:int):
|
|
for label in __label_groups[label_group_id]:
|
|
if label["name"] == __severity_button.text:
|
|
label_array.append(label["id"])
|
|
break
|
|
|
|
func __submission_response(response:Array):
|
|
print(response)
|
|
queue_free()
|
|
closed.emit()
|
|
|
|
func _on_cancel_button_pressed() -> void:
|
|
queue_free()
|
|
closed.emit()
|