From 888bd2910d6584d92e68d52b8b3a4dae5fffc04c Mon Sep 17 00:00:00 2001 From: Roland Date: Sun, 9 Apr 2023 15:08:22 -0600 Subject: [PATCH] Displaying tag file count on edit page. --- app/src/Tags.js | 53 ++++++++++++++++++++++++++++--------------------- wrolpi/tags.py | 18 +++++++++++------ 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/app/src/Tags.js b/app/src/Tags.js index 0123c812..5d6dba9e 100644 --- a/app/src/Tags.js +++ b/app/src/Tags.js @@ -27,6 +27,7 @@ import {Segment} from "./components/Theme"; import _ from "lodash"; import {HexColorPicker} from "react-colorful"; import {useRecurringTimeout} from "./hooks/customHooks"; +import {Media} from "./contexts/contexts"; export const TagsContext = React.createContext({ NameToTagLabel: null, @@ -128,31 +129,34 @@ export const useTagsInterval = () => { return tagsValue } -function EditTagLabel({tag, onDelete, onEdit}) { +function EditTagRow({tag, onDelete, onEdit}) { const {NameToTagLabel} = React.useContext(TagsContext); const [confirmDeleteOpen, setConfirmDeleteOpen] = useState(false); - const {name, color, id} = tag; + const {name, color, id, count} = tag; + + const deleteConfirm = <> + setConfirmDeleteOpen(true)} icon='trash'/> + setConfirmDeleteOpen(false)} + onConfirm={async () => onDelete(id, name)} + /> + ; + const editButton = onEdit(name, color, id)} icon='edit'/>; + const nameLabel = + + ; return - - setConfirmDeleteOpen(true)} icon='trash'/> - setConfirmDeleteOpen(false)} - onConfirm={async () => onDelete(id, name)} - /> - - - onEdit(name, color, id)} icon='edit'/> - - - - - - + {deleteConfirm} + {editButton} + {nameLabel} + + + } @@ -197,8 +201,8 @@ function EditTagsModal() { let content = ; if (tags && tags.length) { - content = tags.map(i => ); + content = tags.map(i => ); } return <> @@ -242,6 +246,9 @@ function EditTagsModal() { Delete Edit Tag + + Count + diff --git a/wrolpi/tags.py b/wrolpi/tags.py index 92fa00b1..847262bd 100644 --- a/wrolpi/tags.py +++ b/wrolpi/tags.py @@ -5,9 +5,8 @@ from sqlalchemy import Column, Integer, String, ForeignKey, BigInteger from sqlalchemy.exc import IntegrityError from sqlalchemy.orm import relationship, Session -from wrolpi.common import ModelHelper, Base, logger, ConfigFile, get_media_directory, background_task, run_after, \ - limit_concurrent -from wrolpi.db import optional_session +from wrolpi.common import ModelHelper, Base, logger, ConfigFile, get_media_directory, background_task, run_after +from wrolpi.db import optional_session, get_db_curs from wrolpi.errors import UnknownTag, UsedTag, InvalidTag from wrolpi.vars import PYTEST @@ -174,9 +173,16 @@ def schedule_save(session: Session = None): background_task(_()) -@optional_session -def get_tags(session: Session) -> List[Tag]: - tags = list(session.query(Tag).order_by(Tag.name)) +def get_tags() -> List[dict]: + with get_db_curs() as curs: + curs.execute(''' + SELECT t.name, t.color, COUNT(tf.tag_id) + FROM tag t + LEFT JOIN tag_file tf on t.id = tf.tag_id + GROUP BY t.name, t.color + ORDER BY t.name + ''') + tags = list(map(dict, curs.fetchall())) return tags