Skip to content

Commit

Permalink
fixing merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Abby Wheelis committed Jun 28, 2023
2 parents a3097ac + aa027ad commit ffd2bc2
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 143 deletions.
31 changes: 31 additions & 0 deletions www/js/control/DemographicsSettingRow.jsx
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;
30 changes: 30 additions & 0 deletions www/js/control/ExpandMenu.jsx
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;
91 changes: 91 additions & 0 deletions www/js/control/ProfileSettings.jsx
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;

50 changes: 50 additions & 0 deletions www/js/control/SettingRow.jsx
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;
29 changes: 26 additions & 3 deletions www/js/control/general-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import angular from 'angular';
import ControlDataTable from './ControlDataTable';
import QrCode from '../components/QrCode';
import SettingRow from './SettingRow';
import ExpansionSection from './ExpandMenu';
import ProfileSettings from './ProfileSettings';

angular.module('emission.main.control',['emission.services',
'emission.i18n.utils',
Expand All @@ -21,7 +24,10 @@ angular.module('emission.main.control',['emission.services',
'emission.plugin.logger',
'emission.config.dynamic',
QrCode.module,
ControlDataTable.module])
ControlDataTable.module,
SettingRow.module,
ExpansionSection.module,
ProfileSettings.module])

.controller('ControlCtrl', function($scope, $window,
$ionicScrollDelegate, $ionicPlatform,
Expand Down Expand Up @@ -163,7 +169,7 @@ angular.module('emission.main.control',['emission.services',
gender: userDataFromStorage.gender == 1? i18next.t('gender-male') : i18next.t('gender-female')
}
for (var i in temp) {
$scope.userData.push({key: i, value: temp[i]});
$scope.userData.push({key: i, val: temp[i]}); //changed from value to val! watch for rammifications!
}
}
});
Expand Down Expand Up @@ -215,10 +221,27 @@ angular.module('emission.main.control',['emission.services',
// we don't really $apply on this field...
return false;
} else {
$scope.settings.collect.lowAccuracy = isMediumAccuracy; //adding to scope to use w/ switches
return isMediumAccuracy;
}
}
$scope.toggleLowAccuracy = ControlCollectionHelper.toggleLowAccuracy;

$scope.getTracking = function() {
console.log("tracking on or off?", $scope.settings.collect.trackingOn);
// return true: toggle on; return false: toggle off.
var isTracking = $scope.settings.collect.trackingOn;
if (!angular.isDefined(isTracking)) {
// config not loaded when loading ui, set default as false
// TODO: Read the value if it is not defined.
// Otherwise, don't we have a race with reading?
// we don't really $apply on this field...
return false;
} else {
console.log("tracking on or off?", $scope.settings.collect.trackingOn);
return $scope.settings.collect.trackingOn;
}
}

$scope.getConnectURL = function() {
ControlHelper.getSettings().then(function(response) {
Expand Down Expand Up @@ -396,7 +419,7 @@ angular.module('emission.main.control',['emission.services',
navigator.clipboard.writeText(textToCopy).then(() => {
ionicToast.show('{Copied to clipboard!}', 'bottom', false, 2000);
});
}
}

$scope.logOut = function() {
$ionicPopup.confirm({
Expand Down
Loading

0 comments on commit ffd2bc2

Please sign in to comment.