diff --git a/ComApp/src/App/Controllers/InstallController.js b/ComApp/src/App/Controllers/InstallController.js index c08570c..91d659e 100644 --- a/ComApp/src/App/Controllers/InstallController.js +++ b/ComApp/src/App/Controllers/InstallController.js @@ -33,7 +33,7 @@ class InstallController { _.forEach(response.data.datas, function (value, key) { switch (key) { case "MainColor": - Setting.add({ key: key, value: value }); + Setting.upsert({ key: key, value: value }); break; case "SquaredLogo": case "RectangleLogo": @@ -55,13 +55,44 @@ class InstallController { }); Alert.alert(i18n.t("alert.info"), i18n.t("install.install_complete")); } else { - Alert.alert(i18n.t("alert.error"), i18n.t("alert.error_has_occurred")); + Alert.alert(i18n.t("alert.error"), i18n.t("error.error_has_occurred")); } } }) .catch(function (error) { console.log(error) - Alert.alert(i18n.t("alert.error"), i18n.t("alert.error_has_occurred")); + Alert.alert(i18n.t("alert.error"), i18n.t("error.error_has_occurred")); + }) + } else { + Alert.alert(i18n.t("alert.error"), i18n.t("error.tablet_not_connected_internet")); + } + }); + } + + getAppConfig(url) { + NetInfo.fetch().then(state => { + if (state.isConnected) { + axios({ + method: 'GET', + url: url + '/api/app', + responseType: 'json', + params: { + token: api_token + }, + }) + .then(function (response) { + if (response.data) { + if (response.data.status === "OK") { + Setting.upsert({ key: 'HomeFolders', value: JSON.stringify(response.data.datas.folders) }); + Alert.alert(i18n.t("alert.info"), i18n.t("install.install_complete")); + } else { + Alert.alert(i18n.t("alert.error"), i18n.t("error.error_has_occurred")); + } + } + }) + .catch(function (error) { + console.log(error) + Alert.alert(i18n.t("alert.error"), i18n.t("error.error_has_occurred")); }) } else { Alert.alert(i18n.t("alert.error"), i18n.t("error.tablet_not_connected_internet")); diff --git a/ComApp/src/App/Models/Setting.js b/ComApp/src/App/Models/Setting.js index 0fe3635..c23248f 100644 --- a/ComApp/src/App/Models/Setting.js +++ b/ComApp/src/App/Models/Setting.js @@ -7,7 +7,7 @@ class SettingModel { add(data) { this.realm.write(() => { if (data.id === undefined) { - let id: any = this.realm.objects(this.schema).max('id'); + let id = this.realm.objects(this.schema).max('id'); data.id = id === undefined ? 1 : id + 1; } try { @@ -18,6 +18,30 @@ class SettingModel { }); } + upsert(data) { + let tmp = this.get(data.key); + if (tmp === false || tmp === undefined) { + this.add(data); + } else { + if (data.id === undefined) { + data.id = tmp.id; + } + this.realm.write(() => { + this.realm.create(this.schema, data, 'modified'); + }); + } + } + + get(key) { + let tmp = this.realm.objects(this.schema); + if (tmp.length === 0) { + return false; + } else { + tmp = tmp.filtered('key = "' + key + '"')[0]; + } + return tmp; + } + } export default SettingModel; diff --git a/ComApp/src/App/Views/HomeScreen.js b/ComApp/src/App/Views/HomeScreen.js index 519902d..bfa31cd 100644 --- a/ComApp/src/App/Views/HomeScreen.js +++ b/ComApp/src/App/Views/HomeScreen.js @@ -8,24 +8,21 @@ import styles from '../../Resources/Styles/HomeStyle'; import i18n from "../../I18n"; // FileSytem import * as FileSystem from 'expo-file-system'; +// Database +import { Setting } from "../../Database"; +import _ from 'lodash'; class HomeScreen extends React.Component { + render() { + let buttons = Setting.get("HomeFolders"); + buttons = JSON.parse(buttons.value); + //console.log(typeof Object.values(buttons)) + const arr = [1, 2, 3] return ( - { }} style={styles.button}> - - {i18n.t('home_s.1')} - - { }} style={styles.button}> - - {i18n.t('home_s.2')} - - { }} style={styles.button}> - - {i18n.t('home_s.3')} - + {/* {this.getHomeButton()} */} { }} style={styles.button}> {i18n.t('global.videos')} @@ -38,6 +35,20 @@ class HomeScreen extends React.Component { ); } + + getHomeButtons() { + let buttons = Setting.get("HomeFolders"); + if (buttons) { + buttons = JSON.parse(buttons.value); + _.forEach(buttons, function (value, key) { + console.log(JSON.parse(value.name).fr) + }); + } + } + + openFolder(id) { + console.log(id) + } } export default HomeScreen; \ No newline at end of file