|
@@ -1282,17 +1282,30 @@ def get_lineage(member_id):
|
|
|
ancestor_ids.append(parent['id'])
|
|
ancestor_ids.append(parent['id'])
|
|
|
displayed_ids.add(parent['id'])
|
|
displayed_ids.add(parent['id'])
|
|
|
|
|
|
|
|
- # Get siblings of this ancestor
|
|
|
|
|
|
|
+ # Get siblings of this ancestor (father's brothers)
|
|
|
|
|
+ # First get grandparent (parent's father)
|
|
|
cursor.execute("""
|
|
cursor.execute("""
|
|
|
- SELECT c.id, c.name, c.simplified_name, c.name_word, c.name_word_generation,
|
|
|
|
|
- EXISTS(SELECT 1 FROM family_relation_info WHERE parent_mid = c.id AND relation_type IN (1, 2)) as has_children
|
|
|
|
|
|
|
+ SELECT gp.id
|
|
|
FROM family_relation_info r
|
|
FROM family_relation_info r
|
|
|
- JOIN family_member_info c ON r.child_mid = c.id
|
|
|
|
|
- WHERE r.parent_mid = %s AND r.relation_type IN (1, 2) AND c.id != %s
|
|
|
|
|
- ORDER BY c.id
|
|
|
|
|
- LIMIT 30
|
|
|
|
|
- """, (parent['id'], current_id))
|
|
|
|
|
- parent_siblings = cursor.fetchall()
|
|
|
|
|
|
|
+ JOIN family_member_info gp ON r.parent_mid = gp.id
|
|
|
|
|
+ WHERE r.child_mid = %s AND r.relation_type IN (1, 2)
|
|
|
|
|
+ LIMIT 1
|
|
|
|
|
+ """, (parent['id'],))
|
|
|
|
|
+ grandparent = cursor.fetchone()
|
|
|
|
|
+
|
|
|
|
|
+ parent_siblings = []
|
|
|
|
|
+ if grandparent:
|
|
|
|
|
+ # Get siblings of parent (father's brothers)
|
|
|
|
|
+ cursor.execute("""
|
|
|
|
|
+ SELECT c.id, c.name, c.simplified_name, c.name_word, c.name_word_generation,
|
|
|
|
|
+ EXISTS(SELECT 1 FROM family_relation_info WHERE parent_mid = c.id AND relation_type IN (1, 2)) as has_children
|
|
|
|
|
+ FROM family_relation_info r
|
|
|
|
|
+ JOIN family_member_info c ON r.child_mid = c.id
|
|
|
|
|
+ WHERE r.parent_mid = %s AND r.relation_type IN (1, 2) AND c.id != %s
|
|
|
|
|
+ ORDER BY c.id
|
|
|
|
|
+ LIMIT 30
|
|
|
|
|
+ """, (grandparent['id'], parent['id']))
|
|
|
|
|
+ parent_siblings = cursor.fetchall()
|
|
|
|
|
|
|
|
# Mark sibling IDs as displayed
|
|
# Mark sibling IDs as displayed
|
|
|
for sibling in parent_siblings:
|
|
for sibling in parent_siblings:
|
|
@@ -1308,7 +1321,11 @@ def get_lineage(member_id):
|
|
|
""", (parent['id'],))
|
|
""", (parent['id'],))
|
|
|
total_children = cursor.fetchone()['count']
|
|
total_children = cursor.fetchone()['count']
|
|
|
|
|
|
|
|
- show_expand = total_children > len(parent_siblings) + 1 # +1 for the current child
|
|
|
|
|
|
|
+ # Check if current child is displayed (current_id is the child of parent)
|
|
|
|
|
+ child_displayed = current_id in displayed_ids
|
|
|
|
|
+
|
|
|
|
|
+ # Show expand if there are children not displayed
|
|
|
|
|
+ show_expand = total_children > (1 if child_displayed else 0)
|
|
|
|
|
|
|
|
parent['show_expand'] = show_expand
|
|
parent['show_expand'] = show_expand
|
|
|
|
|
|