@fto-consult/expo-ui 4.0.4 → 4.2.0
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/babel.config.alias.js +3 -3
- package/bin/index.js +60 -14
- package/bin/init.js +82 -0
- package/bin/package.js +59 -0
- package/electron/app/instance.js +1 -1
- package/electron/create-index-file.js +13 -0
- package/electron/dependencies.js +11 -0
- package/electron/index.js +71 -58
- package/electron/init/index.js +0 -0
- package/electron/init/main.js +10 -0
- package/electron/init/renderer.js +6 -0
- package/electron/is-initialized.js +12 -0
- package/electron/package.json +32 -0
- package/electron/pload.js +2 -2
- package/electron/preload.js +4 -4
- package/electron/{config.js → utils/config.js} +0 -0
- package/electron/{copy.js → utils/copy.js} +0 -0
- package/electron/{createDir.js → utils/createDir.js} +0 -0
- package/electron/{createDirSync.js → utils/createDirSync.js} +0 -0
- package/electron/{exec.js → utils/exec.js} +5 -2
- package/electron/{getDirname.js → utils/getDirname.js} +0 -0
- package/electron/utils/getIcon.js +25 -0
- package/electron/{parseArgs.js → utils/parseArgs.js} +0 -0
- package/electron/{postMessage.js → utils/postMessage.js} +0 -0
- package/electron/{session.js → utils/session.js} +0 -0
- package/electron/{writeFile.js → utils/writeFile.js} +0 -0
- package/package.json +3 -7
- package/readMe.md +8 -3
- package/src/components/Countries/resources/countries-normalized.json +1987 -1987
- package/src/components/Countries/resources/countries-with-not-extra.json +1211 -1211
- package/src/components/Countries/resources/countries.sql +243 -243
- package/src/components/Form/Fields/SelectTableData/Component.js +1 -1
- package/src/layouts/Screen/TableData.js +7 -1
- package/src/navigation/utils.js +2 -1
- package/src/screens/Auth/PermLine.js +195 -0
- package/src/screens/Auth/PermLines.js +102 -355
- package/src/screens/Auth/PermText.js +62 -0
- package/src/screens/Auth/index.js +3 -1
- package/src/screens/Auth/utils.js +36 -1
- package/electron/getIcon.js +0 -24
- package/electron/package.app.json +0 -44
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import PermText from "./PermText";
|
|
2
|
+
import React from "$react";
|
|
3
|
+
import Expandable from "$ecomponents/Expandable";
|
|
4
|
+
import {defaultObj,defaultStr,arrayValueExists,isNonNullString,defaultVal} from "$cutils";
|
|
5
|
+
import PropTypes from "prop-types";
|
|
6
|
+
import {hasResource} from "./utils";
|
|
7
|
+
import { StyleSheet } from "react-native";
|
|
8
|
+
import View from "$ecomponents/View";
|
|
9
|
+
import {Cell} from "$ecomponents/Grid";
|
|
10
|
+
|
|
11
|
+
const PermLine = ({text,cellProps,isUserMasterAdmin,withGrid,defaultActions,resource,perms:cPerms,disabled,allPerms,table,index,onChange,keyname,actions,testID,...rest})=>{
|
|
12
|
+
const [state,setState] = React.useState({
|
|
13
|
+
data : defaultObj(rest.data),
|
|
14
|
+
expanded : defaultBool(rest.expanded,false)
|
|
15
|
+
});
|
|
16
|
+
allPerms = defaultObj(allPerms);
|
|
17
|
+
cellProps = defaultObj(cellProps);
|
|
18
|
+
testID = defaultStr(testID,"RN_AuthPermLineComponent_"+index);
|
|
19
|
+
table = defaultStr(table).toLowerCase();
|
|
20
|
+
resource = resource.toLowerCase();
|
|
21
|
+
if(!table) {
|
|
22
|
+
console.error("table non spécifiée pour la perm line ",table,rest);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
cPerms = defaultObj(cPerms);;
|
|
26
|
+
const perms = React.useMemo(()=>{
|
|
27
|
+
const perms = defaultObj(cPerms);
|
|
28
|
+
if(perms.defaultActions !== false || (isObj(perms[resource]) && Object.size(perms[resource],true)>0)){
|
|
29
|
+
const _acts = perms.defaultActions !== false ? {...defaultActions} : {};
|
|
30
|
+
Object.map(_acts,(a,aa)=>{
|
|
31
|
+
const aa2 = a && a.alias && typeof a.alias =='string' && a.alias;
|
|
32
|
+
if(perms[aa] === false || perms[aa.toLowerCase()+'Action'] === false || (aa2 && (perms[aa2] === false || perms[aa2.toLowerCase()+'Action'] === false))){
|
|
33
|
+
delete _acts[aa];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
if(isObj(perms[resource])){
|
|
37
|
+
perms[resource] = {
|
|
38
|
+
...perms[resource],
|
|
39
|
+
actions : {
|
|
40
|
+
..._acts,
|
|
41
|
+
...defaultObj(perms[resource].actions)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
perms[resource] = {
|
|
46
|
+
text,
|
|
47
|
+
actions : _acts
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return perms;
|
|
52
|
+
},[cPerms.defaultActions,cPerms[resource]])
|
|
53
|
+
let allChecked = true;
|
|
54
|
+
isUserMasterAdmin = !!isUserMasterAdmin;
|
|
55
|
+
let checked = isUserMasterAdmin;
|
|
56
|
+
const onToggleSingle = ({resource,checked,action})=>{
|
|
57
|
+
if(isUserMasterAdmin || !isNonNullString(action) || !isNonNullString(resource) || !isNonNullString(allPerms[resource])){
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const data = {...state.data};
|
|
61
|
+
const allAction = defaultStr(allPerms[resource]);
|
|
62
|
+
if(allAction == "all"){
|
|
63
|
+
if(checked){
|
|
64
|
+
data[resource] = allAction;
|
|
65
|
+
} else delete data[resource];
|
|
66
|
+
} else {
|
|
67
|
+
data[resource] = defaultStr(data[resource]).toLowerCase();
|
|
68
|
+
let spl = data[resource].split("2");
|
|
69
|
+
if(checked){
|
|
70
|
+
if(action !== 'read' && arrayValueExists(allAction.toLowerCase().split("2"),'read') && !arrayValueExists(spl,'read')){
|
|
71
|
+
spl.push('read');
|
|
72
|
+
}
|
|
73
|
+
if(!arrayValueExists(spl,action,true)){
|
|
74
|
+
spl.push(action);
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
let s1 = [];
|
|
78
|
+
for(let i in spl){
|
|
79
|
+
if(spl[i].toLowerCase() !== action.toLowerCase()){
|
|
80
|
+
s1.push(spl[i]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
spl = s1;
|
|
84
|
+
}
|
|
85
|
+
if(spl.length>0){
|
|
86
|
+
data[resource] = spl.join("2").ltrim("2").rtrim("2");
|
|
87
|
+
} else delete data[resource];
|
|
88
|
+
}
|
|
89
|
+
setState({...state,data});
|
|
90
|
+
}
|
|
91
|
+
const toggleAll = (arg)=>{
|
|
92
|
+
const {checked} = arg;
|
|
93
|
+
const data = {...state.data};
|
|
94
|
+
for(let i in allPerms){
|
|
95
|
+
if(hasResource(i,resource)){
|
|
96
|
+
if(!checked){
|
|
97
|
+
delete data[i];
|
|
98
|
+
} else {
|
|
99
|
+
data[i] = allPerms[i];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
setState({...state,data});
|
|
104
|
+
}
|
|
105
|
+
React.useEffect(()=>{
|
|
106
|
+
if(onChange){
|
|
107
|
+
onChange({data:state.data,resource,table});
|
|
108
|
+
}
|
|
109
|
+
},[state.data])
|
|
110
|
+
const content = [];
|
|
111
|
+
Object.map(perms,(perm,i)=>{
|
|
112
|
+
const pText = defaultStr(perm.text,perm.label);
|
|
113
|
+
if(!isObj(perm.actions)){
|
|
114
|
+
if(!isNonNullString(pText)) return null;
|
|
115
|
+
allPerms[i] = "all";
|
|
116
|
+
checked = isUserMasterAdmin? true : isNonNullString(state.data[i]);
|
|
117
|
+
if(!checked){
|
|
118
|
+
allChecked = false;
|
|
119
|
+
}
|
|
120
|
+
content.push(<PermText isUserMasterAdmin={isUserMasterAdmin} key = {i} table={table} tooltip={defaultStr(perm.tooltip,perm.title,perm.desc)} onToggle={onToggleSingle} text={pText} checked ={checked} resource={i} action ={'all'}/>);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
allPerms[i] = "";
|
|
124
|
+
const splitP = defaultStr(state.data[i]).toLowerCase().split("2");
|
|
125
|
+
const pContent = []
|
|
126
|
+
const hasS = isNonNullString(text) && isNonNullString(pText) && pText.toLowerCase() != text.toLowerCase()
|
|
127
|
+
Object.map(perm.actions,(p,j)=>{
|
|
128
|
+
if(!isObj(p) || !isNonNullString(p.text)) return null;
|
|
129
|
+
allPerms[i] = (isNonNullString(allPerms[i])?(allPerms[i]+"2"):"")+j;
|
|
130
|
+
checked = isUserMasterAdmin? true : arrayValueExists(splitP,j,true);
|
|
131
|
+
if(!checked){
|
|
132
|
+
allChecked = false;
|
|
133
|
+
}
|
|
134
|
+
pContent.push(<PermText labelStyle ={hasS? styles.permChildren : undefined} isUserMasterAdmin={isUserMasterAdmin} key={j} table={table} onToggle={onToggleSingle} tooltip={defaultStr(p.tooltip,p.title,p.desc)} text = {p.text} checked ={checked} actions={perm.actions} resource={i} action ={j}/>)
|
|
135
|
+
});
|
|
136
|
+
if(pContent.length){
|
|
137
|
+
content.push(<View key={i} testID={testID+"_Content_"+i}>
|
|
138
|
+
{hasS ? <Label testID={testID+'_Label'}>{pText}</Label> : null}
|
|
139
|
+
{pContent}
|
|
140
|
+
</View>)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
});
|
|
144
|
+
return <Cell testID={testID+"_Cell"} tabletSize={6} desktopSize={4} phoneSize={12} {...cellProps}>
|
|
145
|
+
<Expandable
|
|
146
|
+
expandedIcon ={'chevron-right'}
|
|
147
|
+
unexpandedIcon = {'chevron-down'}
|
|
148
|
+
elevation = {5}
|
|
149
|
+
{...rest}
|
|
150
|
+
testID = {testID}
|
|
151
|
+
expandIconPosition = {"left"}
|
|
152
|
+
onPress={(e)=>{
|
|
153
|
+
setState({...state,expanded:!state.expanded})
|
|
154
|
+
}}
|
|
155
|
+
contentProps = {{style:styles.expandableContent}}
|
|
156
|
+
expanded={state.expanded}
|
|
157
|
+
title = {
|
|
158
|
+
<PermText
|
|
159
|
+
table={table}
|
|
160
|
+
labelStyle = {false}
|
|
161
|
+
checked = {allChecked}
|
|
162
|
+
disabled = {disabled}
|
|
163
|
+
resource={resource} action={allPerms[resource]}
|
|
164
|
+
text={text}
|
|
165
|
+
testID = {testID+"_"+table}
|
|
166
|
+
isUserMasterAdmin = {isUserMasterAdmin}
|
|
167
|
+
onToggle = {toggleAll}
|
|
168
|
+
/>
|
|
169
|
+
}
|
|
170
|
+
>
|
|
171
|
+
{content}
|
|
172
|
+
</Expandable>
|
|
173
|
+
</Cell>
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
PermLine.propTypes = {
|
|
178
|
+
text : PropTypes.string,
|
|
179
|
+
resource : PropTypes.string.isRequired,
|
|
180
|
+
cellProps : PropTypes.object,//les props du composant Cell, wrappeur au composant PermLine
|
|
181
|
+
defaultActions : PropTypes.object.isRequired,//les actions par défault
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const styles = StyleSheet.create({
|
|
185
|
+
expandableContent : {
|
|
186
|
+
paddingLeft : 30,
|
|
187
|
+
},
|
|
188
|
+
permChildren : {
|
|
189
|
+
paddingLeft : 20,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
PermLine.displayName = "AuthPermLineComponent";
|
|
194
|
+
|
|
195
|
+
export default PermLine;
|