def show_run_sequence_from_component_prompt(client_state, username, sequence_id, component_id): ''' Function expects a client state, a string username, an integer sequence id, and an integer component_id to be passed in as parameters. Function calls the save client and return function and returns the output of the function. ''' # Load the sequence and find the component sequence = sequence_manager.GetSequence(username, sequence_id, False) component = None index = 1 for seq_component in sequence["components"]: if seq_component["id"] == component_id: component = seq_component break index += 1 if component == None: raise Exception("Component " + str(component_id) + " not found in sequence " + str(sequence_id)) # Adjust the component index for the cassettes index -= db.get_configuration()["reactors"] # Fill in the state client_state["prompt"]["screen"] = "PROMPT_RUNSEQUENCEFROMCOMPONENT" client_state["prompt"]["show"] = True client_state["prompt"]["title"] = "RUN SEQUENCE" client_state["prompt"]["text1"] = \ "Would you like to run the sequence \"" + \ str(sequence["metadata"]["name"]) + \ "\" starting with unit operation number " + str(index) + \ " (" + component["componenttype"] + ")?" client_state["prompt"]["edit1"] = False client_state["prompt"]["text2"] = "" client_state["prompt"]["edit2"] = False client_state["prompt"]["buttons"] = [{"type":"button", "text":"YES", "id":"YES"}, {"type":"button", "text":"NO", "id":"NO"}] client_state["sequenceid"] = sequence_id return save_client_state_and_return( client_state, username)
def config_index(): ''' Function shall expect no parameters. Function shall return a config object as a JSON object. Function shall query the database and obtain the config object from the db. ''' # Handle GET /configuration current_app.logger.debug(str(request)) auth = request.authorization user = db.get_user(auth.username) config = {"type": "configuration"} config.update(db.get_configuration()) config.update({"supportedoperations": db.get_supported_operations()}) current_app.logger.debug(str(config)) return jsonify(config)
def config_index(): """ Function shall expect no parameters. Function shall return a config object as a JSON object. Function shall query the database and obtain the config object from the db. """ # Handle GET /configuration current_app.logger.debug(str(request)) auth = request.authorization user = db.get_user(auth.username) config = {"type": "configuration"} config.update(db.get_configuration()) config.update({"supportedoperations": db.get_supported_operations()}) current_app.logger.debug(str(config)) return jsonify(config)
def prompt_post_index(): ''' Function shall handle POST /VIEW requests from the client. Function expects no parameters to be passed in. Function returns the output of the save client and return function. ''' # Get objects auth = request.authorization username = str(auth.username) server_state = get_server_state(username) client_state = getCurrentClientState(username) # Get POST object # body = ... obtain POST object sent body = request.data current_app.logger.debug("POST REQUEST:" + str(request) + \ "\nBody Sent: " + str(request.data) + \ "\nclientstate: " + str(client_state) + \ "\nserverstate: " + str(server_state)) if (not client_state["prompt"]["show"] or not client_state["prompt"]["screen"].startswith("PROMPT")): current_app.logger.error("Client[prompt][show] is False, raising " + "State Misalignment Exception") raise Exceptions.StateMisalignmentException() # Parse the JSON string in the body JSON_body = json.loads(body) # Extract the post parameters action_type = str(JSON_body["action"]["type"]) action_target_id = str(JSON_body["action"]["targetid"]) edit1 = str(JSON_body["edit1"]) edit2 = str(JSON_body["edit2"]) # The only recognized action from a prompt is a button click if action_type != "BUTTONCLICK": raise Exceptions.StateMisalignmentException() # Interpret the response in context of the client state if client_state["prompt"]["screen"] == "PROMPT_CREATESEQUENCE": if action_target_id == "OK": # Sequence name is required if edit1 == "": raise Exception("Sequence name is required") # Create the new sequence configuration = db.get_configuration() sequence_id = db.create_sequence( edit1, username, edit2, "Saved", configuration["reactors"], configuration["reagentsperreactor"]) # Hide the prompt and move the client to the editing the new sequence client_state["prompt"]["show"] = False client_state["screen"] = "EDIT" client_state["sequenceid"] = sequence_id current_app.logger.debug("Created a new sequence, calling" + "save_client...from POST /PROMPT" + \ "\nSequence id returned : " + str(sequence_id) + \ "\nClient State: " + str(client_state)) return save_client_state_and_return( client_state, username) if action_target_id == "CANCEL": # Hide the prompt client_state["prompt"]["show"] = False return save_client_state_and_return( client_state, username) elif client_state["prompt"]["screen"] == "PROMPT_COPYSEQUENCE": if action_target_id == "OK": # Sequence name is required if edit1 == "": raise Exception("Sequence name is required") # create a copy of the sequence in the database new_sequence_id = sequence_manager.CopySequence( username, int(client_state["sequenceid"]), str(edit1), str(edit2)) # Hide the prompt and move the client to the saved sequences screen client_state["prompt"]["show"] = False client_state["screen"] = "SELECT_SAVEDSEQUENCES" client_state["lastselectscreen"] = "SAVED" return save_client_state_and_return( client_state, username) if action_target_id == "CANCEL": # Hide the prompt client_state["prompt"]["show"] = False return save_client_state_and_return( client_state, username) elif client_state["prompt"]["screen"] == "PROMPT_DELETESEQUENCE": if action_target_id == "YES": # Delete the sequence from the database db.delete_sequence(client_state["sequenceid"]) # Hide the prompt client_state["prompt"]["show"] = False return save_client_state_and_return( client_state, username) if action_target_id == "NO": # Hide the prompt client_state["prompt"]["show"] = False return save_client_state_and_return( client_state, username) elif client_state["prompt"]["screen"] == "PROMPT_RUNSEQUENCE": if action_target_id == "YES": # Fetch the sequence from the database and make sure it is valid sequence = sequence_manager.GetSequence( username, client_state["sequenceid"]) if not sequence["metadata"]["valid"]: raise Exceptions.InvalidSequenceException( str(client_state['sequenceid'])) # Run the sequence core_server.RunSequence(username, client_state["sequenceid"]) # Hide the prompt and switch states to Run Sequence client_state["prompt"]["show"] = False client_state["screen"] = "RUN" current_app.logger.debug("From POST /PROMPT, calling save client") return save_client_state_and_return( client_state, username) if action_target_id == "NO": # Hide the prompt client_state["prompt"]["show"] = False return save_client_state_and_return( client_state, username) elif client_state["prompt"]["screen"] == "PROMPT_RUNSEQUENCEFROMCOMPONENT": if action_target_id == "YES": # Fetch the sequence from the database and make sure it is valid sequence = sequence_manager.GetSequence( username, int(client_state["sequenceid"])) if not sequence["metadata"]["valid"]: raise Exceptions.InvalidSequenceException(client_state['sequenceid']) # Run the sequence from the component core_server.RunSequenceFromComponent(username, client_state["sequenceid"], client_state["componentid"]) # Hide the prompt and switch states to Run Sequence client_state["prompt"]["show"] = False client_state["screen"] = "RUN" return save_client_state_and_return( client_state, username) if action_target_id == "NO": # Hide the prompt client_state["prompt"]["show"] = False return save_client_state_and_return( client_state, username) elif client_state["prompt"]["screen"] == "PROMPT_UNITOPERATION": # Currently unused return save_client_state_and_return( client_state, username) elif client_state["prompt"]["screen"] == "PROMPT_SOFTERROR": # Pass the user's decision to the core server core_server.SetSoftErrorDecision(username, action_target_id) elif client_state["prompt"]["screen"] == "PROMPT_ABORTRUN": if action_target_id == "YES": # Abort the run and return to the home page core_server.AbortSequence(username) client_state["prompt"]["show"] = False client_state["screen"] = "HOME" return save_client_state_and_return( client_state, username) if action_target_id == "NO": # Hide the prompt core_server.ShowAbortSequencePrompt(username, False) return save_client_state_and_return( client_state, username) # Unhandled use case raise Exceptions.StateMisalignmentException()