diff --git a/ComApp/src/Controllers/Helpers.js b/ComApp/src/Controllers/Helpers.js deleted file mode 100644 index 63d3462..0000000 --- a/ComApp/src/Controllers/Helpers.js +++ /dev/null @@ -1,53 +0,0 @@ -class Helpers { - compareValues(key, order = 'asc') { - return function innerSort(a, b) { - //console.log("--", "A :", a, "B : ", b, "KEY : ", key, a.hasOwnProperty(key), b.hasOwnProperty(key), a.name); - if (!a.hasOwnProperty(key) || !b.hasOwnProperty(key)) { - // 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') - ? b[key].toUpperCase() : b[key]; - - let comparison = 0; - if (varA > varB) { - comparison = 1; - } else if (varA < varB) { - comparison = -1; - } - return ( - (order === 'desc') ? (comparison * -1) : comparison - ); - }; - } - - isEmailValid(email) { - const expression = /(?!.*\.{2})^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([\t]*\r\n)?[\t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([\t]*\r\n)?[\t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i; - return expression.test(String(email).toLowerCase()); - } - - isValidRequiredString(string) { - const expression = /.*\S.*/i; - return expression.test(String(string)); - } - - generateUUID() { // Public Domain/MIT - let d = new Date().getTime();//Timestamp - let d2 = new Date().getUTCMilliseconds() + Math.random();//Time in microseconds since page-load or 0 if unsupported - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { - let r = Math.random() * 16;//random number between 0 and 16 - if(d > 0){//Use timestamp until depleted - r = (d + r)%16 | 0; - d = Math.floor(d/16); - } else {//Use microseconds since page-load if supported - r = (d2 + r)%16 | 0; - d2 = Math.floor(d2/16); - } - return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); - }); - } -} -export default new Helpers(); diff --git a/ComApp/src/Controllers/Sync.js b/ComApp/src/Controllers/Sync.js deleted file mode 100644 index 87dcbed..0000000 --- a/ComApp/src/Controllers/Sync.js +++ /dev/null @@ -1,271 +0,0 @@ -import NetInfo from '@react-native-community/netinfo'; -import Constants from 'expo-constants'; - -const axios = require('axios'); -const api_url = 'https://app-intl.ldc.fr'; -const api_token = 'gP8K77n4568UXYLV63bqykDRs8pyMy'; -const endpoint = api_url + '/api'; -const app_uuid = '746ceb52-2354-40d9-b270-57ca541f2751'; - -import UsersModel from '../Models/Users'; -import DirectoriesModel from '../Models/Directories'; -import DocumentsModel from '../Models/Documents'; -import ContactsModel from '../Models/Contacts'; -import CommonModel from '../Models/Common'; -import SendBrochureModel from '../Models/SendBrochure'; - -class Sync { - getEndpointDocs() { - return api_url + '/storage/docs/'; - } - - getApiToken() { - return api_token; - } - - getAppUUID() { - return app_uuid; - } - - getVersion(callback, errorCallback) { - axios({ - method: 'get', - url: endpoint + '/version', - responseType: 'json', - params: { - token: this.getApiToken(), - app_uuid: app_uuid, - app_version: Constants.nativeAppVersion - }, - }) - .then(response => { - return callback(response.data.version, response.data.ShowIsActive, response.data.newApp); - }) - .catch(function(error) { - console.log(error); - return errorCallback(error); - }); - } - - needSync(callback) { - NetInfo.fetch().then(state => { - if (state.isConnected) { - axios({ - method: 'get', - url: endpoint + '/version', - responseType: 'json', - params: { - token: this.getApiToken(), - }, - }) - .then(response => { - const localVersion = CommonModel.get('version'); - if ( - localVersion === undefined || - localVersion === false || - localVersion.value !== response.data.version - ) { - return callback(); - } - return false; - }) - .catch(function(error) { - console.log(error); - }); - } - return false; - }); - return false; - } - - setInstalled() { - CommonModel.add({key: 'installed', value: '1'}); - CommonModel.add({key: 'locale', value: 'fr'}); - CommonModel.add({key: 'ShowIsActive', value: '0'}); - } - - getUsers(callback) { - axios({ - method: 'get', - url: endpoint + '/users', - responseType: 'json', - params: { - token: this.getApiToken(), - }, - }) - .then(response => { - UsersModel.clear(); - response.data.forEach(user => { - UsersModel.add(user); - }); - console.log('Users Update Done'); - return callback(); - }) - .catch(function(error) { - console.log(error); - }); - } - - getDirectories(callback) { - axios({ - method: 'get', - url: endpoint + '/directories', - responseType: 'json', - params: { - token: this.getApiToken(), - }, - }) - .then(function(response) { - DirectoriesModel.clear(); - response.data.forEach(dir => { - DirectoriesModel.add(dir); - }); - console.log('Directories Update Done'); - return callback(); - }) - .catch(function(error) { - console.log(error); - }); - } - - getDocuments(callback) { - axios({ - method: 'get', - url: endpoint + '/documents', - responseType: 'json', - params: { - token: this.getApiToken(), - }, - }) - .then(response => { - const toDelete = DocumentsModel.clear(response.data); - response.data.forEach(document => { - DocumentsModel.update(document); - }); - console.log('Documents Update Done'); - return callback(DocumentsModel.getAll(), toDelete); - }) - .catch(function(error) { - console.log(error); - }); - } - - getContacts(callback, userId, errorCallback) { - let contacts = ContactsModel.getAll(); - axios({ - method: 'post', - url: endpoint + '/contacts' + '?token=' + this.getApiToken(), - responseType: 'json', - data: { - contacts: contacts, - userId: userId, - }, - }) - .then(response => { - ContactsModel.clear(); - response.data.forEach(contact => { - ContactsModel.add(contact); - }); - console.log('Contacts Update Done'); - callback(); - }) - .catch(function (error) { - console.log(error); - errorCallback(error); - }); - } - - async sendBrochure(brochures, i) { - if (brochures.length > 0) { - const item = brochures[i]; - let response = await axios({ - method: 'post', - url: endpoint + '/sendBrochure', - responseType: 'json', - params: { - token: this.getApiToken(), - emails: {item}, - }, - }); - if (i < brochures.length - 1) { - return this.sendBrochure(brochures, i + 1); - } - return true; - } - return true; - } - - sendBrochures(callback) { - this.sendBrochure(SendBrochureModel.getAll(), 0).then(res => { - SendBrochureModel.clear(); - console.log('SendBrochures Update Done'); - callback(); - }); - } - - updateVersion(version) { - const localVersion = CommonModel.get('version'); - if (localVersion === false || localVersion === undefined) { - CommonModel.add({key: 'version', value: version}); - } else { - CommonModel.update({id: localVersion.id, key: 'version', value: version}); - } - } - - updateShowIsActive(value) { - const local = CommonModel.get('ShowIsActive'); - if (local === false || local === undefined) { - CommonModel.add({key: 'ShowIsActive', value: value}); - } else { - CommonModel.update({id: local.id, key: 'ShowIsActive', value: value}); - } - } - - isLogged() { - const logged = CommonModel.get('isLogged'); - const loggedTime = CommonModel.get('loggedTime'); - if ( - logged !== false && - loggedTime !== false && - logged !== undefined && - loggedTime !== undefined - ) { - let seconds = - Math.abs(new Date(Number(loggedTime.value)) - Date.now()) / 1000; - if (seconds < 14400) { - // 4h - return true; - } - return false; - } - return false; - } - - isInstalled() { - const test = CommonModel.get('installed'); - if (test === false) { - return false; - } - return true; - } - - updateLastModificationDoc(id, date) { - DocumentsModel.update({id: id, updated_at: date.toString()}, true); - } - - isSynced() { - const SendBrochure = SendBrochureModel.getAll(); - const Contacts = ContactsModel.getAll(); - - if (SendBrochure !== undefined && Contacts !== undefined) { - const noSynced = Contacts.filtered('synced = false'); - if (SendBrochure.length > 0 || noSynced.length > 0) { - return false; - } - } - return true; - } - -} - -export default new Sync();