feat: add sources form and table

This commit is contained in:
Alexander Navarro 2025-02-05 19:56:47 -03:00
parent e2a6c92322
commit baf70e6820
11 changed files with 103 additions and 8 deletions

View file

@ -3,3 +3,5 @@ POSTGRES_USER=index
POSTGRES_PASSWORD= POSTGRES_PASSWORD=
DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?sslmode=disable" DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?sslmode=disable"
SQLPAGE_WEB_ROOT=app

View file

@ -11,3 +11,5 @@ dev:
docker compose up --watch docker compose up --watch
dbmate +ARGS: (compose-exec "index dbmate" ARGS) dbmate +ARGS: (compose-exec "index dbmate" ARGS)
migrate: (dbmate "migrate")

View file

@ -6,7 +6,7 @@ COPY --from=lovasoa/sqlpage:latest /usr/local/bin/sqlpage /usr/local/bin/sqlpage
WORKDIR /app WORKDIR /app
ENV SQLPAGE_WEB_ROOT=/app ENV SQLPAGE_WEB_ROOT=/app
ENV SQLPAGE_CONFIGURATION_DIRECTORY=/etc/sqlpage ENV SQLPAGE_CONFIGURATION_DIRECTORY=/app/sqlpage
RUN addgroup --gid 1000 --system index_user && \ RUN addgroup --gid 1000 --system index_user && \
adduser --uid 1000 --system --no-create-home --ingroup index_user index_user && \ adduser --uid 1000 --system --no-create-home --ingroup index_user index_user && \

View file

@ -17,3 +17,8 @@ services:
db: db:
image: postgres:17 image: postgres:17
env_file: ../.env env_file: ../.env
volumes:
- db_data:/var/lib/postgresql/data
volumes:
db_data:

1
src/app/index.sql Normal file
View file

@ -0,0 +1 @@
SELECT 'dynamic' AS component, sqlpage.read_file_as_text('../shared/shell.json') AS properties;

View file

@ -0,0 +1,7 @@
INSERT INTO
public.sources(name, uid, uri)
VALUES
(:name, :uid, :uri)
RETURNING 'redirect' AS component, 'index.sql' AS link
;

45
src/app/sources/index.sql Normal file
View file

@ -0,0 +1,45 @@
SELECT
'dynamic' AS component,
sqlpage.read_file_as_text('../shared/shell.json') AS properties;
-- ╭─────────────────────────────────────────────────────────╮
-- │ Form │
-- ╰─────────────────────────────────────────────────────────╯
SELECT
'form' AS component,
'create.sql' AS action,
'Save' AS validate,
'Sources' AS title;
SELECT
'name' AS name,
'Name' AS label,
8 AS width,
TRUE AS required;
SELECT
'uid' AS name,
'Identifier' AS label,
4 AS width,
5 AS maxlength,
1 AS minlength,
TRUE AS required;
SELECT
'uri' AS name,
'URI' AS label;
-- ╭─────────────────────────────────────────────────────────╮
-- │ Table list │
-- ╰─────────────────────────────────────────────────────────╯
SELECT
'table' AS component,
TRUE as sort,
TRUE as search;
SELECT
*
FROM
public.sources;

View file

@ -3,7 +3,7 @@ CREATE TABLE public.sources (
id serial PRIMARY KEY, id serial PRIMARY KEY,
name character varying(20) NOT NULL, name character varying(20) NOT NULL,
uid character varying(8) NOT NULL, uid character varying(8) NOT NULL,
uri character varying NOT NULL, uri character varying,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at timestamp with time zone, updated_at timestamp with time zone,
deleted_at timestamp with time zone deleted_at timestamp with time zone

View file

@ -1,6 +0,0 @@
SELECT 'list' AS component,
'Popular websites TESTOOO' AS title;
SELECT 'Hello' AS title,
'world' AS description,
'https://wikipedia.org' AS link;

22
src/shared/shell.json Normal file
View file

@ -0,0 +1,22 @@
{
"component": "shell",
"title": "Index",
"link": "/",
"layout": "boxed",
"sidebar": true,
"theme": "dark",
"menu_item": [
{ "link": "index.sql", "title": "Home" },
{
"title": "Dependencies",
"icon": "brand-stackshare",
"submenu": [
{
"link": "/sources/index.sql",
"title": "Sources",
"icon": "external-link"
}
]
}
]
}

View file

@ -0,0 +1,17 @@
<nav aria-label="Page navigation example">
<ul class="pagination pagination-sm justify-content-center">
<li class="page-item">
<a class="page-link"
href="?current_page={{ minus (default current_page 1) 1 }}">{{ icon_img "caret-left" }}</a>
</li>
<li class="page-item disabled">
<a class="page-link" href="#">{{ default current_page 1 }}</a>
</li>
<li class="page-item">
<a class="page-link"
href="?current_page={{ plus (default current_page 1) 1 }}">{{ icon_img "caret-right" }}</a>
</li>
</ul>
</nav>