From 56e98c5d5c37db5bcaa730b214f45e4bd1a7b3ed Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Wed, 28 Dec 2022 13:27:14 +0100 Subject: [PATCH 01/33] Update Reducers + Update DB + tmp clean --- ComApp/src/App.js | 266 ++++++------------- ComApp/src/App/Models/Contact.js | 26 ++ ComApp/src/App/Models/Directory.js | 11 + ComApp/src/App/Models/Document.js | 15 ++ ComApp/src/App/Models/SendBrochure.js | 13 + ComApp/src/App/Models/Setting.js | 12 +- ComApp/src/App/Models/User.js | 14 + ComApp/src/App/Store/Actions/actionType.js | 10 + ComApp/src/App/Store/Actions/contacts.js | 47 ++++ ComApp/src/App/Store/Actions/locale.js | 23 ++ ComApp/src/App/Store/Actions/users.js | 12 + ComApp/src/App/Store/ConfigureStore.js | 8 +- ComApp/src/App/Store/Reducers/AppReducer.js | 111 ++++---- ComApp/src/App/Store/Reducers/contacts.js | 39 +++ ComApp/src/App/Store/Reducers/locales.js | 45 ++++ ComApp/src/App/Store/Reducers/users.js | 22 ++ ComApp/src/App/Views/ContactDetailsScreen.js | 2 +- ComApp/src/App/Views/ContactScreen.js | 2 +- ComApp/src/App/Views/HomeScreen.js | 2 +- ComApp/src/App/Views/InstallScreen.js | 34 ++- ComApp/src/App/Views/LoginScreen.js | 4 +- ComApp/src/App/Views/SyncScreen.js | 1 - ComApp/src/Database.js | 114 ++------ ComApp/src/I18n.js | 3 +- ComApp/src/Locales/fr.json | 4 + ComApp/src/Models/Common.js | 64 ----- ComApp/src/Models/Contacts.js | 60 ----- ComApp/src/Models/Directories.js | 104 -------- ComApp/src/Models/Documents.js | 68 ----- ComApp/src/Models/SendBrochure.js | 49 ---- ComApp/src/Models/Users.js | 40 --- ComApp/src/Views/Contact.js | 2 +- ComApp/src/Views/ContactDetails.js | 2 +- ComApp/src/Views/ContactDetails_MC.js | 2 +- ComApp/src/Views/ContactDetails_RHD.js | 2 +- 35 files changed, 486 insertions(+), 747 deletions(-) create mode 100644 ComApp/src/App/Store/Actions/actionType.js create mode 100644 ComApp/src/App/Store/Actions/contacts.js create mode 100644 ComApp/src/App/Store/Actions/locale.js create mode 100644 ComApp/src/App/Store/Actions/users.js create mode 100644 ComApp/src/App/Store/Reducers/contacts.js create mode 100644 ComApp/src/App/Store/Reducers/locales.js create mode 100644 ComApp/src/App/Store/Reducers/users.js delete mode 100644 ComApp/src/Models/Common.js delete mode 100644 ComApp/src/Models/Contacts.js delete mode 100644 ComApp/src/Models/Directories.js delete mode 100644 ComApp/src/Models/Documents.js delete mode 100644 ComApp/src/Models/SendBrochure.js delete mode 100644 ComApp/src/Models/Users.js diff --git a/ComApp/src/App.js b/ComApp/src/App.js index 1714551..cd73224 100644 --- a/ComApp/src/App.js +++ b/ComApp/src/App.js @@ -1,7 +1,21 @@ -import 'react-native-gesture-handler'; +// V2 import React from 'react'; -import { createStore } from 'redux'; +// Redux import { Provider } from 'react-redux'; +import { store } from './App/Store/ConfigureStore'; +// i18n +import i18n from "./I18n"; +// Controllers +import SyncController from './App/Controllers/SyncController'; +// Views +import InstallScreen from './App/Views/InstallScreen'; +import LoginScreen from './App/Views/LoginScreen'; +// END V2 + +import SyncScreen from './App/Views/SyncScreen'; +import HomeScreen from './App/Views/HomeScreen'; +import 'react-native-gesture-handler'; + import { NavigationContainer } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { TouchableOpacity, View, Image, Text, TextInput, StyleSheet, Alert } from 'react-native'; @@ -10,164 +24,24 @@ import Icon from 'react-native-vector-icons/FontAwesome5'; import FlashMessage, { showMessage } from 'react-native-flash-message'; import * as SplashScreen from 'expo-splash-screen'; -import LoginScreen from './Views/Login'; -import HomeScreen from './Views/Home'; import DirectoriesScreen from './Views/Directories'; import VideoScreen from './Views/Video'; import PDFScreen from './Views/PDF'; -import SyncScreen from './Views/Sync'; + import ContactScreen from './Views/Contact'; import ContactDetailsScreen from './Views/ContactDetails'; import OnlyVideosScreen from './Views/OnlyVideos'; import SearchScreen from "./Views/Search"; import MySpaceScreen from './Views/MySpace'; -import UsersModel from './Models/Users'; -import DirectoriesModel from './Models/Directories'; -import DocumentsModel from './Models/Documents'; -import ContactsModel from './Models/Contacts'; -import SendBrochureModel from './Models/SendBrochure'; -import CommonModel from './Models/Common'; - -import Sync from './Controllers/Sync'; -import Helpers from "./Controllers/Helpers"; -import i18n from "./I18n"; - -SplashScreen.preventAutoHideAsync(); - -const initialState = { - locale: 'fr', - users: {}, - directories: {}, - documents: {}, - contacts: {}, - syncVersion: 0, - logged: undefined, - currentUser: {}, - currentOpenedDoc: {}, - ShowIsActive: 0, -}; - -function reducer(state = initialState, action) { - //console.log('reducer', state, action); - //console.log('DISPATCH'); - - switch (action.type) { - case 'INIT': - let docs = DocumentsModel.getAll(DirectoriesModel.getAll( - state.currentUser.role, - state.currentUser.authorizedFolders, - false, - state.locale - )); - return { - ...state, - users: UsersModel.getAll(), - directories: DirectoriesModel.getAll( - state.currentUser.role, - state.currentUser.authorizedFolders, - true, - state.locale - ), - documents: docs.filter(item => item.lang === state.locale), - contacts: ContactsModel.getByUser(state.currentUser.id), - ShowIsActive: CommonModel.get('ShowIsActive')['value'], - }; - case 'INIT_USERS': - return { - ...state, - users: UsersModel.getAll(), - }; - case 'SET_CURRENT_USER': - return { - ...state, - currentUser: JSON.parse(action.data), - }; - case 'SET_LOGGED': - if (action.data === false) { - CommonModel.delete('isLogged'); - } - return { - ...state, - logged: action.data, - }; - case 'UPDATE_LOCALE': - let nxt; - if (action.data === undefined) { - const availableLocales = ['fr', 'en', 'de']; - if (availableLocales.indexOf(i18n.locale) === availableLocales.length - 1) { - nxt = availableLocales[0]; - } else { - nxt = availableLocales[availableLocales.indexOf(i18n.locale) + 1]; - } - } else { - nxt = action.data; - } - i18n.locale = nxt; - CommonModel.update({ key: 'locale', value: nxt }); - let docsL = DocumentsModel.getAll(DirectoriesModel.getAll( - state.currentUser.role, - state.currentUser.authorizedFolders, - false, - nxt - )); - return { - ...state, - locale: nxt, - directories: DirectoriesModel.getAll( - state.currentUser.role, - state.currentUser.authorizedFolders, - true, - nxt - ), - documents: docsL.filter(item => item.lang === nxt), - }; - case 'SET_CURRENT_OPENED_DOC': - return { - ...state, - currentOpenedDoc: action.data - }; - case 'UPDATE_VERSION': - return { - ...state, - syncVersion: action.data, - }; - case 'UPDATE_SHOW_IS_ACTIVE': - Sync.updateShowIsActive(action.data); - return { - ...state, - ShowIsActive: action.data, - }; - case 'UPDATE_CONTACT': - ContactsModel.update(action.data); - return { - ...state, - contacts: ContactsModel.getByUser(state.currentUser.id), - }; - case 'ADD_CONTACT': - ContactsModel.add(action.data); - return { - ...state, - contacts: ContactsModel.getByUser(state.currentUser.id), - }; - case 'DELETE_CONTACT': - ContactsModel.delete(action.data); - return { - ...state, - contacts: ContactsModel.getByUser(state.currentUser.id), - }; - case 'SEND_BROCHURE': - SendBrochureModel.add(action.data); - return state; - default: - return state; - } -} - -const store = createStore(reducer); -const Stack = createNativeStackNavigator(); +//SplashScreen.preventAutoHideAsync(); //Keep +// V2 +store.dispatch({ type: 'INIT_APP' }); +store.dispatch({ type: 'INIT_LOCALE' }); store.dispatch({ type: 'INIT_USERS' }); + // END V2 +const Stack = createNativeStackNavigator(); class App extends React.Component { state = { @@ -178,29 +52,26 @@ class App extends React.Component { }; componentDidMount(): void { + const unsubscribe = store.subscribe(this.handleChange.bind(this)); - if (Sync.isInstalled() && Sync.isLogged()) { - store.dispatch({ - type: 'SET_CURRENT_USER', - data: CommonModel.get('isLogged').value, - }); - store.dispatch({ type: 'SET_LOGGED', data: true }); - } - const savedLocale = CommonModel.get('locale'); - if (savedLocale !== undefined && savedLocale !== false) { - store.dispatch({ type: 'UPDATE_LOCALE', data: savedLocale.value }); - } + // if (Sync.isLogged()) { + // store.dispatch({ + // type: 'SET_CURRENT_USER', + // data: CommonModel.get('isLogged').value, + // }); + // store.dispatch({ type: 'SET_LOGGED', data: true }); + // } } handleChange() { - const logged = store.getState().logged; + const logged = store.getState().app.logged; if (logged === false) { CommonModel.delete('isLogged'); } if (logged !== undefined) { this.setState({ logged: logged }); } - this.setState({ ShowIsActive: store.getState().ShowIsActive }); + this.setState({ ShowIsActive: store.getState().app.ShowIsActive }); } LogoTitle(title) { @@ -253,32 +124,31 @@ class App extends React.Component { } render() { - const savedLocale = CommonModel.get('locale'); - let locale; - if (savedLocale !== undefined) { - locale = savedLocale.value; - } else { - locale = store.getState().locale; - } - let flag; - switch (locale) { - case "fr": - flag = require('./assets/img/flags/fr.png'); - break; - case "en": - flag = require('./assets/img/flags/en.png'); - break; - case "de": - flag = require('./assets/img/flags/de.png'); - break; - case "es": - flag = require('./assets/img/flags/es.png'); - break; - } return ( + {store.getState().app.isSetup === false && + ({ + headerTitle: () => this.LogoTitle(i18n.t('install.installation')), + headerRight: () => ( + + { + store.dispatch({ type: 'EDIT_LOCALE' }); + this.setState({ state: this.state }); // to force re-rendering + }} + style={{ marginRight: 15 }}> + + + + ), + })} + /> + } {this.state.logged === false ? ( { - store.dispatch({ type: 'UPDATE_LOCALE' }); + store.dispatch({ type: 'EDIT_LOCALE' }); this.setState({ state: this.state }); // to force re-rendering }} style={{ marginRight: 15 }}> - + ), @@ -323,10 +193,10 @@ class App extends React.Component { { - store.dispatch({ type: 'UPDATE_LOCALE' }); + store.dispatch({ type: 'EDIT_LOCALE' }); }} style={{ marginRight: 25 }}> - + {this.state.ShowIsActive === '1' && ( ); } + + renderFlag() { + let flag; + switch (store.getState().locale.locale) { + case "fr": + flag = require('./assets/img/flags/fr.png'); + break; + case "en": + flag = require('./assets/img/flags/en.png'); + break; + case "de": + flag = require('./assets/img/flags/de.png'); + break; + case "es": + flag = require('./assets/img/flags/es.png'); + break; + } + return flag; + } + } const styles = StyleSheet.create({ diff --git a/ComApp/src/App/Models/Contact.js b/ComApp/src/App/Models/Contact.js index 7b727c7..412f236 100644 --- a/ComApp/src/App/Models/Contact.js +++ b/ComApp/src/App/Models/Contact.js @@ -1,3 +1,29 @@ +export const ContactsSchema = { + name: 'Contacts', + primaryKey: 'id', + properties: { + id: 'int', + email: 'string', + type: 'string', + other: { type: 'string', optional: true }, + select1: { type: 'string', optional: true }, + select2: { type: 'string', optional: true }, + name: 'string', + firstname: 'string', + company: { type: 'string', optional: true }, + address: { type: 'string', optional: true }, + phone: 'string', + products: { type: 'string', optional: true }, + // TODO : card_url ? + notes: { type: 'string', optional: true }, + visits: { type: 'string', optional: true }, + user_id: 'int', + uniq_id: 'string', + to_delete: { type: 'bool', default: false }, + synced: { type: 'bool', default: true }, + }, +}; + class ContactModel { constructor(realm) { this.schema = 'Contacts'; diff --git a/ComApp/src/App/Models/Directory.js b/ComApp/src/App/Models/Directory.js index 198da1d..8959ed7 100644 --- a/ComApp/src/App/Models/Directory.js +++ b/ComApp/src/App/Models/Directory.js @@ -1,3 +1,14 @@ +export const DirectoriesSchema = { + name: 'Directories', + primaryKey: 'id', + properties: { + id: 'int', + name: 'string', + parent: { type: 'int', optional: true }, + order: 'int', + needAuthorization: 'int', + }, +}; class DirectoryModel { constructor(realm) { this.schema = 'Directories'; diff --git a/ComApp/src/App/Models/Document.js b/ComApp/src/App/Models/Document.js index 7a8a516..d8cea91 100644 --- a/ComApp/src/App/Models/Document.js +++ b/ComApp/src/App/Models/Document.js @@ -1,3 +1,18 @@ +export const DocumentsSchema = { + name: 'Documents', + primaryKey: 'id', + properties: { + id: 'int', + uuid: 'string', + title: 'string', + type: 'string', + path: 'string', + directory: 'int', + lang: 'string', + updated_at: 'string', + }, +}; + class DocumentModel { constructor(realm) { this.schema = 'Documents'; diff --git a/ComApp/src/App/Models/SendBrochure.js b/ComApp/src/App/Models/SendBrochure.js index 62c55f7..9a6c385 100644 --- a/ComApp/src/App/Models/SendBrochure.js +++ b/ComApp/src/App/Models/SendBrochure.js @@ -1,3 +1,16 @@ +export const SendBrochuresSchema = { + name: 'SendBrochures', + primaryKey: 'id', + properties: { + id: 'int', + email: 'string', + subject: 'string', + message: 'string', + documents: 'string', + user_id: 'int' + }, +}; + class SendBrochureModel { constructor(realm) { this.schema = 'SendBrochures'; diff --git a/ComApp/src/App/Models/Setting.js b/ComApp/src/App/Models/Setting.js index c67a416..210a4ea 100644 --- a/ComApp/src/App/Models/Setting.js +++ b/ComApp/src/App/Models/Setting.js @@ -1,3 +1,13 @@ +export const SettingsSchema = { + name: 'Settings', + primaryKey: 'id', + properties: { + id: 'int', + key: 'string', + value: 'string', + }, +}; + class SettingModel { constructor(realm) { this.schema = 'Settings'; @@ -59,4 +69,4 @@ class SettingModel { } -export default SettingModel; +export default SettingModel; \ No newline at end of file diff --git a/ComApp/src/App/Models/User.js b/ComApp/src/App/Models/User.js index 6e6db47..a25f812 100644 --- a/ComApp/src/App/Models/User.js +++ b/ComApp/src/App/Models/User.js @@ -1,3 +1,17 @@ +export const UsersSchema = { + name: 'Users', + primaryKey: 'id', + properties: { + id: 'int', + email: 'string', + surname: 'string', + firstname: 'string', + password: 'string', + role: 'string', + authorizedFolders: 'string', + }, +}; + class UserModel { constructor(realm) { this.schema = 'Users'; diff --git a/ComApp/src/App/Store/Actions/actionType.js b/ComApp/src/App/Store/Actions/actionType.js new file mode 100644 index 0000000..510d597 --- /dev/null +++ b/ComApp/src/App/Store/Actions/actionType.js @@ -0,0 +1,10 @@ +// Locale +export const INIT_LOCALE = "INIT_LOCALE"; +export const EDIT_LOCALE = "EDIT_LOCALE"; +// Users +export const INIT_USERS = "INIT_USERS"; +// Contacts +export const INIT_CONTACT = "INIT_CONTACT"; +export const ADD_CONTACT = "ADD_CONTACT"; +export const EDIT_CONTACT = "EDIT_CONTACT"; +export const DELETE_CONTACT = "DELETE_CONTACT"; \ No newline at end of file diff --git a/ComApp/src/App/Store/Actions/contacts.js b/ComApp/src/App/Store/Actions/contacts.js new file mode 100644 index 0000000..e8b15f2 --- /dev/null +++ b/ComApp/src/App/Store/Actions/contacts.js @@ -0,0 +1,47 @@ +import { INIT_CONTACT, ADD_CONTACT, EDIT_CONTACT, DELETE_CONTACT } from "./actionType"; + +/** + * Init contact + * @param {object} data The contact data + */ +export const initContact = data => { + return { + type: INIT_CONTACT, + data, + }; +}; + +/** + * Add contact + * @param {object} data The contact data + */ +export const addContact = data => { + return { + type: ADD_CONTACT, + data, + }; +}; + +/** + * Edit contact + * @param {string} uid The contact uid + * @param {object} data The contact data + */ +export const editContact = (uid, data) => { + return { + type: EDIT_CONTACT, + uid, + data, + }; +}; + +/** + * Delete contact + * @param {string} uid The contact uid + */ +export const deleteContact = uid => { + return { + type: DELETE_CONTACT, + uid, + }; +}; \ No newline at end of file diff --git a/ComApp/src/App/Store/Actions/locale.js b/ComApp/src/App/Store/Actions/locale.js new file mode 100644 index 0000000..c7f108a --- /dev/null +++ b/ComApp/src/App/Store/Actions/locale.js @@ -0,0 +1,23 @@ +import { INIT_LOCALE, EDIT_LOCALE } from "./actionType"; + +/** + * Init locale + * @param {object} data The locale data + */ +export const initLocale = data => { + return { + type: INIT_LOCALE, + data, + }; +}; + +/** + * Edit locale + * @param {object} data The locale data + */ +export const editLocale = data => { + return { + type: EDIT_LOCALE, + data, + }; +}; diff --git a/ComApp/src/App/Store/Actions/users.js b/ComApp/src/App/Store/Actions/users.js new file mode 100644 index 0000000..49dfbf1 --- /dev/null +++ b/ComApp/src/App/Store/Actions/users.js @@ -0,0 +1,12 @@ +import { INIT_USERS } from "./actionType"; + +/** + * Init users + * @param {object} data The users data + */ +export const initUsers = data => { + return { + type: INIT_USERS, + data, + }; +}; \ No newline at end of file diff --git a/ComApp/src/App/Store/ConfigureStore.js b/ComApp/src/App/Store/ConfigureStore.js index 489eb85..5b9f8a5 100644 --- a/ComApp/src/App/Store/ConfigureStore.js +++ b/ComApp/src/App/Store/ConfigureStore.js @@ -1,9 +1,15 @@ import { createStore, combineReducers } from "redux"; import appReducer from "./Reducers/AppReducer"; +import localesReducer from "./Reducers/locales"; +import usersReducer from "./Reducers/users"; +import contactsReducer from "./Reducers/contacts"; const rootReducer = combineReducers({ - app: appReducer + app: appReducer, + contacts: contactsReducer, + locale: localesReducer, + users: usersReducer }); export const store = createStore(rootReducer); \ No newline at end of file diff --git a/ComApp/src/App/Store/Reducers/AppReducer.js b/ComApp/src/App/Store/Reducers/AppReducer.js index afc9ddb..732e316 100644 --- a/ComApp/src/App/Store/Reducers/AppReducer.js +++ b/ComApp/src/App/Store/Reducers/AppReducer.js @@ -1,15 +1,12 @@ import SyncController from "../../Controllers/SyncController"; // Database -import { Setting, Contact, User, Directory, Document, SendBrochure } from '../../../Database'; -// Translations -import i18n from "../../../I18n"; +import { Setting, Directory, Document, SendBrochure } from '../../../Database'; const initialState = { + isSetup: false, locale: 'fr', - users: {}, directories: {}, documents: {}, - contacts: {}, syncVersion: 0, logged: undefined, currentUser: {}, @@ -18,7 +15,21 @@ const initialState = { }; const reducer = (state = initialState, action) => { + let saved; switch (action.type) { + case 'INIT_APP': + saved = Setting.get('isSetup'); + return { + ...state, + isSetup: saved === undefined ? false : saved.value === "true" ? true : false + }; + case 'SET_ISSETUP': + Setting.upsert({ key: 'isSetup', value: "true" }); + saved = Setting.get('isSetup'); + return { + ...state, + isSetup: saved === undefined ? false : saved.value === "true" ? true : false + }; case 'INIT': let directories = Directory.getAll( state.currentUser.role, @@ -27,9 +38,9 @@ const reducer = (state = initialState, action) => { state.locale ); let docs = Document.getAll(directories); + let ShowIsActive = Setting.get('ShowIsActive'); return { ...state, - users: User.getAll(), directories: Directory.getAll( state.currentUser.role, state.currentUser.authorizedFolders, @@ -37,13 +48,7 @@ const reducer = (state = initialState, action) => { state.locale ), documents: docs.filter(item => item.lang === state.locale), - contacts: Contact.getByUser(state.currentUser.id), - ShowIsActive: Setting.get('ShowIsActive')['value'], - }; - case 'INIT_USERS': - return { - ...state, - users: User.getAll(), + ShowIsActive: ShowIsActive === undefined ? false : ShowIsActive.value, }; case 'SET_CURRENT_USER': return { @@ -58,37 +63,37 @@ const reducer = (state = initialState, action) => { ...state, logged: action.data, }; - case 'UPDATE_LOCALE': - let nxt; - if (action.data === undefined) { - const availableLocales = ['fr', 'en', 'de']; - if (availableLocales.indexOf(i18n.locale) === availableLocales.length - 1) { - nxt = availableLocales[0]; - } else { - nxt = availableLocales[availableLocales.indexOf(i18n.locale) + 1]; - } - } else { - nxt = action.data; - } - i18n.locale = nxt; - Setting.upsert({ key: 'locale', value: nxt }); - let docsL = Document.getAll(Directory.getAll( - state.currentUser.role, - state.currentUser.authorizedFolders, - false, - nxt - )); - return { - ...state, - locale: nxt, - directories: Directory.getAll( - state.currentUser.role, - state.currentUser.authorizedFolders, - true, - nxt - ), - documents: docsL.filter(item => item.lang === nxt), - }; + // case 'UPDATE_LOCALE': + // let nxt; + // if (action.data === undefined) { + // const availableLocales = ['fr', 'en', 'de']; + // if (availableLocales.indexOf(i18n.locale) === availableLocales.length - 1) { + // nxt = availableLocales[0]; + // } else { + // nxt = availableLocales[availableLocales.indexOf(i18n.locale) + 1]; + // } + // } else { + // nxt = action.data; + // } + // i18n.locale = nxt; + // Setting.upsert({ key: 'locale', value: nxt }); + // let docsL = Document.getAll(Directory.getAll( + // state.currentUser.role, + // state.currentUser.authorizedFolders, + // false, + // nxt + // )); + // return { + // ...state, + // locale: nxt, + // directories: Directory.getAll( + // state.currentUser.role, + // state.currentUser.authorizedFolders, + // true, + // nxt + // ), + // documents: docsL.filter(item => item.lang === nxt), + // }; case 'SET_CURRENT_OPENED_DOC': return { ...state, @@ -105,24 +110,6 @@ const reducer = (state = initialState, action) => { ...state, ShowIsActive: action.data, }; - case 'UPDATE_CONTACT': - Contact.update(action.data); - return { - ...state, - contacts: Contact.getByUser(state.currentUser.id), - }; - case 'ADD_CONTACT': - Contact.add(action.data); - return { - ...state, - contacts: Contact.getByUser(state.currentUser.id), - }; - case 'DELETE_CONTACT': - Contact.delete(action.data); - return { - ...state, - contacts: Contact.getByUser(state.currentUser.id), - }; case 'SEND_BROCHURE': SendBrochure.add(action.data); return state; diff --git a/ComApp/src/App/Store/Reducers/contacts.js b/ComApp/src/App/Store/Reducers/contacts.js new file mode 100644 index 0000000..07d83e7 --- /dev/null +++ b/ComApp/src/App/Store/Reducers/contacts.js @@ -0,0 +1,39 @@ +import { INIT_CONTACT, ADD_CONTACT, EDIT_CONTACT, DELETE_CONTACT } from "../Actions/actionType"; +// Models +import { Contact } from "../../../Database"; + +const initialState = []; + +const reducer = (state = initialState, action) => { + switch (action.type) { + case INIT_CONTACT: + return { + ...state, + contacts: Contact.getByUser(state.currentUser.id), + }; + case ADD_CONTACT: + Contact.add(action.data); + return { + ...state, + contacts: Contact.getByUser(state.currentUser.id), + }; + case EDIT_CONTACT: + Contact.update(action.data); + return { + ...state, + contacts: Contact.getByUser(state.currentUser.id), + }; + case DELETE_CONTACT: + Contact.delete(action.data); + return { + ...state, + contacts: Contact.getByUser(state.currentUser.id), + }; + + default: { + return state; + } + } +}; + +export default reducer; diff --git a/ComApp/src/App/Store/Reducers/locales.js b/ComApp/src/App/Store/Reducers/locales.js new file mode 100644 index 0000000..5ad4852 --- /dev/null +++ b/ComApp/src/App/Store/Reducers/locales.js @@ -0,0 +1,45 @@ +import { INIT_LOCALE, EDIT_LOCALE } from "../Actions/actionType"; +// Models +import { Setting } from "../../../Database"; +// Translations +import i18n from "../../../I18n"; + +const initialState = []; + +const reducer = (state = initialState, action) => { + switch (action.type) { + case INIT_LOCALE: { + const savedLocale = Setting.get('locale'); + return { + ...state, + locale: savedLocale === undefined ? 'fr' : savedLocale === false ? 'fr' : savedLocale.value + }; + } + + case EDIT_LOCALE: { + let nxt; + if (action.data === undefined) { + const availableLocales = ['fr', 'en', 'de']; + if (availableLocales.indexOf(i18n.locale) === availableLocales.length - 1) { + nxt = availableLocales[0]; + } else { + nxt = availableLocales[availableLocales.indexOf(i18n.locale) + 1]; + } + } else { + nxt = action.data; + } + i18n.locale = nxt; + Setting.upsert({ key: 'locale', value: nxt }); + return { + ...state, + locale: nxt, + }; + } + + default: { + return state; + } + } +}; + +export default reducer; diff --git a/ComApp/src/App/Store/Reducers/users.js b/ComApp/src/App/Store/Reducers/users.js new file mode 100644 index 0000000..42494e8 --- /dev/null +++ b/ComApp/src/App/Store/Reducers/users.js @@ -0,0 +1,22 @@ +import { INIT_USERS } from "../Actions/actionType"; +// Models +import { User } from "../../../Database"; + +const initialState = []; + +const reducer = (state = initialState, action) => { + switch (action.type) { + case INIT_USERS: { + return { + ...state, + users: User.getAll(), + }; + } + + default: { + return state; + } + } +}; + +export default reducer; diff --git a/ComApp/src/App/Views/ContactDetailsScreen.js b/ComApp/src/App/Views/ContactDetailsScreen.js index 2959a9e..cb94e38 100644 --- a/ComApp/src/App/Views/ContactDetailsScreen.js +++ b/ComApp/src/App/Views/ContactDetailsScreen.js @@ -162,7 +162,7 @@ class ContactDetailsScreen extends React.Component { }; if (action === 'edit') { contact.id = this.state.tmpID; - this.props.dispatch({ type: 'UPDATE_CONTACT', data: contact }); + this.props.dispatch({ type: 'EDIT_CONTACT', data: contact }); this.populate(); showMessage({ message: i18n.t('contact_details_s.contact_saved') + '.', diff --git a/ComApp/src/App/Views/ContactScreen.js b/ComApp/src/App/Views/ContactScreen.js index 0895672..c1420ae 100644 --- a/ComApp/src/App/Views/ContactScreen.js +++ b/ComApp/src/App/Views/ContactScreen.js @@ -115,7 +115,7 @@ class ContactScreen extends React.Component { synced: false, user_id: nextUser.id, }; - this.props.dispatch({ type: 'UPDATE_CONTACT', data: contact }); + this.props.dispatch({ type: 'EDIT_CONTACT', data: contact }); this.setState({ showTransferContact: false }); showMessage({ message: i18n.t('contact_s.contact_transferred') + '.', diff --git a/ComApp/src/App/Views/HomeScreen.js b/ComApp/src/App/Views/HomeScreen.js index e593185..1dff59f 100644 --- a/ComApp/src/App/Views/HomeScreen.js +++ b/ComApp/src/App/Views/HomeScreen.js @@ -14,7 +14,7 @@ import * as FileSystem from 'expo-file-system'; function mapStateToProps(state) { return { directories: state.app.directories, - locale: state.app.locale, + locale: state.locale.locale, }; } diff --git a/ComApp/src/App/Views/InstallScreen.js b/ComApp/src/App/Views/InstallScreen.js index 3bf1965..0864bfa 100644 --- a/ComApp/src/App/Views/InstallScreen.js +++ b/ComApp/src/App/Views/InstallScreen.js @@ -1,5 +1,7 @@ import React from 'react'; import { ImageBackground, View, Image, Text, TextInput, Button, Alert } from 'react-native'; +// Redux +import { connect } from 'react-redux'; // Helpers import Helpers from '../Lib/Helpers'; // Common Styles @@ -11,7 +13,14 @@ import i18n from "../../I18n"; // Controller import InstallController from '../Controllers/InstallController'; import SyncController from '../Controllers/SyncController'; +// Database +import { User } from '../../Database'; +function mapStateToProps(state) { + return { + isSetup: state.app.isSetup + }; +} class InstallScreen extends React.Component { state = { processing: false, @@ -58,16 +67,33 @@ class InstallScreen extends React.Component { ); } - install() { + async install() { this.setState({ processing: true, txtStep: i18n.t("install.get_app_setting") }); if (InstallController.getConfig(this.state.url)) { this.setState({ txtStep: i18n.t("install.get_content_setting") }); if (InstallController.getAppConfig(this.state.url)) { - this.props.navigation.navigate('SyncScreen', { forceSync: true }); + // getUsers + this.setState({ txtStep: i18n.t('sync_s.updating_users') + '...' }); + const resUsers = await SyncController.getUsers().then(res => { + User.clear(); + return res.data; + }).catch(error => { + console.log(error); + Alert.alert( + i18n.t('error.error'), + i18n.t('error.error_has_occurred') + ); + return + }); + resUsers.forEach(user => { + User.add(user); + }); + this.props.dispatch({ type: 'SET_ISSETUP' }); + this.props.navigation.navigate('LoginScreen'); } } - this.setState({ processing: false }); + this.setState({ processing: false, txtStep: "" }); } } -export default InstallScreen; \ No newline at end of file +export default connect(mapStateToProps)(InstallScreen); \ No newline at end of file diff --git a/ComApp/src/App/Views/LoginScreen.js b/ComApp/src/App/Views/LoginScreen.js index a5f5a08..41f2cb5 100644 --- a/ComApp/src/App/Views/LoginScreen.js +++ b/ComApp/src/App/Views/LoginScreen.js @@ -17,8 +17,8 @@ import SyncController from '../Controllers/SyncController'; function mapStateToProps(state) { return { - users: state.app.users, - locale: state.app.locale, + users: state.users.users, + locale: state.locale.locale, }; } diff --git a/ComApp/src/App/Views/SyncScreen.js b/ComApp/src/App/Views/SyncScreen.js index eb0fbb9..eae4805 100644 --- a/ComApp/src/App/Views/SyncScreen.js +++ b/ComApp/src/App/Views/SyncScreen.js @@ -280,7 +280,6 @@ class SyncScreen extends React.Component { } finishSync(version) { - console.log('here') this.props.dispatch({ type: 'INIT' }); SyncController.updateVersion(version); this.setState({ txtStep: i18n.t('sync_s.update_completed') + '.', processing: false }); diff --git a/ComApp/src/Database.js b/ComApp/src/Database.js index 4e63cbe..8d53114 100644 --- a/ComApp/src/Database.js +++ b/ComApp/src/Database.js @@ -1,103 +1,29 @@ -const CommonSchema = { - name: 'Common', - primaryKey: 'id', - properties: { - id: 'int', - key: 'string', - value: 'string', - }, -}; +import Realm from "realm"; -const UserSchema = { - name: 'Users', - primaryKey: 'id', - properties: { - id: 'int', - email: 'string', - surname: 'string', - firstname: 'string', - password: 'string', - role: 'string', - authorizedFolders: 'string', - }, -}; - -const DirectoriesSchema = { - name: 'Directories', - primaryKey: 'id', - properties: { - id: 'int', - name: 'string', - parent: { type: 'int', optional: true }, - order: 'int', - needAuthorization: 'int', - }, -}; - -const DocumentsSchema = { - name: 'Documents', - primaryKey: 'id', - properties: { - id: 'int', - uuid: 'string', - title: 'string', - type: 'string', - path: 'string', - directory: 'int', - lang: 'string', - updated_at: 'string', - }, -}; - -const ContactsSchema = { - name: 'Contacts', - primaryKey: 'id', - properties: { - id: 'int', - email: 'string', - type: 'string', - other: { type: 'string', optional: true }, - select1: { type: 'string', optional: true }, - select2: { type: 'string', optional: true }, - name: 'string', - firstname: 'string', - company: { type: 'string', optional: true }, - address: { type: 'string', optional: true }, - phone: 'string', - products: { type: 'string', optional: true }, - // TODO : card_url ? - notes: { type: 'string', optional: true }, - visits: { type: 'string', optional: true }, - user_id: 'int', - uniq_id: 'string', - to_delete: { type: 'bool', default: false }, - synced: { type: 'bool', default: true }, - }, -}; - -const SendBrochureSchema = { - name: 'SendBrochure', - primaryKey: 'id', - properties: { - id: 'int', - email: 'string', - subject: 'string', - message: 'string', - documents: 'string', - user_id: 'int' - }, -}; +import ContactModel, { ContactsSchema } from "./App/Models/Contact"; +import DirectoryModel, { DirectoriesSchema } from "./App/Models/Directory"; +import DocumentModel, { DocumentsSchema } from "./App/Models/Document"; +import SendBrochureModel, { SendBrochuresSchema } from "./App/Models/SendBrochure"; +import SettingModel, { SettingsSchema } from "./App/Models/Setting"; +import UserModel, { UsersSchema } from "./App/Models/User"; const Database = { schema: [ - CommonSchema, - UserSchema, + ContactsSchema, DirectoriesSchema, DocumentsSchema, - ContactsSchema, - SendBrochureSchema, + SendBrochuresSchema, + SettingsSchema, + UsersSchema ], - encryptionKey: new Int8Array(64) + //encryptionKey: new Int8Array(64) }; -export default Database; +let realm = new Realm(Database); + +export let Contact = new ContactModel(realm); +export let Directory = new DirectoryModel(realm); +export let Document = new DocumentModel(realm); +export let SendBrochure = new SendBrochureModel(realm); +export let Setting = new SettingModel(realm); +export let User = new UserModel(realm); diff --git a/ComApp/src/I18n.js b/ComApp/src/I18n.js index 3b94187..f67cde5 100644 --- a/ComApp/src/I18n.js +++ b/ComApp/src/I18n.js @@ -12,7 +12,6 @@ const i18n = new I18n({ i18n.defaultLocale = 'fr'; i18n.locale = 'fr'; -i18n.fallbacks = true; -i18n.translations = { fr, en, de }; +i18n.enableFallback = true; export default i18n; diff --git a/ComApp/src/Locales/fr.json b/ComApp/src/Locales/fr.json index f230117..afc8fd6 100644 --- a/ComApp/src/Locales/fr.json +++ b/ComApp/src/Locales/fr.json @@ -1,4 +1,8 @@ { + "install": { + "install": "Installer", + "installation": "Installation" + }, "global": { "yes": "Oui", "no": "Non", diff --git a/ComApp/src/Models/Common.js b/ComApp/src/Models/Common.js deleted file mode 100644 index 3d8ab03..0000000 --- a/ComApp/src/Models/Common.js +++ /dev/null @@ -1,64 +0,0 @@ -import Database from '../Database'; - -const Realm = require('realm'); -let realm = new Realm(Database); - -class CommonModel { - constructor() { - this.schema = 'Common'; - } - - add(data) { - realm.write(() => { - if (data.id === undefined) { - let id: any = realm.objects(this.schema).max('id'); - data.id = id === undefined ? 1 : id + 1; - } - try { - realm.create(this.schema, data, 'never'); - } catch (e) { - console.log('db common add', e); - } - }); - } - - update(data) { - let tmp = this.get(data.key); - if (tmp === undefined) { - this.add(data); - } else { - if (data.id === undefined) { - data.id = tmp.id; - } - realm.write(() => { - realm.create(this.schema, data, 'modified'); - }); - } - } - - get(key) { - let tmp = realm.objects(this.schema); - if (tmp.length === 0) { - return false; - } else { - tmp = tmp.filtered('key = "' + key + '"')[0]; - } - return tmp; - } - - getAll() { - let tmp = realm.objects(this.schema); - return tmp; - } - - delete(key) { - const tmp = this.get(key); - if (typeof tmp === 'object') { - realm.write(() => { - realm.delete(tmp); - }); - } - } -} - -export default new CommonModel(); diff --git a/ComApp/src/Models/Contacts.js b/ComApp/src/Models/Contacts.js deleted file mode 100644 index 8cb1243..0000000 --- a/ComApp/src/Models/Contacts.js +++ /dev/null @@ -1,60 +0,0 @@ -import Database from '../Database'; - -const Realm = require('realm'); -let realm = new Realm(Database); - -class ContactsModel { - constructor() { - this.schema = 'Contacts'; - } - - add(contact) { - contact.uniq_id = contact.id; - contact.id = undefined; - realm.write(() => { - if (contact.id === undefined) { - let id: any = realm.objects(this.schema).max('id'); - contact.id = id === undefined ? 1 : id + 1; - } - realm.create(this.schema, contact); - }); - } - - update(contact) { - realm.write(() => { - realm.create(this.schema, contact, true); - }); - } - - get(id) { - let tmp = realm.objects(this.schema).filtered('id = ' + id)[0]; - return tmp; - } - - getAll() { - let tmp = realm.objects(this.schema); - return tmp; - } - - getByUser(userId) { - let tmp = realm.objects(this.schema); - tmp = tmp.filtered('to_delete = false AND user_id = ' + userId); - return tmp; - } - - delete(id) { - const tmp = this.get(id); - realm.write(() => { - tmp.to_delete = true; - // HARD DELETE - > realm.delete(tmp); - }); - } - - clear() { - realm.write(() => { - realm.delete(this.getAll()); - }); - } -} - -export default new ContactsModel(); diff --git a/ComApp/src/Models/Directories.js b/ComApp/src/Models/Directories.js deleted file mode 100644 index 85d7b99..0000000 --- a/ComApp/src/Models/Directories.js +++ /dev/null @@ -1,104 +0,0 @@ -import Database from '../Database'; - -const Realm = require('realm'); -let realm = new Realm(Database); - -class DirectoriesModel { - constructor() { - this.schema = 'Directories'; - } - - add(directory) { - realm.write(() => { - realm.create(this.schema, directory); - }); - } - - update(directory) { - realm.write(() => { - realm.create(this.schema, directory, true); - }); - } - - get(id) { - let tmp = realm.objects(this.schema).filtered('id = ' + id)[0]; - return tmp; - } - - getAll(role, authorizedFolders, format, lang) { - if (authorizedFolders !== null && authorizedFolders !== undefined) { - authorizedFolders = JSON.parse(authorizedFolders); - } - let tmp = realm.objects(this.schema); - if (role === 'USER') { - if (authorizedFolders.length > 0) { - tmp = tmp.filtered( - 'needAuthorization = 0 OR ' + - authorizedFolders - .map(folder => ' id = "' + folder.id + '"') - .join(' OR '), - ); - } else { - tmp = tmp.filtered( - 'needAuthorization = 0' - ); - } - } - if (format) { - return this._recursiveDir(tmp, lang); - } - return tmp; - } - - clear() { - realm.write(() => { - realm.delete(this.getAll('SYNC', null, false)); - }); - } - - _recursiveDir(list, lang, parent = null) { - let root = list.filter(e => e.parent === parent); - let tmp = []; - for (let i = 0; i < root.length; i++) { - let childs = this._recursiveDir(list, lang, root[i].id); - let name = JSON.parse(root[i].name); - tmp[i] = {}; - tmp[i].id = root[i].id; - tmp[i].name = this.getI18nName(lang, name); - tmp[i].items = []; - for (let j = 0; j < childs.length; j++) { - childs[j].value = childs[j].id; - tmp[i].items.push(childs[j]); - } - if (!tmp[i].items.length) { - delete tmp[i].items; - } - } - return tmp; - } - - getI18nName(lang, name) { - let tmp = undefined; - switch (lang) { - case "fr": - tmp = name.fr; - break; - case "en": - tmp = name.en; - break; - case "de": - tmp = name.de; - break; - case "es": - tmp = name.es; - break; - } - if (tmp === undefined) { - tmp = name.fr; - } - return tmp; - } - -} - -export default new DirectoriesModel(); diff --git a/ComApp/src/Models/Documents.js b/ComApp/src/Models/Documents.js deleted file mode 100644 index 18ce430..0000000 --- a/ComApp/src/Models/Documents.js +++ /dev/null @@ -1,68 +0,0 @@ -import Database from '../Database'; - -const Realm = require('realm'); -let realm = new Realm(Database); - -class DocumentsModel { - constructor() { - this.schema = 'Documents'; - } - - add(document) { - realm.write(() => { - realm.create(this.schema, document, 'never'); - }); - } - - update(document, updatedAtChange = false) { - let tmp = this.get(document.id); - if (tmp === undefined) { - this.add(document); - } else { - realm.write(() => { - if (updatedAtChange === false) { - realm.create(this.schema, { - id: tmp.id, - uuid: document.uuid, - title: document.title, - type: document.type, - path: document.path, - directory: document.directory - }, 'modified'); - } else { - realm.create(this.schema, document, 'modified'); - } - }); - } - } - - get(id) { - let tmp = realm.objects(this.schema).filtered('id = ' + id)[0]; - return tmp; - } - - getAll(authorizedDirs = false) { - let tmp = realm.objects(this.schema); - if (authorizedDirs) { - authorizedDirs = authorizedDirs.map(item => item.id); - tmp = tmp.filter(doc => authorizedDirs.includes(doc.directory)); - } - return tmp; - } - - clear(docs, toDelete = []) { - const localDocs = this.getAll(); - localDocs.forEach(doc => { - let tmp = docs.filter(item => item.uuid === doc.uuid); - if (tmp.length === 0) { - toDelete.push({uuid: doc.uuid, type: doc.type}); - realm.write(() => { - realm.delete(doc); - }); - } - }); - return toDelete; - } -} - -export default new DocumentsModel(); diff --git a/ComApp/src/Models/SendBrochure.js b/ComApp/src/Models/SendBrochure.js deleted file mode 100644 index fab3920..0000000 --- a/ComApp/src/Models/SendBrochure.js +++ /dev/null @@ -1,49 +0,0 @@ -import Database from '../Database'; - -const Realm = require('realm'); -let realm = new Realm(Database); - -class SendBrochureModel { - constructor() { - this.schema = 'SendBrochure'; - } - - add(data) { - realm.write(() => { - if (data.id === undefined) { - let id: any = realm.objects(this.schema).max('id'); - data.id = id === undefined ? 1 : id + 1; - } - realm.create(this.schema, data); - }); - } - - update(data) { - realm.write(() => { - realm.create(this.schema, data, true); - }); - } - - get(id) { - let tmp = realm.objects(this.schema); - if (tmp.length === 0) { - return false; - } else { - tmp = tmp.filtered('id = ' + id)[0]; - } - return tmp; - } - - getAll() { - let tmp = realm.objects(this.schema); - return tmp; - } - - clear() { - realm.write(() => { - realm.delete(this.getAll()); - }); - } -} - -export default new SendBrochureModel(); diff --git a/ComApp/src/Models/Users.js b/ComApp/src/Models/Users.js deleted file mode 100644 index 1d816ed..0000000 --- a/ComApp/src/Models/Users.js +++ /dev/null @@ -1,40 +0,0 @@ -import Database from '../Database'; - -const Realm = require('realm'); -let realm = new Realm(Database); - -class UsersModel { - constructor() { - this.schema = 'Users'; - } - - add(user) { - realm.write(() => { - realm.create(this.schema, user); - }); - } - - update(user) { - realm.write(() => { - realm.create(this.schema, user, true); - }); - } - - get(id) { - let tmp = realm.objects(this.schema).filtered('id = ' + id)[0]; - return tmp; - } - - getAll() { - let tmp = realm.objects(this.schema); - return tmp; - } - - clear() { - realm.write(() => { - realm.delete(this.getAll()); - }); - } -} - -export default new UsersModel(); diff --git a/ComApp/src/Views/Contact.js b/ComApp/src/Views/Contact.js index acb307c..be03ae9 100644 --- a/ComApp/src/Views/Contact.js +++ b/ComApp/src/Views/Contact.js @@ -108,7 +108,7 @@ class ContactScreen extends React.Component { synced: false, user_id: nextUser.id, }; - this.props.dispatch({ type: 'UPDATE_CONTACT', data: contact }); + this.props.dispatch({ type: 'EDIT_CONTACT', data: contact }); this.setState({ showTransferContact: false }); showMessage({ message: i18n.t('contact_s.contact_transferred') + '.', diff --git a/ComApp/src/Views/ContactDetails.js b/ComApp/src/Views/ContactDetails.js index c635aea..161e7e1 100644 --- a/ComApp/src/Views/ContactDetails.js +++ b/ComApp/src/Views/ContactDetails.js @@ -152,7 +152,7 @@ class ContactDetailsScreen extends React.Component { }; if (action === 'edit') { contact.id = this.state.tmpID; - this.props.dispatch({ type: 'UPDATE_CONTACT', data: contact }); + this.props.dispatch({ type: 'EDIT_CONTACT', data: contact }); this.populate(); showMessage({ message: i18n.t('contact_details_s.contact_saved') + '.', diff --git a/ComApp/src/Views/ContactDetails_MC.js b/ComApp/src/Views/ContactDetails_MC.js index 1341caf..7302dfa 100644 --- a/ComApp/src/Views/ContactDetails_MC.js +++ b/ComApp/src/Views/ContactDetails_MC.js @@ -152,7 +152,7 @@ class ContactDetailsScreen extends React.Component { }; if (action === 'edit') { contact.id = this.state.tmpID; - this.props.dispatch({ type: 'UPDATE_CONTACT', data: contact }); + this.props.dispatch({ type: 'EDIT_CONTACT', data: contact }); this.populate(); showMessage({ message: i18n.t('contact_details_s.contact_saved') + '.', diff --git a/ComApp/src/Views/ContactDetails_RHD.js b/ComApp/src/Views/ContactDetails_RHD.js index 9f39b82..eb487c3 100644 --- a/ComApp/src/Views/ContactDetails_RHD.js +++ b/ComApp/src/Views/ContactDetails_RHD.js @@ -152,7 +152,7 @@ class ContactDetailsScreen extends React.Component { }; if (action === 'edit') { contact.id = this.state.tmpID; - this.props.dispatch({ type: 'UPDATE_CONTACT', data: contact }); + this.props.dispatch({ type: 'EDIT_CONTACT', data: contact }); this.populate(); showMessage({ message: i18n.t('contact_details_s.contact_saved') + '.', From 064baab447f047d7167f41ecb0461c8b867e9d95 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Wed, 28 Dec 2022 16:32:30 +0100 Subject: [PATCH 02/33] save tmp clean --- ComApp/src/App.js | 180 +++++++++--------- ComApp/src/App/Controllers/SyncController.js | 8 - ComApp/src/App/Store/Actions/actionType.js | 4 +- ComApp/src/App/Store/Actions/contacts.js | 13 +- ComApp/src/App/Store/Actions/documents.js | 16 ++ .../Store/Actions/{locale.js => locales.js} | 0 ComApp/src/App/Store/ConfigureStore.js | 4 +- ComApp/src/App/Store/Reducers/AppReducer.js | 23 +-- ComApp/src/App/Store/Reducers/contacts.js | 20 +- ComApp/src/App/Store/Reducers/documents.js | 23 +++ ComApp/src/App/Views/ContactDetailsScreen.js | 2 +- ComApp/src/App/Views/ContactScreen.js | 4 +- ComApp/src/App/Views/HomeScreen.js | 14 +- ComApp/src/App/Views/LoginScreen.js | 34 +++- ComApp/src/App/Views/OnlyVideosScreen.js | 2 +- ComApp/src/App/Views/SyncScreen.js | 34 +++- ComApp/src/Locales/fr.json | 1 + 17 files changed, 231 insertions(+), 151 deletions(-) create mode 100644 ComApp/src/App/Store/Actions/documents.js rename ComApp/src/App/Store/Actions/{locale.js => locales.js} (100%) create mode 100644 ComApp/src/App/Store/Reducers/documents.js diff --git a/ComApp/src/App.js b/ComApp/src/App.js index cd73224..7c6eb47 100644 --- a/ComApp/src/App.js +++ b/ComApp/src/App.js @@ -3,6 +3,14 @@ import React from 'react'; // Redux import { Provider } from 'react-redux'; import { store } from './App/Store/ConfigureStore'; +// Deps +import 'react-native-gesture-handler'; +import { NavigationContainer } from '@react-navigation/native'; +import { createNativeStackNavigator } from '@react-navigation/native-stack'; +import { TouchableOpacity, View, Image, Text, TextInput, StyleSheet, Alert } from 'react-native'; +import Icon from 'react-native-vector-icons/FontAwesome5'; +import FlashMessage, { showMessage } from 'react-native-flash-message'; +import * as SplashScreen from 'expo-splash-screen'; // i18n import i18n from "./I18n"; // Controllers @@ -10,117 +18,60 @@ import SyncController from './App/Controllers/SyncController'; // Views import InstallScreen from './App/Views/InstallScreen'; import LoginScreen from './App/Views/LoginScreen'; + +import OnlyVideosScreen from './App/Views/OnlyVideosScreen'; +import ContactScreen from './App/Views/ContactScreen'; +import ContactDetailsScreen from './App/Views/ContactDetailsScreen'; // END V2 import SyncScreen from './App/Views/SyncScreen'; import HomeScreen from './App/Views/HomeScreen'; -import 'react-native-gesture-handler'; -import { NavigationContainer } from '@react-navigation/native'; -import { createNativeStackNavigator } from '@react-navigation/native-stack'; -import { TouchableOpacity, View, Image, Text, TextInput, StyleSheet, Alert } from 'react-native'; -import Icon from 'react-native-vector-icons/FontAwesome5'; - -import FlashMessage, { showMessage } from 'react-native-flash-message'; -import * as SplashScreen from 'expo-splash-screen'; import DirectoriesScreen from './Views/Directories'; import VideoScreen from './Views/Video'; import PDFScreen from './Views/PDF'; -import ContactScreen from './Views/Contact'; -import ContactDetailsScreen from './Views/ContactDetails'; -import OnlyVideosScreen from './Views/OnlyVideos'; + import SearchScreen from "./Views/Search"; import MySpaceScreen from './Views/MySpace'; +// V2 //SplashScreen.preventAutoHideAsync(); //Keep -// V2 store.dispatch({ type: 'INIT_APP' }); store.dispatch({ type: 'INIT_LOCALE' }); store.dispatch({ type: 'INIT_USERS' }); - // END V2 + const Stack = createNativeStackNavigator(); +// END V2 class App extends React.Component { state = { - logged: false, + isSetup: false, + isLogged: false, searchTxt: '', - sendEmail: '', - ShowIsActive: '0' + sendEmail: '' }; - componentDidMount(): void { - + componentDidMount() { const unsubscribe = store.subscribe(this.handleChange.bind(this)); - // if (Sync.isLogged()) { - // store.dispatch({ - // type: 'SET_CURRENT_USER', - // data: CommonModel.get('isLogged').value, - // }); - // store.dispatch({ type: 'SET_LOGGED', data: true }); - // } + if (SyncController.isLogged()) { + store.dispatch({ type: 'SET_CURRENT_USER' }); + store.dispatch({ type: 'SET_LOGGED', data: true }); + } + this.setState({ + isSetup: store.getState().app.isSetup, + isLogged: store.getState().app.logged, + }); } handleChange() { - const logged = store.getState().app.logged; - if (logged === false) { - CommonModel.delete('isLogged'); - } - if (logged !== undefined) { - this.setState({ logged: logged }); - } - this.setState({ ShowIsActive: store.getState().app.ShowIsActive }); - } - - LogoTitle(title) { - return ( - - - {title} - - ); - } - - SendEmail() { - return ( - - this.setState({ sendEmail: text })} /> - { - if (this.state.sendEmail.length > 0) { - if (Helpers.isEmailValid(this.state.sendEmail)) { - const email = { - email: this.state.sendEmail, - subject: i18n.t('app.file_sharing'), - message: '', - documents: JSON.stringify([store.getState().currentOpenedDoc]), - user_id: store.getState().currentUser.id - }; - store.dispatch({ type: 'SEND_BROCHURE', data: email }); - showMessage({ - message: i18n.t('global.message_sent') + '.', - description: i18n.t('global.message_will_be_sent_after_sync') + '.', - type: 'success', - duration: 1500, - }); - this.setState({ sendEmail: '' }); - } else { - Alert.alert(i18n.t('global.warning') + ' !', i18n.t('error.invalid_email_address') + '.', [ - { text: 'OK' }, - ], - { cancelable: false }, - ); - } - } - }}> - - - - ); + this.setState({ + isSetup: store.getState().app.isSetup, + isLogged: store.getState().app.logged, + }); // to force re-rendering + console.log("state changed") } render() { @@ -128,7 +79,7 @@ class App extends React.Component { - {store.getState().app.isSetup === false && + {this.state.isSetup === false && { store.dispatch({ type: 'EDIT_LOCALE' }); - this.setState({ state: this.state }); // to force re-rendering }} style={{ marginRight: 15 }}> @@ -149,7 +99,7 @@ class App extends React.Component { })} /> } - {this.state.logged === false ? ( + {this.state.isLogged === false ? ( { store.dispatch({ type: 'EDIT_LOCALE' }); - this.setState({ state: this.state }); // to force re-rendering }} style={{ marginRight: 15 }}> @@ -170,7 +119,7 @@ class App extends React.Component { })} /> ) : ( - ({ @@ -198,7 +147,7 @@ class App extends React.Component { style={{ marginRight: 25 }}> - {this.state.ShowIsActive === '1' && ( + {store.getState().app.ShowIsActive === '1' && ( navigation.navigation.navigate('MySpaceScreen')} style={{ marginRight: 25 }}> @@ -224,12 +173,14 @@ class App extends React.Component { ), })} - /> + /> )} this.LogoTitle(i18n.t('global.synchronization')) }} + options={{ + headerTitle: () => this.LogoTitle(i18n.t('global.synchronization')) + }} /> + + {title} + + ); + } + + SendEmail() { + return ( + + this.setState({ sendEmail: text })} /> + { + if (this.state.sendEmail.length > 0) { + if (Helpers.isEmailValid(this.state.sendEmail)) { + const email = { + email: this.state.sendEmail, + subject: i18n.t('app.file_sharing'), + message: '', + documents: JSON.stringify([store.getState().currentOpenedDoc]), + user_id: store.getState().currentUser.id + }; + store.dispatch({ type: 'SEND_BROCHURE', data: email }); + showMessage({ + message: i18n.t('global.message_sent') + '.', + description: i18n.t('global.message_will_be_sent_after_sync') + '.', + type: 'success', + duration: 1500, + }); + this.setState({ sendEmail: '' }); + } else { + Alert.alert(i18n.t('global.warning') + ' !', i18n.t('error.invalid_email_address') + '.', [ + { text: 'OK' }, + ], + { cancelable: false }, + ); + } + } + }}> + + + + ); + } + renderFlag() { let flag; switch (store.getState().locale.locale) { diff --git a/ComApp/src/App/Controllers/SyncController.js b/ComApp/src/App/Controllers/SyncController.js index fc9a75c..259566f 100644 --- a/ComApp/src/App/Controllers/SyncController.js +++ b/ComApp/src/App/Controllers/SyncController.js @@ -135,14 +135,6 @@ class SyncController { return true; } - isInstalled() { - const test = Setting.get('installed'); - if (test === false) { - return false; - } - return true; - } - isLogged() { const logged = Setting.get('isLogged'); const loggedTime = Setting.get('loggedTime'); diff --git a/ComApp/src/App/Store/Actions/actionType.js b/ComApp/src/App/Store/Actions/actionType.js index 510d597..0ed17e9 100644 --- a/ComApp/src/App/Store/Actions/actionType.js +++ b/ComApp/src/App/Store/Actions/actionType.js @@ -7,4 +7,6 @@ export const INIT_USERS = "INIT_USERS"; export const INIT_CONTACT = "INIT_CONTACT"; export const ADD_CONTACT = "ADD_CONTACT"; export const EDIT_CONTACT = "EDIT_CONTACT"; -export const DELETE_CONTACT = "DELETE_CONTACT"; \ No newline at end of file +export const DELETE_CONTACT = "DELETE_CONTACT"; +// Documents +export const INIT_DOCUMENTS = "INIT_DOCUMENTS"; \ No newline at end of file diff --git a/ComApp/src/App/Store/Actions/contacts.js b/ComApp/src/App/Store/Actions/contacts.js index e8b15f2..9773353 100644 --- a/ComApp/src/App/Store/Actions/contacts.js +++ b/ComApp/src/App/Store/Actions/contacts.js @@ -2,20 +2,23 @@ import { INIT_CONTACT, ADD_CONTACT, EDIT_CONTACT, DELETE_CONTACT } from "./actio /** * Init contact + * @param {object} currentUser The currentUser * @param {object} data The contact data */ -export const initContact = data => { +export const initContact = (currentUser, data) => { return { type: INIT_CONTACT, + currentUser, data, }; }; /** * Add contact + * @param {object} currentUser The currentUser * @param {object} data The contact data */ -export const addContact = data => { +export const addContact = (currentUser, data) => { return { type: ADD_CONTACT, data, @@ -24,10 +27,11 @@ export const addContact = data => { /** * Edit contact + * @param {object} currentUser The currentUser * @param {string} uid The contact uid * @param {object} data The contact data */ -export const editContact = (uid, data) => { +export const editContact = (currentUser, uid, data) => { return { type: EDIT_CONTACT, uid, @@ -37,9 +41,10 @@ export const editContact = (uid, data) => { /** * Delete contact + * @param {object} currentUser The currentUser * @param {string} uid The contact uid */ -export const deleteContact = uid => { +export const deleteContact = (currentUser, uid) => { return { type: DELETE_CONTACT, uid, diff --git a/ComApp/src/App/Store/Actions/documents.js b/ComApp/src/App/Store/Actions/documents.js new file mode 100644 index 0000000..87ae7c4 --- /dev/null +++ b/ComApp/src/App/Store/Actions/documents.js @@ -0,0 +1,16 @@ +import { INIT_DOCUMENTS } from "./actionType"; + +/** + * Init contact + * @param {string} lang The lang + * @param {object} directories Directories + * @param {object} data The document data + */ +export const initDocuments = (lang, directories, data) => { + return { + type: INIT_DOCUMENTS, + lang, + directories, + data, + }; +}; \ No newline at end of file diff --git a/ComApp/src/App/Store/Actions/locale.js b/ComApp/src/App/Store/Actions/locales.js similarity index 100% rename from ComApp/src/App/Store/Actions/locale.js rename to ComApp/src/App/Store/Actions/locales.js diff --git a/ComApp/src/App/Store/ConfigureStore.js b/ComApp/src/App/Store/ConfigureStore.js index 5b9f8a5..f0d1a8d 100644 --- a/ComApp/src/App/Store/ConfigureStore.js +++ b/ComApp/src/App/Store/ConfigureStore.js @@ -1,13 +1,15 @@ import { createStore, combineReducers } from "redux"; import appReducer from "./Reducers/AppReducer"; +import contactsReducer from "./Reducers/contacts"; +import documentsReducer from "./Reducers/documents"; import localesReducer from "./Reducers/locales"; import usersReducer from "./Reducers/users"; -import contactsReducer from "./Reducers/contacts"; const rootReducer = combineReducers({ app: appReducer, contacts: contactsReducer, + documents: documentsReducer, locale: localesReducer, users: usersReducer }); diff --git a/ComApp/src/App/Store/Reducers/AppReducer.js b/ComApp/src/App/Store/Reducers/AppReducer.js index 732e316..a6deb7f 100644 --- a/ComApp/src/App/Store/Reducers/AppReducer.js +++ b/ComApp/src/App/Store/Reducers/AppReducer.js @@ -1,15 +1,14 @@ import SyncController from "../../Controllers/SyncController"; // Database -import { Setting, Directory, Document, SendBrochure } from '../../../Database'; +import { Setting, Directory, SendBrochure } from '../../../Database'; const initialState = { isSetup: false, locale: 'fr', - directories: {}, - documents: {}, - syncVersion: 0, - logged: undefined, currentUser: {}, + logged: false, + directories: {}, + syncVersion: 0, currentOpenedDoc: {}, ShowIsActive: 0, }; @@ -34,26 +33,20 @@ const reducer = (state = initialState, action) => { let directories = Directory.getAll( state.currentUser.role, state.currentUser.authorizedFolders, - false, + true, state.locale ); - let docs = Document.getAll(directories); let ShowIsActive = Setting.get('ShowIsActive'); return { ...state, - directories: Directory.getAll( - state.currentUser.role, - state.currentUser.authorizedFolders, - true, - state.locale - ), - documents: docs.filter(item => item.lang === state.locale), + directories: directories, ShowIsActive: ShowIsActive === undefined ? false : ShowIsActive.value, }; case 'SET_CURRENT_USER': + let user = Setting.get('isLogged').value return { ...state, - currentUser: JSON.parse(action.data), + currentUser: JSON.parse(user), }; case 'SET_LOGGED': if (action.data === false) { diff --git a/ComApp/src/App/Store/Reducers/contacts.js b/ComApp/src/App/Store/Reducers/contacts.js index 07d83e7..d0c26ad 100644 --- a/ComApp/src/App/Store/Reducers/contacts.js +++ b/ComApp/src/App/Store/Reducers/contacts.js @@ -6,29 +6,33 @@ const initialState = []; const reducer = (state = initialState, action) => { switch (action.type) { - case INIT_CONTACT: + case INIT_CONTACT: { return { ...state, - contacts: Contact.getByUser(state.currentUser.id), + contacts: Contact.getByUser(action.currentUser.id), }; - case ADD_CONTACT: + } + case ADD_CONTACT: { Contact.add(action.data); return { ...state, - contacts: Contact.getByUser(state.currentUser.id), + contacts: Contact.getByUser(action.currentUser.id), }; - case EDIT_CONTACT: + } + case EDIT_CONTACT: { Contact.update(action.data); return { ...state, - contacts: Contact.getByUser(state.currentUser.id), + contacts: Contact.getByUser(action.currentUser.id), }; - case DELETE_CONTACT: + } + case DELETE_CONTACT: { Contact.delete(action.data); return { ...state, - contacts: Contact.getByUser(state.currentUser.id), + contacts: Contact.getByUser(action.currentUser.id), }; + } default: { return state; diff --git a/ComApp/src/App/Store/Reducers/documents.js b/ComApp/src/App/Store/Reducers/documents.js new file mode 100644 index 0000000..596a15d --- /dev/null +++ b/ComApp/src/App/Store/Reducers/documents.js @@ -0,0 +1,23 @@ +import { INIT_DOCUMENTS } from "../Actions/actionType"; +// Models +import { Document } from "../../../Database"; + +const initialState = []; + +const reducer = (state = initialState, action) => { + switch (action.type) { + case INIT_DOCUMENTS: { + let docs = Document.getAll(action.directories); + return [ + ...state, + docs.filter(item => item.lang === action.lang) + ]; + } + + default: { + return state; + } + } +}; + +export default reducer; diff --git a/ComApp/src/App/Views/ContactDetailsScreen.js b/ComApp/src/App/Views/ContactDetailsScreen.js index cb94e38..1dd5b40 100644 --- a/ComApp/src/App/Views/ContactDetailsScreen.js +++ b/ComApp/src/App/Views/ContactDetailsScreen.js @@ -31,7 +31,7 @@ import { BarCodeScanner } from 'expo-barcode-scanner'; function mapStateToProps(state) { return { - contacts: state.app.contacts, + contacts: state.contacts.contacts, currentUser: state.app.currentUser, }; } diff --git a/ComApp/src/App/Views/ContactScreen.js b/ComApp/src/App/Views/ContactScreen.js index c1420ae..c805aef 100644 --- a/ComApp/src/App/Views/ContactScreen.js +++ b/ComApp/src/App/Views/ContactScreen.js @@ -27,8 +27,8 @@ import styles from '../../Resources/Styles/ContactStyle'; function mapStateToProps(state) { return { - users: state.app.users, - contacts: state.app.contacts, + users: state.users.users, + contacts: state.contacts.contacts, documents: state.app.documents, currentUser: state.app.currentUser, }; diff --git a/ComApp/src/App/Views/HomeScreen.js b/ComApp/src/App/Views/HomeScreen.js index 1dff59f..cefdc8a 100644 --- a/ComApp/src/App/Views/HomeScreen.js +++ b/ComApp/src/App/Views/HomeScreen.js @@ -4,6 +4,7 @@ import { View, ImageBackground, TouchableOpacity, Text, Image } from 'react-nati import commonStyles from '../../Resources/CommonStyles'; // Redux import { connect } from 'react-redux'; +import { initDocuments } from '../Store/Actions/documents'; // Style import styles from '../../Resources/Styles/HomeStyle'; // Translations @@ -18,10 +19,19 @@ function mapStateToProps(state) { }; } +const mapDispatchToProps = dispatch => { + return { + init: (locale, directories) => { + dispatch({ type: 'INIT' }) + dispatch(initDocuments(locale, directories)) + } + }; +}; + class HomeScreen extends React.Component { componentDidMount() { - this.props.dispatch({ type: 'INIT' }); + this.props.init(this.props.locale.value, this.props.directories); } render() { @@ -52,4 +62,4 @@ class HomeScreen extends React.Component { } } -export default connect(mapStateToProps)(HomeScreen); \ No newline at end of file +export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen); \ No newline at end of file diff --git a/ComApp/src/App/Views/LoginScreen.js b/ComApp/src/App/Views/LoginScreen.js index 41f2cb5..929a4ef 100644 --- a/ComApp/src/App/Views/LoginScreen.js +++ b/ComApp/src/App/Views/LoginScreen.js @@ -1,6 +1,8 @@ import React from 'react'; import { View, ImageBackground, TextInput, Button, Image, Alert } from 'react-native'; +// Redux import { connect } from 'react-redux'; +import { initContact } from '../Store/Actions/contacts'; // Common Styles import commonStyles from '../../Resources/CommonStyles'; // Style @@ -17,11 +19,23 @@ import SyncController from '../Controllers/SyncController'; function mapStateToProps(state) { return { + app: state.app, users: state.users.users, locale: state.locale.locale, }; } +const mapDispatchToProps = dispatch => { + return { + initContact: currentUser => dispatch(initContact(currentUser)), + setCurrentUser: user => dispatch({ + type: 'SET_CURRENT_USER', + data: JSON.stringify(user), + }), + setIsLogged: () => dispatch({ type: 'SET_LOGGED', data: true }) + }; +}; + class LoginScreen extends React.Component { state = { login: 'v@b.t', @@ -85,7 +99,13 @@ class LoginScreen extends React.Component { return; } const lastUser = Setting.get('lastUser'); - if (lastUser === false || lastUser === undefined || lastUser.value === user.id.toString()) { + // Si on est sur une installation + if (lastUser === false || lastUser === undefined) { + this.loginAction(user, true); + return; + } + // Si on a deja une install avec une précédente connexion + if (lastUser.value === user.id.toString()) { this.loginAction(user); } else { // Si user !== last user && last user not synced @@ -108,15 +128,13 @@ class LoginScreen extends React.Component { loginAction(user, forceSync = false) { this.setState({ login: '', password: '' }); LoginController.login(user); - this.props.dispatch({ - type: 'SET_CURRENT_USER', - data: JSON.stringify(user), - }); - this.props.dispatch({ type: 'SET_LOGGED', data: true }); + this.props.setCurrentUser(user); + this.props.setIsLogged(); + this.props.initContact(this.props.app.currentUser); if (forceSync === true) { - this.props.navigation.navigate('SyncScreen', { isInstalled: true, forceSync: true }); + this.props.navigation.navigate('SyncScreen', { forceSync: true }); } } } -export default connect(mapStateToProps)(LoginScreen); \ No newline at end of file +export default connect(mapStateToProps, mapDispatchToProps)(LoginScreen); \ No newline at end of file diff --git a/ComApp/src/App/Views/OnlyVideosScreen.js b/ComApp/src/App/Views/OnlyVideosScreen.js index 1db6193..19b2ccc 100644 --- a/ComApp/src/App/Views/OnlyVideosScreen.js +++ b/ComApp/src/App/Views/OnlyVideosScreen.js @@ -14,7 +14,7 @@ import styles from '../../Resources/Styles/OnlyVideosStyle'; function mapStateToProps(state) { return { - documents: state.app.documents, + documents: state.documents, }; } diff --git a/ComApp/src/App/Views/SyncScreen.js b/ComApp/src/App/Views/SyncScreen.js index eae4805..cfbbe90 100644 --- a/ComApp/src/App/Views/SyncScreen.js +++ b/ComApp/src/App/Views/SyncScreen.js @@ -2,6 +2,7 @@ import React from 'react'; import { View, Button, Alert, Text } from 'react-native'; // Redux import { connect } from 'react-redux'; +import { initDocuments } from '../Store/Actions/documents'; // Style import styles from '../../Resources/Styles/SyncStyle'; // Translations @@ -20,9 +21,28 @@ function mapStateToProps(state) { documents: state.app.documents, syncVersion: state.app.syncVersion, currentUser: state.app.currentUser, + directories: state.app.directories, + locale: state.locale.locale, }; } +const mapDispatchToProps = dispatch => { + return { + init: (locale, directories) => { + dispatch({ type: 'INIT' }) + dispatch(initDocuments(locale, directories)) + }, + updateVersion: version => dispatch({ + type: 'UPDATE_VERSION', + data: version, + }), + updateShowIsActive: value => dispatch({ + type: 'UPDATE_SHOW_IS_ACTIVE', + data: value, + }) + }; +}; + class SyncScreen extends React.Component { state = { progress: 0, @@ -86,14 +106,8 @@ class SyncScreen extends React.Component { i18n.t('error.error_has_occurred') ); }); - this.props.dispatch({ - type: 'UPDATE_VERSION', - data: resVersion.version, - }); - this.props.dispatch({ - type: 'UPDATE_SHOW_IS_ACTIVE', - data: resVersion.ShowIsActive, - }); + this.props.updateVersion(resVersion.version); + this.props.updateShowIsActive(resVersion.ShowIsActive); this.setState({ newApp: resVersion.newApp }); // getUsers this.setState({ txtStep: i18n.t('sync_s.updating_users') + '...' }); @@ -280,7 +294,7 @@ class SyncScreen extends React.Component { } finishSync(version) { - this.props.dispatch({ type: 'INIT' }); + this.props.init(this.props.locale.value, this.props.directories); SyncController.updateVersion(version); this.setState({ txtStep: i18n.t('sync_s.update_completed') + '.', processing: false }); if (this.state.newApp === true) { @@ -304,4 +318,4 @@ class SyncScreen extends React.Component { } -export default connect(mapStateToProps)(SyncScreen); \ No newline at end of file +export default connect(mapStateToProps, mapDispatchToProps)(SyncScreen); \ No newline at end of file diff --git a/ComApp/src/Locales/fr.json b/ComApp/src/Locales/fr.json index afc8fd6..cac7764 100644 --- a/ComApp/src/Locales/fr.json +++ b/ComApp/src/Locales/fr.json @@ -54,6 +54,7 @@ "no_result": "Aucun résultat" }, "sync_s": { + "back_home": "Retour à l'accueil", "download": "Téléchargement", "update_completed": "Mise à jour effectuée", "updating_docs": "Mise à jour des documents", From 43d2f21591183fadb9a4653b5bfaa80a96490d95 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Wed, 28 Dec 2022 17:53:43 +0100 Subject: [PATCH 03/33] save tmp clean --- ComApp/src/App.js | 2 +- ComApp/src/App/Store/Actions/actionType.js | 2 ++ ComApp/src/App/Store/Actions/contacts.js | 6 ++--- ComApp/src/App/Store/Actions/directories.js | 16 ++++++++++++ ComApp/src/App/Store/ConfigureStore.js | 2 ++ ComApp/src/App/Store/Reducers/AppReducer.js | 22 ++++------------ ComApp/src/App/Store/Reducers/contacts.js | 25 +++++++++--------- ComApp/src/App/Store/Reducers/directories.js | 27 ++++++++++++++++++++ ComApp/src/App/Store/Reducers/documents.js | 3 +++ ComApp/src/App/Views/ContactDetailsScreen.js | 23 +++++++++++------ ComApp/src/App/Views/ContactScreen.js | 6 ++--- ComApp/src/App/Views/HomeScreen.js | 18 ++++++++----- ComApp/src/App/Views/SyncScreen.js | 20 ++++++++++----- 13 files changed, 114 insertions(+), 58 deletions(-) create mode 100644 ComApp/src/App/Store/Actions/directories.js create mode 100644 ComApp/src/App/Store/Reducers/directories.js diff --git a/ComApp/src/App.js b/ComApp/src/App.js index 7c6eb47..a0b8c6e 100644 --- a/ComApp/src/App.js +++ b/ComApp/src/App.js @@ -39,7 +39,7 @@ import MySpaceScreen from './Views/MySpace'; // V2 //SplashScreen.preventAutoHideAsync(); //Keep -store.dispatch({ type: 'INIT_APP' }); +store.dispatch({ type: 'INIT' }); store.dispatch({ type: 'INIT_LOCALE' }); store.dispatch({ type: 'INIT_USERS' }); diff --git a/ComApp/src/App/Store/Actions/actionType.js b/ComApp/src/App/Store/Actions/actionType.js index 0ed17e9..a7688a0 100644 --- a/ComApp/src/App/Store/Actions/actionType.js +++ b/ComApp/src/App/Store/Actions/actionType.js @@ -8,5 +8,7 @@ export const INIT_CONTACT = "INIT_CONTACT"; export const ADD_CONTACT = "ADD_CONTACT"; export const EDIT_CONTACT = "EDIT_CONTACT"; export const DELETE_CONTACT = "DELETE_CONTACT"; +// Directories +export const INIT_DIRECTORIES = "INIT_DIRECTORIES"; // Documents export const INIT_DOCUMENTS = "INIT_DOCUMENTS"; \ No newline at end of file diff --git a/ComApp/src/App/Store/Actions/contacts.js b/ComApp/src/App/Store/Actions/contacts.js index 9773353..ad0c3dc 100644 --- a/ComApp/src/App/Store/Actions/contacts.js +++ b/ComApp/src/App/Store/Actions/contacts.js @@ -21,6 +21,7 @@ export const initContact = (currentUser, data) => { export const addContact = (currentUser, data) => { return { type: ADD_CONTACT, + currentUser, data, }; }; @@ -28,13 +29,12 @@ export const addContact = (currentUser, data) => { /** * Edit contact * @param {object} currentUser The currentUser - * @param {string} uid The contact uid * @param {object} data The contact data */ -export const editContact = (currentUser, uid, data) => { +export const editContact = (currentUser, data) => { return { type: EDIT_CONTACT, - uid, + currentUser, data, }; }; diff --git a/ComApp/src/App/Store/Actions/directories.js b/ComApp/src/App/Store/Actions/directories.js new file mode 100644 index 0000000..1c43502 --- /dev/null +++ b/ComApp/src/App/Store/Actions/directories.js @@ -0,0 +1,16 @@ +import { INIT_DIRECTORIES } from "./actionType"; + +/** + * Init + * @param {string} lang The lang + * @param {object} user User + * @param {object} data The document data + */ +export const initDirectories = (lang, user, data) => { + return { + type: INIT_DIRECTORIES, + lang, + user, + data, + }; +}; \ No newline at end of file diff --git a/ComApp/src/App/Store/ConfigureStore.js b/ComApp/src/App/Store/ConfigureStore.js index f0d1a8d..ff2244d 100644 --- a/ComApp/src/App/Store/ConfigureStore.js +++ b/ComApp/src/App/Store/ConfigureStore.js @@ -3,6 +3,7 @@ import { createStore, combineReducers } from "redux"; import appReducer from "./Reducers/AppReducer"; import contactsReducer from "./Reducers/contacts"; import documentsReducer from "./Reducers/documents"; +import directoriesReducer from "./Reducers/directories"; import localesReducer from "./Reducers/locales"; import usersReducer from "./Reducers/users"; @@ -10,6 +11,7 @@ const rootReducer = combineReducers({ app: appReducer, contacts: contactsReducer, documents: documentsReducer, + directories: directoriesReducer, locale: localesReducer, users: usersReducer }); diff --git a/ComApp/src/App/Store/Reducers/AppReducer.js b/ComApp/src/App/Store/Reducers/AppReducer.js index a6deb7f..b53541e 100644 --- a/ComApp/src/App/Store/Reducers/AppReducer.js +++ b/ComApp/src/App/Store/Reducers/AppReducer.js @@ -1,13 +1,12 @@ import SyncController from "../../Controllers/SyncController"; // Database -import { Setting, Directory, SendBrochure } from '../../../Database'; +import { Setting, SendBrochure } from '../../../Database'; const initialState = { isSetup: false, locale: 'fr', currentUser: {}, logged: false, - directories: {}, syncVersion: 0, currentOpenedDoc: {}, ShowIsActive: 0, @@ -16,11 +15,13 @@ const initialState = { const reducer = (state = initialState, action) => { let saved; switch (action.type) { - case 'INIT_APP': + case 'INIT': + let ShowIsActive = Setting.get('ShowIsActive'); saved = Setting.get('isSetup'); return { ...state, - isSetup: saved === undefined ? false : saved.value === "true" ? true : false + isSetup: saved === undefined ? false : saved.value === "true" ? true : false, + ShowIsActive: ShowIsActive === undefined ? false : ShowIsActive.value }; case 'SET_ISSETUP': Setting.upsert({ key: 'isSetup', value: "true" }); @@ -29,19 +30,6 @@ const reducer = (state = initialState, action) => { ...state, isSetup: saved === undefined ? false : saved.value === "true" ? true : false }; - case 'INIT': - let directories = Directory.getAll( - state.currentUser.role, - state.currentUser.authorizedFolders, - true, - state.locale - ); - let ShowIsActive = Setting.get('ShowIsActive'); - return { - ...state, - directories: directories, - ShowIsActive: ShowIsActive === undefined ? false : ShowIsActive.value, - }; case 'SET_CURRENT_USER': let user = Setting.get('isLogged').value return { diff --git a/ComApp/src/App/Store/Reducers/contacts.js b/ComApp/src/App/Store/Reducers/contacts.js index d0c26ad..6f604f3 100644 --- a/ComApp/src/App/Store/Reducers/contacts.js +++ b/ComApp/src/App/Store/Reducers/contacts.js @@ -7,31 +7,30 @@ const initialState = []; const reducer = (state = initialState, action) => { switch (action.type) { case INIT_CONTACT: { - return { - ...state, - contacts: Contact.getByUser(action.currentUser.id), - }; + console.log("Init contact", Contact.getByUser(action.currentUser.id), action.currentUser.id) + return Contact.getByUser(action.currentUser.id); } case ADD_CONTACT: { + action.data.user_id = action.currentUser.id; Contact.add(action.data); - return { + return [ ...state, - contacts: Contact.getByUser(action.currentUser.id), - }; + Contact.getByUser(action.currentUser.id), + ]; } case EDIT_CONTACT: { Contact.update(action.data); - return { + return [ ...state, - contacts: Contact.getByUser(action.currentUser.id), - }; + Contact.getByUser(action.currentUser.id), + ]; } case DELETE_CONTACT: { Contact.delete(action.data); - return { + return [ ...state, - contacts: Contact.getByUser(action.currentUser.id), - }; + Contact.getByUser(action.currentUser.id), + ]; } default: { diff --git a/ComApp/src/App/Store/Reducers/directories.js b/ComApp/src/App/Store/Reducers/directories.js new file mode 100644 index 0000000..18b4896 --- /dev/null +++ b/ComApp/src/App/Store/Reducers/directories.js @@ -0,0 +1,27 @@ +import { INIT_DIRECTORIES } from "../Actions/actionType"; +// Models +import { Directory } from "../../../Database"; + +const initialState = []; + +const reducer = (state = initialState, action) => { + switch (action.type) { + case INIT_DIRECTORIES: { + return [ + ...state, + Directory.getAll( + action.user.role, + action.user.authorizedFolders, + true, + action.lang + ) + ]; + } + + default: { + return state; + } + } +}; + +export default reducer; diff --git a/ComApp/src/App/Store/Reducers/documents.js b/ComApp/src/App/Store/Reducers/documents.js index 596a15d..bdffa12 100644 --- a/ComApp/src/App/Store/Reducers/documents.js +++ b/ComApp/src/App/Store/Reducers/documents.js @@ -8,6 +8,9 @@ const reducer = (state = initialState, action) => { switch (action.type) { case INIT_DOCUMENTS: { let docs = Document.getAll(action.directories); + if (docs.length === 0) { + return state + } return [ ...state, docs.filter(item => item.lang === action.lang) diff --git a/ComApp/src/App/Views/ContactDetailsScreen.js b/ComApp/src/App/Views/ContactDetailsScreen.js index 1dd5b40..2244625 100644 --- a/ComApp/src/App/Views/ContactDetailsScreen.js +++ b/ComApp/src/App/Views/ContactDetailsScreen.js @@ -10,6 +10,7 @@ import { } from 'react-native'; // Reduxs import { connect } from 'react-redux'; +import { addContact, editContact } from '../Store/Actions/contacts'; // Helpers import Helpers from "../Lib/Helpers"; // Translations @@ -31,11 +32,18 @@ import { BarCodeScanner } from 'expo-barcode-scanner'; function mapStateToProps(state) { return { - contacts: state.contacts.contacts, + contacts: state.contacts, currentUser: state.app.currentUser, }; } +const mapDispatchToProps = dispatch => { + return { + addContact: (user, data) => dispatch(addContact(user, data)), + editContact: (user, data) => dispatch(editContact(user, data)) + }; +}; + let date = new Date().getDate(); if (date < 10) { date = '0' + date.toString(); @@ -57,9 +65,9 @@ class ContactDetailsScreen extends React.Component { showNewVisit: false, tmpID: 0, tmpNote: '', - tmpName: '', - tmpFirstname: '', - tmpEmail: '', + tmpName: 'test', + tmpFirstname: 'test', + tmpEmail: 'test@test.fr', tmpCompany: '', tmpAddress: '', tmpPhone: '', @@ -162,7 +170,7 @@ class ContactDetailsScreen extends React.Component { }; if (action === 'edit') { contact.id = this.state.tmpID; - this.props.dispatch({ type: 'EDIT_CONTACT', data: contact }); + this.props.editContact(this.props.currentUser, contact); this.populate(); showMessage({ message: i18n.t('contact_details_s.contact_saved') + '.', @@ -170,8 +178,7 @@ class ContactDetailsScreen extends React.Component { duration: 500, }); } else { - contact.user_id = this.props.currentUser.id; - this.props.dispatch({ type: 'ADD_CONTACT', data: contact }); + this.props.addContact(this.props.currentUser, contact); this.props.navigation.navigate('ContactScreen', { contactAdded: true }); } } @@ -844,4 +851,4 @@ class ContactDetailsScreen extends React.Component { } } -export default connect(mapStateToProps)(ContactDetailsScreen); +export default connect(mapStateToProps, mapDispatchToProps)(ContactDetailsScreen); diff --git a/ComApp/src/App/Views/ContactScreen.js b/ComApp/src/App/Views/ContactScreen.js index c805aef..c724bf7 100644 --- a/ComApp/src/App/Views/ContactScreen.js +++ b/ComApp/src/App/Views/ContactScreen.js @@ -28,8 +28,8 @@ import styles from '../../Resources/Styles/ContactStyle'; function mapStateToProps(state) { return { users: state.users.users, - contacts: state.contacts.contacts, - documents: state.app.documents, + contacts: state.contacts, + documents: state.documents, currentUser: state.app.currentUser, }; } @@ -261,7 +261,7 @@ class ContactScreen extends React.Component { let arrayContacts = Object.keys(objContacts).map(function (key) { return objContacts[key]; }); let arrayEmails = Object.keys(objContacts).map(function (key) { return objContacts[key]; }); let arrayDocs = Object.keys(objDocs).map(function (key) { return objDocs[key]; }); - + console.log("Contacts", objContacts); this.setState({ contacts: arrayContacts.sort(Helpers.compareValues('name', 'asc')), sortedDocuments: arrayDocs.sort(Helpers.compareValues('title', 'asc')), diff --git a/ComApp/src/App/Views/HomeScreen.js b/ComApp/src/App/Views/HomeScreen.js index cefdc8a..01940a2 100644 --- a/ComApp/src/App/Views/HomeScreen.js +++ b/ComApp/src/App/Views/HomeScreen.js @@ -4,7 +4,9 @@ import { View, ImageBackground, TouchableOpacity, Text, Image } from 'react-nati import commonStyles from '../../Resources/CommonStyles'; // Redux import { connect } from 'react-redux'; +import { initDirectories } from '../Store/Actions/directories'; import { initDocuments } from '../Store/Actions/documents'; +import { initContact } from '../Store/Actions/contacts'; // Style import styles from '../../Resources/Styles/HomeStyle'; // Translations @@ -14,24 +16,28 @@ import * as FileSystem from 'expo-file-system'; function mapStateToProps(state) { return { - directories: state.app.directories, + directories: state.directories, locale: state.locale.locale, + currentUser: state.app.currentUser }; } const mapDispatchToProps = dispatch => { return { - init: (locale, directories) => { - dispatch({ type: 'INIT' }) - dispatch(initDocuments(locale, directories)) - } + init: () => dispatch({ type: 'INIT' }), + initDirectories: (lang, user) => dispatch(initDirectories(lang, user)), + initDocuments: (lang, directories) => dispatch(initDocuments(lang, directories)), + initContact: currentUser => dispatch(initContact(currentUser)), }; }; class HomeScreen extends React.Component { componentDidMount() { - this.props.init(this.props.locale.value, this.props.directories); + this.props.init(); + this.props.initDirectories(this.props.locale.value, this.props.currentUser); + this.props.initDocuments(this.props.locale.value, this.props.directories); + this.props.initContact(this.props.currentUser); } render() { diff --git a/ComApp/src/App/Views/SyncScreen.js b/ComApp/src/App/Views/SyncScreen.js index cfbbe90..75a57ca 100644 --- a/ComApp/src/App/Views/SyncScreen.js +++ b/ComApp/src/App/Views/SyncScreen.js @@ -2,7 +2,9 @@ import React from 'react'; import { View, Button, Alert, Text } from 'react-native'; // Redux import { connect } from 'react-redux'; +import { initDirectories } from '../Store/Actions/directories'; import { initDocuments } from '../Store/Actions/documents'; +import { initContact } from '../Store/Actions/contacts'; // Style import styles from '../../Resources/Styles/SyncStyle'; // Translations @@ -18,20 +20,20 @@ import * as FileSystem from 'expo-file-system'; function mapStateToProps(state) { return { - documents: state.app.documents, + documents: state.documents, syncVersion: state.app.syncVersion, currentUser: state.app.currentUser, - directories: state.app.directories, + directories: state.directories, locale: state.locale.locale, }; } const mapDispatchToProps = dispatch => { return { - init: (locale, directories) => { - dispatch({ type: 'INIT' }) - dispatch(initDocuments(locale, directories)) - }, + init: () => dispatch({ type: 'INIT' }), + initDirectories: (lang, user) => dispatch(initDirectories(lang, user)), + initDocuments: (lang, directories) => dispatch(initDocuments(lang, directories)), + initContact: currentUser => dispatch(initContact(currentUser)), updateVersion: version => dispatch({ type: 'UPDATE_VERSION', data: version, @@ -294,7 +296,11 @@ class SyncScreen extends React.Component { } finishSync(version) { - this.props.init(this.props.locale.value, this.props.directories); + this.props.init(); + this.props.initDirectories(this.props.locale.value, this.props.currentUser); + this.props.initDocuments(this.props.locale.value, this.props.directories); + this.props.initContact(this.props.currentUser); + SyncController.updateVersion(version); this.setState({ txtStep: i18n.t('sync_s.update_completed') + '.', processing: false }); if (this.state.newApp === true) { From 4f415e5cd29c4a7ed77cd2ca0654401cd9160629 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Thu, 29 Dec 2022 10:32:28 +0100 Subject: [PATCH 04/33] save tmp clean + Contacts OK --- ComApp/src/App/Lib/Helpers.js | 3 +-- ComApp/src/App/Models/Contact.js | 9 ++++++++ ComApp/src/App/Store/Actions/contacts.js | 7 ++++--- ComApp/src/App/Store/Reducers/contacts.js | 18 ++++------------ ComApp/src/App/Views/ContactScreen.js | 25 ++++++++++++++++------- ComApp/src/App/Views/LoginScreen.js | 1 - ComApp/src/App/Views/SyncScreen.js | 2 +- 7 files changed, 37 insertions(+), 28 deletions(-) diff --git a/ComApp/src/App/Lib/Helpers.js b/ComApp/src/App/Lib/Helpers.js index e6a64a0..d939b56 100644 --- a/ComApp/src/App/Lib/Helpers.js +++ b/ComApp/src/App/Lib/Helpers.js @@ -1,11 +1,10 @@ class Helpers { compareValues(key, order = 'asc') { return function innerSort(a, b) { - if (!a.hasOwnProperty(key) || !b.hasOwnProperty(key)) { + if (!(key in a) || !(key in b)) { // property doesn't exist on either object return 0; } - const varA = (typeof a[key] === 'string') ? a[key].toUpperCase() : a[key]; const varB = (typeof b[key] === 'string') diff --git a/ComApp/src/App/Models/Contact.js b/ComApp/src/App/Models/Contact.js index 412f236..80c81d1 100644 --- a/ComApp/src/App/Models/Contact.js +++ b/ComApp/src/App/Models/Contact.js @@ -93,6 +93,15 @@ class ContactModel { }); } + delete(key) { + const tmp = this.get(key); + if (typeof tmp === 'object') { + this.realm.write(() => { + this.realm.delete(tmp); + }); + } + } + } export default ContactModel; diff --git a/ComApp/src/App/Store/Actions/contacts.js b/ComApp/src/App/Store/Actions/contacts.js index ad0c3dc..5e2946b 100644 --- a/ComApp/src/App/Store/Actions/contacts.js +++ b/ComApp/src/App/Store/Actions/contacts.js @@ -42,11 +42,12 @@ export const editContact = (currentUser, data) => { /** * Delete contact * @param {object} currentUser The currentUser - * @param {string} uid The contact uid + * @param {string} id The contact id */ -export const deleteContact = (currentUser, uid) => { +export const deleteContact = (currentUser, id) => { return { type: DELETE_CONTACT, - uid, + currentUser, + id, }; }; \ No newline at end of file diff --git a/ComApp/src/App/Store/Reducers/contacts.js b/ComApp/src/App/Store/Reducers/contacts.js index 6f604f3..88edb0c 100644 --- a/ComApp/src/App/Store/Reducers/contacts.js +++ b/ComApp/src/App/Store/Reducers/contacts.js @@ -7,30 +7,20 @@ const initialState = []; const reducer = (state = initialState, action) => { switch (action.type) { case INIT_CONTACT: { - console.log("Init contact", Contact.getByUser(action.currentUser.id), action.currentUser.id) return Contact.getByUser(action.currentUser.id); } case ADD_CONTACT: { action.data.user_id = action.currentUser.id; Contact.add(action.data); - return [ - ...state, - Contact.getByUser(action.currentUser.id), - ]; + return Contact.getByUser(action.currentUser.id); } case EDIT_CONTACT: { Contact.update(action.data); - return [ - ...state, - Contact.getByUser(action.currentUser.id), - ]; + return Contact.getByUser(action.currentUser.id); } case DELETE_CONTACT: { - Contact.delete(action.data); - return [ - ...state, - Contact.getByUser(action.currentUser.id), - ]; + Contact.delete(action.id); + return Contact.getByUser(action.currentUser.id); } default: { diff --git a/ComApp/src/App/Views/ContactScreen.js b/ComApp/src/App/Views/ContactScreen.js index c724bf7..32b2ddd 100644 --- a/ComApp/src/App/Views/ContactScreen.js +++ b/ComApp/src/App/Views/ContactScreen.js @@ -10,6 +10,8 @@ import { } from 'react-native'; // Reduxs import { connect } from 'react-redux'; +import { editContact } from '../Store/Actions/contacts'; +import { deleteContact } from '../Store/Actions/contacts'; // Helpers import Helpers from "../Lib/Helpers"; // Translations @@ -34,6 +36,14 @@ function mapStateToProps(state) { }; } +const mapDispatchToProps = dispatch => { + return { + editContact: (user, data) => dispatch(editContact(user, data)), + deleteContact: (user, id) => dispatch(deleteContact(user, id)), + sendBrochure: (email) => dispatch({ type: 'SEND_BROCHURE', data: email }) + }; +}; + class ContactScreen extends React.Component { state = { contacts: [], @@ -69,7 +79,7 @@ class ContactScreen extends React.Component { documents: JSON.stringify(this.state.sendDocumentList), user_id: this.props.currentUser.id }; - this.props.dispatch({ type: 'SEND_BROCHURE', data: email }); + this.props.sendBrochure(email); this.setState({ showSendBrochure: false, tmpSendBrochureEmail: '', @@ -115,7 +125,7 @@ class ContactScreen extends React.Component { synced: false, user_id: nextUser.id, }; - this.props.dispatch({ type: 'EDIT_CONTACT', data: contact }); + this.props.editContact(this.props.currentUser, contact); this.setState({ showTransferContact: false }); showMessage({ message: i18n.t('contact_s.contact_transferred') + '.', @@ -125,7 +135,7 @@ class ContactScreen extends React.Component { }); } - deleteContact(id) { + deleteContactAction(id) { Alert.alert( i18n.t('global.confirmation'), i18n.t('contact_s.confirm_contact_delete'), @@ -139,7 +149,7 @@ class ContactScreen extends React.Component { text: i18n.t('global.yes'), onPress: () => { this.setState({ contacts: [], sortedEmails: [] }); - this.props.dispatch({ type: 'DELETE_CONTACT', data: id }); + this.props.deleteContact(this.props.currentUser, id); showMessage({ message: i18n.t('contact_s.contact_deleted') + '.', type: 'success', @@ -172,7 +182,7 @@ class ContactScreen extends React.Component { { - this.deleteContact(item.id); + this.deleteContactAction(item.id); }}> @@ -203,6 +213,7 @@ class ContactScreen extends React.Component { } } this.setState({ contacts: this.state.contacts.sort(Helpers.compareValues(field, sort)), sortType: sort, sortField: field }); + //console.log(this.state.contacts[0].name) } HeaderItem() { @@ -261,7 +272,7 @@ class ContactScreen extends React.Component { let arrayContacts = Object.keys(objContacts).map(function (key) { return objContacts[key]; }); let arrayEmails = Object.keys(objContacts).map(function (key) { return objContacts[key]; }); let arrayDocs = Object.keys(objDocs).map(function (key) { return objDocs[key]; }); - console.log("Contacts", objContacts); + this.setState({ contacts: arrayContacts.sort(Helpers.compareValues('name', 'asc')), sortedDocuments: arrayDocs.sort(Helpers.compareValues('title', 'asc')), @@ -537,4 +548,4 @@ class ContactScreen extends React.Component { } } -export default connect(mapStateToProps)(ContactScreen); +export default connect(mapStateToProps, mapDispatchToProps)(ContactScreen); diff --git a/ComApp/src/App/Views/LoginScreen.js b/ComApp/src/App/Views/LoginScreen.js index 929a4ef..adfc837 100644 --- a/ComApp/src/App/Views/LoginScreen.js +++ b/ComApp/src/App/Views/LoginScreen.js @@ -130,7 +130,6 @@ class LoginScreen extends React.Component { LoginController.login(user); this.props.setCurrentUser(user); this.props.setIsLogged(); - this.props.initContact(this.props.app.currentUser); if (forceSync === true) { this.props.navigation.navigate('SyncScreen', { forceSync: true }); } diff --git a/ComApp/src/App/Views/SyncScreen.js b/ComApp/src/App/Views/SyncScreen.js index 75a57ca..9fa8c37 100644 --- a/ComApp/src/App/Views/SyncScreen.js +++ b/ComApp/src/App/Views/SyncScreen.js @@ -128,7 +128,7 @@ class SyncScreen extends React.Component { }); // getContacts this.setState({ progress: 0.1, txtStep: i18n.t('sync_s.updating_contacts') + '...' }); - const resContacts = await SyncController.getContacts().then(res => { + const resContacts = await SyncController.getContacts(this.props.currentUser.id).then(res => { Contact.clear(); return res.data; }).catch(error => { From 5879b502cea5b01fa112681c81625372c76041af Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Thu, 29 Dec 2022 12:44:26 +0100 Subject: [PATCH 05/33] save tmp clean + HomeBtns, Directories + PDF OK --- ComApp/src/App.js | 19 +++++-------- ComApp/src/App/Store/Reducers/AppReducer.js | 9 +++++++ ComApp/src/App/Store/Reducers/directories.js | 12 ++++++--- ComApp/src/App/Store/Reducers/documents.js | 5 +--- ComApp/src/App/Views/ContactScreen.js | 1 - ComApp/src/App/Views/DirectoriesScreen.js | 6 ++++- ComApp/src/App/Views/HomeScreen.js | 28 +++++++++++++++----- ComApp/src/App/Views/PDFScreen.js | 6 ++--- ComApp/src/App/Views/SearchScreen.js | 2 +- ComApp/src/App/Views/SyncScreen.js | 5 ---- 10 files changed, 57 insertions(+), 36 deletions(-) diff --git a/ComApp/src/App.js b/ComApp/src/App.js index a0b8c6e..8eb3684 100644 --- a/ComApp/src/App.js +++ b/ComApp/src/App.js @@ -18,23 +18,18 @@ import SyncController from './App/Controllers/SyncController'; // Views import InstallScreen from './App/Views/InstallScreen'; import LoginScreen from './App/Views/LoginScreen'; - +import SyncScreen from './App/Views/SyncScreen'; +import HomeScreen from './App/Views/HomeScreen'; +import DirectoriesScreen from './App/Views/DirectoriesScreen'; +import PDFScreen from './App/Views/PDFScreen'; import OnlyVideosScreen from './App/Views/OnlyVideosScreen'; import ContactScreen from './App/Views/ContactScreen'; import ContactDetailsScreen from './App/Views/ContactDetailsScreen'; +import SearchScreen from "./App/Views/SearchScreen"; +import MySpaceScreen from './App/Views/MySpaceScreen'; // END V2 -import SyncScreen from './App/Views/SyncScreen'; -import HomeScreen from './App/Views/HomeScreen'; - - -import DirectoriesScreen from './Views/Directories'; import VideoScreen from './Views/Video'; -import PDFScreen from './Views/PDF'; - - -import SearchScreen from "./Views/Search"; -import MySpaceScreen from './Views/MySpace'; // V2 //SplashScreen.preventAutoHideAsync(); //Keep @@ -252,7 +247,7 @@ class App extends React.Component { { - const folder = store.getState().directories.filter(tmp => tmp.id === 1); + const folder = store.getState().directories.treeview.filter(tmp => tmp.id === 1); navigation.navigation.navigate('DirectoriesScreen', { folder: folder }) }} style={{ marginRight: 15 }}> diff --git a/ComApp/src/App/Store/Reducers/AppReducer.js b/ComApp/src/App/Store/Reducers/AppReducer.js index b53541e..b2eb8ba 100644 --- a/ComApp/src/App/Store/Reducers/AppReducer.js +++ b/ComApp/src/App/Store/Reducers/AppReducer.js @@ -10,6 +10,7 @@ const initialState = { syncVersion: 0, currentOpenedDoc: {}, ShowIsActive: 0, + HomeBtns: {}, }; const reducer = (state = initialState, action) => { @@ -23,6 +24,14 @@ const reducer = (state = initialState, action) => { isSetup: saved === undefined ? false : saved.value === "true" ? true : false, ShowIsActive: ShowIsActive === undefined ? false : ShowIsActive.value }; + case 'INIT_HOME_BTNS': { + let HomeFolders = Setting.get('HomeFolders'); + let Btns = JSON.parse(HomeFolders.value); + return { + ...state, + HomeBtns: Btns + } + } case 'SET_ISSETUP': Setting.upsert({ key: 'isSetup', value: "true" }); saved = Setting.get('isSetup'); diff --git a/ComApp/src/App/Store/Reducers/directories.js b/ComApp/src/App/Store/Reducers/directories.js index 18b4896..35f40e4 100644 --- a/ComApp/src/App/Store/Reducers/directories.js +++ b/ComApp/src/App/Store/Reducers/directories.js @@ -7,15 +7,21 @@ const initialState = []; const reducer = (state = initialState, action) => { switch (action.type) { case INIT_DIRECTORIES: { - return [ + return { ...state, - Directory.getAll( + global: Directory.getAll( + action.user.role, + action.user.authorizedFolders, + false, + action.lang + ), + treeview: Directory.getAll( action.user.role, action.user.authorizedFolders, true, action.lang ) - ]; + } } default: { diff --git a/ComApp/src/App/Store/Reducers/documents.js b/ComApp/src/App/Store/Reducers/documents.js index bdffa12..09fef74 100644 --- a/ComApp/src/App/Store/Reducers/documents.js +++ b/ComApp/src/App/Store/Reducers/documents.js @@ -11,10 +11,7 @@ const reducer = (state = initialState, action) => { if (docs.length === 0) { return state } - return [ - ...state, - docs.filter(item => item.lang === action.lang) - ]; + return docs.filter(item => item.lang === action.lang); } default: { diff --git a/ComApp/src/App/Views/ContactScreen.js b/ComApp/src/App/Views/ContactScreen.js index 32b2ddd..9449517 100644 --- a/ComApp/src/App/Views/ContactScreen.js +++ b/ComApp/src/App/Views/ContactScreen.js @@ -213,7 +213,6 @@ class ContactScreen extends React.Component { } } this.setState({ contacts: this.state.contacts.sort(Helpers.compareValues(field, sort)), sortType: sort, sortField: field }); - //console.log(this.state.contacts[0].name) } HeaderItem() { diff --git a/ComApp/src/App/Views/DirectoriesScreen.js b/ComApp/src/App/Views/DirectoriesScreen.js index 8dcee02..7394e75 100644 --- a/ComApp/src/App/Views/DirectoriesScreen.js +++ b/ComApp/src/App/Views/DirectoriesScreen.js @@ -8,6 +8,7 @@ import { } from 'react-native'; // Redux import { connect } from 'react-redux'; +import { initDocuments } from '../Store/Actions/documents'; // Treeview import TreeView from 'react-native-animated-tree-view'; // Icon @@ -19,7 +20,9 @@ import styles from '../../Resources/Styles/DirectoriesStyle'; function mapStateToProps(state) { return { - documents: state.app.documents, + documents: state.documents, + directories: state.directories, + locale: state.locale.locale, }; } @@ -56,6 +59,7 @@ class DirectoriesScreen extends React.Component { rightImage={{ uri: Image.resolveAssetSource(arrowDown).uri }} containerStyle={styles.treeviewContainer} onClick={folder => { + console.log(folder, this.props.documents) this.setState({ documents: this.props.documents.filter( tmp => tmp.directory === folder.id, diff --git a/ComApp/src/App/Views/HomeScreen.js b/ComApp/src/App/Views/HomeScreen.js index 01940a2..0e1089b 100644 --- a/ComApp/src/App/Views/HomeScreen.js +++ b/ComApp/src/App/Views/HomeScreen.js @@ -16,6 +16,7 @@ import * as FileSystem from 'expo-file-system'; function mapStateToProps(state) { return { + btns: state.app.HomeBtns, directories: state.directories, locale: state.locale.locale, currentUser: state.app.currentUser @@ -25,6 +26,7 @@ function mapStateToProps(state) { const mapDispatchToProps = dispatch => { return { init: () => dispatch({ type: 'INIT' }), + initBtns: () => dispatch({ type: 'INIT_HOME_BTNS' }), initDirectories: (lang, user) => dispatch(initDirectories(lang, user)), initDocuments: (lang, directories) => dispatch(initDocuments(lang, directories)), initContact: currentUser => dispatch(initContact(currentUser)), @@ -35,8 +37,8 @@ class HomeScreen extends React.Component { componentDidMount() { this.props.init(); + this.props.initBtns(); this.props.initDirectories(this.props.locale.value, this.props.currentUser); - this.props.initDocuments(this.props.locale.value, this.props.directories); this.props.initContact(this.props.currentUser); } @@ -45,10 +47,7 @@ class HomeScreen extends React.Component { return ( - this.openFolder(2)} style={styles.button}> - - {i18n.t('global.videos')} - + {this.renderBtns()} this.props.navigation.navigate('OnlyVideosScreen')} style={styles.button}> {i18n.t('global.videos')} @@ -62,8 +61,25 @@ class HomeScreen extends React.Component { ); } + renderBtns() { + let locale = this.props.locale; + let objBtns = this.props.btns; + let array = Object.keys(objBtns).map(function (key) { return objBtns[key]; }); + return array.map((item, index) => { + let names = JSON.parse(item.name); + let name = (locale in names) ? names[locale] : names.fr; + return ( + this.openFolder(item.id)} style={styles.button}> + + {name} + + ) + }); + } + openFolder(id) { - const folder = this.props.directories.filter(tmp => tmp.id === id); + const folder = this.props.directories.treeview.filter(tmp => tmp.id === id); + this.props.initDocuments(this.props.locale, this.props.directories.global); this.props.navigation.navigate('DirectoriesScreen', { folder: folder }); } } diff --git a/ComApp/src/App/Views/PDFScreen.js b/ComApp/src/App/Views/PDFScreen.js index 3765ff8..93450da 100644 --- a/ComApp/src/App/Views/PDFScreen.js +++ b/ComApp/src/App/Views/PDFScreen.js @@ -19,16 +19,16 @@ class PDFScreen extends React.Component { { - console.log(`number of pages: ${numberOfPages}`); + //console.log(`number of pages: ${numberOfPages}`); }} onPageChanged={(page, numberOfPages) => { - console.log(`current page: ${page}`); + //console.log(`current page: ${page}`); }} onError={error => { console.log(error); }} onPressLink={uri => { - console.log(`Link presse: ${uri}`); + //console.log(`Link presse: ${uri}`); }} style={styles.pdf} /> diff --git a/ComApp/src/App/Views/SearchScreen.js b/ComApp/src/App/Views/SearchScreen.js index 8a05510..9e76caa 100644 --- a/ComApp/src/App/Views/SearchScreen.js +++ b/ComApp/src/App/Views/SearchScreen.js @@ -18,7 +18,7 @@ import styles from '../../Resources/Styles/SearchStyle'; function mapStateToProps(state) { return { - documents: state.app.documents, + documents: state.documents, }; } diff --git a/ComApp/src/App/Views/SyncScreen.js b/ComApp/src/App/Views/SyncScreen.js index 9fa8c37..87f07d6 100644 --- a/ComApp/src/App/Views/SyncScreen.js +++ b/ComApp/src/App/Views/SyncScreen.js @@ -3,7 +3,6 @@ import { View, Button, Alert, Text } from 'react-native'; // Redux import { connect } from 'react-redux'; import { initDirectories } from '../Store/Actions/directories'; -import { initDocuments } from '../Store/Actions/documents'; import { initContact } from '../Store/Actions/contacts'; // Style import styles from '../../Resources/Styles/SyncStyle'; @@ -20,10 +19,8 @@ import * as FileSystem from 'expo-file-system'; function mapStateToProps(state) { return { - documents: state.documents, syncVersion: state.app.syncVersion, currentUser: state.app.currentUser, - directories: state.directories, locale: state.locale.locale, }; } @@ -32,7 +29,6 @@ const mapDispatchToProps = dispatch => { return { init: () => dispatch({ type: 'INIT' }), initDirectories: (lang, user) => dispatch(initDirectories(lang, user)), - initDocuments: (lang, directories) => dispatch(initDocuments(lang, directories)), initContact: currentUser => dispatch(initContact(currentUser)), updateVersion: version => dispatch({ type: 'UPDATE_VERSION', @@ -298,7 +294,6 @@ class SyncScreen extends React.Component { finishSync(version) { this.props.init(); this.props.initDirectories(this.props.locale.value, this.props.currentUser); - this.props.initDocuments(this.props.locale.value, this.props.directories); this.props.initContact(this.props.currentUser); SyncController.updateVersion(version); From de88957a628102c4173f4843d4f014707e983e4e Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Thu, 29 Dec 2022 15:25:30 +0100 Subject: [PATCH 06/33] save tmp clean + Videos OK --- ComApp/src/App.js | 4 +- ComApp/src/App/Views/VideoScreen.js | 33 ++++-- ComApp/src/I18n.js | 6 +- ComApp/src/Locales/de.json | 157 --------------------------- ComApp/src/Locales/en.json | 157 --------------------------- ComApp/src/Locales/fr.json | 162 ---------------------------- 6 files changed, 30 insertions(+), 489 deletions(-) delete mode 100644 ComApp/src/Locales/de.json delete mode 100644 ComApp/src/Locales/en.json delete mode 100644 ComApp/src/Locales/fr.json diff --git a/ComApp/src/App.js b/ComApp/src/App.js index 8eb3684..fa9d90e 100644 --- a/ComApp/src/App.js +++ b/ComApp/src/App.js @@ -22,15 +22,13 @@ import SyncScreen from './App/Views/SyncScreen'; import HomeScreen from './App/Views/HomeScreen'; import DirectoriesScreen from './App/Views/DirectoriesScreen'; import PDFScreen from './App/Views/PDFScreen'; +import VideoScreen from './App/Views/VideoScreen'; import OnlyVideosScreen from './App/Views/OnlyVideosScreen'; import ContactScreen from './App/Views/ContactScreen'; import ContactDetailsScreen from './App/Views/ContactDetailsScreen'; import SearchScreen from "./App/Views/SearchScreen"; import MySpaceScreen from './App/Views/MySpaceScreen'; // END V2 - -import VideoScreen from './Views/Video'; - // V2 //SplashScreen.preventAutoHideAsync(); //Keep diff --git a/ComApp/src/App/Views/VideoScreen.js b/ComApp/src/App/Views/VideoScreen.js index 99a2cdf..6b0ec69 100644 --- a/ComApp/src/App/Views/VideoScreen.js +++ b/ComApp/src/App/Views/VideoScreen.js @@ -3,26 +3,45 @@ import { View, Dimensions } from 'react-native'; // FileSytem import * as FileSystem from 'expo-file-system'; // Video -import { Video } from 'expo-av'; +import { ResizeMode } from 'expo-av'; import VideoPlayer from 'expo-video-player'; class VideoScreen extends React.Component { render() { const { uuid } = this.props.route.params; + let width = Dimensions.get("window").width; + let height = Dimensions.get("window").height; + + // if portrait + if (height > width) { + let tmpHeight = height; + height = width - 150; + width = tmpHeight + 100; + } else { + height = height - 100; + } return ( - + ); diff --git a/ComApp/src/I18n.js b/ComApp/src/I18n.js index f67cde5..57fcae8 100644 --- a/ComApp/src/I18n.js +++ b/ComApp/src/I18n.js @@ -1,8 +1,8 @@ import { I18n } from 'i18n-js'; -import fr from './Locales/fr'; -import en from './Locales/en'; -import de from './Locales/de'; +import fr from './Resources/Locales/fr'; +import en from './Resources/Locales/en'; +import de from './Resources/Locales/de'; const i18n = new I18n({ fr: fr, diff --git a/ComApp/src/Locales/de.json b/ComApp/src/Locales/de.json deleted file mode 100644 index 522ecf7..0000000 --- a/ComApp/src/Locales/de.json +++ /dev/null @@ -1,157 +0,0 @@ -{ - "global": { - "yes": "Ja", - "no": "Nein", - "home": "Startseite", - "search": "Suche", - "login": "Verbindung", - "email": "Email", - "message_sent": "Email geschickt", - "message_will_be_sent_after_sync": "Die Nachricht wird nach Synchronisation geschickt", - "warning": "Achtung", - "synchronization": "Synchronisation ", - "videos": "Videos", - "contacts": "Kontakt", - "confirmation": "Bestätigung", - "name": "Name", - "firstname": "Vorname", - "address": "Adresse", - "phone": "Telefonnummer", - "company": "Firma", - "add": "Addieren", - "cancel": "Abbrechen", - "subject": "Betreff", - "message": "Nachricht", - "send": "Senden", - "required": "erforderlich", - "save": "Speichern", - "retry": "Noch einmal versuchen", - "next": "Nächstes" - }, - "app": { - "file_sharing": " Dateifreigabe", - "folders": "Ordner", - "video": "Video", - "contact_details": "Kontaktdaten", - "results_search": "Suchergebnisse", - "my_space": "Mein Raum" - }, - "login_s": { - "install": "Installieren", - "username": "Benutzername", - "password": "Passwort" - }, - "home_s": { - "1": "Die Gruppe", - "2": "Unsere Marken", - "3": "Andere" - }, - "search_s": { - "no_result": "Keine Ergebnisse" - }, - "sync_s": { - "download": "Download", - "update_completed": "Update abgeschlossen", - "updating_docs": "Dokumentaktualisierung", - "updating_folders": "Dateien aktualisieren", - "sending_flyers": "Brochure senden", - "updating_contacts": "Kontakt aktualisieren", - "user_install_completed": "Benutzerinstallation abgeschlossen", - "updating_users": "Benutzer-Update", - "user_install": "Benutzerinstallation", - "start_sync": "Synchronisation starten", - "new_app_version": "Eine neue Version der Anwendung ist verfügbar!", - "open_store": "Öffnen Sie den App Store" - }, - "contact_s": { - "contact_transferred": "Kontakt weiterleiten", - "contact_will_be_sent_after_sync": "Der Kontakt wird nach der Synchronisation gesendet", - "confirm_contact_delete": "Möchten Sie diesen Kontakt wirklich löschen?", - "contact_deleted": "Kontakt gelöscht", - "contact_added": "Kontakt hinzugefügt", - "send_flyer": "Senden Sie eine Broschüre", - "select_contact": "Wählen Sie den Kontakt", - "transfer": "weiterleiten", - "contact_list": "Kontaktliste", - "documents_list": "Liste der Dokumente" - }, - "contact_details_s": { - "visits": "Besuche", - "notes": "Notes", - "contact_saved": "Kontakt gespeichert", - "confirm_visit_delete": "Sind Sie sicher, dass Sie diesen Besuch löschen möchten?", - "qrcode_not_vcard_format": "Dieser QRCode ist nicht im vCard-Format", - "customer": "Kunde", - "prospect": "potenzieller Kunde", - "other": "Andere", - "description": "Beschreibung", - "no_visits": "Kein Besuch", - "visit_name": "Besuchsname" - }, - "error": { - "error": "Fehler ", - "tablet_not_connected_internet": "Das Tablet ist nicht mit dem Internet verbunden.", - "tablet_not_synced_last_user": "Das Tablet wurde vom vorherigen Benutzer nicht synchronisiert", - "incorrect_credentials": "Falsche Anmeldeinformationen", - "must_fill_login_fields": "Sie müssen die Verbindungsfelder ausfüllen", - "invalid_email_address": "Ungültige E-Mail-Adresse", - "error_has_occurred": "Ein Fehler ist aufgetreten", - "must_be_connected_internet_sync": "Sie müssen mit dem Internet verbunden sein, um die Synchronisierung zu starten", - "incomplete_form": "Unvollständiges Formular", - "fill_all_fields_and_1_doc_min": "Bitte füllen Sie alle Felder, mindestens 1 Dokument und eine gültige E-Mail-Adresse aus.", - "fill_other_field": "Füllen Sie das Beschreibungsfeld für: Andere", - "specify_type_contact": "Bitte geben Sie die Art des Kontakts an", - "invalid_name": "ungültiger Name", - "invalid_firstname": "ungültiger Vorname", - "camera_permission_denied": "Kameraerlaubnis verweigert", - "pending_camera_permission": "Warten auf Kameraerlaubnis" - }, - "custom": { - "select-1": { - "title": "Art des Geschäfts", - "c1": "Einzelhandel", - "c2": "Home Service / Freezer Center", - "c3": "Restauration Tischservice", - "c4": "Fast Food und Snacking", - "c5": "Cafeteria / Selbstbedienungsladen", - "c6": "Catering-Unternehmen", - "c7": "Freihändige Verpflegung / Centrale Küche", - "c8": "Unabhängiger Vertriebspartner", - "c9": "Bäckerei Konditorei", - "c10": "Lebensmittel Zwischenprodukte", - "c11": "Destocker", - "c12": "Halal-Handel", - "c13": "Verpflegung von Unterkünften", - "c14": "Zentrale Geschäftsrestauration", - "c15": "Catering und Park", - "c16": "Verpflegung von Transport", - "c17": "Öffentlicher Markt", - "c18": "Cash", - "c19": "Nationaler Vertriebspartner", - "c20": "Rungis", - "c21": "Schlachthof", - "c22": "Andere" - }, - "select-2": { - "title": "Site", - "c1": "Celvia Dinde", - "c2": "Celvia Elaborés", - "c3": "Celvia Sérent", - "c4": "Procanar", - "c5": "Celtys", - "c6": "Farmor", - "c7": "Robichon", - "c8": "Les Volailles de Kerana", - "c9": "Bosher Volaille", - "c10": "LDC Bretagne", - "c11": "Doux Farmor", - "c12": "Favreau" - }, - "interest": { - "p1": "Huhn", - "p2": "Pute", - "p3": "Ente", - "p4": "Andere" - } - } -} diff --git a/ComApp/src/Locales/en.json b/ComApp/src/Locales/en.json deleted file mode 100644 index 94d6926..0000000 --- a/ComApp/src/Locales/en.json +++ /dev/null @@ -1,157 +0,0 @@ -{ - "global": { - "yes": "Yes", - "no": "No", - "home": "Home", - "search": "Search", - "login": "Login", - "email": "Email", - "message_sent": "Message Sent", - "message_will_be_sent_after_sync": "Message will be send after synchronization", - "warning": "Warning", - "synchronization": "Synchronization", - "videos": "Videos", - "contacts": "Contacts", - "confirmation": "Confirmation", - "name": "Lastname", - "firstname": "Firstname", - "address": "Adress", - "phone": "Phone number", - "company": "Company", - "add": "Add", - "cancel": "Cancel", - "subject": "Object", - "message": "Message", - "send": "Send", - "required": "required", - "save": "Save", - "retry": "Retry", - "next": "Next" - }, - "app": { - "file_sharing": "File Sharing", - "folders": "Folders", - "video": "Video", - "contact_details": "Contact information", - "results_search": "Search results", - "my_space": "Personal Dashboard" - }, - "login_s": { - "install": "Install", - "username": "Username", - "password": "Password" - }, - "home_s": { - "1": "The Group", - "2": "Our Brands", - "3": "Others" - }, - "search_s": { - "no_result": "No Result" - }, - "sync_s": { - "download": "Download", - "update_completed": "Update Done", - "updating_docs": "Updating documents", - "updating_folders": "Updating folders", - "sending_flyers": "Sending documents", - "updating_contacts": "Updating contacts", - "user_install_completed": "User install completed", - "updating_users": "Updating Users", - "user_install": "Installing Users", - "start_sync": "START SYNCHRONIZATION", - "new_app_version": "A new version of the application is available!", - "open_store": "Open the store" - }, - "contact_s": { - "contact_transferred": "Contact Transferred", - "contact_will_be_sent_after_sync": "The contact will be sent after synchronization", - "confirm_contact_delete": "Are you sure to delete this contact ?", - "contact_deleted": "Contact deleted", - "contact_added": "Contact added", - "send_flyer": "Send a document", - "select_contact": "Select the contact", - "transfer": "Transfer", - "contact_list": "Contact List", - "documents_list": "Documents List" - }, - "contact_details_s": { - "visits": "Visits", - "notes": "Notes", - "contact_saved": "Contact saved", - "confirm_visit_delete": "are you sure to delete this visit ?", - "qrcode_not_vcard_format": "This QRCode is not a VCard", - "customer": "Customer", - "prospect": "Prospect", - "other": "Other", - "description": "Description", - "no_visits": "No visits available", - "visit_name": "visits name" - }, - "error": { - "error": "Error", - "tablet_not_connected_internet": "The tablet is not connected to Internet", - "tablet_not_synced_last_user": "The previous user didn't synchronised the tablet", - "incorrect_credentials": "Incorrect Credentials", - "must_fill_login_fields": "You must fill the login fields.", - "invalid_email_address": "Invalid E-mail adress", - "error_has_occurred": "An error occured", - "must_be_connected_internet_sync": "You must be connected to internet to be able to synchronize", - "incomplete_form": "Incomplete Form", - "fill_all_fields_and_1_doc_min": "Please fill up all the fields, at least one document and a valid e-mail adress", - "fill_other_field": "You must fill the description field for : Other", - "specify_type_contact": "You must specify the contact type", - "invalid_name": "Invalid lastname", - "invalid_firstname": "Invalid firstname", - "camera_permission_denied": "Camera Permission Denied", - "pending_camera_permission": "Waiting for the camera permission" - }, - "custom": { - "select-1": { - "title": "Type of business", - "c1": "Retail trade", - "c2": "Home Service / Freezer Center", - "c3": "Catering table service", - "c4": "Fast food and snacking", - "c5": "Cafeteria / Self Service", - "c6": "Catering company", - "c7": "Contract catering / Central kitchen", - "c8": "Independent distributor", - "c9": "Bakery and pastry shop", - "c10": "Intermediate Food Products", - "c11": "Destocker", - "c12": "Halal trade", - "c13": "Accommodation catering", - "c14": "Commercial catering centre", - "c15": "Event catering and park", - "c16": "Restoration of transport", - "c17": "Public procurement", - "c18": "Cash", - "c19": "National distributor", - "c20": "Rungis", - "c21": "Slaughterhouse", - "c22": "Other" - }, - "select-2": { - "title": "Site", - "c1": "Celvia Dinde", - "c2": "Celvia Elaborés", - "c3": "Celvia Sérent", - "c4": "Procanar", - "c5": "Celtys", - "c6": "Farmor", - "c7": "Robichon", - "c8": "Les Volailles de Kerana", - "c9": "Bosher Volaille", - "c10": "LDC Bretagne", - "c11": "Doux Farmor", - "c12": "Favreau" - }, - "interest": { - "p1": "Chicken", - "p2": "Turkey", - "p3": "Duck", - "p4": "Other" - } - } -} diff --git a/ComApp/src/Locales/fr.json b/ComApp/src/Locales/fr.json deleted file mode 100644 index cac7764..0000000 --- a/ComApp/src/Locales/fr.json +++ /dev/null @@ -1,162 +0,0 @@ -{ - "install": { - "install": "Installer", - "installation": "Installation" - }, - "global": { - "yes": "Oui", - "no": "Non", - "home": "Accueil", - "search": "Recherche", - "login": "Connexion", - "email": "Email", - "message_sent": "Message envoyé", - "message_will_be_sent_after_sync": "Le message sera envoyé après synchronisation", - "warning": "Attention", - "synchronization": "Synchronisation", - "videos": "Vidéos", - "contacts": "Contacts", - "confirmation": "Confirmation", - "name": "Nom", - "firstname": "Prénom", - "address": "Adresse", - "phone": "Téléphone", - "company": "Société", - "add": "Ajouter", - "cancel": "Annuler", - "subject": "Objet", - "message": "Message", - "send": "Envoyer", - "required": "requis", - "save": "Enregistrer", - "retry": "Réessayer", - "next": "Suivant" - }, - "app": { - "file_sharing": "Partage de fichier", - "folders": "Dossiers", - "video": "Vidéo", - "contact_details": "Détails du contact", - "results_search": "Résultat(s) de votre recherche", - "my_space": "Mon espace" - }, - "login_s": { - "install": "Installer", - "username": "Identifiant", - "password": "Mot de passe" - }, - "home_s": { - "1": "Le Groupe", - "2": "Nos Marques", - "3": "Autres" - }, - "search_s": { - "no_result": "Aucun résultat" - }, - "sync_s": { - "back_home": "Retour à l'accueil", - "download": "Téléchargement", - "update_completed": "Mise à jour effectuée", - "updating_docs": "Mise à jour des documents", - "updating_folders": "Mise à jour des dossiers", - "sending_flyers": "Envoi des brochures", - "updating_contacts": "Mise à jour des contacts", - "user_install_completed": "Installation des utilisateurs effectuée", - "updating_users": "Mise à jour des utilisateurs", - "user_install": "Installation des utilisateurs", - "start_sync": "LANCER LA SYNCHRONISATION", - "new_app_version": "Une nouvelle version de l'application est disponible !", - "open_store": "Ouvrir le store" - }, - "contact_s": { - "contact_transferred": "Contact transféré", - "contact_will_be_sent_after_sync": "Le contact sera envoyé après synchronisation", - "confirm_contact_delete": "Êtes-vous sûr de vouloir supprimer ce contact ?", - "contact_deleted": "Contact supprimé", - "contact_added": "Contact ajouté", - "send_flyer": "Envoyer une brochure", - "select_contact": "Sélectionnez le contact", - "transfer": "Transférer", - "contact_list": "Liste des contacts", - "documents_list": "Liste des documents" - }, - "contact_details_s": { - "visits": "Visites", - "notes": "Notes", - "contact_saved": "Contact enregistré", - "confirm_visit_delete": "Êtes-vous sûr de vouloir supprimer cette visite ?", - "qrcode_not_vcard_format": "Ce QRCode n'est pas au format vCard", - "customer": "Client", - "prospect": "Prospect", - "other": "Autre", - "description": "Description", - "no_visits": "Aucune visites", - "visit_name": "Nom de la visite" - }, - "error": { - "error": "Erreur", - "tablet_not_connected_internet": "La tablette n'est pas connectée à internet.", - "tablet_not_synced_last_user": "La tablette n'as pas été synchronisée par l'utilisateur précédent.", - "incorrect_credentials": "Identifiants incorrect.", - "must_fill_login_fields": "Vous devez-remplir les champs de connexion.", - "invalid_email_address": "Adresse email invalide", - "error_has_occurred": "Une erreur est survenue", - "must_be_connected_internet_sync": "Vous devez être connecté à internet pour lancer la synchronisation", - "incomplete_form": "Formulaire incomplet", - "fill_all_fields_and_1_doc_min": "Veuillez remplir tous les champs, 1 document minimum et une adresse email valide", - "fill_other_field": "Vous devez remplir le champs description pour : Autre", - "specify_type_contact": "Vous devez préciser le type de contact", - "invalid_name": "Nom invalide", - "invalid_firstname": "Prénom invalide", - "camera_permission_denied": "Permission caméra refusée", - "pending_camera_permission": "En attente de permission caméra" - }, - "custom": { - "select-1": { - "title": "Type de commerce", - "c1": "Commerce de détail", - "c2": "Home Service / Freezer Center", - "c3": "Restauration service à table", - "c4": "Fast food et snacking", - "c5": "Cafétaria / Self Service", - "c6": "Société de restauration", - "c7": "Restauration gré à gré / cuisine Centrale", - "c8": "Distributeur indépendant", - "c9": "Boulangerie pâtisserie", - "c10": "PAI", - "c11": "Destockeur", - "c12": "Commerce Halal", - "c13": "Restauration d'hébergement", - "c14": "Centrale restauration commerciale", - "c15": "Restauration évenementielle et parc", - "c16": "Restauration de transport", - "c17": "Marché public", - "c18": "Cash", - "c19": "Distributeur national", - "c20": "Rungis", - "c21": "Abbatoir", - "c22": "Autre" - }, - "select-2": { - "title": "Site", - "c1": "Celvia Dinde", - "c2": "Celvia Elaborés", - "c3": "Celvia Sérent", - "c4": "Procanar", - "c5": "Celtys", - "c6": "Farmor", - "c7": "Robichon", - "c8": "Les Volailles de Kerana", - "c9": "Bosher Volaille", - "c10": "LDC Bretagne", - "c11": "Doux Farmor", - "c12": "Favreau" - }, - "interest": { - "p1": "Poulet", - "p2": "Dinde", - "p3": "Canard", - "p4": "Autre" - } - } -} From 04407b6f650bb7ddf925c377651b1cde32645148 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Thu, 29 Dec 2022 19:22:49 +0100 Subject: [PATCH 07/33] Update header btn --- ComApp/src/App.js | 48 ++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/ComApp/src/App.js b/ComApp/src/App.js index fa9d90e..49afa7e 100644 --- a/ComApp/src/App.js +++ b/ComApp/src/App.js @@ -77,7 +77,7 @@ class App extends React.Component { name="InstallScreen" component={InstallScreen} options={(navigation, route) => ({ - headerTitle: () => this.LogoTitle(i18n.t('install.installation')), + headerTitle: () => this.LogoTitle(navigation, i18n.t('install.installation')), headerRight: () => ( ({ - headerTitle: () => this.LogoTitle(i18n.t('global.login')), + headerTitle: () => this.LogoTitle(navigation, i18n.t('global.login')), headerRight: () => ( ({ - headerTitle: () => this.LogoTitle(i18n.t('global.home')), + headerTitle: () => this.LogoTitle(navigation, i18n.t('global.home')), headerRight: () => ( @@ -171,20 +171,22 @@ class App extends React.Component { this.LogoTitle(i18n.t('global.synchronization')) - }} + options={(navigation, route) => ({ + headerTitle: () => this.LogoTitle(navigation, i18n.t('global.synchronization')) + })} /> this.LogoTitle(i18n.t('app.folders')) }} + options={(navigation, route) => ({ + headerTitle: () => this.LogoTitle(navigation, i18n.t('app.folders')) + })} /> ({ - headerTitle: () => this.LogoTitle(i18n.t('global.videos')), + headerTitle: () => this.LogoTitle(navigation, i18n.t('global.videos')), headerRight: () => ( this.setState({ searchTxt: text })} /> @@ -207,7 +209,7 @@ class App extends React.Component { name="VideoScreen" component={VideoScreen} options={(navigation, route) => ({ - headerTitle: () => this.LogoTitle(i18n.t('app.video')), + headerTitle: () => this.LogoTitle(navigation, i18n.t('app.video')), headerRight: () => this.SendEmail(), orientation: 'landscape' })} @@ -216,31 +218,37 @@ class App extends React.Component { name="PDFScreen" component={PDFScreen} options={(navigation, route) => ({ - headerTitle: () => this.LogoTitle('PDF'), + headerTitle: () => this.LogoTitle(navigation, 'PDF'), headerRight: () => this.SendEmail() })} /> this.LogoTitle(i18n.t('global.contacts')) }} + options={(navigation, route) => ({ + headerTitle: () => this.LogoTitle(navigation, i18n.t('global.contacts')) + })} initialParams={{ contactAdded: false }} /> this.LogoTitle(i18n.t('app.contact_details')) }} + options={(navigation, route) => ({ + headerTitle: () => this.LogoTitle(navigation, i18n.t('app.contact_details')) + })} /> this.LogoTitle(i18n.t('app.results_search')) }} + options={(navigation, route) => ({ + headerTitle: () => this.LogoTitle(navigation, i18n.t('app.results_search')) + })} /> ({ - headerTitle: () => this.LogoTitle(i18n.t('app.my_space')), + headerTitle: () => this.LogoTitle(navigation, i18n.t('app.my_space')), headerRight: () => ( - + { navigation.navigation.navigate('HomeScreen') }}> + + {title} ); From 793ef4a1fa8ef42b3b8311a23f770902366d99dd Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Fri, 30 Dec 2022 10:02:07 +0100 Subject: [PATCH 08/33] add MainColor --- ComApp/src/App.js | 70 +++++++++++-------- ComApp/src/App/Store/Reducers/AppReducer.js | 5 +- ComApp/src/App/Views/ContactDetailsScreen.js | 37 +++++----- ComApp/src/App/Views/ContactScreen.js | 25 +++---- ComApp/src/App/Views/DirectoriesScreen.js | 4 +- ComApp/src/App/Views/HomeScreen.js | 9 ++- ComApp/src/App/Views/LoginScreen.js | 3 +- ComApp/src/App/Views/OnlyVideosScreen.js | 3 +- ComApp/src/App/Views/SearchScreen.js | 3 +- ComApp/src/App/Views/SyncScreen.js | 4 +- ComApp/src/App/Views/VideoScreen.js | 14 +++- ComApp/src/Resources/CommonStyles.js | 24 +++---- ComApp/src/Resources/Styles/ContactStyle.js | 4 +- .../src/Resources/Styles/DirectoriesStyle.js | 1 - .../src/Resources/Styles/NavigationStyle.js | 2 - .../src/Resources/Styles/OnlyVideosStyle.js | 1 - ComApp/src/Resources/Styles/SearchStyle.js | 1 - ComApp/src/Views/ContactDetails.js | 14 ++-- ComApp/src/Views/ContactDetails_MC.js | 14 ++-- ComApp/src/Views/ContactDetails_RHD.js | 24 +++---- 20 files changed, 142 insertions(+), 120 deletions(-) diff --git a/ComApp/src/App.js b/ComApp/src/App.js index 49afa7e..225cd9e 100644 --- a/ComApp/src/App.js +++ b/ComApp/src/App.js @@ -13,6 +13,8 @@ import FlashMessage, { showMessage } from 'react-native-flash-message'; import * as SplashScreen from 'expo-splash-screen'; // i18n import i18n from "./I18n"; +// FileSytem +import * as FileSystem from 'expo-file-system'; // Controllers import SyncController from './App/Controllers/SyncController'; // Views @@ -28,6 +30,8 @@ import ContactScreen from './App/Views/ContactScreen'; import ContactDetailsScreen from './App/Views/ContactDetailsScreen'; import SearchScreen from "./App/Views/SearchScreen"; import MySpaceScreen from './App/Views/MySpaceScreen'; +// Style +import styles from './Resources/Styles/NavigationStyle'; // END V2 // V2 //SplashScreen.preventAutoHideAsync(); //Keep @@ -44,7 +48,8 @@ class App extends React.Component { isSetup: false, isLogged: false, searchTxt: '', - sendEmail: '' + sendEmail: '', + mainColor: '' }; componentDidMount() { @@ -63,6 +68,7 @@ class App extends React.Component { this.setState({ isSetup: store.getState().app.isSetup, isLogged: store.getState().app.logged, + mainColor: store.getState().app.mainColor }); // to force re-rendering console.log("state changed") } @@ -77,7 +83,7 @@ class App extends React.Component { name="InstallScreen" component={InstallScreen} options={(navigation, route) => ({ - headerTitle: () => this.LogoTitle(navigation, i18n.t('install.installation')), + headerTitle: () => this.LogoTitle(navigation, i18n.t('install.installation'), false), headerRight: () => ( ({ - headerTitle: () => this.LogoTitle(navigation, i18n.t('global.login')), + headerTitle: () => this.LogoTitle(navigation, i18n.t('global.login'), false), headerRight: () => ( ( - this.setState({ searchTxt: text })} /> - { + this.setState({ searchTxt: text })} + /> + { if (this.state.searchTxt.length > 0) { navigation.navigation.navigate('SearchScreen', { needle: this.state.searchTxt, @@ -189,8 +202,8 @@ class App extends React.Component { headerTitle: () => this.LogoTitle(navigation, i18n.t('global.videos')), headerRight: () => ( - this.setState({ searchTxt: text })} /> - { + this.setState({ searchTxt: text })} /> + { if (this.state.searchTxt.length > 0) { navigation.navigation.navigate('SearchScreen', { needle: this.state.searchTxt, @@ -270,14 +283,25 @@ class App extends React.Component { ); } - LogoTitle(navigation, title) { + LogoTitle(navigation, title, wantBtn = true) { return ( - { navigation.navigation.navigate('HomeScreen') }}> - + { + if (wantBtn) { + navigation.navigation.navigate('HomeScreen') + } + }}> + {this.state.isSetup ? ( + + ) : ( + + )} {title} @@ -287,8 +311,8 @@ class App extends React.Component { SendEmail() { return ( - this.setState({ sendEmail: text })} /> - { + this.setState({ sendEmail: text })} /> + { if (this.state.sendEmail.length > 0) { if (Helpers.isEmailValid(this.state.sendEmail)) { const email = { @@ -342,20 +366,4 @@ class App extends React.Component { } -const styles = StyleSheet.create({ - searchInput: { - borderWidth: 1, - borderColor: '#ea4f52', - width: 200, - paddingLeft: 20, - }, - btnSearch: { - width: 50, - height: 50, - alignItems: 'center', - justifyContent: 'center', - backgroundColor: '#ea4f52' - } -}); - export default App; diff --git a/ComApp/src/App/Store/Reducers/AppReducer.js b/ComApp/src/App/Store/Reducers/AppReducer.js index b2eb8ba..53115e2 100644 --- a/ComApp/src/App/Store/Reducers/AppReducer.js +++ b/ComApp/src/App/Store/Reducers/AppReducer.js @@ -11,6 +11,7 @@ const initialState = { currentOpenedDoc: {}, ShowIsActive: 0, HomeBtns: {}, + mainColor: '#ea4f52' }; const reducer = (state = initialState, action) => { @@ -18,11 +19,13 @@ const reducer = (state = initialState, action) => { switch (action.type) { case 'INIT': let ShowIsActive = Setting.get('ShowIsActive'); + let MainColor = Setting.get('MainColor'); saved = Setting.get('isSetup'); return { ...state, isSetup: saved === undefined ? false : saved.value === "true" ? true : false, - ShowIsActive: ShowIsActive === undefined ? false : ShowIsActive.value + ShowIsActive: ShowIsActive === undefined ? false : ShowIsActive.value, + mainColor: MainColor === undefined ? initialState.mainColor : MainColor === false ? initialState.mainColor : MainColor.value }; case 'INIT_HOME_BTNS': { let HomeFolders = Setting.get('HomeFolders'); diff --git a/ComApp/src/App/Views/ContactDetailsScreen.js b/ComApp/src/App/Views/ContactDetailsScreen.js index 2244625..a551884 100644 --- a/ComApp/src/App/Views/ContactDetailsScreen.js +++ b/ComApp/src/App/Views/ContactDetailsScreen.js @@ -34,6 +34,7 @@ function mapStateToProps(state) { return { contacts: state.contacts, currentUser: state.app.currentUser, + mainColor: state.app.mainColor }; } @@ -361,7 +362,7 @@ class ContactDetailsScreen extends React.Component { justifyContent: 'center', }}> this.updateContactType('client')} /> this.updateContactType('prospect')} /> this.setState({ p1: !this.state.p1 })} containerStyle={styles.clearCheckbox} /> this.setState({ p2: !this.state.p2 })} containerStyle={styles.clearCheckbox} /> this.setState({ p3: !this.state.p3 })} containerStyle={styles.clearCheckbox} /> this.setState({ p4: !this.state.p4 })} @@ -550,7 +551,7 @@ class ContactDetailsScreen extends React.Component { this.setState({ selectedIndex: index })} @@ -602,13 +603,13 @@ class ContactDetailsScreen extends React.Component { this.setState({ showNewVisit: true })}> - + {this.state.visits.length > 0 && ( this.deleteVisit()}> - + )} @@ -641,10 +642,10 @@ class ContactDetailsScreen extends React.Component { {this.state.action === 'add' && ( <> -