Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Re-enable "Download JSON dump" #1174

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.cordovabuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"cordova-plugin-app-version": "0.1.14",
"cordova-plugin-customurlscheme": "5.0.2",
"cordova-plugin-device": "2.1.0",
"cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.8.9",
"cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.9.0",
"cordova-plugin-em-opcodeauth": "git+https://github.com/e-mission/cordova-jwt-auth.git#v1.7.2",
"cordova-plugin-em-server-communication": "git+https://github.com/e-mission/cordova-server-communication.git#v1.2.7",
"cordova-plugin-em-serversync": "git+https://github.com/e-mission/cordova-server-sync.git#v1.3.3",
Expand Down
3 changes: 3 additions & 0 deletions setup/activate_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ then
echo "ANDROID_HOME and ANDROID_SDK_ROOT not set, android SDK not found"
fi

echo "Activating sdkman, and by default, gradle"
source ~/.sdkman/bin/sdkman-init.sh

echo "Ensuring that we use the most recent version of the command line tools"
export PATH=$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/emulator:$PATH

Expand Down
1 change: 1 addition & 0 deletions setup/export_shared_dep_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export NODE_VERSION=20.9.0
# Looks like brew supports only major and minor, not patch version
export RUBY_VERSION=3.0
export COCOAPODS_VERSION=1.15.2
export GRADLE_VERSION=8.10
export OSX_EXP_VERSION=12

export NVM_DIR="$HOME/.nvm"
Expand Down
15 changes: 15 additions & 0 deletions setup/setup_android_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,19 @@ else
echo "ANDROID_HOME = $ANDROID_HOME; ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT"
fi

echo "Setting up sdkman"
curl -s "https://get.sdkman.io" | bash
source ~/.sdkman/bin/sdkman-init.sh

CURR_GRADLE_VER=`sdk current gradle | cut -d " " -f 4 | xargs`

echo "CURR_GRADLE_VER = '$CURR_GRADLE_VER', expected $GRADLE_VERSION"

if [[ $CURR_GRADLE_VER == $GRADLE_VERSION ]]; then
echo "Already have gradle version $GRADLE_VERSION"
else
echo "Setting up gradle using SDKMan"
sdk install gradle $GRADLE_VERSION
fi

source setup/setup_shared_native.sh
79 changes: 35 additions & 44 deletions www/js/services/controlHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,48 +39,38 @@
function localShareData() {
return new Promise<void>((resolve, reject) => {
window['resolveLocalFileSystemURL'](window['cordova'].file.cacheDirectory, (fs) => {
fs.filesystem.root.getFile(fileName, null, (fileEntry) => {
logDebug(`fileEntry ${fileEntry.nativeURL} is file? ${fileEntry.isFile.toString()}`);
fileEntry.file(
(file) => {
const reader = new FileReader();

reader.onloadend = () => {
const readResult = this.result as string;
logDebug(`Successfull file read with ${readResult.length} characters`);
const dataArray = JSON.parse(readResult);
logDebug(`Successfully read resultList of size ${dataArray.length}`);
let attachFile = fileEntry.nativeURL;
const shareObj = {
files: [attachFile],
message: i18next.t(
'shareFile-service.send-data.body-data-consists-of-list-of-entries',
),
subject: i18next.t('shareFile-service.send-data.subject-data-dump-from-to', {
start: startTimeString,
end: endTimeString,
}),
};
window['plugins'].socialsharing.shareWithOptions(
shareObj,
(result) => {
logDebug(`Share Completed? ${result.completed}`); // On Android, most likely returns false
logDebug(`Shared to app: ${result.app}`);
resolve();
},
(msg) => {
logDebug(`Sharing failed with message ${msg}`);
},
);
};
reader.readAsText(file);
},
(error) => {
displayError(error, 'Error while downloading JSON dump');
reject(error);
},
);
});
fs.filesystem.root.getFile(

Check warning on line 42 in www/js/services/controlHelper.ts

View check run for this annotation

Codecov / codecov/patch

www/js/services/controlHelper.ts#L42

Added line #L42 was not covered by tests
fileName,
null,
(fileEntry) => {
logDebug(`fileEntry ${fileEntry.nativeURL} is file? ${fileEntry.isFile.toString()}`);
const shareObj = {

Check warning on line 47 in www/js/services/controlHelper.ts

View check run for this annotation

Codecov / codecov/patch

www/js/services/controlHelper.ts#L45-L47

Added lines #L45 - L47 were not covered by tests
files: [fileEntry.nativeURL],
message: i18next.t(
'shareFile-service.send-data.body-data-consists-of-list-of-entries',
),
subject: i18next.t('shareFile-service.send-data.subject-data-dump-from-to', {
start: startTimeString,
end: endTimeString,
}),
};
window['plugins'].socialsharing.shareWithOptions(

Check warning on line 57 in www/js/services/controlHelper.ts

View check run for this annotation

Codecov / codecov/patch

www/js/services/controlHelper.ts#L57

Added line #L57 was not covered by tests
shareObj,
(result) => {
logDebug(`Share Completed? ${result.completed}`); // On Android, most likely returns false
logDebug(`Shared to app: ${result.app}`);
resolve();

Check warning on line 62 in www/js/services/controlHelper.ts

View check run for this annotation

Codecov / codecov/patch

www/js/services/controlHelper.ts#L59-L62

Added lines #L59 - L62 were not covered by tests
},
(error) => {
displayError(error, `Sharing failed with message`);

Check warning on line 65 in www/js/services/controlHelper.ts

View check run for this annotation

Codecov / codecov/patch

www/js/services/controlHelper.ts#L64-L65

Added lines #L64 - L65 were not covered by tests
},
);
},
(error) => {
displayError(error, 'Error while downloading JSON dump');
reject(error);

Check warning on line 71 in www/js/services/controlHelper.ts

View check run for this annotation

Codecov / codecov/patch

www/js/services/controlHelper.ts#L69-L71

Added lines #L69 - L71 were not covered by tests
},
);
});
});
}
Expand Down Expand Up @@ -117,15 +107,16 @@
* getMyData fetches timeline data for a given day, and then gives the user a prompt to share the data
* @param timeStamp initial timestamp of the timeline to be fetched.
*/
export function getMyData(timeStamp: Date) {
export async function getMyData(timeStamp: Date) {

Check warning on line 110 in www/js/services/controlHelper.ts

View check run for this annotation

Codecov / codecov/patch

www/js/services/controlHelper.ts#L110

Added line #L110 was not covered by tests
// We are only retrieving data for a single day to avoid
// running out of memory on the phone
const endTime = DateTime.fromJSDate(timeStamp);
const startTime = endTime.startOf('day');
const startTimeString = startTime.toFormat("yyyy'-'MM'-'dd");
const endTimeString = endTime.toFormat("yyyy'-'MM'-'dd");

const dumpFile = startTimeString + '.' + endTimeString + '.timeline';
// let's rename this to .txt so that we can email it on iPhones
const dumpFile = startTimeString + '.' + endTimeString + '.timeline.txt';

Check warning on line 119 in www/js/services/controlHelper.ts

View check run for this annotation

Codecov / codecov/patch

www/js/services/controlHelper.ts#L119

Added line #L119 was not covered by tests
alert(`Going to retrieve data to ${dumpFile}`);

const getDataMethods = getMyDataHelpers(dumpFile, startTimeString, endTimeString);
Expand Down
Loading