From eba9b410c6da6ad5ba83197b58144c77cbc300a8 Mon Sep 17 00:00:00 2001 From: clonejo Date: Sun, 14 Jan 2024 18:56:43 +0100 Subject: [PATCH 01/42] autoformat by black+isort --- crud.py | 13 +++++++++---- main.py | 18 ++++++++++++------ models.py | 3 ++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/crud.py b/crud.py index f5e1f39..6f453f2 100644 --- a/crud.py +++ b/crud.py @@ -1,14 +1,19 @@ -from sqlalchemy.orm import Session -from sqlalchemy import DECIMAL, cast -import models, schemas +from sqlalchemy import DECIMAL, cast +from sqlalchemy.orm import Session + +import models +import schemas + def get_items(db: Session) -> list[models.Item]: return db.query(models.Item).all() def put_item(db: Session, id: str, item: schemas.Item): - updated = bool(db.query(models.Item).filter(models.Item.id == id).update(item.dict())) + updated = bool( + db.query(models.Item).filter(models.Item.id == id).update(item.dict()) + ) if not updated: db.add(models.Item(**item.dict())) db.commit() diff --git a/main.py b/main.py index ecaeea6..dbc0409 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,10 @@ +import re + from fastapi import Depends, FastAPI, Response from fastapi.staticfiles import StaticFiles from sqlalchemy import event -from sqlalchemy.orm import Session from sqlalchemy.engine import Engine -import re +from sqlalchemy.orm import Session import crud from database import SessionLocal, engine @@ -14,6 +15,7 @@ Base.metadata.create_all(bind=engine) app = FastAPI() + def get_db(): db = SessionLocal() try: @@ -21,6 +23,7 @@ def get_db(): finally: db.close() + @event.listens_for(Engine, "connect") def _set_sqlite_pragma(conn, _): cursor = conn.cursor() @@ -31,21 +34,24 @@ def _set_sqlite_pragma(conn, _): @app.get("/api/items", response_model=dict[str, Item]) async def list_items(db: Session = Depends(get_db)): # natural sort by id - natsort = lambda item: [int(t) if t.isdigit() else t.lower() for t in re.split('(\d+)', item.id)] + natsort = lambda item: [ + int(t) if t.isdigit() else t.lower() for t in re.split("(\d+)", item.id) + ] items = crud.get_items(db) items = sorted(items, key=natsort) - return {i.id:i for i in items} + return {i.id: i for i in items} @app.put("/api/items/{id}") async def put_item(id: str, item: Item, db: Session = Depends(get_db)): if crud.put_item(db, id, item): - return Response(b'', status_code=204) - return Response(b'', status_code=201) + return Response(b"", status_code=204) + return Response(b"", status_code=201) @app.delete("/api/items/{id}", status_code=204) async def delete_item(id: str, db: Session = Depends(get_db)): crud.delete_item(db, id) + app.mount("/", StaticFiles(directory="static", html=True), name="static") diff --git a/models.py b/models.py index d7618a6..7aa9b21 100644 --- a/models.py +++ b/models.py @@ -1,7 +1,8 @@ -from sqlalchemy import Column, ForeignKey, String, Text, Boolean +from sqlalchemy import Boolean, Column, ForeignKey, String, Text from database import Base + class Item(Base): __tablename__ = "items" From 99df802a40144f41674c8bfb453c66daee2c5b71 Mon Sep 17 00:00:00 2001 From: clonejo Date: Sun, 14 Jan 2024 18:57:32 +0100 Subject: [PATCH 02/42] make return value of crud.put_item easier to understand --- crud.py | 11 ++++++++++- main.py | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crud.py b/crud.py index 6f453f2..277c881 100644 --- a/crud.py +++ b/crud.py @@ -1,3 +1,4 @@ +from enum import Enum from sqlalchemy import DECIMAL, cast from sqlalchemy.orm import Session @@ -17,7 +18,15 @@ def put_item(db: Session, id: str, item: schemas.Item): if not updated: db.add(models.Item(**item.dict())) db.commit() - return updated + if updated: + return PutItemResult.UPDATED + else: + return PutItemResult.ADDED + + +class PutItemResult(Enum): + ADDED = 1 + UPDATED = 2 def delete_item(db: Session, id: str): diff --git a/main.py b/main.py index dbc0409..6df84df 100644 --- a/main.py +++ b/main.py @@ -44,7 +44,7 @@ async def list_items(db: Session = Depends(get_db)): @app.put("/api/items/{id}") async def put_item(id: str, item: Item, db: Session = Depends(get_db)): - if crud.put_item(db, id, item): + if crud.put_item(db, id, item) == crud.PutItemResult.UPDATED: return Response(b"", status_code=204) return Response(b"", status_code=201) From 1bf4eb801f3a7f28f6f4104200a309eae2b73812 Mon Sep 17 00:00:00 2001 From: clonejo Date: Sun, 14 Jan 2024 20:23:08 +0100 Subject: [PATCH 03/42] Add last_updated field to be able to track outdated information / lost items --- main.py | 9 +++++++++ models.py | 3 ++- schemas.py | 3 ++- static/form.html | 3 +++ static/form.js | 6 ++++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 6df84df..23b9fd5 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import re +import time from fastapi import Depends, FastAPI, Response from fastapi.staticfiles import StaticFiles @@ -44,6 +45,8 @@ async def list_items(db: Session = Depends(get_db)): @app.put("/api/items/{id}") async def put_item(id: str, item: Item, db: Session = Depends(get_db)): + if item.last_updated is None: + item.last_updated = rough_timestamp() if crud.put_item(db, id, item) == crud.PutItemResult.UPDATED: return Response(b"", status_code=204) return Response(b"", status_code=201) @@ -54,4 +57,10 @@ async def delete_item(id: str, db: Session = Depends(get_db)): crud.delete_item(db, id) +def rough_timestamp() -> int: + """Provides an current timestamp with reduced resolution, to improve anonymity.""" + granularity = 2**20 # about 12 days + return int(time.time()) // granularity * granularity + + app.mount("/", StaticFiles(directory="static", html=True), name="static") diff --git a/models.py b/models.py index 7aa9b21..1df2c2b 100644 --- a/models.py +++ b/models.py @@ -1,4 +1,4 @@ -from sqlalchemy import Boolean, Column, ForeignKey, String, Text +from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, Text from database import Base @@ -15,3 +15,4 @@ class Item(Base): content = Column(Text) note = Column(Text) hidden = Column(Boolean, nullable=False) + last_updated = Column(Integer) diff --git a/schemas.py b/schemas.py index 218fe94..bf6f444 100644 --- a/schemas.py +++ b/schemas.py @@ -1,4 +1,4 @@ -from pydantic import BaseModel +from pydantic import BaseModel, Field class Item(BaseModel): @@ -11,6 +11,7 @@ class Item(BaseModel): content: str | None note: str | None hidden: bool + last_updated: int | None = Field(None) class Config: orm_mode = True diff --git a/static/form.html b/static/form.html index a5de3f2..d894279 100644 --- a/static/form.html +++ b/static/form.html @@ -43,6 +43,9 @@ + + + diff --git a/static/form.js b/static/form.js index 4ae4968..ec00949 100644 --- a/static/form.js +++ b/static/form.js @@ -39,6 +39,7 @@ function fillForm() { document.getElementById('content').value = item.content; document.getElementById('note').value = item.note; document.getElementById('hidden').checked = item.hidden; + document.getElementById('last_updated').value = formatTimestamp(item.last_updated); formCoordsToMap(); } @@ -172,3 +173,8 @@ function formCoordsToMap() { coordsToMap(coords_bl, coords_tr); } } + +function formatTimestamp(ts) { + const date = new Date(ts * 1000); + return date.toLocaleDateString(); +} From f3658a76ffcf22ba022ceb46c7583dc9bc0d1ee0 Mon Sep 17 00:00:00 2001 From: jomo Date: Thu, 1 Feb 2024 00:01:22 +0100 Subject: [PATCH 04/42] format database.py using black --- database.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/database.py b/database.py index ac9f8a6..44a3006 100644 --- a/database.py +++ b/database.py @@ -5,9 +5,7 @@ from sqlalchemy.orm import sessionmaker SQLALCHEMY_DATABASE_URL = "sqlite:///./inventory.sqlite3" engine = create_engine( - SQLALCHEMY_DATABASE_URL, - connect_args = {"check_same_thread": False}, - echo=True + SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}, echo=True ) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) From f1384b72f208b1623becb79f8ded7390cd524e74 Mon Sep 17 00:00:00 2001 From: jomo Date: Thu, 1 Feb 2024 00:01:55 +0100 Subject: [PATCH 05/42] orm_mode has been renamed to from_attributes --- schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemas.py b/schemas.py index bf6f444..30f7545 100644 --- a/schemas.py +++ b/schemas.py @@ -14,4 +14,4 @@ class Item(BaseModel): last_updated: int | None = Field(None) class Config: - orm_mode = True + from_attributes = True From 621db6ad2c1064f8e9df015def60a9c9911fefe2 Mon Sep 17 00:00:00 2001 From: jomo Date: Thu, 1 Feb 2024 00:03:33 +0100 Subject: [PATCH 06/42] use current month for last_updated value --- main.py | 12 ++++++------ static/form.js | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 23b9fd5..138806b 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ import re -import time +from calendar import timegm +from datetime import date from fastapi import Depends, FastAPI, Response from fastapi.staticfiles import StaticFiles @@ -46,7 +47,7 @@ async def list_items(db: Session = Depends(get_db)): @app.put("/api/items/{id}") async def put_item(id: str, item: Item, db: Session = Depends(get_db)): if item.last_updated is None: - item.last_updated = rough_timestamp() + item.last_updated = month_timestamp() if crud.put_item(db, id, item) == crud.PutItemResult.UPDATED: return Response(b"", status_code=204) return Response(b"", status_code=201) @@ -57,10 +58,9 @@ async def delete_item(id: str, db: Session = Depends(get_db)): crud.delete_item(db, id) -def rough_timestamp() -> int: - """Provides an current timestamp with reduced resolution, to improve anonymity.""" - granularity = 2**20 # about 12 days - return int(time.time()) // granularity * granularity +def month_timestamp() -> int: + """Provides the timestamp of the current month's beginning (for improved privacy)""" + return timegm(date.today().replace(day=1).timetuple()) app.mount("/", StaticFiles(directory="static", html=True), name="static") diff --git a/static/form.js b/static/form.js index ec00949..b69f358 100644 --- a/static/form.js +++ b/static/form.js @@ -176,5 +176,6 @@ function formCoordsToMap() { function formatTimestamp(ts) { const date = new Date(ts * 1000); - return date.toLocaleDateString(); + // using Swedish format as a hack to get an iso formatted date + return date.toLocaleDateString("sv", {timeZone: "UTC"}).replace(/\-\d+$/,'') } From 6d01523d8d91a7025129bc98c6cd2c4e65767cb4 Mon Sep 17 00:00:00 2001 From: jomo Date: Thu, 1 Feb 2024 01:04:20 +0100 Subject: [PATCH 07/42] update python version and modules --- Dockerfile | 2 +- main.py | 2 +- requirements.txt | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 228fbb6..9cfa1aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10-alpine +FROM python:3.12-alpine3.19 WORKDIR /app diff --git a/main.py b/main.py index 138806b..cc4092d 100644 --- a/main.py +++ b/main.py @@ -37,7 +37,7 @@ def _set_sqlite_pragma(conn, _): async def list_items(db: Session = Depends(get_db)): # natural sort by id natsort = lambda item: [ - int(t) if t.isdigit() else t.lower() for t in re.split("(\d+)", item.id) + int(t) if t.isdigit() else t.lower() for t in re.split(r"(\d+)", item.id) ] items = crud.get_items(db) items = sorted(items, key=natsort) diff --git a/requirements.txt b/requirements.txt index 54b2b3d..92fc06b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -fastapi>=0.79.0 -sqlalchemy>=1.4.39 -uvicorn>=0.17.6 +fastapi>=0.109.0 +sqlalchemy>=2.0.25 +uvicorn>=0.27.0.post1 From 2b7342b90284c7d9b6ede9a3fe56ad07d83fb913 Mon Sep 17 00:00:00 2001 From: jomo Date: Thu, 1 Feb 2024 01:04:49 +0100 Subject: [PATCH 08/42] update openapi docs for PUT request --- main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index cc4092d..eb66394 100644 --- a/main.py +++ b/main.py @@ -44,7 +44,11 @@ async def list_items(db: Session = Depends(get_db)): return {i.id: i for i in items} -@app.put("/api/items/{id}") +@app.put( + "/api/items/{id}", + status_code=201, + responses={201: {"description": "created"}, 204: {"description": "updated"}}, +) async def put_item(id: str, item: Item, db: Session = Depends(get_db)): if item.last_updated is None: item.last_updated = month_timestamp() From ea0538f90ca7575d6fbc9bc640537ee4ae54bef4 Mon Sep 17 00:00:00 2001 From: jomo Date: Thu, 1 Feb 2024 01:42:00 +0100 Subject: [PATCH 09/42] ignore all dotfiles in .dockerignore --- .dockerignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index 0fdd12c..3db5969 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,4 @@ -/.dockerignore -/.gitignore +.* /inventory.sqlite3 /README.md *.pyc From 8f5a82fb418df5fca5d926a18b9bb6ecc91ece34 Mon Sep 17 00:00:00 2001 From: clonejo Date: Sat, 6 Jan 2024 06:28:38 +0100 Subject: [PATCH 10/42] add client-side python script to create items in bulk --- contrib/bulk_create.py | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 contrib/bulk_create.py diff --git a/contrib/bulk_create.py b/contrib/bulk_create.py new file mode 100755 index 0000000..8ed6aed --- /dev/null +++ b/contrib/bulk_create.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +import sys + +import requests + +BASE = "https://in.ccc.ac/api" +COUNT = 0 +START_ID = 1 + + +session = requests.Session() +# session.auth = (":)", ":)") + +res = session.get(f"{BASE}/items") +res.raise_for_status() +ids = res.json().keys() +kiste_ids = {int(i.lstrip("K")) for i in ids if i.startswith("K") and i != "K"} +print("existing ids:", repr(kiste_ids), file=sys.stderr) + +current_id = START_ID +new_ids = [] +while len(new_ids) < COUNT: + if current_id not in kiste_ids: + new_ids.append(current_id) + current_id += 1 + +print("created:", file=sys.stderr) +if len(new_ids) == 0: + print("(none)", file=sys.stderr) + + +for i in new_ids: + j = { + "id": f"K{i}", + "is_in": None, + "coords_bl": None, + "coords_tr": None, + "type": "Kiste", + "name": None, + "content": None, + "note": "Bitte Name, Ort, Inhalt eintragen", + "hidden": False, + } + res = session.put(f"{BASE}/items/{j['id']}", json=j) + res.raise_for_status() + print(f"{j['id']},https://in.ccc.ac/form.html?id={j['id']}") From ec64e818291059b04d7577d729275351edfe3db9 Mon Sep 17 00:00:00 2001 From: jomo Date: Thu, 1 Feb 2024 01:48:51 +0100 Subject: [PATCH 11/42] add contrib/ to .dockerignore --- .dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.dockerignore b/.dockerignore index 3db5969..4bc1268 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,3 +3,4 @@ /README.md *.pyc Dockerfile +/contrib/ From 703a210f1ef92e0449245472b3b8d53cb7721dff Mon Sep 17 00:00:00 2001 From: jomo Date: Thu, 1 Feb 2024 02:03:02 +0100 Subject: [PATCH 12/42] use BASE var in bulk_create output --- contrib/bulk_create.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/bulk_create.py b/contrib/bulk_create.py index 8ed6aed..3d7fbf5 100755 --- a/contrib/bulk_create.py +++ b/contrib/bulk_create.py @@ -4,7 +4,7 @@ import sys import requests -BASE = "https://in.ccc.ac/api" +BASE = "https://in.ccc.ac" COUNT = 0 START_ID = 1 @@ -12,7 +12,7 @@ START_ID = 1 session = requests.Session() # session.auth = (":)", ":)") -res = session.get(f"{BASE}/items") +res = session.get(f"{BASE}/api/items") res.raise_for_status() ids = res.json().keys() kiste_ids = {int(i.lstrip("K")) for i in ids if i.startswith("K") and i != "K"} @@ -42,6 +42,6 @@ for i in new_ids: "note": "Bitte Name, Ort, Inhalt eintragen", "hidden": False, } - res = session.put(f"{BASE}/items/{j['id']}", json=j) + res = session.put(f"{BASE}/api/items/{j['id']}", json=j) res.raise_for_status() - print(f"{j['id']},https://in.ccc.ac/form.html?id={j['id']}") + print(f"{j['id']},{BASE}/form.html?id={j['id']}") From 111a0f6e452d667ddc6b4220b9693a6e6e5f9d10 Mon Sep 17 00:00:00 2001 From: snoopy Date: Tue, 30 Apr 2024 01:56:38 +0200 Subject: [PATCH 13/42] Changes map and update coordinate grid to c4 map --- static/80x80.svg | 442 ++++++++++++++++++++++++++++++++++++++++++++++- static/form.js | 8 +- static/shared.js | 18 +- static/style.css | 6 +- 4 files changed, 457 insertions(+), 17 deletions(-) diff --git a/static/80x80.svg b/static/80x80.svg index d0124e9..831049d 100644 --- a/static/80x80.svg +++ b/static/80x80.svg @@ -1 +1,441 @@ -/home/me/stuff/cccac/clubraum/plan_0.5.sh3dCreator: FreeHEP Graphics2D Driver Producer: com.eteks.sweethome3d.swing.PlanComponent$SVGSupport$1 Revision: 12753 Source: me Date: Monday, June 6, 2022 11:58:58 PM CEST \ No newline at end of file + + + + diff --git a/static/form.js b/static/form.js index b69f358..16ebf7e 100644 --- a/static/form.js +++ b/static/form.js @@ -136,14 +136,14 @@ function del() { let clicks = {x: [], y: []}; function mapClick(e) { - let x = Math.floor(31 / e.target.width * e.layerX); - let y = Math.floor(10 / e.target.height * e.layerY); + let x = Math.floor(37 / e.target.width * e.layerX); + let y = Math.floor(18 / e.target.height * e.layerY); let humanPos = (x, y) => { - return `${String.fromCharCode(65 + 8 - y)}${x}`; + return `${String.fromCharCode(65 + 16 - y)}${x}`; }; - if (x > 0 && x < 31 && y > 0 && y < 9) { + if (x > 0 && x < 37 && y > 0 && y < 18) { if (clicks.x.length > 1) { clicks.x = [x]; clicks.y = [y]; diff --git a/static/shared.js b/static/shared.js index 7a51e29..6d01e23 100644 --- a/static/shared.js +++ b/static/shared.js @@ -1,12 +1,12 @@ function renderMap(xx, yy) { - if (xx[0] > 0 && xx[0] < 31 && yy[0] > 0 && yy[0] < 9 && - xx[1] > 0 && xx[1] < 31 && yy[1] > 0 && yy[1] < 9 && + if (xx[0] > 0 && xx[0] < 37 && yy[0] > 0 && yy[0] < 18 && + xx[1] > 0 && xx[1] < 37 && yy[1] > 0 && yy[1] < 18 && xx[1] >= xx[0] && yy[1] >= yy[0]) { let grid = document.getElementById('mapgrid'); - grid.style.top = `${yy[0]*10}%`; - grid.style.left = `${100/31*xx[0]}%`; - grid.style.height = `${(yy[1] - yy[0] + 1) * 10}%`; - grid.style.width = `${100/31*(xx[1] - xx[0] + 1)}%`; + grid.style.top = `${yy[0]*100/18}%`; + grid.style.left = `${100/37*xx[0]}%`; + grid.style.height = `${(yy[1] - yy[0] + 1) * 100/18}%`; + grid.style.width = `${100/37*(xx[1] - xx[0] + 1)}%`; } else { alert(`invalid coordinates x=${xx} y=${yy}`); } @@ -26,8 +26,8 @@ function coordsToMap(coords_bl, coords_tr) { let bl_x = parseInt(coords_bl.slice(1)); let tr_x = parseInt(coords_tr.slice(1)); - bl_y = 8 - (bl_y.charCodeAt(0) - 65); - tr_y = 8 - (tr_y.charCodeAt(0) - 65); + bl_y = 16 - (bl_y.charCodeAt(0) - 65); + tr_y = 16 - (tr_y.charCodeAt(0) - 65); renderMap([bl_x, tr_x], [tr_y, bl_y]); -} \ No newline at end of file +} diff --git a/static/style.css b/static/style.css index be8a9bd..3b538ec 100644 --- a/static/style.css +++ b/static/style.css @@ -172,9 +172,9 @@ textarea { position: relative; border: 1px solid black; background: #fff; - max-width: 800px; + max-width: 1480px; max-height: 50vh; - aspect-ratio: 31 / 10; + aspect-ratio: 37 / 18; margin: 0 auto; } @@ -238,4 +238,4 @@ form #map { max-width: 100%; text-align: center; margin: auto; -} \ No newline at end of file +} From 277b2aec575014869ec686adac64df1d4743708d Mon Sep 17 00:00:00 2001 From: snoopy Date: Tue, 30 Apr 2024 02:05:36 +0200 Subject: [PATCH 14/42] Add Dockerfile build action --- .forgejo/workflows/deployment.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .forgejo/workflows/deployment.yaml diff --git a/.forgejo/workflows/deployment.yaml b/.forgejo/workflows/deployment.yaml new file mode 100644 index 0000000..391e59c --- /dev/null +++ b/.forgejo/workflows/deployment.yaml @@ -0,0 +1,24 @@ +name: deployment +on: + push: + branches: + - 'main' + +jobs: + deployment: + runs-on: docker + container: + image: node:bookworm + steps: + - uses: actions/checkout@v4 + - name: Build inventory + uses: https://codeberg.org/umglurf/kaniko-action@main + with: + cache: true + cache_repo: git.koeln.ccc.de/${{ github.repository }}/cache + push: 'true' + context: /workspace/snoopy/in-c4/ + credentials: | + git.koeln.ccc.de=snoopy:${{ secrets.REGISTRY_WRITE }} + destinations: | + git.koeln.ccc.de/${{ github.repository }}/in-c4:latest From 0bc3cac6f527b0eff8fb32c2e62f41497e2f459a Mon Sep 17 00:00:00 2001 From: snoopy Date: Tue, 30 Apr 2024 02:14:18 +0200 Subject: [PATCH 15/42] Puts database into a subfolder --- database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database.py b/database.py index 44a3006..7759e10 100644 --- a/database.py +++ b/database.py @@ -2,7 +2,7 @@ from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker -SQLALCHEMY_DATABASE_URL = "sqlite:///./inventory.sqlite3" +SQLALCHEMY_DATABASE_URL = "sqlite:///./data/inventory.sqlite3" engine = create_engine( SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}, echo=True From 6cdeb1a3da867631528c7088d38c4455614d8d60 Mon Sep 17 00:00:00 2001 From: Shy Date: Tue, 30 Apr 2024 16:27:00 +0200 Subject: [PATCH 16/42] Updated map und grid --- static/80x80.svg | 97 ++++++++++++++++++++---------------------------- static/form.js | 4 +- static/shared.js | 8 ++-- static/style.css | 6 +-- 4 files changed, 50 insertions(+), 65 deletions(-) diff --git a/static/80x80.svg b/static/80x80.svg index 831049d..cdaaaf1 100644 --- a/static/80x80.svg +++ b/static/80x80.svg @@ -2,9 +2,9 @@ diff --git a/static/form.js b/static/form.js index 16ebf7e..a82d2a5 100644 --- a/static/form.js +++ b/static/form.js @@ -136,14 +136,14 @@ function del() { let clicks = {x: [], y: []}; function mapClick(e) { - let x = Math.floor(37 / e.target.width * e.layerX); + let x = Math.floor(36 / e.target.width * e.layerX); let y = Math.floor(18 / e.target.height * e.layerY); let humanPos = (x, y) => { return `${String.fromCharCode(65 + 16 - y)}${x}`; }; - if (x > 0 && x < 37 && y > 0 && y < 18) { + if (x > 0 && x < 36 && y > 0 && y < 18) { if (clicks.x.length > 1) { clicks.x = [x]; clicks.y = [y]; diff --git a/static/shared.js b/static/shared.js index 6d01e23..c2b9c35 100644 --- a/static/shared.js +++ b/static/shared.js @@ -1,12 +1,12 @@ function renderMap(xx, yy) { - if (xx[0] > 0 && xx[0] < 37 && yy[0] > 0 && yy[0] < 18 && - xx[1] > 0 && xx[1] < 37 && yy[1] > 0 && yy[1] < 18 && + if (xx[0] > 0 && xx[0] < 36 && yy[0] > 0 && yy[0] < 18 && + xx[1] > 0 && xx[1] < 36 && yy[1] > 0 && yy[1] < 18 && xx[1] >= xx[0] && yy[1] >= yy[0]) { let grid = document.getElementById('mapgrid'); grid.style.top = `${yy[0]*100/18}%`; - grid.style.left = `${100/37*xx[0]}%`; + grid.style.left = `${100/36*xx[0]}%`; grid.style.height = `${(yy[1] - yy[0] + 1) * 100/18}%`; - grid.style.width = `${100/37*(xx[1] - xx[0] + 1)}%`; + grid.style.width = `${100/36*(xx[1] - xx[0] + 1)}%`; } else { alert(`invalid coordinates x=${xx} y=${yy}`); } diff --git a/static/style.css b/static/style.css index 3b538ec..d055b22 100644 --- a/static/style.css +++ b/static/style.css @@ -171,10 +171,10 @@ textarea { #map { position: relative; border: 1px solid black; - background: #fff; - max-width: 1480px; + background: #4d4d4d; + max-width: 1440px; max-height: 50vh; - aspect-ratio: 37 / 18; + aspect-ratio: 2 / 1; margin: 0 auto; } From f91b83d3caf78aa7704f63e279b05ba9cd24cb54 Mon Sep 17 00:00:00 2001 From: Shy Date: Tue, 30 Apr 2024 18:18:11 +0200 Subject: [PATCH 17/42] C4 inspired stylesheet --- static/c4.css | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 static/c4.css diff --git a/static/c4.css b/static/c4.css new file mode 100644 index 0000000..a74dc49 --- /dev/null +++ b/static/c4.css @@ -0,0 +1,60 @@ +body { + color: #f0f0f0; + background-color: #333; +} + +h1, h1 a { + color: #fcbb06; /* C4 Yellow */ +} + +.result { + background-color: #202020; + border-color: #4d4d4d; +} + +.result:focus { + background-color: #202020; + border-color: #fcbb06; + outline-color: #fcbb06; +} + +.result a { + color: #fcbb06; +} + +.note { + background-color: #333; + font-size: smaller; +} + +.btn.green { + color: #020; + background-color: #6f3; +} + +.btn.green:hover ,.btn.green:focus { + background-color: #3f0; +} + +.btn.red { + color: #200; + background-color: #f36; +} + +.btn.red:hover, .btn.red:focus { + background-color: #f03; +} + +@keyframes blinker { + 0% { opacity: 1; } + 40% { opacity: 1; } + 90% { opacity: 0; } + 100% { opacity: 1; } +} + +#mapgrid { + outline: 2px solid #fcbb06; + background: #fcbb0680; + animation: blinker 1s infinite; +} + From 2aae5dd4413e8ad40022f0de99b0a2318dc2693d Mon Sep 17 00:00:00 2001 From: Shy Date: Tue, 30 Apr 2024 18:18:56 +0200 Subject: [PATCH 18/42] Include C4 style sheet --- static/form.html | 1 + static/index.html | 1 + 2 files changed, 2 insertions(+) diff --git a/static/form.html b/static/form.html index d894279..8447427 100644 --- a/static/form.html +++ b/static/form.html @@ -3,6 +3,7 @@ in? + diff --git a/static/index.html b/static/index.html index 585514b..472846b 100644 --- a/static/index.html +++ b/static/index.html @@ -3,6 +3,7 @@ in? + From c25188611e456e214502df8f1d4fa2acf2e2f1e5 Mon Sep 17 00:00:00 2001 From: snoopy Date: Tue, 30 Apr 2024 20:18:37 +0200 Subject: [PATCH 19/42] Adds actions workflow for pull-requests --- .../workflows/deployment-pull-request.yaml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .forgejo/workflows/deployment-pull-request.yaml diff --git a/.forgejo/workflows/deployment-pull-request.yaml b/.forgejo/workflows/deployment-pull-request.yaml new file mode 100644 index 0000000..bef68b9 --- /dev/null +++ b/.forgejo/workflows/deployment-pull-request.yaml @@ -0,0 +1,22 @@ +name: deployment-on-pull-request +on: + pull_request: + pull_request_target: + types: + - opened + - reopened + - synchronize + +jobs: + deployment: + runs-on: docker + container: + image: node:bookworm + steps: + - uses: actions/checkout@v4 + - name: Build inventory + uses: https://codeberg.org/umglurf/kaniko-action@main + with: + cache: false + push: 'false' + context: /workspace/snoopy/in-c4/ From b41f74bf7b8dac41e3900e78677c21a80d06b2e3 Mon Sep 17 00:00:00 2001 From: snoopy Date: Tue, 30 Apr 2024 20:19:15 +0200 Subject: [PATCH 20/42] Fix gitignore Goal is to not have the contents of /data/ inside the git workflow --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 53c9ebf..03899e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/inventory.sqlite3 +/data/* *.pyc From b6a0d226741876458cc5839967bf9552916657d0 Mon Sep 17 00:00:00 2001 From: snoopy Date: Tue, 30 Apr 2024 21:22:07 +0200 Subject: [PATCH 21/42] Change button names --- static/c4.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/c4.css b/static/c4.css index a74dc49..3293b31 100644 --- a/static/c4.css +++ b/static/c4.css @@ -27,12 +27,12 @@ h1, h1 a { font-size: smaller; } -.btn.green { +.btn.primary { color: #020; background-color: #6f3; } -.btn.green:hover ,.btn.green:focus { +.btn.primary:hover ,.btn.primary:focus { background-color: #3f0; } From 299a2f5914bab2dd6118659720e972906d05e370 Mon Sep 17 00:00:00 2001 From: Shy Date: Tue, 30 Apr 2024 21:45:01 +0200 Subject: [PATCH 22/42] Modified button colors --- static/c4.css | 16 +++++++++++++--- static/index.html | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/static/c4.css b/static/c4.css index 3293b31..7e9d5e0 100644 --- a/static/c4.css +++ b/static/c4.css @@ -28,17 +28,27 @@ h1, h1 a { } .btn.primary { - color: #020; - background-color: #6f3; + color: #220; + background-color: #fcbb06; } .btn.primary:hover ,.btn.primary:focus { + background-color: #ffcc33; +} + +.btn.grn { + color: #020; + background-color: #9f6; +} + +.btn.grn:hover ,.btn.primary:focus { background-color: #3f0; } + .btn.red { color: #200; - background-color: #f36; + background-color: #f48; } .btn.red:hover, .btn.red:focus { diff --git a/static/index.html b/static/index.html index 472846b..c656402 100644 --- a/static/index.html +++ b/static/index.html @@ -38,7 +38,7 @@ - + + + From a6e363220a1573257c284a30837064d6c1f3f370 Mon Sep 17 00:00:00 2001 From: snoopy Date: Wed, 1 May 2024 00:04:37 +0200 Subject: [PATCH 23/42] Fixes wrong active button color and use primary color --- static/c4.css | 4 ++-- static/form.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/static/c4.css b/static/c4.css index 7e9d5e0..c05e5b0 100644 --- a/static/c4.css +++ b/static/c4.css @@ -32,7 +32,7 @@ h1, h1 a { background-color: #fcbb06; } -.btn.primary:hover ,.btn.primary:focus { +.btn.primary:hover,.btn.primary:focus { background-color: #ffcc33; } @@ -41,7 +41,7 @@ h1, h1 a { background-color: #9f6; } -.btn.grn:hover ,.btn.primary:focus { +.btn.grn:hover ,.btn.grn:focus { background-color: #3f0; } diff --git a/static/form.html b/static/form.html index 8447427..c01f0f4 100644 --- a/static/form.html +++ b/static/form.html @@ -50,6 +50,6 @@ - + From 9935c0562b974e3d9f489342dfbacbed27c8d998 Mon Sep 17 00:00:00 2001 From: snoopy Date: Wed, 1 May 2024 01:08:43 +0200 Subject: [PATCH 24/42] Changes colors slightly --- static/80x80.svg | 2 +- static/c4.css | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/static/80x80.svg b/static/80x80.svg index cdaaaf1..2478ce7 100644 --- a/static/80x80.svg +++ b/static/80x80.svg @@ -421,6 +421,6 @@ aria-label="Keller" /> diff --git a/static/c4.css b/static/c4.css index c05e5b0..504bf3a 100644 --- a/static/c4.css +++ b/static/c4.css @@ -4,7 +4,7 @@ body { } h1, h1 a { - color: #fcbb06; /* C4 Yellow */ + color: #dfaa37; /* C4 Yellow */ } .result { @@ -14,12 +14,12 @@ h1, h1 a { .result:focus { background-color: #202020; - border-color: #fcbb06; - outline-color: #fcbb06; + border-color: #dfaa37; + outline-color: #dfaa37; } .result a { - color: #fcbb06; + color: #dfaa37; } .note { @@ -27,13 +27,17 @@ h1, h1 a { font-size: smaller; } +.btn { + box-shadow: 0 3px 6px -1px rgba(0,0,0,0.3); +} + .btn.primary { color: #220; - background-color: #fcbb06; + background-color: #dfaa37; } .btn.primary:hover,.btn.primary:focus { - background-color: #ffcc33; + background-color: #f5c251; } .btn.grn { @@ -48,11 +52,11 @@ h1, h1 a { .btn.red { color: #200; - background-color: #f48; + background-color: #ec6d5f; } .btn.red:hover, .btn.red:focus { - background-color: #f03; + background-color: #ff7667; } @keyframes blinker { @@ -63,8 +67,8 @@ h1, h1 a { } #mapgrid { - outline: 2px solid #fcbb06; - background: #fcbb0680; + outline: 2px solid #dfaa37; + background: #dfaa3780; animation: blinker 1s infinite; } From 5b5728f7e2f7ffb2c57ae2585ee2d934f3755522 Mon Sep 17 00:00:00 2001 From: Shy Date: Wed, 1 May 2024 17:17:35 +0200 Subject: [PATCH 25/42] Add drop shadow to map --- static/c4.css | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/static/c4.css b/static/c4.css index 504bf3a..7805a9b 100644 --- a/static/c4.css +++ b/static/c4.css @@ -7,6 +7,15 @@ h1, h1 a { color: #dfaa37; /* C4 Yellow */ } +#map { + border: 1px solid #202020; + background: #4d4d4d; + max-width: 1440px; + max-height: 50vh; + aspect-ratio: 2 / 1; + box-shadow: 0px 6px 12px #000c; +} + .result { background-color: #202020; border-color: #4d4d4d; @@ -49,7 +58,6 @@ h1, h1 a { background-color: #3f0; } - .btn.red { color: #200; background-color: #ec6d5f; From 9f95e704b9b95e59f335f082e9ee54160baa2f85 Mon Sep 17 00:00:00 2001 From: Shy Date: Sat, 4 May 2024 18:28:09 +0200 Subject: [PATCH 26/42] Added buttons for known types. --- static/c4.css | 15 +++++++++++++++ static/form.js | 18 ++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/static/c4.css b/static/c4.css index 7805a9b..c0ca189 100644 --- a/static/c4.css +++ b/static/c4.css @@ -36,6 +36,21 @@ h1, h1 a { font-size: smaller; } +#knowntypes button { + color: #220; + background-color: #dfaa37; + border: 1px solid #220; + border-radius: 4px; + padding: 0.2em 0.4em; + margin: 0.2em; + font-weight: bolder; + cursor: pointer; +} + +#knowntypes button:hover, #knowntypes button:focus { + background-color: #f5c251; +} + .btn { box-shadow: 0 3px 6px -1px rgba(0,0,0,0.3); } diff --git a/static/form.js b/static/form.js index a82d2a5..d5ab745 100644 --- a/static/form.js +++ b/static/form.js @@ -65,8 +65,22 @@ function knownTypes() { map[i.type] = true; } } - let types = Object.keys(map).sort().join(', ') - document.getElementById('knowntypes').textContent = `Known types: ${types}.`; + + // Get location in document. + let known_types = document.getElementById('knowntypes'); + known_types.textContent = `Known types: `; + + // Create a button for every known type. + for (let label of Object.keys(map).sort()) { + btn = document.createElement('button'); + btn.setAttribute('type', 'button'); + btn.textContent = label; + btn.addEventListener('click', function() { + document.getElementById('type').value = label; + }); + + known_types.appendChild(btn); + } } function save() { From c9cda14f38631eb717593c0ceab9234fb005394c Mon Sep 17 00:00:00 2001 From: Shy Date: Mon, 6 May 2024 14:42:21 +0200 Subject: [PATCH 27/42] Fix indentation and use const where preferable --- static/form.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/static/form.js b/static/form.js index d5ab745..d1affc1 100644 --- a/static/form.js +++ b/static/form.js @@ -67,19 +67,19 @@ function knownTypes() { } // Get location in document. - let known_types = document.getElementById('knowntypes'); + const known_types = document.getElementById('knowntypes'); known_types.textContent = `Known types: `; // Create a button for every known type. for (let label of Object.keys(map).sort()) { - btn = document.createElement('button'); - btn.setAttribute('type', 'button'); - btn.textContent = label; - btn.addEventListener('click', function() { - document.getElementById('type').value = label; - }); + btn = document.createElement('button'); + btn.setAttribute('type', 'button'); + btn.textContent = label; + btn.addEventListener('click', function() { + document.getElementById('type').value = label; + }); - known_types.appendChild(btn); + known_types.appendChild(btn); } } From 1b3de458faf97db780b92de14efbf395a7c35a4e Mon Sep 17 00:00:00 2001 From: Shy Date: Mon, 6 May 2024 17:26:31 +0200 Subject: [PATCH 28/42] Fixed colors for #mapnote --- static/c4.css | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/static/c4.css b/static/c4.css index 7805a9b..cb49d2d 100644 --- a/static/c4.css +++ b/static/c4.css @@ -8,12 +8,18 @@ h1, h1 a { } #map { - border: 1px solid #202020; - background: #4d4d4d; - max-width: 1440px; - max-height: 50vh; - aspect-ratio: 2 / 1; - box-shadow: 0px 6px 12px #000c; + border: 1px solid #202020; + background: #4d4d4d; + max-width: 1440px; + max-height: 50vh; + aspect-ratio: 2 / 1; + box-shadow: 0px 6px 12px #000c; +} + +#mapnote { + background: #202020; + border: 1px solid #000; + border-top: none; } .result { From 065fa5adbff32c4b6706f277fa175346261f8ede Mon Sep 17 00:00:00 2001 From: Shy Date: Mon, 6 May 2024 18:43:03 +0200 Subject: [PATCH 29/42] More beautiful #mapnote --- static/c4.css | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/static/c4.css b/static/c4.css index cb49d2d..962e63e 100644 --- a/static/c4.css +++ b/static/c4.css @@ -9,7 +9,7 @@ h1, h1 a { #map { border: 1px solid #202020; - background: #4d4d4d; + background-color: #4d4d4d; max-width: 1440px; max-height: 50vh; aspect-ratio: 2 / 1; @@ -17,9 +17,17 @@ h1, h1 a { } #mapnote { - background: #202020; - border: 1px solid #000; - border-top: none; + background-color: #ccc; + color: #333; + border-color: #202020; + padding: 0.25em 0.5em; + position: relative; + top: -1px; + box-shadow: 0px 6px 12px #000c; +} + +#mapnote:empty { + display: none; } .result { From f8ecf20b750b2fec4d72bf49ea48b3728025c826 Mon Sep 17 00:00:00 2001 From: Shy Date: Tue, 7 May 2024 18:38:00 +0200 Subject: [PATCH 30/42] Yellow outline around search input --- static/c4.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/static/c4.css b/static/c4.css index 962e63e..b80be1d 100644 --- a/static/c4.css +++ b/static/c4.css @@ -7,6 +7,10 @@ h1, h1 a { color: #dfaa37; /* C4 Yellow */ } +#search:focus { + outline: 2px solid #dfaa37; +} + #map { border: 1px solid #202020; background-color: #4d4d4d; From 7236d859ebf415143d561e58a017a54514ce04ea Mon Sep 17 00:00:00 2001 From: Shy Date: Tue, 7 May 2024 19:13:45 +0200 Subject: [PATCH 31/42] Enhance visibility of marker --- static/c4.css | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/static/c4.css b/static/c4.css index b80be1d..c5a403f 100644 --- a/static/c4.css +++ b/static/c4.css @@ -93,8 +93,9 @@ h1, h1 a { } #mapgrid { - outline: 2px solid #dfaa37; - background: #dfaa3780; + outline: 2px solid #333; + background-color: #dfaa37; + border-radius: 4px; animation: blinker 1s infinite; } From d98342bd02124b7f0f24e6b17c77e17b7c8ee86b Mon Sep 17 00:00:00 2001 From: Shy Date: Mon, 6 May 2024 17:26:31 +0200 Subject: [PATCH 32/42] Fixed colors for #mapnote --- static/c4.css | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/static/c4.css b/static/c4.css index c0ca189..d54dce4 100644 --- a/static/c4.css +++ b/static/c4.css @@ -8,12 +8,18 @@ h1, h1 a { } #map { - border: 1px solid #202020; - background: #4d4d4d; - max-width: 1440px; - max-height: 50vh; - aspect-ratio: 2 / 1; - box-shadow: 0px 6px 12px #000c; + border: 1px solid #202020; + background: #4d4d4d; + max-width: 1440px; + max-height: 50vh; + aspect-ratio: 2 / 1; + box-shadow: 0px 6px 12px #000c; +} + +#mapnote { + background: #202020; + border: 1px solid #000; + border-top: none; } .result { From 0c1a280a190157de33dd56ad417c4a1dc155cf6f Mon Sep 17 00:00:00 2001 From: Shy Date: Mon, 6 May 2024 18:43:03 +0200 Subject: [PATCH 33/42] More beautiful #mapnote --- static/c4.css | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/static/c4.css b/static/c4.css index d54dce4..0a62228 100644 --- a/static/c4.css +++ b/static/c4.css @@ -9,7 +9,7 @@ h1, h1 a { #map { border: 1px solid #202020; - background: #4d4d4d; + background-color: #4d4d4d; max-width: 1440px; max-height: 50vh; aspect-ratio: 2 / 1; @@ -17,9 +17,17 @@ h1, h1 a { } #mapnote { - background: #202020; - border: 1px solid #000; - border-top: none; + background-color: #ccc; + color: #333; + border-color: #202020; + padding: 0.25em 0.5em; + position: relative; + top: -1px; + box-shadow: 0px 6px 12px #000c; +} + +#mapnote:empty { + display: none; } .result { From bf182251ec3fca5a2854fd1a967644b5bb51f366 Mon Sep 17 00:00:00 2001 From: Shy Date: Tue, 7 May 2024 18:38:00 +0200 Subject: [PATCH 34/42] Yellow outline around search input --- static/c4.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/static/c4.css b/static/c4.css index 0a62228..224b6ae 100644 --- a/static/c4.css +++ b/static/c4.css @@ -7,6 +7,10 @@ h1, h1 a { color: #dfaa37; /* C4 Yellow */ } +#search:focus { + outline: 2px solid #dfaa37; +} + #map { border: 1px solid #202020; background-color: #4d4d4d; From 15d914fae3ad85cab91c4033662359ecba949603 Mon Sep 17 00:00:00 2001 From: Shy Date: Tue, 7 May 2024 19:13:45 +0200 Subject: [PATCH 35/42] Enhance visibility of marker --- static/c4.css | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/static/c4.css b/static/c4.css index 224b6ae..baa870b 100644 --- a/static/c4.css +++ b/static/c4.css @@ -108,8 +108,9 @@ h1, h1 a { } #mapgrid { - outline: 2px solid #dfaa37; - background: #dfaa3780; + outline: 2px solid #333; + background-color: #dfaa37; + border-radius: 4px; animation: blinker 1s infinite; } From 62699c90eb3ffaaedc0b6d15b4584a212a8640f4 Mon Sep 17 00:00:00 2001 From: Shy Date: Thu, 9 May 2024 03:02:42 +0200 Subject: [PATCH 36/42] Limit marker roundness on small screens --- static/c4.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/c4.css b/static/c4.css index baa870b..b9a0d3a 100644 --- a/static/c4.css +++ b/static/c4.css @@ -110,7 +110,7 @@ h1, h1 a { #mapgrid { outline: 2px solid #333; background-color: #dfaa37; - border-radius: 4px; + border-radius: min(4px, 25%); animation: blinker 1s infinite; } From 0fa4e48ff515d6d576f2f50d5ad51b22b089a001 Mon Sep 17 00:00:00 2001 From: Shy Date: Fri, 10 May 2024 14:40:36 +0200 Subject: [PATCH 37/42] Change misleading file name --- static/form.html | 2 +- static/index.html | 2 +- static/{80x80.svg => map.svg} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename static/{80x80.svg => map.svg} (100%) diff --git a/static/form.html b/static/form.html index c01f0f4..44d5c16 100644 --- a/static/form.html +++ b/static/form.html @@ -22,7 +22,7 @@ Coordinates (click on map)
- +
diff --git a/static/index.html b/static/index.html index c656402..b1d8ceb 100644 --- a/static/index.html +++ b/static/index.html @@ -17,7 +17,7 @@
- +

diff --git a/static/80x80.svg b/static/map.svg similarity index 100% rename from static/80x80.svg rename to static/map.svg From 060560d8a24e074df18b104379ff1ab87db302d5 Mon Sep 17 00:00:00 2001 From: Shy Date: Fri, 10 May 2024 14:50:22 +0200 Subject: [PATCH 38/42] Refined corridor --- static/map.svg | 937 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 662 insertions(+), 275 deletions(-) diff --git a/static/map.svg b/static/map.svg index 2478ce7..66e3ac3 100644 --- a/static/map.svg +++ b/static/map.svg @@ -7,17 +7,58 @@ viewBox="0 0 381.00001 190.50001" version="1.1" id="svg1" + inkscape:version="1.3.2 (091e20ef0f, 2023-11-25, custom)" + sodipodi:docname="chaoslabor.svg" xml:space="preserve" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" - xmlns:svg="http://www.w3.org/2000/svg">ABCDEFGHIJKLMNOP12345678910111213141516171819202122232425262728293031323334PlenarsaalKücheWohnzimmerWC++WCBällebadServer-raumFnordcenterKeller From e5e61fb9c4f0f045ac0eaf3fa20793e44d9d81f1 Mon Sep 17 00:00:00 2001 From: Shy Date: Fri, 10 May 2024 14:40:36 +0200 Subject: [PATCH 39/42] Change misleading file name --- static/form.html | 2 +- static/index.html | 2 +- static/{80x80.svg => map.svg} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename static/{80x80.svg => map.svg} (100%) diff --git a/static/form.html b/static/form.html index c01f0f4..44d5c16 100644 --- a/static/form.html +++ b/static/form.html @@ -22,7 +22,7 @@ Coordinates (click on map)
- +
diff --git a/static/index.html b/static/index.html index c656402..b1d8ceb 100644 --- a/static/index.html +++ b/static/index.html @@ -17,7 +17,7 @@
- +

diff --git a/static/80x80.svg b/static/map.svg similarity index 100% rename from static/80x80.svg rename to static/map.svg From 360164be7ab42b129eceefd8825b057d91c3124b Mon Sep 17 00:00:00 2001 From: Shy Date: Fri, 10 May 2024 14:50:22 +0200 Subject: [PATCH 40/42] Refined corridor --- static/map.svg | 937 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 662 insertions(+), 275 deletions(-) diff --git a/static/map.svg b/static/map.svg index 2478ce7..66e3ac3 100644 --- a/static/map.svg +++ b/static/map.svg @@ -7,17 +7,58 @@ viewBox="0 0 381.00001 190.50001" version="1.1" id="svg1" + inkscape:version="1.3.2 (091e20ef0f, 2023-11-25, custom)" + sodipodi:docname="chaoslabor.svg" xml:space="preserve" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" - xmlns:svg="http://www.w3.org/2000/svg">ABCDEFGHIJKLMNOP12345678910111213141516171819202122232425262728293031323334PlenarsaalKücheWohnzimmerWC++WCBällebadServer-raumFnordcenterKeller From c2334642fb9fce2cccc072d91d47e82ee626173e Mon Sep 17 00:00:00 2001 From: Shy Date: Thu, 16 May 2024 22:07:04 +0200 Subject: [PATCH 41/42] Added item counter. --- static/c4.css | 10 ++++++++-- static/index.html | 1 + static/index.js | 39 +++++++++++++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/static/c4.css b/static/c4.css index b9a0d3a..abeae82 100644 --- a/static/c4.css +++ b/static/c4.css @@ -7,8 +7,9 @@ h1, h1 a { color: #dfaa37; /* C4 Yellow */ } -#search:focus { - outline: 2px solid #dfaa37; +#search.failed { + color: #200; + background-color: #ec6d5f; } #map { @@ -34,6 +35,11 @@ h1, h1 a { display: none; } +#itemcount { + display: inline-block; + margin-right: 1ch; +} + .result { background-color: #202020; border-color: #4d4d4d; diff --git a/static/index.html b/static/index.html index b1d8ceb..07dceb7 100644 --- a/static/index.html +++ b/static/index.html @@ -12,6 +12,7 @@
+

diff --git a/static/index.js b/static/index.js index 2d7b1aa..f7bb046 100644 --- a/static/index.js +++ b/static/index.js @@ -17,6 +17,7 @@ function renderItems() { const container = document.getElementById('results'); const template = document.getElementById('item'); const loading = document.getElementById('loading'); + let count = 0; for (const [id, item] of Object.entries(items)) { const clone = template.content.cloneNode(true); @@ -31,11 +32,14 @@ function renderItems() { clone.querySelector(".result").id = `item-${id}`; clone.querySelector("a").href = `form.html?id=${encodeURIComponent(id)}`; if (item.hidden) { - clone.querySelector(".result").classList.add('hidden') - }; + clone.querySelector(".result").classList.add('hidden'); + } else { + count++; + } container.appendChild(clone); - }; + } loading.remove(); + updateCounter(count); } function getLocString(items, item) { @@ -67,6 +71,7 @@ function search(e) { const searchAttrs = ['id', 'name', 'type', 'note', 'content']; const query = e.target.value; const regex = new RegExp(query, 'i') + let count = 0; for (const elem of document.getElementsByClassName('result')) { const item = items[elem.id.slice(5)]; @@ -85,10 +90,36 @@ function search(e) { if (found) { elem.classList.remove('filtered'); + count++; } else { elem.classList.add('filtered'); } } + + // Indicate failed search. + if (count) { + e.target.classList.remove('failed'); + } else { + e.target.classList.add('failed'); + } + + updateCounter(count); +} + +function updateCounter(count) { + const itemcount = document.getElementById('itemcount'); + + switch(count) { + case 0: + itemcount.textContent = 'No items found.'; + break; + case 1: + itemcount.textContent = '1 item found.'; + break; + default: + itemcount.textContent = `${count} items found.`; + break; + } } function showhidden(e){ @@ -118,4 +149,4 @@ function showItem(e) { function hideItem(e) { clearMap(); -} \ No newline at end of file +} From 45c1d0f9cc5cd039e7fcf3dc4a93c9bd0420d879 Mon Sep 17 00:00:00 2001 From: Shy Date: Thu, 16 May 2024 22:09:54 +0200 Subject: [PATCH 42/42] Converted text to path --- static/map.svg | 912 +++++++++++++++---------------------------------- 1 file changed, 266 insertions(+), 646 deletions(-) diff --git a/static/map.svg b/static/map.svg index 66e3ac3..4210fd9 100644 --- a/static/map.svg +++ b/static/map.svg @@ -7,58 +7,17 @@ viewBox="0 0 381.00001 190.50001" version="1.1" id="svg1" - inkscape:version="1.3.2 (091e20ef0f, 2023-11-25, custom)" - sodipodi:docname="chaoslabor.svg" xml:space="preserve" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" - xmlns:svg="http://www.w3.org/2000/svg">ABCDEFGHIJKLMNOP12345678910111213141516171819202122232425262728293031323334PlenarsaalKücheWohnzimmerWC++WCBällebadServer-raumFnordcenterKeller