Skip to content

Commit aa9c518

Browse files
committed
Add display number to contents
1 parent 8f82986 commit aa9c518

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

admin_app/src/app/content/components/ContentCard.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const ContentCard = ({
1414
title,
1515
text,
1616
content_id,
17+
display_number,
1718
last_modified,
1819
tags,
1920
positive_votes,
@@ -26,6 +27,7 @@ const ContentCard = ({
2627
title: string;
2728
text: string;
2829
content_id: number;
30+
display_number: number;
2931
last_modified: string;
3032
tags: Tag[];
3133
positive_votes: number;
@@ -135,6 +137,7 @@ const ContentCard = ({
135137
title={title}
136138
text={text}
137139
content_id={content_id}
140+
display_number={display_number}
138141
last_modified={last_modified}
139142
tags={tags}
140143
open={openReadModal}

admin_app/src/app/content/components/ContentModal.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const ContentViewModal = ({
1414
title,
1515
text,
1616
content_id,
17+
display_number,
1718
positive_votes,
1819
negative_votes,
1920
last_modified,
@@ -25,6 +26,7 @@ const ContentViewModal = ({
2526
title: string;
2627
text: string;
2728
content_id: number;
29+
display_number: number;
2830
last_modified: string;
2931
tags: Tag[];
3032
positive_votes: number;
@@ -53,7 +55,7 @@ const ContentViewModal = ({
5355
}}
5456
>
5557
<Layout.FlexBox flexDirection={"row"} justifyContent={"space-between"}>
56-
<Typography variant="h5">Content #{content_id}</Typography>
58+
<Typography variant="h5">Content #{display_number}</Typography>
5759
<IconButton onClick={onClose}>
5860
<Close />
5961
</IconButton>

admin_app/src/app/content/edit/page.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434

3535
export interface Content extends EditContentBody {
3636
content_id: number | null;
37+
display_number: number;
3738
positive_votes: number;
3839
negative_votes: number;
3940
created_datetime_utc: string;

admin_app/src/app/content/page.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ const CardsGrid = ({
652652
title={item.content_title}
653653
text={item.content_text}
654654
content_id={item.content_id}
655+
display_number={item.display_number}
655656
last_modified={item.updated_datetime_utc}
656657
tags={
657658
tags

core_backend/migrations/versions/2025_03_12_b1daed9f42c4_add_display_number.py

+20
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@
2121
def upgrade() -> None:
2222
# ### commands auto generated by Alembic - please adjust! ###
2323
op.add_column("content", sa.Column("display_number", sa.Integer(), nullable=False))
24+
25+
connection = op.get_bind()
26+
27+
# 2
28+
workspaces = connection.execute(sa.text('SELECT * FROM "workspaces"')).mappings()
29+
for workspace in workspaces:
30+
workspace_id = workspace["id"]
31+
content = connection.execute(
32+
sa.text(
33+
f'SELECT * FROM "content" WHERE "workspace_id" = {workspace_id}'
34+
f'ORDER BY "created_datetime_utc"'
35+
)
36+
).mappings()
37+
for i, row in enumerate(content):
38+
connection.execute(
39+
sa.text(
40+
f'UPDATE "content" SET "display_number" = {i + 1}'
41+
f'WHERE "content_id" = {row["content_id"]}'
42+
)
43+
)
2444
# ### end Alembic commands ###
2545

2646

0 commit comments

Comments
 (0)