@fto-consult/expo-ui 2.48.2 → 2.48.3
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 +2 -2
- package/src/auth/Login.js +5 -1
- package/src/components/AppBar/utils.js +2 -2
- package/src/components/Button/index.js +11 -5
- 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/Dialog/Dialog.js +8 -4
- package/src/components/Form/Fields/Checkbox.js +0 -5
- package/src/components/Form/Fields/Field.js +2 -1
- package/src/components/Form/Fields/Radio.js +0 -5
- package/src/components/Form/Fields/SelectField.js +1 -0
- package/src/components/Form/Fields/Slider.js +0 -5
- package/src/components/Form/Fields/Switch.js +0 -5
- package/src/components/Form/FormData/DialogProvider.js +4 -2
- package/src/components/Form/FormData/FormDataActions.js +1 -0
- package/src/components/Form/FormData/utils.js +1 -2
- package/src/components/Icon/utils.js +2 -0
- package/src/components/ScrollView/index.js +9 -2
- package/src/screens/Auth/PermLines.js +417 -0
- package/src/screens/Auth/PermProfile.js +182 -0
- package/src/screens/Auth/PermProfiles.js +38 -0
- package/src/screens/Auth/Profile.js +1 -1
- package/src/screens/Auth/index.js +8 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import showConfirm from "$components/Dialog/confirm";
|
|
2
|
+
import notify from "$components/Dialog/notify";
|
|
3
|
+
import {defaultArray,arrayValueExists,defaultStr,uniqid} from "$utils";
|
|
4
|
+
import userDbName from "$database/data/tables/users/dbName";
|
|
5
|
+
import Auth from "$auth";
|
|
6
|
+
import getData from "$database/getData";
|
|
7
|
+
import getDB from "$database/getDB";
|
|
8
|
+
import {FormData,getForm,getFormData} from "$components/Form";
|
|
9
|
+
import Icon from "$components/Icon";
|
|
10
|
+
import React from "$react";
|
|
11
|
+
import Label from "$components/Label";
|
|
12
|
+
import {open as showPreloader,close as hidePreloader} from "$preloader";
|
|
13
|
+
import Expandable from "$components/Expandable";
|
|
14
|
+
import theme from "$theme";
|
|
15
|
+
import View from "$components/View";
|
|
16
|
+
import Link from "$components/Link";
|
|
17
|
+
import Button from "$components/Button";
|
|
18
|
+
|
|
19
|
+
const tableName = Auth.permProfilesTableName.toUpperCase();
|
|
20
|
+
|
|
21
|
+
const PermProfile = React.forwardRef((props,ref)=>{
|
|
22
|
+
const formName = React.useRef(defaultStr(props.formName,uniqid("perm-profile-name"))).current;
|
|
23
|
+
const user = defaultObj(props.user);
|
|
24
|
+
const permDataRef = React.useRef({});
|
|
25
|
+
const dialogProviderRef = React.useRef(null);
|
|
26
|
+
const {isMasterAdmin,text,label,editProfileRouteName} = props;
|
|
27
|
+
const [state,setState] = React.useState({
|
|
28
|
+
profiles : {},
|
|
29
|
+
selected : defaultArray(user.permProfiles),
|
|
30
|
+
loading : true,
|
|
31
|
+
canAssignPerms : Auth.isTableDataAllowed({table:'users',action:'assignPerms'}),
|
|
32
|
+
canViewPerms : Auth.isTableDataAllowed({table:'users',action:'readPerms'})
|
|
33
|
+
});
|
|
34
|
+
const {canAssignPerms,canViewPerms,selected} = state;
|
|
35
|
+
const reload = ()=>{
|
|
36
|
+
getData(userDbName+"["+tableName+"]").then((profiles)=>{
|
|
37
|
+
setState({...state,profiles,loading:false})
|
|
38
|
+
}).catch((e)=>{
|
|
39
|
+
setState({...state,loading:false})
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
const assignProfile = (profile,select)=>{
|
|
43
|
+
if(isMasterAdmin) return null;
|
|
44
|
+
const {selected} = state;
|
|
45
|
+
profile = defaultObj(profile);
|
|
46
|
+
const sel = [];
|
|
47
|
+
const allP = {};
|
|
48
|
+
if(selected.length <= 0){
|
|
49
|
+
if(select){
|
|
50
|
+
sel.push(profile.code);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
for(let i in selected){
|
|
54
|
+
const val = selected[i];
|
|
55
|
+
if(selected[i] == profile.code){
|
|
56
|
+
if(select && !allP[profile.code]){
|
|
57
|
+
sel.push(profile.code);
|
|
58
|
+
allP[profile.code] = true;
|
|
59
|
+
}
|
|
60
|
+
} else if(!allP[val]) {
|
|
61
|
+
sel.push(val);
|
|
62
|
+
allP[val] = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if(select && !allP[profile.code]){
|
|
66
|
+
sel.push(profile.code);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
setState({...state,selected:sel});
|
|
70
|
+
if(props.onChange){
|
|
71
|
+
props.onChange({context:{},...state,selected:sel});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const onChange = ({data})=>{
|
|
75
|
+
permDataRef.current = data;
|
|
76
|
+
}
|
|
77
|
+
const onSaveProfile = ({data,goBack})=>{
|
|
78
|
+
const d = {...data,table:tableName,perms:permDataRef.current};
|
|
79
|
+
if(!isNonNullString(d._id)) return;
|
|
80
|
+
showPreloader()
|
|
81
|
+
getDB(userDbName).then(({db})=>{
|
|
82
|
+
db.upsert(d._id,()=>{
|
|
83
|
+
return d;
|
|
84
|
+
}).then((up)=>{
|
|
85
|
+
let d = up.newDoc;
|
|
86
|
+
notify.success("Le profil ["+d.code+"] a été inséré/modifié avec succès");
|
|
87
|
+
reload();
|
|
88
|
+
if(goBack){
|
|
89
|
+
goBack(true);
|
|
90
|
+
}
|
|
91
|
+
hidePreloader();
|
|
92
|
+
}).catch((e)=>{
|
|
93
|
+
console.log(e," upserting profile group");
|
|
94
|
+
hidePreloader();
|
|
95
|
+
});
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
const removeProfile = (profile)=>{
|
|
99
|
+
if(!isObj(profile) || !isNonNullString(profile.code) || !isNonNullString(profile._id)){
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
showConfirm({
|
|
103
|
+
title:'Suppr profil['+profile.code+"]",
|
|
104
|
+
msg : 'Voulez vous vraiment supprimer le profil <<'+profile.code+">>",
|
|
105
|
+
onSuccess : ()=>{
|
|
106
|
+
getDB(userDbName).then(({db})=>{
|
|
107
|
+
showPreloader('Suppression du profil '+defaultStr(profile.code)+"...");
|
|
108
|
+
db.get(profile._id).then((doc)=>{
|
|
109
|
+
db.remove(doc).then((e)=>{
|
|
110
|
+
hidePreloader();
|
|
111
|
+
notify.success("Le profil ["+profile.code+"] a été supprimé avec succès");
|
|
112
|
+
reload();
|
|
113
|
+
});
|
|
114
|
+
}).catch((e)=>{
|
|
115
|
+
console.log(e,' is removing doc profile')
|
|
116
|
+
hidePreloader();
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
React.useEffect(()=>{
|
|
123
|
+
if(!canAssignPerms && !canViewPerms) return;
|
|
124
|
+
reload();
|
|
125
|
+
return ()=>{
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
},[])
|
|
129
|
+
if(!canAssignPerms && !canViewPerms) return null;
|
|
130
|
+
const profiles = [];
|
|
131
|
+
Object.map(state.profiles,(profile,index)=>{
|
|
132
|
+
if(!isObj(profile) || !isNonNullString(profile.code)){
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
const isAssigned = isMasterAdmin? true : arrayValueExists(selected,profile.code);
|
|
136
|
+
profiles.push(<View key={index} style={[theme.styles.row,{justifyContent:'space-between'}]}>
|
|
137
|
+
<Label>{profile.code}</Label>
|
|
138
|
+
<View style={[theme.styles.row]}>
|
|
139
|
+
<Icon primary title={isAssigned?'Profil de permission ['+profile.code+'] assigné à l\'utilisateur':'Profil de permission ['+profile.code+'] non assigné à l\'utilisateur '+defaultStr(user.code)} name={isAssigned?'checkbox-marked':'checkbox-blank-outline'}
|
|
140
|
+
onPress={()=>{
|
|
141
|
+
assignProfile(profile,isAssigned?false:true)
|
|
142
|
+
}}
|
|
143
|
+
/>
|
|
144
|
+
{canAssignPerms ? <Link Component = {Icon}
|
|
145
|
+
title={"Modifier le profil ["+profile.code+"]"}
|
|
146
|
+
name={"file-document-edit"}
|
|
147
|
+
success
|
|
148
|
+
routeParams = {{data:profile,formName,onChange,onSave:onSaveProfile}}
|
|
149
|
+
routeName = {editProfileRouteName}
|
|
150
|
+
/>:null}
|
|
151
|
+
{canAssignPerms ? <Icon
|
|
152
|
+
title={"Supprimer le profil ["+profile.code+"]"}
|
|
153
|
+
name={"delete"}
|
|
154
|
+
error
|
|
155
|
+
onPress={(e)=>{
|
|
156
|
+
React.stopEventPropagation(e);
|
|
157
|
+
removeProfile(profile);
|
|
158
|
+
}}
|
|
159
|
+
/> : null}
|
|
160
|
+
</View>
|
|
161
|
+
</View>)
|
|
162
|
+
})
|
|
163
|
+
return <Expandable title={defaultStr(label,text)+" ("+profiles.length.formatNumber()+")"} style={[theme.styles.p1]}>
|
|
164
|
+
<Link
|
|
165
|
+
primary
|
|
166
|
+
Component = {Button}
|
|
167
|
+
routeName = {editProfileRouteName}
|
|
168
|
+
routeParams = {{formName,onChange,onSave:onSaveProfile}}
|
|
169
|
+
icon={"text-box-plus-outline"}
|
|
170
|
+
mode = "contained"
|
|
171
|
+
>
|
|
172
|
+
Ajouter un profil
|
|
173
|
+
</Link>
|
|
174
|
+
<View style={[theme.styles.w100]}>
|
|
175
|
+
{profiles}
|
|
176
|
+
</View>
|
|
177
|
+
</Expandable>
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
PermProfile.tableName = PermProfile.table = tableName;
|
|
181
|
+
PermProfile.dbName = userDbName;
|
|
182
|
+
export default PermProfile;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import FormDataScreen from "$elayouts/Screen/FormData";
|
|
2
|
+
import {defaultStr,defaultObj} from "$utils";
|
|
3
|
+
import PermLines from "./PermLines";
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
|
+
import Label from "$components/Label";
|
|
6
|
+
import theme from "$theme";
|
|
7
|
+
|
|
8
|
+
export const screenName = "PermProfileScreens";
|
|
9
|
+
|
|
10
|
+
export default function PermProfilesScreen({onChange,fields,data,profile,perms,user,...props}){
|
|
11
|
+
return <FormDataScreen
|
|
12
|
+
{...props}
|
|
13
|
+
modal
|
|
14
|
+
withScrollView
|
|
15
|
+
header = {<Label primary upperCase textBold style={[theme.styles.p1]}>Permissions liées au profil</Label>}
|
|
16
|
+
fields = {isObj(fields) && Object.size(fields,true) && fields || { code : {
|
|
17
|
+
text : 'Nom du profil',
|
|
18
|
+
type : 'id',
|
|
19
|
+
maxLength:30,
|
|
20
|
+
primaryKey : true,
|
|
21
|
+
}}}
|
|
22
|
+
data = {defaultObj(profile,profile)}
|
|
23
|
+
testID = {"RN_PermProfile_FormData"}
|
|
24
|
+
title = {defaultStr(props.title,"Groupe de profil")}
|
|
25
|
+
children = {<PermLines user={user} perms = {perms} isMasterAdmin={false}
|
|
26
|
+
onChange={onChange}/>}
|
|
27
|
+
/>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
PermProfilesScreen.screenName = screenName;
|
|
31
|
+
|
|
32
|
+
PermProfilesScreen.Modal = true;
|
|
33
|
+
|
|
34
|
+
PermProfilesScreen.propTypes = {
|
|
35
|
+
user : PropTypes.object,//l'objet user
|
|
36
|
+
perms : PropTypes.object,//les permissions associées à l'utilisateur user
|
|
37
|
+
profile : PropTypes.object,//les informations sur le profil en cour de modification
|
|
38
|
+
}
|
|
@@ -16,7 +16,7 @@ export default function UserProfileScreen(props){
|
|
|
16
16
|
const themeRef = React.useRef(defaultObj(user.theme));
|
|
17
17
|
const hasChangeRef = React.useRef(false);
|
|
18
18
|
const authProfileFields = typeof SignIn2SignOut.authProfileFields =='function'?SignIn2SignOut.authProfileFields(props) : SignIn2SignOut.authProfileFields;
|
|
19
|
-
const fields = isObj(authProfileFields)? authProfileFields : {};
|
|
19
|
+
const fields = isObj(authProfileFields)? Object.clone(authProfileFields) : {};
|
|
20
20
|
const formFields = {
|
|
21
21
|
avatar : {
|
|
22
22
|
...avatarProps,
|
|
@@ -4,5 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import AuthSignInScreen from "./SignIn";
|
|
6
6
|
import UserProfileScreen from "./Profile";
|
|
7
|
+
//import PermProfiles from "./PermProfiles";
|
|
8
|
+
export default [AuthSignInScreen,UserProfileScreen,
|
|
9
|
+
//PermProfiles
|
|
10
|
+
];
|
|
7
11
|
|
|
8
|
-
export
|
|
12
|
+
//export {PermProfiles};
|
|
13
|
+
|
|
14
|
+
//export {default as PermLines} from "./PermLines";
|
|
15
|
+
//export {default as PermProfile} from "./PermProfile";
|