1
0

chore: package

This commit is contained in:
2025-07-05 01:34:59 +02:00
parent 8e324b2a1f
commit 9e411cee54
16 changed files with 424 additions and 4 deletions

31
webroot/add_instance.sql Normal file
View File

@@ -0,0 +1,31 @@
-- TODO check for duplicate to avoid
-- error returned from database: (code: 2067) UNIQUE constraint failed: instances.domain
select
'alert' as component
, 'Error' as title
, 'domain must be minimum four characters' as description
, 'alert-circle' as icon
, 'red' as color
where length($domain) <4
or $domain is null
;
-- TODO perform better validation of the domain
insert into instances(domain, failure) select $domain, -1
where length($domain) >3
and $domain is not null
;
select
'empty_state' as component
, 'mood-check' as icon
, 'Thanks you' as title
, 'This domain ' || $domain || ' has been added to the list and will be be displayed after next refresh, usually once a day' as description
, 'Go back to the list' as link_text
, 'home' as link_icon
, '/' as link
where length($domain) >3
and $domain is not null
;

44
webroot/index.sql Normal file
View File

@@ -0,0 +1,44 @@
select
'shell' as component
, 'Mobilizon Instances' as title
, 'social' as icon
, JSON('{"title":"Statistics","link":"/stats", "icon":"chart-dots"}') as menu_item
, JSON('{"link":"mailto:contact@kaihuri.org?subject=report%20an%20instance","title":"Report an instance","icon":"forms"}') as menu_item
, '' as footer
;
-- add form
select
'form' as component
, 'GET' as method
, 'add an instance' as validate
, '/add_instance' as action
;
select
'domain' as name
, 70 as maxlength
, '[0-9.a-z]{4,70}' as pattern
--, 'url' as type
, 'events.example.net' as placeholder
, true as required
, 6 as width
;
-- instances list
select
'table' as component
, true as search
, true as small
, true as sort
, true as freeze_headers
, true as striped_rows
;
select
domain as Url
, name
, version
, slogan
, description
from instances
where failure >= 0
;

123
webroot/stats.sql Normal file
View File

@@ -0,0 +1,123 @@
select
'shell' as component
, 'Mobilizon statistics' as title
, 'chart-dots' as icon
, JSON('{"title":"Instances list","link":"/", "icon":"social"}') as menu_item
, JSON('{"link":"mailto:contact@kaihuri.org?subject=report%20an%20instance","title":"Report an instance","icon":"forms"}') as menu_item
, '' as footer
;
select
'big_number' as component
, 4 as columns
;
-- total Instances
select
'Instances' as title
, (select count(*) from instances where failure>=0 and failure<5) as value
;
-- total Users
select
'Users' as title
, (select sum(users) from ( SELECT
instance_id,
users,
MAX(insertedAt)
FROM stats
GROUP BY instance_id)) as value
;
-- total Groups
select
'Groups' as title
, (select sum(local_groups) from ( SELECT
instance_id,
local_groups,
MAX(insertedAt)
FROM stats
GROUP BY instance_id)) as value
;
-- total Events
select
'Events' as title
, (select sum(local_events) from ( SELECT
instance_id,
local_events,
MAX(insertedAt)
FROM stats
GROUP BY instance_id)) as value
;
----- over time ----
select
'title' as component
, 'Over time' as contents
;
-- instances
select
'chart' as component
, 'Instances' as title
, 'area' as type
, 'blue-lt' as color
--, 5 as marker
, TRUE as time
;
SELECT
count(instance_id) as y
, insertedAt as x
, insertedAt / (3600*24) as j
FROM stats
GROUP BY j
order by j
;
-- users
select
'chart' as component
, 'Users' as title
, 'area' as type
, 'blue-lt' as color
--, 5 as marker
, TRUE as time
;
SELECT
sum(users) as y
, insertedAt as x
, insertedAt / (3600*24) as j
FROM stats
GROUP BY j
order by j
;
-- events
select
'chart' as component
, 'Events' as title
, 'area' as type
, 'blue-lt' as color
--, 5 as marker
, TRUE as time
;
SELECT
sum(local_events) as y
, insertedAt as x
, insertedAt / (3600*24) as j
FROM stats
GROUP BY j
order by j
;
-- groups
select
'chart' as component
, 'Groups' as title
, 'area' as type
, 'blue-lt' as color
--, 5 as marker
, TRUE as time
;
SELECT
sum(local_groups) as y
, insertedAt as x
, insertedAt / (3600*24) as j
FROM stats
GROUP BY j
order by j
;