@opengis/admin 0.4.35 → 0.4.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/admin",
3
- "version": "0.4.35",
3
+ "version": "0.4.37",
4
4
  "description": "This project Softpro Admin",
5
5
  "main": "dist/admin.js",
6
6
  "type": "module",
@@ -17,8 +17,11 @@ export default async function descriptionList(data, opt) {
17
17
 
18
18
  // no data
19
19
  if (hash.nodata && !data) {
20
- const noDataText = typeof hash.nodata == 'string' ? hash.nodata : '<div class="bg-gray-200 text-center p-6 rounded-xl"><h3 class="text-lg font-semibold">Інформація відсутня</h3></div>';
21
- return noDataText
20
+ const noDataText =
21
+ typeof hash.nodata == 'string'
22
+ ? hash.nodata
23
+ : '<div class="bg-gray-200 dark:bg-transparent dark:text-white text-center p-6 rounded-xl"><h3 class="text-lg font-semibold">Інформація відсутня</h3></div>';
24
+ return noDataText;
22
25
  }
23
26
  if (!hash.columns) return 'columns empty'
24
27
  const keys = hash.columns.split(hash.divider || ',').map(el => hash.comma ? el.trim().replace(new RegExp(hash.comma || '#', 'g'), ',') : el.trim());
@@ -35,12 +38,22 @@ export default async function descriptionList(data, opt) {
35
38
 
36
39
  const d1 = await format(data[key], key, data) || '-';
37
40
 
38
- result.push(`<div class="grid grid-cols-1 gap-1 py-3 sm:grid-cols-3 sm:gap-4 even:bg-gray-50 text-[12px]">
39
- <dt class="text-gray-900">${nameHBS || name}</dt>
40
- <dd class="text-gray-700 sm:col-span-2">${d1}</dd>
41
+ result.push(`
42
+ <div class="grid grid-cols-1 gap-1 py-3 sm:grid-cols-3 sm:gap-4
43
+ even:bg-gray-50 dark:bg-transparent bg-white
44
+ text-[12px] text-gray-700 dark:text-white">
45
+ <dt class="text-gray-900 dark:text-white">${nameHBS || name}</dt>
46
+ <dd class="text-gray-700 dark:text-white sm:col-span-2">${d1}</dd>
41
47
  </div>
42
48
  `);
43
49
 
44
50
  }
45
- return '<dl class=" divide-y divide-gray-100 py-[5px] w-full">' + result.join('') + '</dl>';
51
+ return `
52
+ <div class="min-w-full relative overflow-auto
53
+ divide-y divide-gray-200 dark:divide-gray-700
54
+ bg-white dark:bg-transparent
55
+ text-[12px] text-gray-600 dark:text-white">
56
+ ${result.join('')}
57
+ </div>
58
+ `;
46
59
  }
@@ -31,7 +31,7 @@ export default async function tableList(data, opt) {
31
31
  const keys = hash.columns.split(hash.divider || ',').map(el => hash.comma ? el.trim().replace(new RegExp(hash.comma, 'g'), ',') : el.trim()).concat(hash.uid && hash.table && hash.id && !hash.noactions ? ['Дії', 'actions'] : []);
32
32
 
33
33
  const result = [];
34
- result.push('<thead class="text-left font-medium text-gray-700"> <tr>');
34
+ result.push('<thead class="text-left font-medium text-gray-700 dark:text-white dark:bg-transparent"> <tr>');
35
35
 
36
36
  // thead
37
37
  const skip = {}
@@ -48,16 +48,19 @@ export default async function tableList(data, opt) {
48
48
  if (skip[name]) continue;
49
49
 
50
50
  const isActionsColumn = hash.noactions && i === keys.length - 2;
51
- result.push(`<th class="py-2 min-w-[200px] ${isActionsColumn ? 'last:min-w-[60px] last:max-w-[60px] last:bg-white last:sticky last:right-0' : ''}">
52
- ${nameHBS || name}
53
- </th>`)
51
+ result.push(`
52
+ <th class="py-2 min-w-[200px] ${isActionsColumn
53
+ ? 'last:min-w-[60px] last:max-w-[60px] last:bg-white last:sticky last:right-0'
54
+ : ''}">
55
+ ${nameHBS || name}
56
+ </th>`);
54
57
  }
55
- result.push('</tr></thead><tbody class="divide-y divide-gray-200">');
58
+ result.push('</tr></thead><tbody class="divide-y divide-gray-200 dark:divide-gray-700">');
56
59
 
57
60
  // body
58
61
  for (let k = 0; k < data.length; k += 1) {
59
62
  const row = data[k];
60
- result.push('<tr class="bg-white odd:bg-gray-50 ">');
63
+ result.push('<tr class="bg-white odd:bg-gray-50 dark:bg-transparent dark:odd:bg-transparent">');
61
64
  const obj = { form: hash.form, table: hash.table, id: row[hash.id] }
62
65
  const token = hash.table ? setToken({ ids: [JSON.stringify(obj)], uid: hash.uid, array: 1 })[0] : null;
63
66
  for (let i = 0; i < keys.length; i += 2) {
@@ -70,9 +73,10 @@ export default async function tableList(data, opt) {
70
73
  const tokenData = key == 'actions' ? token : null;
71
74
  const d1 = key.includes('{{') ? await handlebars.compile(key)({ ...row, token, hash }) || '-' : null
72
75
  const isActionsColumn = hash.noactions && i === keys.length - 2;
73
- result.push(`<td class="py-2 pr-5 ${isActionsColumn ? 'last:sticky last:right-0' : ''}">
74
- ${d1 || format(tokenData || row[key], key, row, hash)}
75
- </td>`);
76
+ result.push(`
77
+ <td class="py-2 pr-5 ${isActionsColumn ? 'last:sticky last:right-0' : ''} dark:text-white">
78
+ ${d1 || format(tokenData || row[key], key, row, hash)}
79
+ </td>`);
76
80
 
77
81
  }
78
82
  // action token
@@ -82,5 +86,10 @@ export default async function tableList(data, opt) {
82
86
  result.push('</tbody>');
83
87
 
84
88
  // console.log(Date.now() - time)
85
- return '<table class="min-w-full relative divide-y-2 divide-gray-200 bg-white min-w-full overflow-auto divide-y-2 divide-gray-200 bg-white text-[12px] text-gray-600">' + result.join('') + '</table>';
89
+ return `<table class="min-w-full relative overflow-auto
90
+ divide-y-2 divide-gray-200 dark:divide-gray-700
91
+ bg-white dark:bg-transparent
92
+ text-[12px] text-gray-600 dark:text-white">
93
+ ${result.join('')}
94
+ </table>`;
86
95
  }
@@ -2,8 +2,8 @@ import { addHook } from '@opengis/fastify-table/utils.js';
2
2
 
3
3
  // api
4
4
  import testEmail from './controllers/testEmail.js';
5
- import readNotifications from './controllers/readNotifications.js'; // mark as read
6
- import userNotifications from './controllers/userNotifications.js'; // check all, backend pagination
5
+ // import readNotifications from './controllers/readNotifications.js'; // mark as read
6
+ // import userNotifications from './controllers/userNotifications.js'; // check all, backend pagination
7
7
 
8
8
  // hook
9
9
  import onWidgetSet from './hook/onWidgetSet.js'; // send notification on comment
@@ -12,7 +12,14 @@ import onWidgetSet from './hook/onWidgetSet.js'; // send notification on comment
12
12
  // import addNotification from '../notifications/funcs/addNotification.js'; // add to db
13
13
  // import notification from '../notifications/funcs/sendNotification.js'; // send notification
14
14
 
15
- import { notificationSchema, emailSchema } from './schema.js';
15
+ const emailSchema = {
16
+ type: 'object',
17
+ properties: {
18
+ quertstring: {
19
+ to: { type: 'string', pattern: '^((?!\\.)[\\w\\-_.]*[^.])(@\\w+)(\\.\\w+(\\.\\w+)?[^.\\W])$' },
20
+ },
21
+ },
22
+ };
16
23
 
17
24
  export default async function route(fastify) {
18
25
 
@@ -20,7 +27,7 @@ export default async function route(fastify) {
20
27
  // fastify.decorate('notification', notification);
21
28
 
22
29
  fastify.get('/test-email', { config: { policy: ['user'] }, schema: emailSchema }, testEmail);
23
- fastify.get('/notification', { config: { policy: ['user'] }, schema: notificationSchema }, userNotifications);
24
- fastify.get('/notification-read/:id?', { config: { policy: ['user'] }, schema: notificationSchema }, readNotifications);
30
+ // fastify.get('/notification', { config: { policy: ['user'] }, schema: notificationSchema }, userNotifications); // moved to fastify-table
31
+ // fastify.get('/notification-read/:id?', { config: { policy: ['user'] }, schema: notificationSchema }, readNotifications); // moved to fastify-table
25
32
  addHook('onWidgetSet', onWidgetSet);
26
33
  }
@@ -1,18 +0,0 @@
1
- export default async function readNotifications({
2
- pg, params = {}, query = {}, user = {},
3
- }, reply) {
4
- const { uid } = user || {};
5
-
6
- if (!uid) {
7
- return reply.status(401).send('access restricted: user ');
8
- }
9
-
10
- const q = `update crm.notifications set read=true where read is not true
11
- and ${params?.id ? 'notification_id=$2' : '1=1'} and addressee_id=$1`;
12
-
13
- if (query.sql) return q;
14
-
15
- const { rowCount = 0 } = await pg.query(q, [uid, params?.id].filter((el) => el));
16
-
17
- return reply.status(200).send(`${rowCount} unread notifications marked as read`);
18
- }
@@ -1,53 +0,0 @@
1
- // for example only
2
- /*
3
- const res = await dataInsert({
4
- pg,
5
- table: 'crm.notifications',
6
- data: {
7
- subject: 'notif title',
8
- body: 'notif body',
9
- link: 'http://localhost:3000/api/notification',
10
- addressee_id: userId,
11
- author_id: userId,
12
- },
13
- });
14
- */
15
-
16
- import { getSelectVal } from '@opengis/fastify-table/utils.js';
17
-
18
- const maxLimit = 100;
19
-
20
- export default async function userNotifications({
21
- pg, query = {}, user = {},
22
- }) {
23
- const time = Date.now();
24
-
25
- const { uid } = user || {};
26
-
27
- if (!uid) {
28
- return { message: 'access restricted', status: 403 };
29
- }
30
-
31
- const limit = Math.min(maxLimit, +(query.limit || 5));
32
- const offset = query.page && query.page > 0 ? (query.page - 1) * limit : 0;
33
-
34
- const q = `select notification_id as id, subject, body, cdate,
35
- author_id, read, link, entity_id, (select avatar from admin.users where uid=a.author_id limit 1) as avatar from crm.notifications a where addressee_id=$1 order by cdate desc limit $2 offset $3`;
36
-
37
- if (query.sql) return q;
38
-
39
- const { rows = [] } = pg.pk?.['crm.notifications'] ? await pg.query(q, [uid, limit, offset]) : {};
40
-
41
- const values = rows.map((el) => el.author_id)
42
- ?.filter((el, idx, arr) => el && arr.indexOf(el) === idx);
43
-
44
- if (values?.length) {
45
- const vals = await getSelectVal({ name: 'core.user_mentioned', values });
46
- rows.forEach((row) => {
47
- Object.assign(row, { author: vals?.[row.author_id] });
48
- });
49
- }
50
-
51
- return { time: Date.now() - time, total: rows?.length, rows };
52
-
53
- }
@@ -1,23 +0,0 @@
1
- const notificationSchema = {
2
- type: 'object',
3
- properties: {
4
- params: {
5
- id: { type: 'string', pattern: '^([\\d\\w]+)$' },
6
- },
7
- querystring: {
8
- nocache: { type: 'string', pattern: '^(\\d+)$' },
9
- },
10
- },
11
- };
12
-
13
- const emailSchema = {
14
- type: 'object',
15
- properties: {
16
- quertstring: {
17
- to: { type: 'string', pattern: '^((?!\\.)[\\w\\-_.]*[^.])(@\\w+)(\\.\\w+(\\.\\w+)?[^.\\W])$' },
18
- },
19
- },
20
- };
21
-
22
- export default null;
23
- export { notificationSchema, emailSchema }