Skip to content

Commit

Permalink
Refractored emailService into shareLocalDBFile
Browse files Browse the repository at this point in the history
- Moved into `services/` directory
- Refractored `emailService.ts` to now use sharePlugin, to match controlHelper
- To reflect this change, renamed the service to `shareLocalDBFile`
- Reworked 18next translations to reflect change
  • Loading branch information
the-bay-kay committed May 21, 2024
1 parent a16bbc0 commit f25a2e9
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 70 deletions.
2 changes: 0 additions & 2 deletions package.cordovabuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"ANDROID_HOST": " ",
"ANDROID_PATHPREFIX": "/"
},
"cordova-plugin-email-composer": {},
"cordova-plugin-x-socialsharing": {
"PHOTO_LIBRARY_ADD_USAGE_DESCRIPTION": "This app requires photo library access to share photos on social media.",
"PHOTO_LIBRARY_USAGE_DESCRIPTION": "This app requires photo library access to share photos on social media."
Expand Down Expand Up @@ -128,7 +127,6 @@
"cordova-plugin-em-settings": "git+https://github.com/e-mission/cordova-connection-settings.git#v1.2.3",
"cordova-plugin-em-unifiedlogger": "git+https://github.com/e-mission/cordova-unified-logger.git#v1.3.6",
"cordova-plugin-em-usercache": "git+https://github.com/e-mission/cordova-usercache.git#v1.1.9",
"cordova-plugin-email-composer": "git+https://github.com/katzer/cordova-plugin-email-composer.git#0.10.1",
"cordova-plugin-file": "8.0.0",
"cordova-plugin-inappbrowser": "5.0.0",
"cordova-plugin-ionic-keyboard": "2.2.0",
Expand Down
12 changes: 5 additions & 7 deletions www/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"force-sync": "Force sync",
"share": "Share",
"download-json-dump": "Download json dump",
"email-log": "Email log",
"share-log": "Share log",
"upload-log": "Upload log",
"view-privacy": "View Privacy Policy",
"user-data": "User data",
Expand Down Expand Up @@ -260,16 +260,14 @@
"reading-unprocessed-data": "Reading unprocessed data..."
},

"email-service": {
"email-account-not-configured": "Email account is not configured, cannot send email",
"email-account-mail-app": "You must have the mail app on your phone configured with an email address. Otherwise, this won't work",
"going-to-email": "Going to email database from {{parentDir}}",
"email-log": {
"shareFile-service": {
"send-to": "Please send this file to k.shankari@nrel.gov, or another OpenPATH team member.",
"send-log": {
"subject-logs": "emission logs",
"body-please-fill-in-what-is-wrong": "please fill in what is wrong"
},
"no-email-address-configured": "No email address configured.",
"email-data": {
"send-data": {
"subject-data-dump-from-to": "Data dump from {{start}} to {{end}}",
"body-data-consists-of-list-of-entries": "Data consists of a list of entries.\nEntry formats are at https://github.com/e-mission/e-mission-server/tree/master/emission/core/wrapper \nData can be loaded locally using instructions at https://github.com/e-mission/e-mission-server#loading-test-data \n and can be manipulated using the example at https://github.com/e-mission/e-mission-server/blob/master/Timeseries_Sample.ipynb"
}
Expand Down
4 changes: 2 additions & 2 deletions www/js/control/LogPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
import { FlashList } from '@shopify/flash-list';
import { DateTime } from 'luxon';
import { AlertManager } from '../components/AlertBar';
import { sendEmail } from './emailService';
import { sendLocalDBFile } from '../services/shareLocalDBFile';
import { displayError, logDebug } from '../plugin/logger';
import NavBar from '../components/NavBar';

Expand Down Expand Up @@ -93,7 +93,7 @@ const LogPage = ({ pageVis, setPageVis }) => {
}

function emailLog() {
sendEmail('loggerDB');
sendLocalDBFile('loggerDB');
}

const separator = () => <View style={{ height: 8 }} />;
Expand Down
6 changes: 3 additions & 3 deletions www/js/control/ProfileSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import useAppConfig from '../useAppConfig';
import { AlertManager } from '../components/AlertBar';
import DataDatePicker from './DataDatePicker';
import PrivacyPolicyModal from './PrivacyPolicyModal';
import { sendEmail } from './emailService';
import { sendLocalDBFile } from '../services/shareLocalDBFile';
import { uploadFile } from './uploadService';
import ActionMenu from '../components/ActionMenu';
import SensedPage from './SensedPage';
Expand Down Expand Up @@ -441,9 +441,9 @@ const ProfileSettings = () => {
action={() => setDateDumpVis(true)}></SettingRow>
{logUploadSection}
<SettingRow
textKey="control.email-log"
textKey="control.share-log"
iconName="email"
action={() => sendEmail('loggerDB')}></SettingRow>
action={() => sendLocalDBFile('loggerDB')}></SettingRow>
<SettingRow
textKey="control.refresh-app-config"
desc={t('control.current-version', { version: appConfig?.version })}
Expand Down
4 changes: 2 additions & 2 deletions www/js/control/SensedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTheme, Appbar, IconButton, Text } from 'react-native-paper';
import { useTranslation } from 'react-i18next';
import { FlashList } from '@shopify/flash-list';
import { DateTime } from 'luxon';
import { sendEmail } from './emailService';
import { sendLocalDBFile } from '../services/shareLocalDBFile';
import NavBar from '../components/NavBar';

const SensedPage = ({ pageVis, setPageVis }) => {
Expand Down Expand Up @@ -60,7 +60,7 @@ const SensedPage = ({ pageVis, setPageVis }) => {
<View
style={{ paddingHorizontal: 15, flexDirection: 'row', justifyContent: 'space-between' }}>
<IconButton icon="refresh" onPress={() => updateEntries()} />
<IconButton icon="email" onPress={() => sendEmail('userCacheDB')} />
<IconButton icon="email" onPress={() => sendLocalDBFile('userCacheDB')} />
</View>

<FlashList
Expand Down
52 changes: 0 additions & 52 deletions www/js/control/emailService.ts

This file was deleted.

4 changes: 2 additions & 2 deletions www/js/services/controlHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export function getMyDataHelpers(fileName: string, startTimeString: string, endT
const shareObj = {
files: [attachFile],
message: i18next.t(
'email-service.email-data.body-data-consists-of-list-of-entries',
'shareFile-service.send-data.body-data-consists-of-list-of-entries',
),
subject: i18next.t('email-service.email-data.subject-data-dump-from-to', {
subject: i18next.t('shareFile-service.send-data.subject-data-dump-from-to', {
start: startTimeString,
end: endTimeString,
}),
Expand Down
40 changes: 40 additions & 0 deletions www/js/services/shareLocalDBFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import i18next from 'i18next';
import { displayErrorMsg, logDebug, logInfo, logWarn } from '../plugin/logger';

export async function sendLocalDBFile(database: string) {
let parentDir = 'unknown';

if (window['cordova'].platformId == 'android') {
parentDir = 'app://databases';
}

if (window['cordova'].platformId == 'ios') {
logDebug(window['cordova'].file.dataDirectory);
parentDir = window['cordova'].file.dataDirectory + '../LocalDatabase';
}

if (parentDir == 'unknown') {
displayErrorMsg('parentDir unexpectedly = ' + parentDir + '!');
return;
}

logInfo('Going to email ' + database);
parentDir = parentDir + '/' + database;

const shareObj = {
files: [parentDir],
message: i18next.t('shareFile-service.send-log.body-please-fill-in-what-is-wrong'),
subject: i18next.t('shareFile-service.send-log.subject-logs'),
};

alert(i18next.t('shareFile-service.send-to'));
window['plugins'].socialsharing.shareWithOptions(
shareObj,
(result) => {
logDebug(`Shared to app: ${result.app}`);
},
(err) => {
logWarn(`Sharing failed with error: ${err}`);
},
);
}

0 comments on commit f25a2e9

Please sign in to comment.