@iotready/nextjs-components-library 1.0.0-preview4 → 1.0.0-preview41
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/assets/translations/en.json +92 -0
- package/assets/translations/index.d.ts +95 -0
- package/assets/translations/index.js +4 -0
- package/assets/translations/it.json +92 -0
- package/assets/translations/scripts/export.js +74 -0
- package/assets/translations/scripts/import.js +66 -0
- package/components/accounts/AccountMenu.d.ts +2 -1
- package/components/accounts/AccountMenu.js +2 -2
- package/components/accounts/AccountProfile.d.ts +2 -1
- package/components/accounts/AccountProfile.js +15 -15
- package/components/charts/TrendChart.d.ts +28 -6
- package/components/charts/TrendChart.js +555 -149
- package/components/groups/GroupUpdate.d.ts +9 -10
- package/components/groups/GroupUpdate.js +21 -38
- package/components/groups/GroupsDevices.d.ts +22 -17
- package/components/groups/GroupsDevices.js +165 -110
- package/components/groups/Map.d.ts +5 -9
- package/components/groups/Map.js +2 -2
- package/components/settings/DynamicMenu.d.ts +1 -0
- package/components/settings/DynamicMenu.js +2 -1
- package/components/users/UserUpdate.d.ts +2 -1
- package/components/users/UserUpdate.js +2 -2
- package/components/users/UsersDataGrid.d.ts +11 -3
- package/components/users/UsersDataGrid.js +49 -32
- package/package.json +8 -4
- package/server-actions/annotations.d.ts +4 -0
- package/server-actions/annotations.js +12 -0
- package/server-actions/groups.d.ts +16 -16
- package/server-actions/groups.js +157 -72
- package/server-actions/index.d.ts +1 -0
- package/server-actions/index.js +1 -0
- package/server-actions/influx.d.ts +17 -13
- package/server-actions/influx.js +207 -98
- package/server-actions/trackle.d.ts +10 -4
- package/server-actions/trackle.js +59 -38
- package/server-actions/types.d.ts +16 -0
- package/server-actions/types.js +6 -0
- package/types/device.d.ts +19 -0
- package/types/device.js +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/user.d.ts +2 -0
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
2
|
-
import { useState, useEffect } from 'react';
|
|
3
|
-
import { DataGrid,
|
|
4
|
-
import { Card, Box,
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
const UsersDataGrid = ({ handleGetUsersList, pageSize, container = 'Box', containerProps = {}, props = {}, loadingComponent = _jsx(CircularProgress, {}), theme }) => {
|
|
9
|
-
const router = useRouter();
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useMemo } from 'react';
|
|
3
|
+
import { DataGrid, GridLogicOperator, GridToolbarExport } from '@mui/x-data-grid';
|
|
4
|
+
import { Card, Box, CircularProgress, ThemeProvider, FormControl, IconButton, InputLabel, MenuItem, Select, TextField } from '@mui/material';
|
|
5
|
+
import { ClearIcon } from "@mui/x-date-pickers";
|
|
6
|
+
import debounce from 'lodash.debounce';
|
|
7
|
+
const UsersDataGrid = ({ handleGetUsersList, pageSize, container = 'Box', containerProps = {}, props = {}, loadingComponent = _jsx(CircularProgress, {}), theme, columns, filterTypes, t, dataGridLocaleText }) => {
|
|
10
8
|
const [usersList, setUsersList] = useState(undefined);
|
|
11
9
|
const [userCount, setUserCount] = useState(undefined);
|
|
10
|
+
const filterType = filterTypes || {
|
|
11
|
+
email: t('library.usersDataGrid.emailAddress'),
|
|
12
|
+
name: t('library.usersDataGrid.fullName'),
|
|
13
|
+
role: t('library.usersDataGrid.role')
|
|
14
|
+
};
|
|
15
|
+
const [selectedFilterValue, setSelectedFilterValue] = useState(undefined);
|
|
16
|
+
const [selectedFilterType, setSelectedFilterType] = useState('email');
|
|
12
17
|
const [isLoading, setIsLoading] = useState(true);
|
|
18
|
+
const [sortModel, setSortModel] = useState([
|
|
19
|
+
{ field: "email", sort: "desc" },
|
|
20
|
+
]);
|
|
13
21
|
const [paginationModel, setPaginationModel] = useState({
|
|
14
22
|
page: 0,
|
|
15
23
|
pageSize: pageSize || 1,
|
|
@@ -29,7 +37,8 @@ const UsersDataGrid = ({ handleGetUsersList, pageSize, container = 'Box', contai
|
|
|
29
37
|
{ value: filterModel.quickFilterValues[0] }
|
|
30
38
|
: filterModel.items.length > 0 ?
|
|
31
39
|
{ field: filterModel.items[0].field, operator: filterModel.items[0].operator, value: filterModel.items[0].value }
|
|
32
|
-
: undefined
|
|
40
|
+
: undefined,
|
|
41
|
+
sortModel
|
|
33
42
|
});
|
|
34
43
|
setUsersList(usersList.users);
|
|
35
44
|
setUserCount(usersList.rowCount);
|
|
@@ -41,36 +50,44 @@ const UsersDataGrid = ({ handleGetUsersList, pageSize, container = 'Box', contai
|
|
|
41
50
|
setIsLoading(false);
|
|
42
51
|
}
|
|
43
52
|
};
|
|
53
|
+
const debouncedUpdateFilter = useMemo(() => debounce((value) => {
|
|
54
|
+
setFilterModel({
|
|
55
|
+
items: [{
|
|
56
|
+
field: selectedFilterType || 'email',
|
|
57
|
+
operator: 'startsWith',
|
|
58
|
+
value: value
|
|
59
|
+
}],
|
|
60
|
+
});
|
|
61
|
+
}, 500), [selectedFilterType]);
|
|
62
|
+
const handleFilterModelChange = (value) => {
|
|
63
|
+
setSelectedFilterValue(value);
|
|
64
|
+
// const value = newModel.quickFilterValues?.[0] || '';
|
|
65
|
+
if (value.length >= 3 || value.length === 0) {
|
|
66
|
+
debouncedUpdateFilter(value);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
44
69
|
useEffect(() => {
|
|
45
70
|
getUsersList();
|
|
46
|
-
}, [paginationModel, filterModel]);
|
|
71
|
+
}, [paginationModel, filterModel, sortModel]);
|
|
47
72
|
if (!usersList && isLoading) {
|
|
48
73
|
return loadingComponent;
|
|
49
74
|
}
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
{
|
|
58
|
-
field: 'email', filterOperators: getGridStringOperators().filter((operator) => operator.value === 'contains' || operator.value === 'equals'), display: 'flex', flex: 0.400, minWidth: 180, headerName: 'Email address', renderCell: (params) => (_jsx(_Fragment, { children: params.value }))
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
field: 'lastSignInAt', filterable: false, disableColumnMenu: true, display: 'flex', minWidth: 160, headerName: 'Last Signed In', renderCell: (params) => (_jsx(_Fragment, { children: params.value ? moment(params.value).format('DD/MM/YYYY HH:mm:ss') : '' }))
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
field: 'id', filterable: false, disableExport: true, disableColumnMenu: true, headerName: '', display: 'flex', align: 'right', renderCell: (params) => (_jsxs(Button, { onClick: () => router.push(`/users/${params.value}`), variant: 'contained', color: 'secondary', size: 'small', children: [_jsx(EditIcon, { fontSize: 'small', sx: { mr: 1 } }), " EDIT"] }))
|
|
65
|
-
}
|
|
66
|
-
], rows: usersList, slots: {
|
|
67
|
-
toolbar: GridToolbar,
|
|
75
|
+
const handleSortModelChange = (model) => {
|
|
76
|
+
setSortModel(model);
|
|
77
|
+
setPaginationModel(prev => ({ ...prev, page: 0 }));
|
|
78
|
+
};
|
|
79
|
+
const CustomToolbar = () => (_jsx(Box, { sx: { display: 'flex', alignItems: 'center', p: 1, justifyContent: 'space-between' }, children: _jsx(GridToolbarExport, {}) }));
|
|
80
|
+
const renderUsersList = () => (_jsx("div", { style: { display: 'flex', flexDirection: 'column', minHeight: 323 }, children: _jsx(DataGrid, { disableDensitySelector: true, disableColumnSelector: true, disableRowSelectionOnClick: true, onSortModelChange: handleSortModelChange, disableColumnResize: true, columns: columns, rows: usersList, localeText: dataGridLocaleText, slots: {
|
|
81
|
+
toolbar: CustomToolbar,
|
|
68
82
|
}, slotProps: {
|
|
69
83
|
toolbar: {
|
|
70
84
|
printOptions: { disableToolbarButton: true },
|
|
71
|
-
showQuickFilter:
|
|
85
|
+
showQuickFilter: false,
|
|
72
86
|
},
|
|
73
|
-
}, rowCount: userCount, loading: isLoading, pageSizeOptions: [], paginationModel: paginationModel, paginationMode: "server", onPaginationModelChange: setPaginationModel,
|
|
74
|
-
|
|
87
|
+
}, rowCount: userCount, loading: isLoading, pageSizeOptions: [], paginationModel: paginationModel, paginationMode: "server", onPaginationModelChange: setPaginationModel, ...props }) }));
|
|
88
|
+
const renderFilter = () => (_jsxs(Box, { sx: { position: "absolute", top: 10, right: 10, zIndex: 1 }, children: [_jsxs(FormControl, { children: [_jsx(InputLabel, { shrink: true, id: "filter-by-select-label", children: t('library.usersDataGrid.filterBy') }), _jsx(Select, { value: selectedFilterType || '', onChange: (e) => setSelectedFilterType(e.target.value), labelId: "filter-by-select-label", label: t('library.usersDataGrid.filterBy'), size: "small", sx: { mr: 2 }, children: Object.entries(filterType).map(([key, label]) => (_jsx(MenuItem, { value: key, children: label }, key))) })] }), _jsx(TextField, { value: selectedFilterValue || "", onChange: (e) => handleFilterModelChange(e.target.value), placeholder: t('library.usersDataGrid.search'), size: "small", InputProps: {
|
|
89
|
+
endAdornment: selectedFilterValue ? (_jsx(IconButton, { size: "small", onClick: () => handleFilterModelChange(""), children: _jsx(ClearIcon, { fontSize: "small" }) })) : null,
|
|
90
|
+
} })] }));
|
|
91
|
+
return _jsx(ThemeProvider, { theme: theme, children: container === "Card" ? (_jsx(_Fragment, { children: _jsxs(Card, { ...containerProps, sx: { position: 'relative', ...(containerProps?.sx) }, children: [renderFilter(), renderUsersList()] }) })) : (_jsxs(_Fragment, { children: [renderFilter(), _jsxs(Box, { ...containerProps, sx: { position: 'relative', ...(containerProps?.sx) }, children: [renderFilter(), renderUsersList()] })] })) });
|
|
75
92
|
};
|
|
76
93
|
export default UsersDataGrid;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iotready/nextjs-components-library",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-preview41",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"build": "rm -rf dist && tsc --project tsconfig.build.json && cp package.json dist/",
|
|
6
|
+
"build": "rm -rf dist && tsc --project tsconfig.build.json && cp package.json dist/ && cp -r assets dist/",
|
|
7
7
|
"dev": "next dev",
|
|
8
8
|
"start": "next start",
|
|
9
9
|
"lint": "next lint"
|
|
@@ -19,9 +19,12 @@
|
|
|
19
19
|
"chartjs-adapter-moment": "^1.0.1",
|
|
20
20
|
"chartjs-plugin-annotation": "^3.1.0",
|
|
21
21
|
"chartjs-plugin-zoom": "^2.0.1",
|
|
22
|
-
"
|
|
22
|
+
"csv-parse": "^5.6.0",
|
|
23
|
+
"exceljs": "^4.4.0",
|
|
24
|
+
"firebase-admin": "^13.4.0",
|
|
23
25
|
"leaflet": "^1.9.4",
|
|
24
26
|
"leaflet-defaulticon-compatibility": "^0.1.2",
|
|
27
|
+
"lodash.debounce": "^4.0.8",
|
|
25
28
|
"material-ui-confirm": "^3.0.16",
|
|
26
29
|
"moment": "^2.30.1",
|
|
27
30
|
"next": "^14.2.9",
|
|
@@ -34,6 +37,7 @@
|
|
|
34
37
|
},
|
|
35
38
|
"devDependencies": {
|
|
36
39
|
"@types/leaflet": "^1.9.13",
|
|
40
|
+
"@types/lodash.debounce": "^4.0.9",
|
|
37
41
|
"@types/node": "^20",
|
|
38
42
|
"@types/react": "^18",
|
|
39
43
|
"@types/react-csv": "^1.1.10",
|
|
@@ -42,4 +46,4 @@
|
|
|
42
46
|
"eslint-config-next": "14.2.9",
|
|
43
47
|
"typescript": "^5"
|
|
44
48
|
}
|
|
45
|
-
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
export const getAnnotations = async (db, deviceID) => {
|
|
3
|
+
const annotationsRef = db.collection("annotations");
|
|
4
|
+
const snapshot = await annotationsRef
|
|
5
|
+
.where("target", "==", deviceID)
|
|
6
|
+
.orderBy("createdAt", "desc")
|
|
7
|
+
.get();
|
|
8
|
+
return snapshot.docs.map((doc) => ({
|
|
9
|
+
id: doc.id,
|
|
10
|
+
...doc.data()
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
authDomain: string;
|
|
4
|
-
projectId: string;
|
|
5
|
-
storageBucket: string;
|
|
6
|
-
messagingSenderId: string;
|
|
7
|
-
appId: string;
|
|
8
|
-
};
|
|
9
|
-
export declare const getGroups: (firebaseConfig: FirebaseConfig, productID: number, userID?: string) => Promise<{
|
|
1
|
+
import { Firestore } from "firebase-admin/firestore";
|
|
2
|
+
export declare const getGroups: (db: Firestore, productID: number, userID?: string, parentID?: string, assetID?: string) => Promise<{
|
|
10
3
|
id: string;
|
|
11
4
|
}[]>;
|
|
12
|
-
export declare const getGroupById: (
|
|
5
|
+
export declare const getGroupById: (db: Firestore, id: string) => Promise<{
|
|
13
6
|
id: string;
|
|
14
7
|
}>;
|
|
15
|
-
export declare const createGroup: (
|
|
16
|
-
export declare const updateGroup: (
|
|
17
|
-
export declare const deleteGroup: (
|
|
18
|
-
export declare const getUsersGroup: (
|
|
8
|
+
export declare const createGroup: (db: Firestore, group: any) => Promise<string>;
|
|
9
|
+
export declare const updateGroup: (db: Firestore, id: string, group: any) => Promise<any>;
|
|
10
|
+
export declare const deleteGroup: (db: Firestore, id: string) => Promise<void>;
|
|
11
|
+
export declare const getUsersGroup: (db: Firestore, groupID: string) => Promise<{
|
|
19
12
|
id: string;
|
|
20
13
|
}[]>;
|
|
21
|
-
export declare const
|
|
22
|
-
|
|
14
|
+
export declare const getGroupsUser: (db: Firestore, userID: string) => Promise<{
|
|
15
|
+
id: string;
|
|
16
|
+
}[]>;
|
|
17
|
+
export declare const addUsersGroup: (db: Firestore, groupID: string, userName: string, userID: string) => Promise<string>;
|
|
18
|
+
export declare const removeUserGroup: (db: Firestore, groupID: string, userID: string) => Promise<string | undefined>;
|
|
19
|
+
export declare const getUserOrganizations: (db: Firestore, productID: number, userID?: string, searchParentIds?: boolean, assetID?: string) => Promise<{
|
|
20
|
+
id: string;
|
|
21
|
+
}[]>;
|
|
22
|
+
export declare const getCustomerOrganizations: (db: Firestore, userOrganizations: string[]) => Promise<any[]>;
|
package/server-actions/groups.js
CHANGED
|
@@ -1,87 +1,94 @@
|
|
|
1
1
|
"use server";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
// 1. GET GROUPS
|
|
3
|
+
export const getGroups = async (db, productID, userID, parentID, assetID) => {
|
|
4
|
+
let groupsRef = db.collection("groups").where("productID", "==", productID);
|
|
5
|
+
if (parentID) {
|
|
6
|
+
if (parentID === "all") {
|
|
7
|
+
groupsRef = groupsRef.where("parent_id", "!=", null);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
groupsRef = groupsRef.where("parent_id", "==", parentID);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
if (assetID) {
|
|
14
|
+
groupsRef = groupsRef.where("assets", "array-contains", assetID);
|
|
15
|
+
}
|
|
16
|
+
groupsRef = groupsRef.orderBy("created", "desc");
|
|
10
17
|
let groupIds = null;
|
|
11
18
|
if (userID) {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
const userGroupsSnapshot = await db
|
|
20
|
+
.collection("userGroups")
|
|
21
|
+
.where("user.userId", "==", userID)
|
|
22
|
+
.get();
|
|
23
|
+
groupIds = userGroupsSnapshot.docs.map((doc) => doc.data().groupId);
|
|
15
24
|
}
|
|
16
|
-
const groupsSnapshot = await
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.map((doc) => ({
|
|
21
|
-
id: doc.id,
|
|
22
|
-
...doc.data()
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
return groupsSnapshot.docs.map((doc) => ({
|
|
25
|
+
const groupsSnapshot = await groupsRef.get();
|
|
26
|
+
return groupsSnapshot.docs
|
|
27
|
+
.filter((doc) => !groupIds || groupIds.includes(doc.id))
|
|
28
|
+
.map((doc) => ({
|
|
26
29
|
id: doc.id,
|
|
27
30
|
...doc.data()
|
|
28
31
|
}));
|
|
29
32
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const groupSnapshot = await getDoc(doc(db, "groups", id));
|
|
33
|
+
// 2. GET GROUP BY ID
|
|
34
|
+
export const getGroupById = async (db, id) => {
|
|
35
|
+
const docSnapshot = await db.collection("groups").doc(id).get();
|
|
34
36
|
return {
|
|
35
|
-
id:
|
|
36
|
-
...
|
|
37
|
+
id: docSnapshot.id,
|
|
38
|
+
...docSnapshot.data()
|
|
37
39
|
};
|
|
38
40
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
// 3. CREATE GROUP
|
|
42
|
+
export const createGroup = async (db, group) => {
|
|
41
43
|
const newGroup = {
|
|
42
44
|
...group,
|
|
43
|
-
created
|
|
45
|
+
created: new Date().toISOString()
|
|
44
46
|
};
|
|
45
|
-
const
|
|
46
|
-
const db = getFirestore(app);
|
|
47
|
-
const docRef = await addDoc(collection(db, "groups"), newGroup);
|
|
47
|
+
const docRef = await db.collection("groups").add(newGroup);
|
|
48
48
|
return docRef.id;
|
|
49
49
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const groupRef = doc(db, "groups", id);
|
|
54
|
-
await updateDoc(groupRef, group);
|
|
50
|
+
// 4. UPDATE GROUP
|
|
51
|
+
export const updateGroup = async (db, id, group) => {
|
|
52
|
+
await db.collection("groups").doc(id).update(group);
|
|
55
53
|
return group;
|
|
56
54
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
// 5. DELETE GROUP
|
|
56
|
+
export const deleteGroup = async (db, id) => {
|
|
57
|
+
const userGroupsSnapshot = await db
|
|
58
|
+
.collection("userGroups")
|
|
59
|
+
.where("groupId", "==", id)
|
|
60
|
+
.get();
|
|
61
|
+
const batch = db.batch();
|
|
62
|
+
userGroupsSnapshot.docs.forEach((doc) => {
|
|
63
|
+
batch.delete(doc.ref);
|
|
65
64
|
});
|
|
66
|
-
|
|
67
|
-
await
|
|
65
|
+
batch.delete(db.collection("groups").doc(id));
|
|
66
|
+
await batch.commit();
|
|
68
67
|
};
|
|
69
|
-
// USERS
|
|
70
|
-
export const getUsersGroup = async (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return groupsSnapshot.docs.map((doc) => ({
|
|
68
|
+
// 6. GET USERS GROUP
|
|
69
|
+
export const getUsersGroup = async (db, groupID) => {
|
|
70
|
+
const snapshot = await db
|
|
71
|
+
.collection("userGroups")
|
|
72
|
+
.where("groupId", "==", groupID)
|
|
73
|
+
.get();
|
|
74
|
+
return snapshot.docs.map((doc) => ({
|
|
77
75
|
id: doc.id,
|
|
78
76
|
...doc.data()
|
|
79
77
|
}));
|
|
80
78
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
79
|
+
// 6b. GET GROUPS USER
|
|
80
|
+
export const getGroupsUser = async (db, userID) => {
|
|
81
|
+
const snapshot = await db
|
|
82
|
+
.collection("userGroups")
|
|
83
|
+
.where("user.userId", "==", userID)
|
|
84
|
+
.get();
|
|
85
|
+
return snapshot.docs.map((doc) => ({
|
|
86
|
+
id: doc.id,
|
|
87
|
+
...doc.data()
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
// 7. ADD USER TO GROUP
|
|
91
|
+
export const addUsersGroup = async (db, groupID, userName, userID) => {
|
|
85
92
|
const created = new Date().toISOString();
|
|
86
93
|
const newUserGroup = {
|
|
87
94
|
user: {
|
|
@@ -91,19 +98,97 @@ export const addUsersGroup = async (firebaseConfig, groupID, userName, userID) =
|
|
|
91
98
|
groupId: groupID,
|
|
92
99
|
created
|
|
93
100
|
};
|
|
94
|
-
const docRef = await
|
|
101
|
+
const docRef = await db.collection("userGroups").add(newUserGroup);
|
|
95
102
|
return docRef.id;
|
|
96
103
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
await
|
|
107
|
-
return
|
|
104
|
+
// 8. REMOVE USER FROM GROUP
|
|
105
|
+
export const removeUserGroup = async (db, groupID, userID) => {
|
|
106
|
+
const snapshot = await db
|
|
107
|
+
.collection("userGroups")
|
|
108
|
+
.where("groupId", "==", groupID)
|
|
109
|
+
.where("user.userId", "==", userID)
|
|
110
|
+
.get();
|
|
111
|
+
const doc = snapshot.docs[0];
|
|
112
|
+
if (doc) {
|
|
113
|
+
await doc.ref.delete();
|
|
114
|
+
return doc.id;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
// 9. GET ORGANIZATIONS
|
|
118
|
+
export const getUserOrganizations = async (db, productID, userID, searchParentIds, assetID) => {
|
|
119
|
+
let groupsRef = db.collection("groups").where("productID", "==", productID);
|
|
120
|
+
if (assetID) {
|
|
121
|
+
groupsRef = groupsRef.where("assets", "array-contains", assetID);
|
|
122
|
+
}
|
|
123
|
+
groupsRef = groupsRef.orderBy("created", "desc");
|
|
124
|
+
let groupIds = null;
|
|
125
|
+
if (userID) {
|
|
126
|
+
const userGroupsSnapshot = await db
|
|
127
|
+
.collection("userGroups")
|
|
128
|
+
.where("user.userId", "==", userID)
|
|
129
|
+
.get();
|
|
130
|
+
const userGroupIds = userGroupsSnapshot.docs.map((doc) => doc.data().groupId);
|
|
131
|
+
if (userGroupIds.length > 0) {
|
|
132
|
+
if (searchParentIds) {
|
|
133
|
+
const chunks = [];
|
|
134
|
+
let parentIds = [];
|
|
135
|
+
for (let i = 0; i < userGroupIds.length; i += 10) {
|
|
136
|
+
chunks.push(userGroupIds.slice(i, i + 10));
|
|
137
|
+
}
|
|
138
|
+
for (const chunk of chunks) {
|
|
139
|
+
const groupsSnapshot = await db
|
|
140
|
+
.collection("groups")
|
|
141
|
+
.where("__name__", "in", chunk)
|
|
142
|
+
.get();
|
|
143
|
+
const ids = groupsSnapshot.docs
|
|
144
|
+
.map((doc) => doc.data().parent_id)
|
|
145
|
+
.filter((id) => id !== null && id !== undefined);
|
|
146
|
+
parentIds.push(...ids);
|
|
147
|
+
}
|
|
148
|
+
// Rimuove duplicati
|
|
149
|
+
groupIds = Array.from(new Set(parentIds));
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
// support role
|
|
153
|
+
groupIds = userGroupIds;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
groupIds = [];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const groupsSnapshot = await groupsRef.get();
|
|
161
|
+
const organizations = groupsSnapshot.docs
|
|
162
|
+
.filter((doc) => {
|
|
163
|
+
const data = doc.data();
|
|
164
|
+
const parentId = data.parent_id;
|
|
165
|
+
return ((parentId === null || parentId === undefined) &&
|
|
166
|
+
(!groupIds || groupIds.includes(doc.id)));
|
|
167
|
+
})
|
|
168
|
+
.map((doc) => ({
|
|
169
|
+
id: doc.id,
|
|
170
|
+
...doc.data()
|
|
171
|
+
}));
|
|
172
|
+
return organizations;
|
|
173
|
+
};
|
|
174
|
+
export const getCustomerOrganizations = async (db, userOrganizations) => {
|
|
175
|
+
if (userOrganizations.length === 0) {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
const chunks = [];
|
|
179
|
+
const organizations = [];
|
|
180
|
+
for (let i = 0; i < userOrganizations.length; i += 10) {
|
|
181
|
+
chunks.push(userOrganizations.slice(i, i + 10));
|
|
182
|
+
}
|
|
183
|
+
for (const chunk of chunks) {
|
|
184
|
+
const groupsSnapshot = await db
|
|
185
|
+
.collection("groups")
|
|
186
|
+
.where("__name__", "in", chunk)
|
|
187
|
+
.get();
|
|
188
|
+
organizations.push(...groupsSnapshot.docs.map((doc) => ({
|
|
189
|
+
id: doc.id,
|
|
190
|
+
...doc.data()
|
|
191
|
+
})));
|
|
108
192
|
}
|
|
193
|
+
return organizations;
|
|
109
194
|
};
|
package/server-actions/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { FilterTagMode, InfluxConfig, InfluxFillType } from "./types";
|
|
2
|
+
export declare function getInfluxAlerts(influxConfig: InfluxConfig, fields: string[], limit: number, offset: number, sort: any, filter: {
|
|
3
|
+
field: string;
|
|
4
|
+
value: string;
|
|
5
|
+
}, timeStart: number, timeEnd: number, aggregate?: boolean): Promise<any>;
|
|
6
|
+
export declare function getDwSlots(influxConfig: InfluxConfig, timeStart: number, timeEnd: number, filter: {
|
|
7
|
+
field: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}): Promise<any>;
|
|
10
|
+
export declare function getInfluxDataV1(influxConfig: InfluxConfig, field: string, timeStart: number, timeEnd: number, filter: {
|
|
11
|
+
field: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}, timeGroup: string, raw: boolean, fill?: InfluxFillType, filterTag?: number, tagInclude?: FilterTagMode): Promise<any>;
|
|
14
|
+
export declare function exportDataV1(influxConfig: InfluxConfig, field: string, timeStart: number, timeEnd: number, filter: {
|
|
15
|
+
field: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}): Promise<any>;
|