Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -739,7 +739,7 @@ h3 {
|
|
| 739 |
|
| 740 |
# ========== توابع اصلی ==========
|
| 741 |
def enhanced_likert_scale(question_data):
|
| 742 |
-
"""لیکرت اسکیل با دکمههای کاملاً HTML و منطق Streamlit"""
|
| 743 |
question = question_data["question"]
|
| 744 |
key = question_data["key"]
|
| 745 |
scale = question_data["scale"]
|
|
@@ -748,6 +748,8 @@ def enhanced_likert_scale(question_data):
|
|
| 748 |
# مقداردهی اولیه
|
| 749 |
if key not in st.session_state:
|
| 750 |
st.session_state[key] = None
|
|
|
|
|
|
|
| 751 |
|
| 752 |
# استایلدهی و ساختار HTML
|
| 753 |
html_content = f"""
|
|
@@ -791,7 +793,7 @@ def enhanced_likert_scale(question_data):
|
|
| 791 |
justify-content: center !important;
|
| 792 |
cursor: pointer !important;
|
| 793 |
transition: all 0.3s ease !important;
|
| 794 |
-
font-size:
|
| 795 |
color: #6a0dad !important;
|
| 796 |
}}
|
| 797 |
.likert-btn.selected {{
|
|
@@ -811,6 +813,23 @@ def enhanced_likert_scale(question_data):
|
|
| 811 |
margin-top: 10px !important;
|
| 812 |
font-size: 16px !important;
|
| 813 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 814 |
</style>
|
| 815 |
<div class="likert-container">
|
| 816 |
<div class="likert-question">{question}</div>
|
|
@@ -818,49 +837,57 @@ def enhanced_likert_scale(question_data):
|
|
| 818 |
<span style="text-align:right">{labels[0]}</span>
|
| 819 |
<span style="text-align:left">{labels[1]}</span>
|
| 820 |
</div>
|
| 821 |
-
<div class="likert-buttons">
|
| 822 |
"""
|
| 823 |
|
| 824 |
# افزودن دکمههای HTML
|
| 825 |
for i in range(scale):
|
| 826 |
value = scale - i # 7 تا 1
|
| 827 |
-
is_selected = st.session_state
|
| 828 |
html_content += f"""
|
| 829 |
<button class="likert-btn {'selected' if is_selected else ''}"
|
| 830 |
-
onclick="
|
| 831 |
{'•' if is_selected else '○'}
|
| 832 |
</button>
|
| 833 |
"""
|
| 834 |
|
| 835 |
-
html_content += """
|
|
|
|
|
|
|
|
|
|
| 836 |
</div>
|
|
|
|
|
|
|
|
|
|
| 837 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 838 |
"""
|
| 839 |
|
| 840 |
# رندر HTML
|
| 841 |
-
components.html(html_content, height=
|
| 842 |
|
| 843 |
-
#
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
if
|
| 847 |
-
|
| 848 |
-
key=f"hidden-btn-{key}-{value}",
|
| 849 |
-
help=str(value),
|
| 850 |
-
type="secondary",
|
| 851 |
-
use_container_width=True
|
| 852 |
-
):
|
| 853 |
-
st.session_state[key] = value
|
| 854 |
st.rerun()
|
| 855 |
|
| 856 |
-
# ��مایش پاسخ انتخابشده
|
| 857 |
-
if st.session_state.get(key) is not None:
|
| 858 |
-
st.markdown(f"""
|
| 859 |
-
<div class="likert-response">
|
| 860 |
-
پاسخ شما: {st.session_state[key]}
|
| 861 |
-
</div>
|
| 862 |
-
""", unsafe_allow_html=True)
|
| 863 |
-
|
| 864 |
return st.session_state.get(key)
|
| 865 |
|
| 866 |
def create_ride_map():
|
|
|
|
| 739 |
|
| 740 |
# ========== توابع اصلی ==========
|
| 741 |
def enhanced_likert_scale(question_data):
|
| 742 |
+
"""لیکرت اسکیل با دکمههای کاملاً HTML و منطق حداقل Streamlit"""
|
| 743 |
question = question_data["question"]
|
| 744 |
key = question_data["key"]
|
| 745 |
scale = question_data["scale"]
|
|
|
|
| 748 |
# مقداردهی اولیه
|
| 749 |
if key not in st.session_state:
|
| 750 |
st.session_state[key] = None
|
| 751 |
+
if f"{key}_temp" not in st.session_state:
|
| 752 |
+
st.session_state[f"{key}_temp"] = st.session_state[key] or None
|
| 753 |
|
| 754 |
# استایلدهی و ساختار HTML
|
| 755 |
html_content = f"""
|
|
|
|
| 793 |
justify-content: center !important;
|
| 794 |
cursor: pointer !important;
|
| 795 |
transition: all 0.3s ease !important;
|
| 796 |
+
font-size: 18px !important;
|
| 797 |
color: #6a0dad !important;
|
| 798 |
}}
|
| 799 |
.likert-btn.selected {{
|
|
|
|
| 813 |
margin-top: 10px !important;
|
| 814 |
font-size: 16px !important;
|
| 815 |
}}
|
| 816 |
+
/* دکمه تأیید */
|
| 817 |
+
.confirm-btn {{
|
| 818 |
+
background-color: #6a0dad !important;
|
| 819 |
+
color: white !important;
|
| 820 |
+
border: none !important;
|
| 821 |
+
border-radius: 8px !important;
|
| 822 |
+
padding: 10px 20px !important;
|
| 823 |
+
font-weight: bold !important;
|
| 824 |
+
cursor: pointer !important;
|
| 825 |
+
margin-top: 15px !important;
|
| 826 |
+
transition: all 0.3s ease !important;
|
| 827 |
+
}}
|
| 828 |
+
.confirm-btn:hover {{
|
| 829 |
+
background-color: #5a0a96 !important;
|
| 830 |
+
transform: translateY(-1px) !important;
|
| 831 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important;
|
| 832 |
+
}}
|
| 833 |
</style>
|
| 834 |
<div class="likert-container">
|
| 835 |
<div class="likert-question">{question}</div>
|
|
|
|
| 837 |
<span style="text-align:right">{labels[0]}</span>
|
| 838 |
<span style="text-align:left">{labels[1]}</span>
|
| 839 |
</div>
|
| 840 |
+
<div class="likert-buttons" id="likert-buttons-{key}">
|
| 841 |
"""
|
| 842 |
|
| 843 |
# افزودن دکمههای HTML
|
| 844 |
for i in range(scale):
|
| 845 |
value = scale - i # 7 تا 1
|
| 846 |
+
is_selected = st.session_state[f"{key}_temp"] == value
|
| 847 |
html_content += f"""
|
| 848 |
<button class="likert-btn {'selected' if is_selected else ''}"
|
| 849 |
+
onclick="selectLikert('{key}', {value})">
|
| 850 |
{'•' if is_selected else '○'}
|
| 851 |
</button>
|
| 852 |
"""
|
| 853 |
|
| 854 |
+
html_content += f"""
|
| 855 |
+
</div>
|
| 856 |
+
<div class="likert-response" id="likert-response-{key}">
|
| 857 |
+
پاسخ شما: {st.session_state[f"{key}_temp"] or "هیچکدام"}
|
| 858 |
</div>
|
| 859 |
+
<button class="confirm-btn" onclick="confirmSelection('{key}')">
|
| 860 |
+
تأیید
|
| 861 |
+
</button>
|
| 862 |
</div>
|
| 863 |
+
<script>
|
| 864 |
+
function selectLikert(key, value) {{
|
| 865 |
+
// بهروزرسانی متغیر موقت
|
| 866 |
+
window.sessionStorage.setItem('{key}_temp', value);
|
| 867 |
+
// بهروزرسانی استایل دکمهها
|
| 868 |
+
const buttons = document.querySelectorAll('#likert-buttons-{key} .likert-btn');
|
| 869 |
+
buttons.forEach(btn => btn.classList.remove('selected'));
|
| 870 |
+
event.currentTarget.classList.add('selected');
|
| 871 |
+
// بهروزرسانی متن پاسخ
|
| 872 |
+
document.getElementById('likert-response-{key}').innerText = 'پاسخ شما: ' + value;
|
| 873 |
+
}}
|
| 874 |
+
function confirmSelection(key) {{
|
| 875 |
+
// فعال کردن دکمه مخفی Streamlit
|
| 876 |
+
document.getElementById('confirm-btn-{key}').click();
|
| 877 |
+
}}
|
| 878 |
+
</script>
|
| 879 |
"""
|
| 880 |
|
| 881 |
# رندر HTML
|
| 882 |
+
components.html(html_content, height=250)
|
| 883 |
|
| 884 |
+
# دکمه مخفی Streamlit برای ثبت نهایی
|
| 885 |
+
if st.button("Confirm", key=f"confirm-btn-{key}", help="Hidden confirm button", type="secondary", use_container_width=True):
|
| 886 |
+
temp_value = st.session_state.get(f"{key}_temp")
|
| 887 |
+
if temp_value is not None:
|
| 888 |
+
st.session_state[key] = temp_value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 889 |
st.rerun()
|
| 890 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 891 |
return st.session_state.get(key)
|
| 892 |
|
| 893 |
def create_ride_map():
|