From 2c522915f5f41357523c766b8cf88dc22a94000b Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Mon, 2 Jan 2023 16:27:03 +0100 Subject: [PATCH] Clean synchro check + remove useless files --- ComApp/src/App.js | 5 +- ComApp/src/App/Controllers/SyncController.js | 14 +- ComApp/src/App/Store/Reducers/AppReducer.js | 1 + ComApp/src/App/Views/HomeScreen.js | 1 - ComApp/src/App/Views/LoginScreen.js | 37 +- ComApp/src/Views/Contact.js | 614 ------------------- ComApp/src/Views/Directories.js | 114 ---- ComApp/src/Views/Home.js | 112 ---- ComApp/src/Views/Login.js | 163 ----- ComApp/src/Views/MySpace.js | 35 -- ComApp/src/Views/OnlyVideos.js | 95 --- ComApp/src/Views/PDF.js | 57 -- ComApp/src/Views/Search.js | 111 ---- ComApp/src/Views/Sync.js | 320 ---------- ComApp/src/Views/Video.js | 52 -- 15 files changed, 31 insertions(+), 1700 deletions(-) delete mode 100644 ComApp/src/Views/Contact.js delete mode 100644 ComApp/src/Views/Directories.js delete mode 100644 ComApp/src/Views/Home.js delete mode 100644 ComApp/src/Views/Login.js delete mode 100644 ComApp/src/Views/MySpace.js delete mode 100644 ComApp/src/Views/OnlyVideos.js delete mode 100644 ComApp/src/Views/PDF.js delete mode 100644 ComApp/src/Views/Search.js delete mode 100644 ComApp/src/Views/Sync.js delete mode 100644 ComApp/src/Views/Video.js diff --git a/ComApp/src/App.js b/ComApp/src/App.js index e63f2b0..8bc36ac 100644 --- a/ComApp/src/App.js +++ b/ComApp/src/App.js @@ -159,9 +159,7 @@ class App extends React.Component { )} - navigation.navigation.navigate('SyncScreen', { - isInstalled: true, - }) + navigation.navigation.navigate('SyncScreen') } style={{ marginRight: 25 }}> @@ -181,6 +179,7 @@ class App extends React.Component { ({ headerTitle: () => this.LogoTitle(navigation, i18n.t('global.synchronization')) })} diff --git a/ComApp/src/App/Controllers/SyncController.js b/ComApp/src/App/Controllers/SyncController.js index 0d4a11c..12b9263 100644 --- a/ComApp/src/App/Controllers/SyncController.js +++ b/ComApp/src/App/Controllers/SyncController.js @@ -130,12 +130,12 @@ class SyncController { } isSynced() { - const SendBrochure = SendBrochure.getAll(); + const brochures = SendBrochure.getAll(); const Contacts = Contact.getAll(); - if (SendBrochure !== undefined && Contacts !== undefined) { + if (brochures !== undefined && Contacts !== undefined) { const noSynced = Contacts.filtered('synced = false'); - if (SendBrochure.length > 0 || noSynced.length > 0) { + if (brochures.length > 0 || noSynced.length > 0) { return false; } } @@ -193,8 +193,12 @@ class SyncController { return false; } - setInstalled() { - Setting.add({ key: 'installed', value: "true" }); + setInstalled(remove = false) { + if (remove) { + Setting.delete('installed'); + } else { + Setting.add({ key: 'installed', value: "true" }); + } } isInstalled() { diff --git a/ComApp/src/App/Store/Reducers/AppReducer.js b/ComApp/src/App/Store/Reducers/AppReducer.js index 531d5f8..8b0ebed 100644 --- a/ComApp/src/App/Store/Reducers/AppReducer.js +++ b/ComApp/src/App/Store/Reducers/AppReducer.js @@ -8,6 +8,7 @@ const initialState = { currentUser: {}, logged: false, syncVersion: 0, + forceSync: false, currentOpenedDoc: {}, ShowIsActive: 0, HomeBtns: {}, diff --git a/ComApp/src/App/Views/HomeScreen.js b/ComApp/src/App/Views/HomeScreen.js index 7c0ffff..8c6d878 100644 --- a/ComApp/src/App/Views/HomeScreen.js +++ b/ComApp/src/App/Views/HomeScreen.js @@ -44,7 +44,6 @@ class HomeScreen extends React.Component { }; componentDidMount() { - // Si on est sur une installation if (!SyncController.isInstalled()) { return this.openSync(); } diff --git a/ComApp/src/App/Views/LoginScreen.js b/ComApp/src/App/Views/LoginScreen.js index ff87b07..eabfcb0 100644 --- a/ComApp/src/App/Views/LoginScreen.js +++ b/ComApp/src/App/Views/LoginScreen.js @@ -39,7 +39,7 @@ class LoginScreen extends React.Component { componentDidMount() { if (SyncController.isLogged()) { - this.props.setCurrentUser(); + this.props.setCurrentUser(false); } } @@ -102,38 +102,39 @@ class LoginScreen extends React.Component { const lastUser = Setting.get('lastUser'); // Si on est sur une installation if (lastUser === false || lastUser == undefined) { - return this.loginAction(user); - } - // TODO : a deplacer dans home screen - // Si on a deja une install avec une précédente connexion - if (lastUser !== false && lastUser !== undefined && lastUser.value === user.id.toString()) { - this.loginAction(user); - } else { - // Si user !== last user && last user not synced - if (lastUser.value !== user.id.toString() && !SyncController.isSynced()) { - Alert.alert(i18n.t('error.error'), i18n.t('error.tablet_not_synced_last_user')); + // Si la tablette est connectée à internet pour forcer la synchro + if (!SyncController.checkConnection()) { + Alert.alert(i18n.t('error.error'), i18n.t('error.tablet_not_connected_internet')); return; } - // Si user !== last user - if (lastUser.value !== user.id.toString()) { + return this.loginAction(user); + } + // Si on a deja une install + if (lastUser !== false && lastUser !== undefined) { + // Si on a une précédente connexion + if (lastUser.value === user.id.toString()) { + this.loginAction(user); + } else { // Si le user precedent est different du user courant + // Si user !== last user && last user not synced + if (!SyncController.isSynced()) { + Alert.alert(i18n.t('error.error'), i18n.t('error.tablet_not_synced_last_user')); + return; + } // Si la tablette est connectée à internet pour forcer la synchro if (!SyncController.checkConnection()) { Alert.alert(i18n.t('error.error'), i18n.t('error.tablet_not_connected_internet')); return; } + SyncController.setInstalled(true); this.loginAction(user, true); } } } - loginAction(user, forceSync = false) { + loginAction(user) { this.setState({ login: '', password: '' }); LoginController.login(user); this.props.setCurrentUser(); - - if (forceSync === true) { - this.props.navigation.navigate('SyncScreen', { forceSync: true }); - } } } diff --git a/ComApp/src/Views/Contact.js b/ComApp/src/Views/Contact.js deleted file mode 100644 index be03ae9..0000000 --- a/ComApp/src/Views/Contact.js +++ /dev/null @@ -1,614 +0,0 @@ -import React from 'react'; -import { - View, - StyleSheet, - Button, - FlatList, - Text, - Dimensions, - TouchableOpacity, - Alert, - TextInput, -} from 'react-native'; -import Icon from 'react-native-vector-icons/FontAwesome'; -import { connect, ReactReduxContext } from 'react-redux'; -import { showMessage } from 'react-native-flash-message'; -import { Overlay } from '@rneui/themed'; -import Helpers from "../Controllers/Helpers"; -import i18n from "../I18n"; -import { Picker } from '@react-native-picker/picker'; - -function mapStateToProps(state) { - return { - users: state.users, - contacts: state.contacts, - documents: state.documents, - currentUser: state.currentUser, - }; -} - -class ContactScreen extends React.Component { - state = { - contacts: [], - sortType: 'asc', - sortField: 'name', - searchTxt: '', - showTransferContact: false, - selectedTransferUser: 0, - contactToTransfer: {}, - showSendBrochure: false, - selectedDocument: -1, - sendDocumentList: [], - selectedSendBrochureEmail: -1, - tmpSendBrochureEmail: '', - tmpSendBrochureSubject: '', - tmpSendBrochureMessage: '', - sortedDocuments: [], - sortedEmails: [], - }; - - sendBrochure() { - if ( - this.state.tmpSendBrochureEmail !== '' && - this.state.tmpSendBrochureSubject !== '' && - this.state.tmpSendBrochureMessage !== '' && - this.state.sendDocumentList.length > 0 && - Helpers.isEmailValid(this.state.tmpSendBrochureEmail) - ) { - const email = { - email: this.state.tmpSendBrochureEmail, - subject: this.state.tmpSendBrochureSubject, - message: this.state.tmpSendBrochureMessage, - documents: JSON.stringify(this.state.sendDocumentList), - user_id: this.props.currentUser.id - }; - this.props.dispatch({ type: 'SEND_BROCHURE', data: email }); - this.setState({ - showSendBrochure: false, - tmpSendBrochureEmail: '', - tmpSendBrochureSubject: '', - tmpSendBrochureMessage: '', - selectedSendBrochureEmail: -1, - selectedDocument: -1, - sendDocumentList: [], - }); - showMessage({ - message: i18n.t('global.message_sent') + '.', - description: i18n.t('global.message_will_be_sent_after_sync') + '.', - type: 'success', - duration: 1500, - }); - } else { - Alert.alert( - i18n.t('error.incomplete_form'), - i18n.t('error.fill_all_fields_and_1_doc_min') + '.', - ); - } - } - - transferContact() { - const nextUser = this.props.users.filter(user => user.id !== this.props.currentUser.id)[this.state.selectedTransferUser]; - const transferContact = this.state.contactToTransfer; - const contact = { - id: transferContact.id, - email: transferContact.email, - type: transferContact.type, - other: transferContact.other, - network: transferContact.network, - name: transferContact.name, - firstname: transferContact.firstname, - office: transferContact.office, - company: transferContact.company, - address: transferContact.address, - phone: transferContact.phone, - products: transferContact.products, - notes: transferContact.note, - visits: transferContact.visits, - to_delete: false, - synced: false, - user_id: nextUser.id, - }; - this.props.dispatch({ type: 'EDIT_CONTACT', data: contact }); - this.setState({ showTransferContact: false }); - showMessage({ - message: i18n.t('contact_s.contact_transferred') + '.', - description: i18n.t('contact_s.contact_will_be_sent_after_sync') + '.', - type: 'success', - duration: 1500, - }); - } - - deleteContact(id) { - Alert.alert( - i18n.t('global.confirmation'), - i18n.t('contact_s.confirm_contact_delete'), - [ - { - text: i18n.t('global.no'), - onPress: () => console.log('Cancel Pressed'), - style: 'cancel', - }, - { - text: i18n.t('global.yes'), - onPress: () => { - this.setState({ contacts: [], sortedEmails: [] }); - this.props.dispatch({ type: 'DELETE_CONTACT', data: id }); - showMessage({ - message: i18n.t('contact_s.contact_deleted') + '.', - type: 'success', - duration: 500, - }); - }, - }, - ], - { cancelable: false }, - ); - } - - Item(item) { - return ( - - - this.props.navigation.navigate('ContactDetailsScreen', { - action: 'edit', - contactId: item.id, - }) - }> - - {item.name.toUpperCase()} {item.firstname} - - - {item.company} - {item.email} - - { - this.deleteContact(item.id); - }}> - - - { - this.setState({ - showTransferContact: true, - contactToTransfer: item, - }); - }}> - - - - - ); - } - - sortContacts(field) { - let sort; - if (field !== this.state.sortField) { - sort = 'asc'; - } else { - if (this.state.sortType === 'asc') { - sort = 'desc'; - } else { - sort = 'asc'; - } - } - let obj = this.props.contacts; - let array = Object.keys(obj).map(function (key) { return obj[key]; }); - this.setState({ contacts: array.sort(Helpers.compareValues(field, sort)), sortType: sort, sortField: field }); - //this.setState({ contacts: this.state.contacts.sort(Helpers.compareValues(field, sort)), sortType: sort, sortField: field }); - } - - HeaderItem() { - return ( - - { - this.sortContacts('name'); - }}> - {i18n.t('global.name')} - - { - this.sortContacts('company'); - }}> - {i18n.t('global.company')} - - {i18n.t('global.email')} - - - ); - } - - handleSearchBtn() { - if (this.state.searchTxt.length > 0) { - let obj = this.props.contacts; - let array = Object.keys(obj).map(function (key) { return obj[key]; }); - this.setState({ contacts: array.sort(Helpers.compareValues('name', 'asc')), sortType: 'asc', searchTxt: '' }); - } - } - handleSearchTxt(text) { - this.setState({ searchTxt: text }); - if (text.length > 0) { - let tmpContactsName = this.props.contacts.filter(item => item.name.toLowerCase().indexOf(text.toLowerCase()) >= 0); - let tmpContactsCompany = this.props.contacts.filter(item => { - if (item.company === null) { - return false; - } - return item.company.toLowerCase().indexOf(text.toLowerCase()) >= 0 - }); - let resSearch = Object.assign(tmpContactsName, tmpContactsCompany); - this.setState({ contacts: resSearch.sort(Helpers.compareValues('name', 'asc')), sortType: 'asc' }); - } else { - let obj = this.props.contacts; - let array = Object.keys(obj).map(function (key) { return obj[key]; }); - this.setState({ contacts: array.sort(Helpers.compareValues('name', 'asc')), sortType: 'asc' }); - } - } - - componentDidMount() { - this.init(); - } - - componentDidUpdate(prevProps, prevState, snapshot) { - if (prevProps.contacts !== this.props.contacts) { - this.init(); - } - } - - init() { - let objContacts = this.props.contacts; - let objDocs = this.props.documents; - 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]; }); - - this.setState({ - contacts: arrayContacts.sort(Helpers.compareValues('name', 'asc')), - sortedDocuments: arrayDocs.sort(Helpers.compareValues('title', 'asc')), - sortedEmails: arrayEmails.sort(Helpers.compareValues('email', 'asc')), - sortType: 'asc', - sortField: 'name', - }); - } - - render() { - const { contactAdded } = this.props.route.params; - if (contactAdded === true) { - this.props.navigation.setParams({ contactAdded: false }); - showMessage({ - message: i18n.t('contact_s.contact_added') + '.', - type: 'success', - duration: 500, - }); - } - return ( - - -