Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -773,10 +773,8 @@ body, .stApp {
|
|
| 773 |
""", unsafe_allow_html=True)
|
| 774 |
|
| 775 |
# ========== توابع اصلی ==========
|
| 776 |
-
import streamlit as st
|
| 777 |
-
|
| 778 |
def enhanced_likert_scale(question_data):
|
| 779 |
-
"""لیکرت اسکیل با
|
| 780 |
question = question_data["question"]
|
| 781 |
key = question_data["key"]
|
| 782 |
scale = question_data["scale"]
|
|
@@ -791,6 +789,7 @@ def enhanced_likert_scale(question_data):
|
|
| 791 |
unsafe_allow_html=True)
|
| 792 |
|
| 793 |
# HTML و CSS برای نمایش خط و نقاط
|
|
|
|
| 794 |
scale_html = f"""
|
| 795 |
<style>
|
| 796 |
@font-face {{
|
|
@@ -856,30 +855,55 @@ def enhanced_likert_scale(question_data):
|
|
| 856 |
"""
|
| 857 |
|
| 858 |
# اضافه کردن نقاط
|
| 859 |
-
current_value = st.session_state.get(key, 0)
|
| 860 |
for i in range(1, scale + 1):
|
| 861 |
value = i
|
| 862 |
active_class = "active" if current_value == value else ""
|
| 863 |
scale_html += f"""
|
| 864 |
-
<div class='likert-dot {active_class}' id='dot-{key}-{value}'
|
|
|
|
|
|
|
| 865 |
"""
|
| 866 |
|
| 867 |
scale_html += "</div></div>"
|
| 868 |
-
st.markdown(scale_html, unsafe_allow_html=True)
|
| 869 |
|
| 870 |
# فرم برای ثبت انتخاب
|
| 871 |
with st.form(key=f"{key}_form", clear_on_submit=True):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 872 |
selected_option = st.radio(
|
| 873 |
"",
|
| 874 |
options=list(range(1, scale + 1)),
|
| 875 |
index=current_value - 1 if current_value > 0 else None,
|
| 876 |
label_visibility="collapsed",
|
| 877 |
-
horizontal=True,
|
| 878 |
key=f"{key}_radio"
|
| 879 |
)
|
| 880 |
if st.form_submit_button("ثبت", use_container_width=True):
|
| 881 |
st.session_state[key] = selected_option
|
| 882 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 883 |
# نمایش پاسخ انتخابشده
|
| 884 |
if st.session_state[key] != 0:
|
| 885 |
st.markdown(f"<p style='text-align:right; color:#6a0dad; direction: rtl;'>پاسخ شما: {st.session_state[key]}</p>",
|
|
@@ -907,7 +931,7 @@ def enhanced_likert_scale(question_data):
|
|
| 907 |
[data-testid="stRadio"] > div {
|
| 908 |
display: none !important;
|
| 909 |
}
|
| 910 |
-
/*
|
| 911 |
[data-testid="stFormSubmitButton"] {
|
| 912 |
display: none !important;
|
| 913 |
}
|
|
@@ -915,24 +939,6 @@ def enhanced_likert_scale(question_data):
|
|
| 915 |
<div class="likert-separator"></div>
|
| 916 |
""", unsafe_allow_html=True)
|
| 917 |
|
| 918 |
-
# جاوااسکریپت برای شبیهسازی کلیک روی دکمههای رادیویی
|
| 919 |
-
st.markdown(
|
| 920 |
-
f"""
|
| 921 |
-
<script>
|
| 922 |
-
document.querySelectorAll('.likert-dot').forEach(dot => {{
|
| 923 |
-
dot.addEventListener('click', function() {{
|
| 924 |
-
const value = this.id.split('-').pop();
|
| 925 |
-
document.querySelector(`input[type="radio"][value="${{value}}"]`).click();
|
| 926 |
-
document.querySelector('[data-testid="stFormSubmitButton"] button').click();
|
| 927 |
-
document.querySelectorAll('.likert-dot').forEach(d => d.classList.remove('active'));
|
| 928 |
-
this.classList.add('active');
|
| 929 |
-
}});
|
| 930 |
-
}});
|
| 931 |
-
</script>
|
| 932 |
-
""",
|
| 933 |
-
unsafe_allow_html=True
|
| 934 |
-
)
|
| 935 |
-
|
| 936 |
return st.session_state.get(key)
|
| 937 |
|
| 938 |
def create_ride_map():
|
|
|
|
| 773 |
""", unsafe_allow_html=True)
|
| 774 |
|
| 775 |
# ========== توابع اصلی ==========
|
|
|
|
|
|
|
| 776 |
def enhanced_likert_scale(question_data):
|
| 777 |
+
"""لیکرت اسکیل با HTML/CSS ساده و مدیریت انتخاب با st.session_state"""
|
| 778 |
question = question_data["question"]
|
| 779 |
key = question_data["key"]
|
| 780 |
scale = question_data["scale"]
|
|
|
|
| 789 |
unsafe_allow_html=True)
|
| 790 |
|
| 791 |
# HTML و CSS برای نمایش خط و نقاط
|
| 792 |
+
current_value = st.session_state.get(key, 0)
|
| 793 |
scale_html = f"""
|
| 794 |
<style>
|
| 795 |
@font-face {{
|
|
|
|
| 855 |
"""
|
| 856 |
|
| 857 |
# اضافه کردن نقاط
|
|
|
|
| 858 |
for i in range(1, scale + 1):
|
| 859 |
value = i
|
| 860 |
active_class = "active" if current_value == value else ""
|
| 861 |
scale_html += f"""
|
| 862 |
+
<div class='likert-dot {active_class}' id='dot-{key}-{value}'
|
| 863 |
+
onclick='this.closest("form").querySelector(`input[value="${{value}}"]').checked = true; this.closest("form").querySelector("button[type=submit]").click();'>
|
| 864 |
+
</div>
|
| 865 |
"""
|
| 866 |
|
| 867 |
scale_html += "</div></div>"
|
|
|
|
| 868 |
|
| 869 |
# فرم برای ثبت انتخاب
|
| 870 |
with st.form(key=f"{key}_form", clear_on_submit=True):
|
| 871 |
+
scale_html += f"""
|
| 872 |
+
<input type="radio" name="likert_radio" value="1" style="display: none;" {"checked" if current_value == 1 else ""}>
|
| 873 |
+
"""
|
| 874 |
+
for i in range(2, scale + 1):
|
| 875 |
+
value = i
|
| 876 |
+
scale_html += f"""
|
| 877 |
+
<input type="radio" name="likert_radio" value="{value}" style="display: none;" {"checked" if current_value == value else ""}>
|
| 878 |
+
"""
|
| 879 |
+
scale_html += '<button type="submit" style="display: none;">Submit</button>'
|
| 880 |
+
components.html(scale_html, height=60)
|
| 881 |
+
|
| 882 |
selected_option = st.radio(
|
| 883 |
"",
|
| 884 |
options=list(range(1, scale + 1)),
|
| 885 |
index=current_value - 1 if current_value > 0 else None,
|
| 886 |
label_visibility="collapsed",
|
|
|
|
| 887 |
key=f"{key}_radio"
|
| 888 |
)
|
| 889 |
if st.form_submit_button("ثبت", use_container_width=True):
|
| 890 |
st.session_state[key] = selected_option
|
| 891 |
|
| 892 |
+
# جاوااسکریپت برای بهروزرسانی ظاهر نقاط
|
| 893 |
+
st.markdown(
|
| 894 |
+
f"""
|
| 895 |
+
<script>
|
| 896 |
+
document.querySelectorAll('.likert-dot').forEach(dot => {{
|
| 897 |
+
dot.addEventListener('click', function() {{
|
| 898 |
+
document.querySelectorAll('.likert-dot').forEach(d => d.classList.remove('active'));
|
| 899 |
+
this.classList.add('active');
|
| 900 |
+
}});
|
| 901 |
+
}});
|
| 902 |
+
</script>
|
| 903 |
+
""",
|
| 904 |
+
unsafe_allow_html=True
|
| 905 |
+
)
|
| 906 |
+
|
| 907 |
# نمایش پاسخ انتخابشده
|
| 908 |
if st.session_state[key] != 0:
|
| 909 |
st.markdown(f"<p style='text-align:right; color:#6a0dad; direction: rtl;'>پاسخ شما: {st.session_state[key]}</p>",
|
|
|
|
| 931 |
[data-testid="stRadio"] > div {
|
| 932 |
display: none !important;
|
| 933 |
}
|
| 934 |
+
/* مخفی کردن دکمه ثبت */
|
| 935 |
[data-testid="stFormSubmitButton"] {
|
| 936 |
display: none !important;
|
| 937 |
}
|
|
|
|
| 939 |
<div class="likert-separator"></div>
|
| 940 |
""", unsafe_allow_html=True)
|
| 941 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 942 |
return st.session_state.get(key)
|
| 943 |
|
| 944 |
def create_ride_map():
|