forked from Support/sp-hydra-veil-gui
Location change for non-ticket subs is now possible if the node is down
This commit is contained in:
parent
a0b39365a3
commit
dfb90d8f3b
6 changed files with 35 additions and 11 deletions
|
|
@ -56,3 +56,8 @@ def navigate_to_singbox_setup() -> Result:
|
||||||
return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="networking_setup")
|
return Result(valid=False, error_type=ResultError.NAVIGATE_TO, navigate_to="networking_setup")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@register_action(ResultError.NODE_ERROR)
|
||||||
|
def down_location_edit_page():
|
||||||
|
print(f"going to the edit page and boolean_value as true, for the location being down.")
|
||||||
|
return Result(valid=False, data=True, error_type=ResultError.NAVIGATE_TO, navigate_to="editor")
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,14 @@ def create_profile(potential_data: dict, ui_caller: Callable):
|
||||||
)
|
)
|
||||||
|
|
||||||
@type_checker
|
@type_checker
|
||||||
def edit_profile(profile_id: int, potential_data: dict, ui_caller: Callable):
|
def edit_profile(profile_id: int, location_down: bool, potential_data: dict, ui_caller: Callable):
|
||||||
"""Pass the data through the plumbing, to edit a profile."""
|
"""Pass the data through the plumbing, to edit a profile."""
|
||||||
take_action(
|
take_action(
|
||||||
action=update_profile,
|
action=update_profile,
|
||||||
ui_caller=ui_caller,
|
ui_caller=ui_caller,
|
||||||
profile_id=profile_id,
|
profile_id=profile_id,
|
||||||
new_choices=potential_data
|
new_choices=potential_data,
|
||||||
|
server_location_change=location_down
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_all_profiles(ui_caller: Callable):
|
def get_all_profiles(ui_caller: Callable):
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class Navigator(QObject):
|
||||||
return getattr(module, class_name)
|
return getattr(module, class_name)
|
||||||
|
|
||||||
|
|
||||||
def _instantiate(self, name, prepared=None, profile_id=None):
|
def _instantiate(self, name, prepared=None, profile_id=None, location_down=None):
|
||||||
cls = self.get_class(name)
|
cls = self.get_class(name)
|
||||||
|
|
||||||
# 1. Inspect the constructor's parameters
|
# 1. Inspect the constructor's parameters
|
||||||
|
|
@ -70,6 +70,10 @@ class Navigator(QObject):
|
||||||
if "prepared" in params:
|
if "prepared" in params:
|
||||||
kwargs["prepared"] = prepared
|
kwargs["prepared"] = prepared
|
||||||
|
|
||||||
|
# Only add location_down if the class accepts it
|
||||||
|
if location_down is not None and "location_down" in params:
|
||||||
|
kwargs["location_down"] = location_down
|
||||||
|
|
||||||
# 3. Instantiate using the filtered dictionary
|
# 3. Instantiate using the filtered dictionary
|
||||||
return cls(**kwargs)
|
return cls(**kwargs)
|
||||||
|
|
||||||
|
|
@ -78,7 +82,7 @@ class Navigator(QObject):
|
||||||
self.page_stack.addWidget(page)
|
self.page_stack.addWidget(page)
|
||||||
self._instances[name] = page
|
self._instances[name] = page
|
||||||
|
|
||||||
def navigate(self, name, profile_id = None):
|
def navigate(self, name, profile_id = None, location_down = None):
|
||||||
page = self._instances.get(name)
|
page = self._instances.get(name)
|
||||||
|
|
||||||
if page is None:
|
if page is None:
|
||||||
|
|
@ -93,6 +97,10 @@ class Navigator(QObject):
|
||||||
logger.info(f"Navigator is setting profile_id data of {profile_id}")
|
logger.info(f"Navigator is setting profile_id data of {profile_id}")
|
||||||
page.profile_id = profile_id
|
page.profile_id = profile_id
|
||||||
|
|
||||||
|
if location_down is not None:
|
||||||
|
logger.info(f"Navigator is setting location_down data of {location_down}")
|
||||||
|
page.location_down = location_down
|
||||||
|
|
||||||
# Make it visible:
|
# Make it visible:
|
||||||
self.page_stack.setCurrentIndex(self.page_stack.indexOf(page))
|
self.page_stack.setCurrentIndex(self.page_stack.indexOf(page))
|
||||||
return page
|
return page
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class PreEdit:
|
||||||
|
|
||||||
|
|
||||||
class RegistrationState:
|
class RegistrationState:
|
||||||
def __init__(self, btn_path, profile_id: Optional[int] = None):
|
def __init__(self, btn_path, profile_id: Optional[int] = None, location_down: Optional[bool] = False):
|
||||||
self.btn_path = btn_path
|
self.btn_path = btn_path
|
||||||
self.all_options = {}
|
self.all_options = {}
|
||||||
self.selections = {}
|
self.selections = {}
|
||||||
|
|
@ -36,6 +36,7 @@ class RegistrationState:
|
||||||
self.proceed = False
|
self.proceed = False
|
||||||
self.warnings_dict = {}
|
self.warnings_dict = {}
|
||||||
self.key_choices = []
|
self.key_choices = []
|
||||||
|
self.location_down = location_down
|
||||||
|
|
||||||
# Maps a category to the function that validates its current selection.
|
# Maps a category to the function that validates its current selection.
|
||||||
self._filter_map = {
|
self._filter_map = {
|
||||||
|
|
@ -341,7 +342,8 @@ class RegistrationState:
|
||||||
# 2. Map keys to their specific warning messages
|
# 2. Map keys to their specific warning messages
|
||||||
WARNING_MESSAGES = {
|
WARNING_MESSAGES = {
|
||||||
"location": lambda: "If you change the location, it wipes the subscription, proceed?"
|
"location": lambda: "If you change the location, it wipes the subscription, proceed?"
|
||||||
if not profile_can_respawn(self.profile_id).valid
|
if not self.location_down
|
||||||
|
and not profile_can_respawn(self.profile_id).valid
|
||||||
and profile_can_respawn(self.profile_id).error_type != ResultError.SUBSCRIPTION
|
and profile_can_respawn(self.profile_id).error_type != ResultError.SUBSCRIPTION
|
||||||
else None,
|
else None,
|
||||||
"browser": lambda: "If you change the browser, it wipes the cookies/bookmarks, proceed?"
|
"browser": lambda: "If you change the browser, it wipes the cookies/bookmarks, proceed?"
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,10 @@ from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
class EditPage(Page):
|
class EditPage(Page):
|
||||||
def __init__(self, page_stack, main_window, prepared=None, profile_id: Optional[int] = None):
|
def __init__(self, page_stack, main_window, prepared=None, profile_id: Optional[int] = None, location_down: Optional[bool] = False):
|
||||||
super().__init__("EditPage", page_stack, main_window)
|
super().__init__("EditPage", page_stack, main_window)
|
||||||
self.profile_id = profile_id
|
self.profile_id = profile_id
|
||||||
|
self.location_down = location_down
|
||||||
|
|
||||||
# 1. Permanent Structure: Created once in init
|
# 1. Permanent Structure: Created once in init
|
||||||
self.content_area = QWidget()
|
self.content_area = QWidget()
|
||||||
|
|
@ -62,7 +63,7 @@ class EditPage(Page):
|
||||||
|
|
||||||
# 2. State Reset: Wipe old widgets and old state
|
# 2. State Reset: Wipe old widgets and old state
|
||||||
self.clear_ui()
|
self.clear_ui()
|
||||||
self.state = RegistrationState(btn_path=self.btn_path, profile_id=profile_id)
|
self.state = RegistrationState(btn_path=self.btn_path, profile_id=profile_id, location_down=self.location_down)
|
||||||
print("Created a new RegistrationState")
|
print("Created a new RegistrationState")
|
||||||
|
|
||||||
# 3. Create groups, passing the category string and the state object
|
# 3. Create groups, passing the category string and the state object
|
||||||
|
|
@ -143,18 +144,19 @@ class EditPage(Page):
|
||||||
|
|
||||||
def proceed_with_edit(self, different_content):
|
def proceed_with_edit(self, different_content):
|
||||||
|
|
||||||
print(f"different_content is {different_content}")
|
print(f"different_content is {different_content} and self.location_down is {self.location_down}")
|
||||||
|
|
||||||
edit_profile(
|
edit_profile(
|
||||||
profile_id=self.profile_id,
|
profile_id=self.profile_id,
|
||||||
potential_data=different_content,
|
potential_data=different_content,
|
||||||
|
location_down=self.location_down,
|
||||||
ui_caller=self.after_submission
|
ui_caller=self.after_submission
|
||||||
)
|
)
|
||||||
self.created_display = False
|
self.created_display = False
|
||||||
|
|
||||||
|
|
||||||
def submit_edits(self):
|
def submit_edits(self):
|
||||||
print("submit_edits")
|
print(f"submit_edits with self.location as {self.location_down}")
|
||||||
# name
|
# name
|
||||||
input_text = self.group_name.text_input.text()
|
input_text = self.group_name.text_input.text()
|
||||||
if not input_text:
|
if not input_text:
|
||||||
|
|
|
||||||
|
|
@ -684,7 +684,13 @@ class MenuPage(Page):
|
||||||
def deal_with_errors(self, result: Result):
|
def deal_with_errors(self, result: Result):
|
||||||
if result.error_type == ResultError.NAVIGATE_TO:
|
if result.error_type == ResultError.NAVIGATE_TO:
|
||||||
print(f"We are auto-navigating to page {result.navigate_to}")
|
print(f"We are auto-navigating to page {result.navigate_to}")
|
||||||
self.custom_window.navigator.navigate(result.navigate_to)
|
if result.navigate_to == "editor" and result.data:
|
||||||
|
print("going to editor page with a different location")
|
||||||
|
profile_id = self.reverse_id
|
||||||
|
print(f"profile_id is {profile_id}")
|
||||||
|
self.custom_window.navigator.navigate(name="editor", profile_id=profile_id, location_down=result.data)
|
||||||
|
else:
|
||||||
|
self.custom_window.navigator.navigate(name=result.navigate_to)
|
||||||
|
|
||||||
elif result.error_type == ResultError.SUBSCRIPTION:
|
elif result.error_type == ResultError.SUBSCRIPTION:
|
||||||
print("We are navigating to the subscription page")
|
print("We are navigating to the subscription page")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue