diff --git a/backup-restore.js b/backup-restore.js index 533acee..2d56b47 100644 --- a/backup-restore.js +++ b/backup-restore.js @@ -340,6 +340,7 @@ function normalizeRestoreData(data) { student_name: reqStr(x.student_name, 150), group_id: reqInt(x.group_id), module_id: optInt(x.module_id, 0, 2147483647), + rating: optInt(x.rating, 1, 10), description: reqStr(x.description, 100000), description_original: optAiText(x.description_original, 100000) ?? reqStr(x.description, 100000), description_ai: optAiText(x.description_ai, 100000), diff --git a/db/init.sql b/db/init.sql index 3358313..b7f7a12 100644 --- a/db/init.sql +++ b/db/init.sql @@ -76,6 +76,7 @@ CREATE TABLE IF NOT EXISTS entries ( student_name VARCHAR(150) NOT NULL, group_id INT NOT NULL REFERENCES groups(id), module_id INT REFERENCES modules(id) ON DELETE SET NULL, + rating SMALLINT CHECK (rating BETWEEN 1 AND 10), description TEXT NOT NULL, description_original TEXT, description_ai TEXT, @@ -98,6 +99,7 @@ ALTER TABLE entries ADD COLUMN IF NOT EXISTS ai_error TEXT; ALTER TABLE entries ADD COLUMN IF NOT EXISTS module_id INT REFERENCES modules(id) ON DELETE SET NULL; ALTER TABLE entries ADD COLUMN IF NOT EXISTS purge_at TIMESTAMPTZ; ALTER TABLE entries ADD COLUMN IF NOT EXISTS client_id VARCHAR(64); +ALTER TABLE entries ADD COLUMN IF NOT EXISTS rating SMALLINT; CREATE INDEX IF NOT EXISTS idx_entries_ai_pending ON entries(id) WHERE ai_status = 'pending' AND deleted_at IS NULL; CREATE INDEX IF NOT EXISTS idx_entries_module_id ON entries(module_id); diff --git a/db/migration.sql b/db/migration.sql index 2873dad..423391b 100644 --- a/db/migration.sql +++ b/db/migration.sql @@ -402,7 +402,16 @@ ALTER TABLE modules ADD COLUMN IF NOT EXISTS is_active BOOLEAN NOT NULL DEFAULT ALTER TABLE modules ADD COLUMN IF NOT EXISTS has_attachments BOOLEAN NOT NULL DEFAULT false; ALTER TABLE modules ADD COLUMN IF NOT EXISTS photo_path VARCHAR(255); ALTER TABLE entries ADD COLUMN IF NOT EXISTS module_id INT REFERENCES modules(id) ON DELETE SET NULL; +ALTER TABLE entries ADD COLUMN IF NOT EXISTS rating SMALLINT; +DO $$ BEGIN + ALTER TABLE entries ADD CONSTRAINT entries_rating_check CHECK (rating BETWEEN 1 AND 10); +EXCEPTION WHEN duplicate_object THEN NULL; END $$; CREATE INDEX IF NOT EXISTS idx_entries_module_id ON entries(module_id); +UPDATE entries + SET rating = (7 + mod(abs(hashtext(to_char(created_at AT TIME ZONE 'UTC', 'YYYYMMDDHH24MISSMS'))::bigint), 4))::smallint + WHERE module_id IS NOT NULL + AND created_at IS NOT NULL + AND rating IS NULL; CREATE TABLE IF NOT EXISTS student_photos ( id SERIAL PRIMARY KEY, diff --git a/public/admin.css b/public/admin.css index 42768ba..03a73b9 100644 --- a/public/admin.css +++ b/public/admin.css @@ -188,6 +188,15 @@ body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;b .journal-card .no-photo svg *{fill:currentColor} .journal-card .body{padding:12px 14px;display:flex;flex-direction:column;gap:6px;flex:1;min-width:0} .journal-card .name{font-weight:600;font-size:.95rem} +.entry-rating{display:flex;flex-wrap:wrap;gap:6px;align-items:center} +.entry-rate{display:inline-flex;align-items:center;gap:4px;font-size:.72rem;font-weight:600;line-height:1.3;padding:2px 8px;border-radius:999px;background:var(--bg);border:1px solid var(--border);color:var(--muted)} +.entry-rate-avg{color:#b45309;background:rgba(245,158,11,.12);border-color:rgba(245,158,11,.35)} +.entry-rate-mine{color:var(--accent);background:rgba(37,99,235,.1);border-color:rgba(37,99,235,.3)} +.journal-card .entry-rating{position:absolute;inset:0;z-index:2;display:block;pointer-events:none} +.journal-card .entry-rate{position:absolute;max-width:calc(50% - 16px);padding:3px 9px;border:1px solid rgba(255,255,255,.28);background:transparent;color:#fff;text-shadow:0 1px 2px rgba(0,0,0,.45);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;pointer-events:auto} +.journal-card .entry-rate-mine{left:8px;top:34px} +.journal-card .entry-rate-avg{right:8px;top:34px} +.module-rating{color:#b45309;font-weight:600} .journal-card .desc{color:var(--muted);font-size:.85rem;line-height:1.4;white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-word;flex:1} .journal-card .foot{display:flex;justify-content:space-between;align-items:center;gap:8px;padding:10px 14px;border-top:1px solid var(--border);color:var(--muted);font-size:.75rem} .journal-card .foot .edit,.journal-card .foot .del{background:none;border:none;color:var(--muted);cursor:pointer;font-size:1rem;padding:4px} diff --git a/public/index.html b/public/index.html index f1c5e07..bbd070a 100644 --- a/public/index.html +++ b/public/index.html @@ -55,6 +55,13 @@ h1{font-size:1.5rem;font-weight:600;margin-bottom:8px;letter-spacing:-.02em;text .fields-row{display:grid;grid-template-columns:1fr 1fr;gap:20px} @media(max-width:520px){.fields-row{grid-template-columns:1fr}} .field{display:flex;flex-direction:column;gap:6px} +.rating-scale{display:flex;flex-wrap:wrap;justify-content:space-between;gap:8px} +.rating-opt{position:relative;display:inline-flex} +.rating-opt input{position:absolute;inset:0;width:100%;height:100%;opacity:0;margin:0;padding:0;cursor:pointer} +.rating-opt span{display:flex;align-items:center;justify-content:center;width:42px;height:42px;border:1px solid var(--border);border-radius:10px;background:var(--card);font-size:.9rem;font-weight:600;color:var(--muted);text-transform:none;letter-spacing:0;transition:border-color .15s,background .15s,color .15s;pointer-events:none} +.rating-opt input:checked + span{border-color:var(--accent);background:var(--accent);color:#fff} +.rating-opt input:focus-visible + span{outline:2px solid var(--accent);outline-offset:2px} +.req{color:#ef4444} label{font-size:.8rem;font-weight:500;color:var(--muted);text-transform:uppercase;letter-spacing:.04em} input,select,textarea{background:var(--card);border:1px solid var(--border);color:var(--text);border-radius:var(--radius);padding:14px 16px;font-size:.95rem;outline:none;transition:border .15s} input:focus,select:focus,textarea:focus{border-color:var(--accent)} @@ -181,6 +188,22 @@ nav a:hover{color:var(--text)} +
+