Skip to content

Commit 52d4f16

Browse files
authored
Merge pull request #54 from sunmh207/feature/20250321-config
dashboard增加按项目名称查询
2 parents fa22186 + f2b5bfd commit 52d4f16

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

biz/service/review_service.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def insert_mr_review_log(entity: MergeRequestReviewEntity):
6363
print(f"Error inserting review log: {e}")
6464

6565
@staticmethod
66-
def get_mr_review_logs(authors: list = None, updated_at_gte: int = None,
66+
def get_mr_review_logs(authors: list = None, project_names: list = None, updated_at_gte: int = None,
6767
updated_at_lte: int = None) -> pd.DataFrame:
6868
"""获取符合条件的合并请求审核日志"""
6969
try:
@@ -80,6 +80,11 @@ def get_mr_review_logs(authors: list = None, updated_at_gte: int = None,
8080
query += f" AND author IN ({placeholders})"
8181
params.extend(authors)
8282

83+
if project_names:
84+
placeholders = ','.join(['?'] * len(project_names))
85+
query += f" AND project_name IN ({placeholders})"
86+
params.extend(project_names)
87+
8388
if updated_at_gte is not None:
8489
query += " AND updated_at >= ?"
8590
params.append(updated_at_gte)

ui.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
DASHBOARD_USER: DASHBOARD_PASSWORD
1717
}
1818

19+
1920
# 登录验证函数
2021
def authenticate(username, password):
2122
return username in USER_CREDENTIALS and USER_CREDENTIALS[username] == password
2223

24+
2325
# 获取数据函数
24-
def get_data(service_func, authors=None, updated_at_gte=None, updated_at_lte=None, columns=None):
25-
df = service_func(authors=authors, updated_at_gte=updated_at_gte, updated_at_lte=updated_at_lte)
26+
def get_data(service_func, authors=None, project_names=None, updated_at_gte=None, updated_at_lte=None, columns=None):
27+
df = service_func(authors=authors, project_names=project_names, updated_at_gte=updated_at_gte, updated_at_lte=updated_at_lte)
2628

2729
if df.empty:
2830
return pd.DataFrame(columns=columns)
@@ -36,9 +38,11 @@ def get_data(service_func, authors=None, updated_at_gte=None, updated_at_lte=Non
3638
data = df[columns]
3739
return data
3840

41+
3942
# Streamlit 配置
4043
st.set_page_config(layout="wide")
4144

45+
4246
# 登录界面
4347
def login_page():
4448
# 使用 st.columns 创建居中布局
@@ -83,10 +87,9 @@ def main_page():
8387
else:
8488
mr_tab = st.container()
8589

86-
8790
def display_data(tab, service_func, columns, column_config):
8891
with tab:
89-
col1, col2, col3 = st.columns(3)
92+
col1, col2, col3, col4 = st.columns(4)
9093
with col1:
9194
start_date = st.date_input("开始日期", start_date_default, key=f"{tab}_start_date")
9295
with col2:
@@ -100,10 +103,13 @@ def display_data(tab, service_func, columns, column_config):
100103
df = pd.DataFrame(data)
101104

102105
unique_authors = sorted(df["author"].dropna().unique().tolist()) if not df.empty else []
106+
unique_projects = sorted(df["project_name"].dropna().unique().tolist()) if not df.empty else []
103107
with col3:
104108
authors = st.multiselect("用户名", unique_authors, default=[], key=f"{tab}_authors")
109+
with col4:
110+
project_names = st.multiselect("项目名", unique_projects, default=[], key=f"{tab}_projects")
105111

106-
data = get_data(service_func, authors=authors, updated_at_gte=int(start_datetime.timestamp()),
112+
data = get_data(service_func, authors=authors,project_names=project_names, updated_at_gte=int(start_datetime.timestamp()),
107113
updated_at_lte=int(end_datetime.timestamp()), columns=columns)
108114
df = pd.DataFrame(data)
109115

@@ -117,7 +123,6 @@ def display_data(tab, service_func, columns, column_config):
117123
average_score = df["score"].mean() if not df.empty else 0
118124
st.markdown(f"**总记录数:** {total_records},**平均分:** {average_score:.2f}")
119125

120-
121126
# Merge Request 数据展示
122127
mr_columns = ["project_name", "author", "source_branch", "target_branch", "updated_at", "commit_messages", "score",
123128
"url"]
@@ -149,11 +154,13 @@ def display_data(tab, service_func, columns, column_config):
149154
}
150155

151156
display_data(push_tab, ReviewService().get_push_review_logs, push_columns, push_column_config)
157+
158+
152159
# 应用入口
153160
if "authenticated" not in st.session_state:
154161
st.session_state["authenticated"] = False
155162

156163
if st.session_state["authenticated"]:
157164
main_page()
158165
else:
159-
login_page()
166+
login_page()

0 commit comments

Comments
 (0)