Add seasons’ relation, functions, and admin section
Seasons have a color to show on the calendar. I need them in HTML format
(e.g., #123abc) in order to set as value to `<input type="color">`, but
i did not want to save them as text in the database, as integers are
better representations of colors—in fact, that’s what the HTML syntax
also is: an integer.
I think the best would be to create an extension that adds an HTML color
type, with functions to convert from many representations (e.g., CSS’
rgb or even color names) to integer and back. However, that’s a lot of
work and i can satisfy Camper’s needs with just a couple of functions
and a domain.
To show the color on the index, at first tried to use a read-only
`<input type="color">`, but seems that this type of input can not be
read-only and must be disabled instead. However, i do not know whether
it makes sense to have a disabled input outside a form “just” to show
a color; i suspect it does not. Thus, at the end i use SVG with a
single circle, which is better that a 50%-rounded div with a background
color, even if the result is the same—SVG **is** intended for showing
pictures, which is this case.
2023-08-16 18:15:57 +00:00
|
|
|
-- Test add_season
|
|
|
|
set client_min_messages to warning;
|
|
|
|
create extension if not exists pgtap;
|
|
|
|
reset client_min_messages;
|
|
|
|
|
|
|
|
begin;
|
|
|
|
|
|
|
|
set search_path to camper, public;
|
|
|
|
|
|
|
|
select plan(13);
|
|
|
|
|
|
|
|
select has_function('camper', 'add_season', array ['integer', 'text', 'color']);
|
|
|
|
select function_lang_is('camper', 'add_season', array ['integer', 'text', 'color'], 'sql');
|
|
|
|
select function_returns('camper', 'add_season', array ['integer', 'text', 'color'], 'uuid');
|
|
|
|
select isnt_definer('camper', 'add_season', array ['integer', 'text', 'color']);
|
|
|
|
select volatility_is('camper', 'add_season', array ['integer', 'text', 'color'], 'volatile');
|
|
|
|
select function_privs_are('camper', 'add_season', array ['integer', 'text', 'color'], 'guest', array[]::text[]);
|
|
|
|
select function_privs_are('camper', 'add_season', array ['integer', 'text', 'color'], 'employee', array[]::text[]);
|
|
|
|
select function_privs_are('camper', 'add_season', array ['integer', 'text', 'color'], 'admin', array['EXECUTE']);
|
|
|
|
select function_privs_are('camper', 'add_season', array ['integer', 'text', 'color'], 'authenticator', array[]::text[]);
|
|
|
|
|
|
|
|
|
|
|
|
set client_min_messages to warning;
|
|
|
|
truncate season cascade;
|
|
|
|
truncate company cascade;
|
|
|
|
reset client_min_messages;
|
|
|
|
|
2024-01-14 01:09:17 +00:00
|
|
|
insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, rtc_number, tourist_tax, country_code, currency_code, default_lang_tag)
|
|
|
|
values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', '', 60, 'ES', 'EUR', 'ca')
|
|
|
|
, (2, 'Company 4', 'XX234', '', '666-666-666', 'b@b', '', '', '', '', '', '', 60, 'FR', 'USD', 'ca')
|
Add seasons’ relation, functions, and admin section
Seasons have a color to show on the calendar. I need them in HTML format
(e.g., #123abc) in order to set as value to `<input type="color">`, but
i did not want to save them as text in the database, as integers are
better representations of colors—in fact, that’s what the HTML syntax
also is: an integer.
I think the best would be to create an extension that adds an HTML color
type, with functions to convert from many representations (e.g., CSS’
rgb or even color names) to integer and back. However, that’s a lot of
work and i can satisfy Camper’s needs with just a couple of functions
and a domain.
To show the color on the index, at first tried to use a read-only
`<input type="color">`, but seems that this type of input can not be
read-only and must be disabled instead. However, i do not know whether
it makes sense to have a disabled input outside a form “just” to show
a color; i suspect it does not. Thus, at the end i use SVG with a
single circle, which is better that a 50%-rounded div with a background
color, even if the result is the same—SVG **is** intended for showing
pictures, which is this case.
2023-08-16 18:15:57 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
select lives_ok(
|
|
|
|
$$ select add_season(1, 'Low', '#232323') $$,
|
|
|
|
'Should be able to add a season to the first company'
|
|
|
|
);
|
|
|
|
|
|
|
|
select lives_ok(
|
|
|
|
$$ select add_season(1, 'Mid', '#555555') $$,
|
|
|
|
'Should be able to add another season to the same company'
|
|
|
|
);
|
|
|
|
|
|
|
|
select lives_ok(
|
|
|
|
$$ select add_season(2, 'High', '#a0a0a0') $$,
|
|
|
|
'Should be able to add a season to the second company'
|
|
|
|
);
|
|
|
|
|
|
|
|
select bag_eq(
|
|
|
|
$$ select company_id, name, to_color(color)::text, active from season $$,
|
|
|
|
$$ values (1, 'Low', '#232323', true)
|
|
|
|
, (1, 'Mid', '#555555', true)
|
|
|
|
, (2, 'High', '#a0a0a0', true)
|
|
|
|
$$,
|
|
|
|
'Should have added all seasons'
|
|
|
|
);
|
|
|
|
|
|
|
|
select *
|
|
|
|
from finish();
|
|
|
|
|
|
|
|
rollback;
|