-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
247 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from "react"; | ||
import { angularize } from "../angular-react-helper"; | ||
import { getAngularService } from "../angular-react-helper"; | ||
import SettingRow from "./SettingRow"; | ||
|
||
const DemographicsSettingRow = ({ }) => { | ||
|
||
const EnketoDemographicsService = getAngularService('EnketoDemographicsService'); | ||
const EnketoSurveyLaunch = getAngularService('EnketoSurveyLaunch'); | ||
const $rootScope = getAngularService('$rootScope'); | ||
|
||
// copied from /js/survey/enketo/enketo-demographics.js | ||
function openPopover() { | ||
return EnketoDemographicsService.loadPriorDemographicSurvey().then((lastSurvey) => { | ||
return EnketoSurveyLaunch | ||
.launch($rootScope, 'UserProfileSurvey', { | ||
prefilledSurveyResponse: lastSurvey?.data?.xmlResponse, | ||
showBackButton: true, showFormFooterJumpNav: true | ||
}) | ||
.then(result => { | ||
console.log("demographic survey result ", result); | ||
}); | ||
}); | ||
} | ||
|
||
return <SettingRow action={openPopover} iconName="account" | ||
textKey="control.edit-demographics" isToggle={false} /> | ||
}; | ||
|
||
angularize(DemographicsSettingRow, 'emission.main.control.demographicsSettingRow'); | ||
export default DemographicsSettingRow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from "react"; | ||
import { angularize} from "../angular-react-helper"; | ||
import { List } from 'react-native-paper'; | ||
import { useTranslation } from "react-i18next"; | ||
import { array, string } from "prop-types"; | ||
|
||
//any pure functions can go outside | ||
const ExpansionSection = (props) => { | ||
const { t } = useTranslation(); //this accesses the translations | ||
const [expanded, setExpanded] = React.useState(false); | ||
|
||
const handlePress = () => setExpanded(!expanded); | ||
|
||
// anything that mutates must go in --- depend on props or state... | ||
|
||
return ( | ||
<List.Accordion | ||
title={t(props.sectionTitle)} | ||
expanded={expanded} | ||
onPress={handlePress}> | ||
{props.children} | ||
</List.Accordion> | ||
); | ||
}; | ||
ExpansionSection.propTypes = { | ||
sectionTitle: string | ||
} | ||
|
||
angularize(ExpansionSection, 'emission.main.control.expansionSection'); | ||
export default ExpansionSection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React from "react"; | ||
import { angularize } from "../angular-react-helper"; | ||
import { object } from "prop-types"; | ||
import ExpansionSection from "./ExpandMenu"; | ||
import SettingRow from "./SettingRow"; | ||
import ControlDataTable from "./ControlDataTable"; | ||
import DemographicsSettingRow from "./DemographicsSettingRow"; | ||
|
||
const ProfileSettings = ({ settingsScope }) => { | ||
|
||
// settingsScope is the $scope of general-settings.js | ||
// grab any variables or functions you need from it like this: | ||
const { logOut, viewPrivacyPolicy, viewQRCode, userStartStopTracking, | ||
fixAppStatus, toggleLowAccuracy, changeCarbonDataset, | ||
forceSync, share, openDatePicker, uploadLog, emailLog, | ||
eraseUserData, userData, carbonDatasetString, settings, | ||
refreshScreen, endForceSync, checkConsent, dummyNotification, | ||
invalidateCache, nukeUserCache, showLog, showSensed, | ||
editCollectionConfig, editSyncConfig } = settingsScope; | ||
|
||
// let opcode = settings.auth.opcode | ||
function getTracking(){ | ||
if(settings?.collect?.trackingOn){ | ||
return settings.collect.trackingOn; | ||
} | ||
else{ | ||
return false; | ||
} | ||
} | ||
function getOpcode(){ | ||
if(settings?.auth?.opcode){ | ||
return settings.auth.opcode; | ||
} | ||
else{ | ||
return "ERROR GETTING OPCODE"; | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
{/* <SettingRow textKey={getOpcode()} iconName='logout' action={logOut}></SettingRow> */} | ||
<DemographicsSettingRow></DemographicsSettingRow> | ||
<SettingRow textKey='control.view-privacy' iconName='eye' action={viewPrivacyPolicy}></SettingRow> | ||
<SettingRow textKey="control.view-qrc" iconName="grid" action={viewQRCode}></SettingRow> | ||
{/* this toggle only kinda works */} | ||
{/* <SettingRow textKey="control.tracking" action={userStartStopTracking} switchValue={getTracking()}></SettingRow> */} | ||
<SettingRow textKey="control.app-status" iconName="check" action={fixAppStatus}></SettingRow> | ||
{/* this switch is also a troublemaker (it's just not fully implemented well yet) */} | ||
{/* <SettingRow textKey="control.medium-accuracy" action={toggleLowAccuracy} switchValue={settings.collect.lowAccuracy}></SettingRow> */} | ||
<SettingRow textKey={carbonDatasetString} iconName="database-cog" action={changeCarbonDataset}></SettingRow> | ||
<SettingRow textKey="control.force-sync" iconName="sync" action={forceSync}></SettingRow> | ||
<SettingRow textKey="control.share" iconName="share" action={share}></SettingRow> | ||
<SettingRow textKey="control.download-json-dump" iconName="calendar" action={openDatePicker}></SettingRow> | ||
{/* this row missing condition!!! Should only show iff ui_config.profile_controls.support_upload == true */} | ||
<SettingRow textKey="control.upload-log" iconName="cloud" action={uploadLog}></SettingRow> | ||
<SettingRow textKey="control.email-log" iconName="email" action={emailLog}></SettingRow> | ||
|
||
<ExpansionSection sectionTitle="control.user-data"> | ||
<SettingRow textKey="control.erase-data" iconName="delete-forever" action={eraseUserData}></SettingRow> | ||
<ControlDataTable controlData={userData}></ControlDataTable> | ||
</ExpansionSection> | ||
|
||
<ExpansionSection sectionTitle="control.dev-zone"> | ||
<SettingRow textKey="control.refresh" iconName="refresh" action={refreshScreen}></SettingRow> | ||
<SettingRow textKey="control.end-trip-sync" iconName="sync-alert" action={endForceSync}></SettingRow> | ||
<SettingRow textKey="control.check-consent" iconName="check" action={checkConsent}></SettingRow> | ||
<SettingRow textKey="control.dummy-notification" iconName="bell" action={dummyNotification}></SettingRow> | ||
<SettingRow textKey="control.upcoming-notifications" iconName="bell-check" action={()=>console.log("")}></SettingRow> | ||
{/* <ControlDataTable controlData={settings.notification.scheduledNotifs}></ControlDataTable> */} | ||
<SettingRow textKey="control.invalidate-cached-docs" iconName="delete" action={invalidateCache}></SettingRow> | ||
<SettingRow textKey="control.nuke-all" iconName="delete-forever" action={nukeUserCache}></SettingRow> | ||
{/* <SettingRow textKey={parseState(settings.collect.state)} iconName="pencil" action={forceState}></SettingRow> */} | ||
<SettingRow textKey="control.check-log" iconName="arrow-expand-right" action={showLog}></SettingRow> | ||
<SettingRow textKey="control.check-sensed-data" iconName="arrow-expand-right" action={showSensed}></SettingRow> | ||
<SettingRow textKey="control.collection" iconName="pencil" action={editCollectionConfig}></SettingRow> | ||
{/* <ControlDataTable controlData={settings.collect.show_config}></ControlDataTable> */} | ||
<SettingRow textKey="control.sync" iconName="pencil" action={editSyncConfig}></SettingRow> | ||
<SettingRow textKey="control.app-version" iconName="application" action={()=>console.log("")}></SettingRow> | ||
{/* <SettingRow textKey={settings.clientAppVer} iconName="" action={()=>console.log("")}></SettingRow> */} | ||
</ExpansionSection> | ||
</> | ||
); | ||
}; | ||
|
||
ProfileSettings.propTypes = { | ||
settingsScope: object | ||
} | ||
|
||
angularize(ProfileSettings, 'emission.main.control.profileSettings'); | ||
export default ProfileSettings; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from "react"; | ||
import { angularize} from "../angular-react-helper"; | ||
import { List, IconButton, Switch} from 'react-native-paper'; | ||
import { useTranslation } from "react-i18next"; | ||
import { string, func, bool} from "prop-types"; | ||
|
||
// const ToggleSwitch = ({onSwitch, switchVal}) => { | ||
// // const startResult = getVal(); | ||
// const [isSwitchOn, setIsSwitchOn] = React.useState(true); | ||
|
||
// const onToggleSwitch = function() { | ||
// onSwitch(); | ||
// setIsSwitchOn(!isSwitchOn); | ||
// }; | ||
|
||
// return <Switch value={isSwitchOn} onValueChange={onToggleSwitch} />; | ||
// }; | ||
// ToggleSwitch.propTypes = { | ||
// onSwitch: func, | ||
// startVal: func | ||
// } | ||
|
||
const SettingRow = ({textKey, iconName, action, switchValue}) => { | ||
const { t } = useTranslation(); //this accesses the translations | ||
|
||
let rightComponent; | ||
// will using switchValue here only render when the value is true? | ||
if (switchValue) { | ||
rightComponent = <Switch value={switchValue} onValueChange={(e) => action(e)}/>; | ||
} else { | ||
rightComponent = <IconButton icon={iconName} onPress={(e) => action(e)} />; | ||
} | ||
|
||
return ( | ||
<List.Item | ||
title={t(textKey)} | ||
onPress={() => console.log("empty")} | ||
right={() => rightComponent} | ||
/> | ||
); | ||
}; | ||
SettingRow.propTypes = { | ||
textKey: string, | ||
iconName: string, | ||
action: func, | ||
switchValue: bool | ||
} | ||
|
||
angularize(SettingRow, 'emission.main.control.settingRow'); | ||
export default SettingRow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.