Skip to content

Commit

Permalink
Merge pull request #731 from zanllp/feature/custom-tag-color
Browse files Browse the repository at this point in the history
Add support for custom tag colors
  • Loading branch information
zanllp authored Sep 28, 2024
2 parents 24443ba + 3c3808d commit 9370eb3
Show file tree
Hide file tree
Showing 51 changed files with 246 additions and 104 deletions.
2 changes: 1 addition & 1 deletion javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Promise.resolve().then(async () => {
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Infinite Image Browsing</title>
<script type="module" crossorigin src="/infinite_image_browsing/fe-static/assets/index-a0a34372.js"></script>
<script type="module" crossorigin src="/infinite_image_browsing/fe-static/assets/index-ee40c384.js"></script>
<link rel="stylesheet" href="/infinite_image_browsing/fe-static/assets/index-c05ac913.css">
</head>
Expand Down
19 changes: 19 additions & 0 deletions scripts/iib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,25 @@ async def get_img_selected_custom_tag(path: str):
async def get_img_tags(req: PathsReq):
conn = DataBase.get_conn()
return ImageTag.batch_get_tags_by_path(conn, req.paths)


# update tag
class UpdateTagReq(BaseModel):
id: int
color: str

@app.post(
db_api_base + "/update_tag",
dependencies=[Depends(verify_secret), Depends(write_permission_required)],
)
async def update_tag(req: UpdateTagReq):
conn = DataBase.get_conn()
tag = Tag.get(conn, req.id)
if tag:
tag.color = req.color
tag.save(conn)
conn.commit()


class ToggleCustomTagToImgReq(BaseModel):
img_path: str
Expand Down
16 changes: 12 additions & 4 deletions scripts/iib/db/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,20 @@ def find_by_substring(


class Tag:
def __init__(self, name: str, score: int, type: str, count=0):
def __init__(self, name: str, score: int, type: str, count=0, color = ""):
self.name = name
self.score = score
self.type = type
self.count = count
self.id = None
self.color = color
self.display_name = tags_translate.get(name)

def save(self, conn):
with closing(conn.cursor()) as cur:
cur.execute(
"INSERT OR REPLACE INTO tag (id, name, score, type, count) VALUES (?, ?, ?, ?, ?)",
(self.id, self.name, self.score, self.type, self.count),
"INSERT OR REPLACE INTO tag (id, name, score, type, count, color) VALUES (?, ?, ?, ?, ?, ?)",
(self.id, self.name, self.score, self.type, self.count, self.color),
)
self.id = cur.lastrowid

Expand Down Expand Up @@ -326,7 +327,7 @@ def get_or_create(cls, conn: Connection, name: str, type: str):

@classmethod
def from_row(cls, row: tuple):
tag = cls(name=row[1], score=row[2], type=row[3], count=row[4])
tag = cls(name=row[1], score=row[2], type=row[3], count=row[4], color=row[5])
tag.id = row[0]
return tag

Expand All @@ -350,6 +351,13 @@ def create_table(cls, conn):
VALUES ("like", 0, "custom", 0);
"""
)
try:
cur.execute(
"""ALTER TABLE tag
ADD COLUMN color TEXT DEFAULT ''"""
)
except sqlite3.OperationalError as e:
pass


class ImageTag:
Expand Down
3 changes: 3 additions & 0 deletions vue/dist/assets/FileItem-a74cdf88.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions vue/dist/assets/FileItem-bc5ed3c6.js

This file was deleted.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vue/dist/assets/MatchedImageGrid-42f6d525.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion vue/dist/assets/MatchedImageGrid-4990f0f7.js

This file was deleted.

3 changes: 3 additions & 0 deletions vue/dist/assets/MultiSelectKeep-28b76528.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions vue/dist/assets/MultiSelectKeep-4f8b7fe4.js

This file was deleted.

1 change: 1 addition & 0 deletions vue/dist/assets/MultiSelectKeep-6b9ba5fd.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9370eb3

Please sign in to comment.