Spaces:
Sleeping
Sleeping
Update refApp.py
Browse files
refApp.py
CHANGED
|
@@ -1933,7 +1933,256 @@ elif st.session_state.view_mode == "generator":
|
|
| 1933 |
should_expand_config = SHOW_CONFIG_SECTION and st.session_state.get('go_to_config_section', False)
|
| 1934 |
if SHOW_CONFIG_SECTION:
|
| 1935 |
with st.expander(f"⚙️ Paramétrage du Prompt: {generator_use_case}", expanded=should_expand_config):
|
| 1936 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1937 |
|
| 1938 |
if st.session_state.get('go_to_config_section'):
|
| 1939 |
st.session_state.go_to_config_section = False
|
|
|
|
| 1933 |
should_expand_config = SHOW_CONFIG_SECTION and st.session_state.get('go_to_config_section', False)
|
| 1934 |
if SHOW_CONFIG_SECTION:
|
| 1935 |
with st.expander(f"⚙️ Paramétrage du Prompt: {generator_use_case}", expanded=should_expand_config):
|
| 1936 |
+
st.subheader("Template du Prompt")
|
| 1937 |
+
safe_family_key_part = str(generator_family).replace(' ', '_').replace('.', '_').replace('{', '_').replace('}', '_').replace('(', '_').replace(')', '_')
|
| 1938 |
+
safe_uc_key_part = str(generator_use_case).replace(' ', '_').replace('.', '_').replace('{', '_').replace('}', '_').replace('(', '_').replace(')', '_')
|
| 1939 |
+
template_text_area_key = f"template_text_area_{safe_family_key_part}_{safe_uc_key_part}"; new_tpl = st.text_area("Template:", value=current_prompt_config.get('template', ''), height=200, key=template_text_area_key)
|
| 1940 |
+
# Description
|
| 1941 |
+
new_desc = st.text_area("Description (aide pour l'utilisateur):", value=current_prompt_config.get('description', ''), height=100, key=f"desc_text_area_{safe_family_key_part}_{safe_uc_key_part}")
|
| 1942 |
+
st.markdown("""<style> div[data-testid=\"stExpander\"] div[data-testid=\"stCodeBlock\"] { margin-top: 0.1rem !important; margin-bottom: 0.15rem !important; padding-top: 0.1rem !important; padding-bottom: 0.1rem !important; } div[data-testid=\"stExpander\"] div[data-testid=\"stCodeBlock\"] pre { padding-top: 0.2rem !important; padding-bottom: 0.2rem !important; line-height: 1.1 !important; font-size: 0.85em !important; margin: 0 !important; } </style>""", unsafe_allow_html=True)
|
| 1943 |
+
st.markdown("##### Variables disponibles à insérer :"); variables_config = current_prompt_config.get('variables', [])
|
| 1944 |
+
if not variables_config: st.caption("Aucune variable définie pour ce prompt. Ajoutez-en ci-dessous.")
|
| 1945 |
+
else:
|
| 1946 |
+
col1, col2 = st.columns(2)
|
| 1947 |
+
for i, var_info in enumerate(variables_config):
|
| 1948 |
+
if 'name' in var_info:
|
| 1949 |
+
variable_string_to_display = f"{{{var_info['name']}}}"; target_column = col1 if i % 2 == 0 else col2
|
| 1950 |
+
with target_column: st.code(variable_string_to_display, language=None)
|
| 1951 |
+
st.caption("Survolez une variable ci-dessus et cliquez sur l'icône qui apparaît pour la copier.")
|
| 1952 |
+
save_template_button_key = f"save_template_button_{safe_family_key_part}_{safe_uc_key_part}"
|
| 1953 |
+
if st.button("Sauvegarder Template & Description", key=save_template_button_key):
|
| 1954 |
+
current_prompt_config['template'] = new_tpl
|
| 1955 |
+
current_prompt_config['description'] = new_desc
|
| 1956 |
+
current_prompt_config["updated_at"] = datetime.now().isoformat()
|
| 1957 |
+
save_editable_prompts_to_local()
|
| 1958 |
+
st.success("Template et Description sauvegardés!");
|
| 1959 |
+
st.rerun()
|
| 1960 |
+
st.markdown("---"); st.subheader("Variables du Prompt"); current_variables_list = current_prompt_config.get('variables', [])
|
| 1961 |
+
if not current_variables_list: st.info("Aucune variable définie.")
|
| 1962 |
+
else: pass
|
| 1963 |
+
for idx, var_data in enumerate(list(current_variables_list)):
|
| 1964 |
+
var_id_for_key = var_data.get('name', f"varidx{idx}").replace(" ", "_"); action_key_prefix = f"var_action_{generator_family.replace(' ','_')}_{generator_use_case.replace(' ','_')}_{var_id_for_key}"
|
| 1965 |
+
col_info, col_up, col_down, col_edit, col_delete = st.columns([3, 0.5, 0.5, 0.8, 0.8])
|
| 1966 |
+
with col_info: st.markdown(f"**{idx + 1}. {var_data.get('name', 'N/A')}** ({var_data.get('label', 'N/A')})\n*Type: `{var_data.get('type', 'N/A')}`*")
|
| 1967 |
+
with col_up:
|
| 1968 |
+
disable_up_button = (idx == 0)
|
| 1969 |
+
if st.button("↑", key=f"{action_key_prefix}_up", help="Monter cette variable", disabled=disable_up_button, use_container_width=True): current_variables_list[idx], current_variables_list[idx-1] = current_variables_list[idx-1], current_variables_list[idx]; current_prompt_config["variables"] = current_variables_list; current_prompt_config["updated_at"] = datetime.now().isoformat(); save_editable_prompts_to_local(); st.session_state.editing_variable_info = None; st.session_state.variable_type_to_create = None; st.rerun()
|
| 1970 |
+
with col_down:
|
| 1971 |
+
disable_down_button = (idx == len(current_variables_list) - 1)
|
| 1972 |
+
if st.button("↓", key=f"{action_key_prefix}_down", help="Descendre cette variable", disabled=disable_down_button, use_container_width=True): current_variables_list[idx], current_variables_list[idx+1] = current_variables_list[idx+1], current_variables_list[idx]; current_prompt_config["variables"] = current_variables_list; current_prompt_config["updated_at"] = datetime.now().isoformat(); save_editable_prompts_to_local(); st.session_state.editing_variable_info = None; st.session_state.variable_type_to_create = None; st.rerun()
|
| 1973 |
+
with col_edit:
|
| 1974 |
+
if st.button("Modifier", key=f"{action_key_prefix}_edit", use_container_width=True): st.session_state.editing_variable_info = { "family": generator_family, "use_case": generator_use_case, "index": idx, "data": copy.deepcopy(var_data) }; st.session_state.variable_type_to_create = var_data.get('type'); st.rerun()
|
| 1975 |
+
with col_delete:
|
| 1976 |
+
if st.button("Suppr.", key=f"{action_key_prefix}_delete", type="secondary", use_container_width=True): variable_name_to_delete = current_variables_list.pop(idx).get('name', 'Variable inconnue'); current_prompt_config["variables"] = current_variables_list; current_prompt_config["updated_at"] = datetime.now().isoformat(); save_editable_prompts_to_local(); st.success(f"Variable '{variable_name_to_delete}' supprimée."); st.session_state.editing_variable_info = None; st.session_state.variable_type_to_create = None; st.rerun()
|
| 1977 |
+
st.markdown("---"); st.subheader("Ajouter une Variable"); is_editing_var = False; variable_data_for_form = {"name": "", "label": "", "type": "", "options": "", "default": ""}
|
| 1978 |
+
if st.session_state.editing_variable_info and st.session_state.editing_variable_info.get("family") == generator_family and st.session_state.editing_variable_info.get("use_case") == generator_use_case:
|
| 1979 |
+
edit_var_idx = st.session_state.editing_variable_info["index"]
|
| 1980 |
+
if edit_var_idx < len(current_prompt_config.get('variables',[])):
|
| 1981 |
+
is_editing_var = True; current_editing_data_snapshot = current_prompt_config['variables'][edit_var_idx]; variable_data_for_form.update(copy.deepcopy(current_editing_data_snapshot))
|
| 1982 |
+
if isinstance(variable_data_for_form.get("options"), list): variable_data_for_form["options"] = ", ".join(map(str, variable_data_for_form["options"]))
|
| 1983 |
+
raw_def_edit_form = variable_data_for_form.get("default")
|
| 1984 |
+
if isinstance(raw_def_edit_form, date): variable_data_for_form["default"] = raw_def_edit_form.strftime("%Y-%m-%d")
|
| 1985 |
+
elif raw_def_edit_form is not None: variable_data_for_form["default"] = str(raw_def_edit_form)
|
| 1986 |
+
else: variable_data_for_form["default"] = ""
|
| 1987 |
+
else: st.session_state.editing_variable_info = None; st.session_state.variable_type_to_create = None; st.warning("La variable que vous tentiez de modifier n'existe plus. Annulation de l'édition."); st.rerun() # pragma: no cover
|
| 1988 |
+
if not is_editing_var and st.session_state.variable_type_to_create is None:
|
| 1989 |
+
st.markdown("##### 1. Choisissez le type de variable à créer :"); variable_types_map = { "Zone de texte (courte)": "text_input", "Liste choix": "selectbox", "Date": "date_input", "Nombre": "number_input", "Zone de texte (longue)": "text_area" }; num_type_buttons = len(variable_types_map); cols_type_buttons = st.columns(min(num_type_buttons, 5)); button_idx = 0
|
| 1990 |
+
for btn_label, type_val in variable_types_map.items():
|
| 1991 |
+
if cols_type_buttons[button_idx % len(cols_type_buttons)].button(btn_label, key=f"btn_type_{type_val}_{generator_use_case.replace(' ','_')}", use_container_width=True): st.session_state.variable_type_to_create = type_val; st.rerun()
|
| 1992 |
+
button_idx += 1
|
| 1993 |
+
st.markdown("---")
|
| 1994 |
+
if st.session_state.variable_type_to_create:
|
| 1995 |
+
current_type_for_form = st.session_state.variable_type_to_create
|
| 1996 |
+
variable_types_map_display = {
|
| 1997 |
+
"text_input": "Zone de texte (courte)", "selectbox": "Liste choix",
|
| 1998 |
+
"date_input": "Date", "number_input": "Nombre", "text_area": "Zone de texte (longue)"
|
| 1999 |
+
}
|
| 2000 |
+
readable_type = variable_types_map_display.get(current_type_for_form, "Type Inconnu")
|
| 2001 |
+
form_title = f"Modifier Variable : {variable_data_for_form.get('name','N/A')} ({readable_type})" if is_editing_var else f"Nouvelle Variable : {readable_type}"
|
| 2002 |
+
st.markdown(f"##### 2. Configurez la variable")
|
| 2003 |
+
|
| 2004 |
+
form_key_suffix = f"_edit_{st.session_state.editing_variable_info['index']}" if is_editing_var and st.session_state.editing_variable_info else "_create"
|
| 2005 |
+
form_var_specific_key = f"form_var_{current_type_for_form}_{generator_use_case.replace(' ','_')}{form_key_suffix}"
|
| 2006 |
+
|
| 2007 |
+
with st.form(key=form_var_specific_key, clear_on_submit=(not is_editing_var)):
|
| 2008 |
+
st.subheader(form_title)
|
| 2009 |
+
var_name_input_form = st.text_input(
|
| 2010 |
+
"Nom technique (ex : nom_client. Sans espaces, accents ou caractères spéciaux)",
|
| 2011 |
+
value=variable_data_for_form.get("name", ""),
|
| 2012 |
+
key=f"{form_var_specific_key}_name",
|
| 2013 |
+
disabled=is_editing_var
|
| 2014 |
+
)
|
| 2015 |
+
var_label_input_form = st.text_input(
|
| 2016 |
+
"Label pour l'utilisateur (description affichée)",
|
| 2017 |
+
value=variable_data_for_form.get("label", ""),
|
| 2018 |
+
key=f"{form_var_specific_key}_label"
|
| 2019 |
+
)
|
| 2020 |
+
var_options_str_input_form = ""
|
| 2021 |
+
if current_type_for_form == "selectbox":
|
| 2022 |
+
var_options_str_input_form = st.text_input(
|
| 2023 |
+
"Options (séparées par une virgule)",
|
| 2024 |
+
value=variable_data_for_form.get("options", ""),
|
| 2025 |
+
key=f"{form_var_specific_key}_options"
|
| 2026 |
+
)
|
| 2027 |
+
date_hint = " (Format AAAA-MM-JJ)" if current_type_for_form == "date_input" else ""
|
| 2028 |
+
var_default_val_str_input_form = st.text_input(
|
| 2029 |
+
f"Valeur par défaut{date_hint}",
|
| 2030 |
+
value=str(variable_data_for_form.get("default", "")),
|
| 2031 |
+
key=f"{form_var_specific_key}_default"
|
| 2032 |
+
)
|
| 2033 |
+
|
| 2034 |
+
min_val_input_form, max_val_input_form, step_val_input_form, height_val_input_form = None, None, None, None
|
| 2035 |
+
if current_type_for_form == "number_input":
|
| 2036 |
+
num_cols_var_form = st.columns(3)
|
| 2037 |
+
min_val_edit_default = variable_data_for_form.get("min_value")
|
| 2038 |
+
max_val_edit_default = variable_data_for_form.get("max_value")
|
| 2039 |
+
step_val_edit_default = variable_data_for_form.get("step", 1.0)
|
| 2040 |
+
min_val_input_form = num_cols_var_form[0].number_input("Valeur minimale (optionnel)", value=float(min_val_edit_default) if min_val_edit_default is not None else None, format="%g", key=f"{form_var_specific_key}_min")
|
| 2041 |
+
max_val_input_form = num_cols_var_form[1].number_input("Valeur maximale (optionnel)", value=float(max_val_edit_default) if max_val_edit_default is not None else None, format="%g", key=f"{form_var_specific_key}_max")
|
| 2042 |
+
step_val_input_form = num_cols_var_form[2].number_input("Pas (incrément)", value=float(step_val_edit_default), format="%g", min_value=1e-9, key=f"{form_var_specific_key}_step")
|
| 2043 |
+
if current_type_for_form == "text_area":
|
| 2044 |
+
height_val_input_form = st.number_input("Hauteur de la zone de texte (pixels)", value=int(variable_data_for_form.get("height", 100)), min_value=68, step=25, key=f"{form_var_specific_key}_height")
|
| 2045 |
+
|
| 2046 |
+
submit_button_label_form = "Sauvegarder Modifications" if is_editing_var else "Ajouter Variable"
|
| 2047 |
+
submitted_specific_var_form = st.form_submit_button(submit_button_label_form)
|
| 2048 |
+
|
| 2049 |
+
if submitted_specific_var_form:
|
| 2050 |
+
var_name_val_submit = var_name_input_form.strip()
|
| 2051 |
+
if not var_name_val_submit or not var_label_input_form.strip(): st.error("Le nom technique et le label de la variable sont requis.")
|
| 2052 |
+
elif not var_name_val_submit.isidentifier(): st.error("Nom technique invalide. Utilisez lettres, chiffres, underscores. Ne pas commencer par un chiffre. Ne pas utiliser de mot-clé Python.")
|
| 2053 |
+
elif current_type_for_form == "selectbox" and not [opt.strip() for opt in var_options_str_input_form.split(',') if opt.strip()]: st.error("Pour une variable de type 'Liste choix', au moins une option est requise.")
|
| 2054 |
+
else:
|
| 2055 |
+
new_var_data_to_submit = { "name": var_name_val_submit, "label": var_label_input_form.strip(), "type": current_type_for_form }; parsed_def_val_submit = parse_default_value(var_default_val_str_input_form.strip(), current_type_for_form)
|
| 2056 |
+
if current_type_for_form == "selectbox":
|
| 2057 |
+
options_list_submit = [opt.strip() for opt in var_options_str_input_form.split(',') if opt.strip()]; new_var_data_to_submit["options"] = options_list_submit
|
| 2058 |
+
if options_list_submit:
|
| 2059 |
+
if parsed_def_val_submit not in options_list_submit: st.warning(f"La valeur par défaut '{parsed_def_val_submit}' n'est pas dans la liste d'options. La première option '{options_list_submit[0]}' sera utilisée comme défaut."); new_var_data_to_submit["default"] = options_list_submit[0]
|
| 2060 |
+
else: new_var_data_to_submit["default"] = parsed_def_val_submit
|
| 2061 |
+
else: new_var_data_to_submit["default"] = ""
|
| 2062 |
+
else: new_var_data_to_submit["default"] = parsed_def_val_submit
|
| 2063 |
+
if current_type_for_form == "number_input":
|
| 2064 |
+
if min_val_input_form is not None: new_var_data_to_submit["min_value"] = float(min_val_input_form)
|
| 2065 |
+
if max_val_input_form is not None: new_var_data_to_submit["max_value"] = float(max_val_input_form)
|
| 2066 |
+
if step_val_input_form is not None: new_var_data_to_submit["step"] = float(step_val_input_form)
|
| 2067 |
+
else: new_var_data_to_submit["step"] = 1.0
|
| 2068 |
+
if current_type_for_form == "text_area" and height_val_input_form is not None:
|
| 2069 |
+
new_var_data_to_submit["height"] = int(height_val_input_form)
|
| 2070 |
+
|
| 2071 |
+
can_proceed_with_save = True; target_vars_list = current_prompt_config.get('variables', [])
|
| 2072 |
+
if is_editing_var:
|
| 2073 |
+
idx_to_edit_submit_form = st.session_state.editing_variable_info["index"]; target_vars_list[idx_to_edit_submit_form] = new_var_data_to_submit; st.success(f"Variable '{var_name_val_submit}' mise à jour avec succès."); st.session_state.editing_variable_info = None; st.session_state.variable_type_to_create = None
|
| 2074 |
+
else:
|
| 2075 |
+
existing_var_names_in_uc = [v['name'] for v in target_vars_list]
|
| 2076 |
+
if var_name_val_submit in existing_var_names_in_uc: st.error(f"Une variable avec le nom technique '{var_name_val_submit}' existe déjà pour ce cas d'usage."); can_proceed_with_save = False
|
| 2077 |
+
else: target_vars_list.append(new_var_data_to_submit); st.success(f"Variable '{var_name_val_submit}' ajoutée avec succès.")
|
| 2078 |
+
if can_proceed_with_save:
|
| 2079 |
+
current_prompt_config["variables"] = target_vars_list; current_prompt_config["updated_at"] = datetime.now().isoformat(); save_editable_prompts_to_local()
|
| 2080 |
+
if not is_editing_var: st.session_state.variable_type_to_create = None
|
| 2081 |
+
st.rerun()
|
| 2082 |
+
|
| 2083 |
+
cancel_button_label_form = "Annuler Modification" if is_editing_var else "Changer de Type / Annuler Création"
|
| 2084 |
+
cancel_btn_key = f"cancel_var_action_btn_{form_var_specific_key}_outside"
|
| 2085 |
+
|
| 2086 |
+
if st.button(cancel_button_label_form, key=cancel_btn_key, help="Réinitialise le formulaire de variable."):
|
| 2087 |
+
st.session_state.variable_type_to_create = None
|
| 2088 |
+
if is_editing_var:
|
| 2089 |
+
st.session_state.editing_variable_info = None
|
| 2090 |
+
st.rerun()
|
| 2091 |
+
st.markdown("---"); st.subheader("🏷️ Tags"); current_tags_str = ", ".join(current_prompt_config.get("tags", []))
|
| 2092 |
+
new_tags_str_input = st.text_input("Tags (séparés par des virgules):", value=current_tags_str, key=f"tags_input_{generator_family}_{generator_use_case}")
|
| 2093 |
+
if st.button("Sauvegarder Tags", key=f"save_tags_btn_{generator_family}_{generator_use_case}"): current_prompt_config["tags"] = sorted(list(set(t.strip() for t in new_tags_str_input.split(',') if t.strip()))); current_prompt_config["updated_at"] = datetime.now().isoformat(); save_editable_prompts_to_local(); st.success("Tags sauvegardés!"); st.rerun()
|
| 2094 |
+
|
| 2095 |
+
st.markdown("---")
|
| 2096 |
+
st.subheader("Actions sur le Cas d'Usage")
|
| 2097 |
+
|
| 2098 |
+
if st.session_state.duplicating_use_case_details and \
|
| 2099 |
+
st.session_state.duplicating_use_case_details["family"] == generator_family and \
|
| 2100 |
+
st.session_state.duplicating_use_case_details["use_case"] == generator_use_case:
|
| 2101 |
+
|
| 2102 |
+
original_uc_name_for_dup_form = st.session_state.duplicating_use_case_details["use_case"]
|
| 2103 |
+
original_family_name_for_dup = st.session_state.duplicating_use_case_details["family"]
|
| 2104 |
+
st.markdown(f"#### Dupliquer '{original_uc_name_for_dup_form}' (depuis: {original_family_name_for_dup})")
|
| 2105 |
+
|
| 2106 |
+
form_key_duplicate = f"form_duplicate_name_{original_family_name_for_dup.replace(' ','_')}_{original_uc_name_for_dup_form.replace(' ','_')}"
|
| 2107 |
+
with st.form(key=form_key_duplicate):
|
| 2108 |
+
available_families_list = list(st.session_state.editable_prompts.keys())
|
| 2109 |
+
try:
|
| 2110 |
+
default_family_idx = available_families_list.index(original_family_name_for_dup)
|
| 2111 |
+
except ValueError:
|
| 2112 |
+
default_family_idx = 0
|
| 2113 |
+
|
| 2114 |
+
selected_target_family_for_duplicate = st.selectbox(
|
| 2115 |
+
"Choisir la famille de destination pour la copie :",
|
| 2116 |
+
options=available_families_list,
|
| 2117 |
+
index=default_family_idx,
|
| 2118 |
+
key=f"target_family_dup_select_{form_key_duplicate}"
|
| 2119 |
+
)
|
| 2120 |
+
|
| 2121 |
+
suggested_new_name_base = f"{original_uc_name_for_dup_form} (copie)"
|
| 2122 |
+
suggested_new_name = suggested_new_name_base
|
| 2123 |
+
temp_copy_count = 1
|
| 2124 |
+
while suggested_new_name in st.session_state.editable_prompts.get(selected_target_family_for_duplicate, {}):
|
| 2125 |
+
suggested_new_name = f"{suggested_new_name_base} {temp_copy_count}"
|
| 2126 |
+
temp_copy_count += 1
|
| 2127 |
+
|
| 2128 |
+
new_duplicated_uc_name_input = st.text_input(
|
| 2129 |
+
"Nouveau nom pour le cas d'usage dupliqué:",
|
| 2130 |
+
value=suggested_new_name,
|
| 2131 |
+
key=f"new_dup_name_input_{form_key_duplicate}"
|
| 2132 |
+
)
|
| 2133 |
+
|
| 2134 |
+
submitted_duplicate_form = st.form_submit_button("✅ Confirmer la Duplication", use_container_width=True)
|
| 2135 |
+
|
| 2136 |
+
if submitted_duplicate_form:
|
| 2137 |
+
new_uc_name_val_from_form = new_duplicated_uc_name_input.strip()
|
| 2138 |
+
target_family_on_submit = selected_target_family_for_duplicate
|
| 2139 |
+
|
| 2140 |
+
if not new_uc_name_val_from_form:
|
| 2141 |
+
st.error("Le nom du nouveau cas d'usage ne peut pas être vide.")
|
| 2142 |
+
elif new_uc_name_val_from_form in st.session_state.editable_prompts.get(target_family_on_submit, {}):
|
| 2143 |
+
st.error(f"Un cas d'usage nommé '{new_uc_name_val_from_form}' existe déjà dans la famille '{target_family_on_submit}'.")
|
| 2144 |
+
else:
|
| 2145 |
+
st.session_state.editable_prompts[target_family_on_submit][new_uc_name_val_from_form] = copy.deepcopy(current_prompt_config)
|
| 2146 |
+
now_iso_dup_create, now_iso_dup_update = get_default_dates()
|
| 2147 |
+
st.session_state.editable_prompts[target_family_on_submit][new_uc_name_val_from_form]["created_at"] = now_iso_dup_create
|
| 2148 |
+
st.session_state.editable_prompts[target_family_on_submit][new_uc_name_val_from_form]["updated_at"] = now_iso_dup_update
|
| 2149 |
+
st.session_state.editable_prompts[target_family_on_submit][new_uc_name_val_from_form]["usage_count"] = 0
|
| 2150 |
+
save_editable_prompts_to_local()
|
| 2151 |
+
st.success(f"Cas d'usage '{original_uc_name_for_dup_form}' dupliqué en '{new_uc_name_val_from_form}' dans la famille '{target_family_on_submit}'.")
|
| 2152 |
+
|
| 2153 |
+
st.session_state.duplicating_use_case_details = None
|
| 2154 |
+
st.session_state.force_select_family_name = target_family_on_submit
|
| 2155 |
+
st.session_state.force_select_use_case_name = new_uc_name_val_from_form
|
| 2156 |
+
st.session_state.active_generated_prompt = ""
|
| 2157 |
+
st.session_state.variable_type_to_create = None
|
| 2158 |
+
st.session_state.editing_variable_info = None
|
| 2159 |
+
st.session_state.go_to_config_section = True
|
| 2160 |
+
st.rerun()
|
| 2161 |
+
|
| 2162 |
+
cancel_key_duplicate = f"cancel_dup_process_{original_family_name_for_dup.replace(' ','_')}_{original_uc_name_for_dup_form.replace(' ','_')}"
|
| 2163 |
+
if st.button("❌ Annuler la Duplication", key=cancel_key_duplicate, use_container_width=True):
|
| 2164 |
+
st.session_state.duplicating_use_case_details = None
|
| 2165 |
+
st.rerun()
|
| 2166 |
+
else:
|
| 2167 |
+
action_cols_manage = st.columns(2)
|
| 2168 |
+
with action_cols_manage[0]:
|
| 2169 |
+
dup_key_init = f"initiate_dup_uc_btn_{generator_family.replace(' ','_')}_{generator_use_case.replace(' ','_')}"
|
| 2170 |
+
if st.button("🔄 Dupliquer ce Cas d'Usage", key=dup_key_init, use_container_width=True):
|
| 2171 |
+
st.session_state.duplicating_use_case_details = {
|
| 2172 |
+
"family": generator_family,
|
| 2173 |
+
"use_case": generator_use_case
|
| 2174 |
+
}
|
| 2175 |
+
st.session_state.go_to_config_section = True
|
| 2176 |
+
st.rerun()
|
| 2177 |
+
|
| 2178 |
+
with action_cols_manage[1]:
|
| 2179 |
+
del_uc_key_exp_main = f"del_uc_btn_exp_main_{generator_family.replace(' ','_')}_{generator_use_case.replace(' ','_')}"
|
| 2180 |
+
is_confirming_this_uc_delete_main = bool(st.session_state.confirming_delete_details and \
|
| 2181 |
+
st.session_state.confirming_delete_details.get("family") == generator_family and \
|
| 2182 |
+
st.session_state.confirming_delete_details.get("use_case") == generator_use_case)
|
| 2183 |
+
if st.button("🗑️ Supprimer Cas d'Usage", key=del_uc_key_exp_main, type="secondary", disabled=is_confirming_this_uc_delete_main, use_container_width=True):
|
| 2184 |
+
st.session_state.confirming_delete_details = {"family": generator_family, "use_case": generator_use_case}
|
| 2185 |
+
st.rerun()
|
| 2186 |
|
| 2187 |
if st.session_state.get('go_to_config_section'):
|
| 2188 |
st.session_state.go_to_config_section = False
|