@olea-bps/views 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/Callmanager/index.js +148 -0
  2. package/Callmanager/styles.js +62 -0
  3. package/Canteens/index.js +383 -0
  4. package/Canteens/styles.js +89 -0
  5. package/Dashboard/index.js +176 -0
  6. package/Dashboard/styles.js +16 -0
  7. package/DashboardHtwk/index.js +197 -0
  8. package/DashboardHtwk/styles.js +24 -0
  9. package/Event/index.js +369 -0
  10. package/Event/styles.js +63 -0
  11. package/FeedList/index.js +165 -0
  12. package/FeedList/styles.js +15 -0
  13. package/FeedNews/index.js +243 -0
  14. package/FeedNews/styles.js +32 -0
  15. package/Flexmenu/index.js +185 -0
  16. package/Flexmenu/styles.js +62 -0
  17. package/FlexmenuWebview/index.js +167 -0
  18. package/FlexmenuWebview/styles.js +16 -0
  19. package/Howhy/index.js +151 -0
  20. package/Howhy/styles.js +11 -0
  21. package/Jobs/index.js +217 -0
  22. package/Jobs/styles.js +41 -0
  23. package/MainMenu/index.js +329 -0
  24. package/MainMenu/styles.js +36 -0
  25. package/NewsTabbar/index.js +164 -0
  26. package/NewsTabbar/styles.js +27 -0
  27. package/Opal/index.js +136 -0
  28. package/Opal/styles.js +11 -0
  29. package/PublicTransportTicket/index.js +173 -0
  30. package/PublicTransportTicket/styles.js +17 -0
  31. package/Search/index.js +186 -0
  32. package/Search/styles.js +67 -0
  33. package/SettingsAccessibility/index.js +148 -0
  34. package/SettingsAccessibility/styles.js +13 -0
  35. package/SettingsAppInfo/index.js +86 -0
  36. package/SettingsAppInfo/styles.js +18 -0
  37. package/SettingsCanteens/index.js +249 -0
  38. package/SettingsCanteens/styles.js +33 -0
  39. package/SettingsGeneral/index.js +173 -0
  40. package/SettingsGeneral/styles.js +28 -0
  41. package/SettingsNotifications/index.js +204 -0
  42. package/SettingsNotifications/styles.js +38 -0
  43. package/SettingsUser/index.js +170 -0
  44. package/SettingsUser/styles.js +17 -0
  45. package/TimetableCalendar/index.js +322 -0
  46. package/TimetableCalendar/styles.js +117 -0
  47. package/TimetableList/index.js +397 -0
  48. package/TimetableList/styles.js +55 -0
  49. package/Webviews/index.js +158 -0
  50. package/Webviews/styles.js +11 -0
  51. package/index.js +25 -0
  52. package/package.json +41 -0
@@ -0,0 +1,204 @@
1
+ /**
2
+ * Licensed under the Apache License, Version 2.0 (the "License");
3
+ * you may not use this file except in compliance with the License.
4
+ * You may obtain a copy of the License at
5
+ *
6
+ * http://www.apache.org/licenses/LICENSE-2.0
7
+ *
8
+ * Unless required by applicable law or agreed to in writing, software
9
+ * distributed under the License is distributed on an "AS IS" BASIS,
10
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ * See the License for the specific language governing permissions and
12
+ * limitations under the License.
13
+ */
14
+
15
+ import React from 'react';
16
+ import { Alert, SafeAreaView, View } from 'react-native';
17
+
18
+ import {connect} from 'react-redux'
19
+ import { withTheme, Checkbox, Text, Switch } from "react-native-paper";
20
+ import {withTranslation} from "react-i18next";
21
+
22
+ import merge from 'lodash/merge';
23
+
24
+ import { onSettingNotificationsOverride, store } from "@olea-bps/core"
25
+ import { AppBar as AppbarComponent } from '@olea-bps/components';
26
+ import componentStyles from "./styles";
27
+
28
+ /**
29
+ * Settings Notifications
30
+ *
31
+ * Parameters:
32
+ * - none
33
+ *
34
+ * Navigation-Parameters:
35
+ * - none
36
+ */
37
+ class NotificationsSettingsView extends React.Component {
38
+ // Styles of this component
39
+ styles;
40
+
41
+ constructor(props) {
42
+ super(props);
43
+
44
+ // ------------------------------------------------------------------------
45
+ // PLUGIN FUNCTIONALITY
46
+ // ------------------------------------------------------------------------
47
+
48
+ const {pluginStyles, theme, settings} = this.props;
49
+ this.styles = componentStyles(theme);
50
+
51
+ if (pluginStyles) {
52
+ this.styles = merge(this.styles, pluginStyles);
53
+ }
54
+
55
+ const {enablePushNotifications, enableAllNotifications, enabledFeedNotifications} = settings.settingsNotifications;
56
+ this.state = {
57
+ enablePushNotifications: enablePushNotifications ? enablePushNotifications : false,
58
+ enableAllNotifications: enableAllNotifications ? enableAllNotifications : false,
59
+ enabledFeedNotifications: enabledFeedNotifications ? enabledFeedNotifications : []
60
+ };
61
+ }
62
+
63
+
64
+ /**
65
+ * Save new settings to the store
66
+ */
67
+ _saveSettings(newSettings) {
68
+ store.dispatch(onSettingNotificationsOverride('notificationSettings', {...this.state, ...newSettings}));
69
+ this.setState(newSettings);
70
+ }
71
+
72
+ /**
73
+ * update the settings
74
+ *
75
+ * @private
76
+ */
77
+ _handleChange(type, id) {
78
+ const { enablePushNotifications, enabledFeedNotifications, enableAllNotifications } = this.state;
79
+ const { feeds, t } = this.props;
80
+
81
+ let newSettings = {};
82
+ if(type === 'feed') {
83
+ let isEnabled = enabledFeedNotifications.indexOf(id) !== -1;
84
+ newSettings['enabledFeedNotifications'] = isEnabled
85
+ ? enabledFeedNotifications.filter(feedid => feedid !== id)
86
+ : [...enabledFeedNotifications, id];
87
+
88
+ // Enable AllNotifications if all feeds are enabled, otherwise disable it
89
+ newSettings['enableAllNotifications'] = newSettings['enabledFeedNotifications'].length === feeds.length;
90
+
91
+ } else {
92
+ newSettings[type] = !this.state[type];
93
+ }
94
+
95
+ // Enable all notifications
96
+ if(type === 'enableAllNotifications') {
97
+ newSettings['enabledFeedNotifications'] = enableAllNotifications ? [] : feeds.map(feed => feed.feedid);
98
+ }
99
+
100
+ // Inform user about the use of google services for notifications
101
+ if(type === 'enablePushNotifications' && !enablePushNotifications) {
102
+ Alert.alert(
103
+ t('settings:notifications.activationMessageTitle'),
104
+ t('settings:notifications.activationMessageDesc'),
105
+ [{
106
+ text: t('settings:notifications.activationMessageCancel'),
107
+ style: 'cancel',
108
+ onPress: () => {
109
+ }
110
+ },
111
+ {
112
+ text: t('settings:notifications.activationMessageOk'),
113
+ onPress: async () => {
114
+ this._saveSettings(newSettings, true);
115
+ },
116
+ },
117
+ ]
118
+ );
119
+ } else {
120
+ this._saveSettings(newSettings);
121
+ }
122
+ }
123
+
124
+ feedSettings() {
125
+ const { theme: { colors }, t, feeds } = this.props;
126
+ const { enablePushNotifications, enabledFeedNotifications } = this.state;
127
+
128
+ let feedItems = [];
129
+ feedItems.push(
130
+ <Text key="enabledFeedNotifications" style={this.styles.labelStyleBold}>{t('settings:notifications.feeds')}</Text>
131
+ );
132
+ feeds.forEach(feed => {
133
+ feedItems.push(
134
+ <Checkbox.Item
135
+ disabled={!enablePushNotifications}
136
+ key={feed.feedid}
137
+ label={feed.title}
138
+ labelStyle={this.styles.labelStyle}
139
+ status={enabledFeedNotifications.indexOf(feed.feedid) > -1 ? 'checked' : 'unchecked'}
140
+ onPress={() => this._handleChange('feed', feed.feedid)}
141
+ color={colors.checkboxChecked}
142
+ uncheckedColor={colors.checkboxUnchecked}
143
+ mode="android"
144
+ />
145
+ )
146
+ });
147
+ return <View style={this.styles.innerContainer} key={'feedSettings'}>{feedItems}</View>;
148
+ }
149
+
150
+
151
+ render() {
152
+ // ------------------------------------------------------------------------
153
+ // PLUGIN FUNCTIONALITY
154
+ // ------------------------------------------------------------------------
155
+ const PluginComponent = this.props.pluginComponent;
156
+ if (PluginComponent) {
157
+ return <PluginComponent />;
158
+ }
159
+ // ------------------------------------------------------------------------
160
+
161
+ const { theme: { themeStyles, colors }, t, feeds } = this.props;
162
+ const { enablePushNotifications, enableAllNotifications } = this.state;
163
+ const items = [];
164
+ [
165
+ {key: 'enablePushNotifications', checked: enablePushNotifications, disabled: false, title: t('settings:notifications.enablePushNotifications') },
166
+ {key: 'enableAllNotifications', checked: enableAllNotifications, disabled: !enablePushNotifications, title: t('settings:notifications.enableAllNotifications') }
167
+ ].forEach(item => {
168
+ items.push(
169
+ <View style={this.styles.setting} key={item.key}>
170
+ <Text style={this.styles.labelStyleBold}>{item.title}</Text>
171
+ <Switch value={item.checked} disabled={item.disabled} onValueChange={() => this._handleChange(item.key)} color={colors.checkboxChecked} />
172
+ </View>
173
+
174
+ );
175
+ });
176
+
177
+ // List all enabledFeedNotifications with checkboxes to enable/disable notifications
178
+ if (feeds.length > 0) {
179
+ items.push(<View style={this.styles.horizontalSeparator} key={'separator'}/>);
180
+ items.push(this.feedSettings())
181
+ }
182
+
183
+
184
+ return (
185
+ <SafeAreaView style={[this.styles.container, themeStyles.appSafeAreaContainer]}>
186
+ <AppbarComponent {...this.props} title={t('settings:notifications.title')}/>
187
+ <View style={themeStyles.container}>
188
+ {items}
189
+ </View>
190
+ </SafeAreaView>
191
+ );
192
+ }
193
+ }
194
+
195
+ const mapStateToProps = state => {
196
+ return {
197
+ pluginComponent: state.pluginReducer.settingsNotifications.component,
198
+ pluginStyles: state.pluginReducer.settingsNotifications.styles,
199
+ settings: state.settingReducer,
200
+ feeds: state.apiReducer.feeds
201
+ };
202
+ };
203
+
204
+ export default connect(mapStateToProps, null)(withTranslation()(withTheme(NotificationsSettingsView)))
@@ -0,0 +1,38 @@
1
+ export default function(theme) {
2
+ return {
3
+ selectOption: {
4
+ display: 'flex',
5
+ flexDirection: 'row',
6
+ justifyContent: 'space-between'
7
+ },
8
+ labelStyle: {
9
+ fontSize: theme.fontSizes.l,
10
+ color: theme.colors.text
11
+ },
12
+ labelStyleBold: {
13
+ fontSize: theme.fontSizes.xl,
14
+ fontWeight: 'bold',
15
+ color: theme.colors.text
16
+ },
17
+ horizontalSeparator: {
18
+ height: 1,
19
+ width: "100%",
20
+ backgroundColor: theme.colors.listSeperator,
21
+ marginTop: theme.paddings.small,
22
+ marginBottom: theme.paddings.small
23
+ },
24
+ innerContainer: {
25
+ paddingLeft: theme.paddings.small,
26
+ paddingRight: theme.paddings.small,
27
+ margin: theme.paddings.xsmall
28
+ },
29
+ setting: {
30
+ flexDirection:'row',
31
+ alignItems:'center',
32
+ marginVertical: theme.paddings.xsmall,
33
+ paddingVertical: theme.paddings.small,
34
+ paddingHorizontal: theme.paddings.small,
35
+ justifyContent:'space-between'
36
+ }
37
+ }
38
+ };
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Licensed under the Apache License, Version 2.0 (the "License");
3
+ * you may not use this file except in compliance with the License.
4
+ * You may obtain a copy of the License at
5
+ *
6
+ * http://www.apache.org/licenses/LICENSE-2.0
7
+ *
8
+ * Unless required by applicable law or agreed to in writing, software
9
+ * distributed under the License is distributed on an "AS IS" BASIS,
10
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ * See the License for the specific language governing permissions and
12
+ * limitations under the License.
13
+ */
14
+
15
+ import { useMemo } from 'react';
16
+ import { SafeAreaView, View, StyleSheet, Alert } from 'react-native';
17
+
18
+ import { useTheme, Text, Button } from 'react-native-paper';
19
+ import { useTranslation } from 'react-i18next';
20
+
21
+ import { DateTime } from 'luxon';
22
+
23
+ import { useLanguage } from '@olea-bps/core';
24
+ import { AppBar as AppbarComponent } from '@olea-bps/components';
25
+ import { useUser, useUserContext } from '@olea-bps/context-user';
26
+
27
+ import componentStyles from './styles';
28
+
29
+ /**
30
+ * Renders the User Settings view.
31
+ *
32
+ * @param {Object} props - The component props.
33
+ */
34
+ export default function UserSettingsView(props) {
35
+ const componentName = UserSettingsView.name;
36
+ // Get theme from theme context
37
+ const theme = useTheme();
38
+ const { themeStyles } = theme;
39
+ // Get translation function from translation hook
40
+ const { t } = useTranslation();
41
+ const language = useLanguage();
42
+
43
+ const [user, login, logout] = useUser();
44
+ const { refreshTokenExpiresAt } = useUserContext();
45
+ const refreshTokenExpiresAtDateTime = refreshTokenExpiresAt
46
+ ? DateTime.fromSeconds(refreshTokenExpiresAt, { locale: language })
47
+ : null;
48
+
49
+ // Create styles object using useMemo to prevent unnecessary re-renders
50
+ const styles = useMemo(
51
+ () => StyleSheet.create(componentStyles(theme)),
52
+ [theme]
53
+ );
54
+
55
+ return (
56
+ // SafeAreaView is used to render content within the safe area boundaries of a device.
57
+ <SafeAreaView style={[styles.container, themeStyles.appSafeAreaContainer]}>
58
+ {/* AppbarComponent is a custom component for the app's header bar. */}
59
+ <AppbarComponent {...props} title={t('user:settingsTitle')} />
60
+
61
+ {/* This View contains the main content of the screen. */}
62
+ <View accessible={false} style={themeStyles.container}>
63
+ {
64
+ user
65
+ ? <>
66
+ <Text style={styles.userinfoGreeting}>
67
+ Hallo {user.name}
68
+ </Text>
69
+
70
+ <Text style={styles.userinfoHeadline}>
71
+ {t('user:username')}
72
+ </Text>
73
+ <Text style={styles.userinfoValue}>
74
+ {user.sub}
75
+ </Text>
76
+
77
+ <Text style={styles.userinfoHeadline}>
78
+ {t('user:email')}
79
+ </Text>
80
+ <Text style={styles.userinfoValue}>
81
+ {user.email}
82
+ </Text>
83
+
84
+ <Text style={styles.userinfoHeadline}>
85
+ {t('user:memberTypes')}
86
+ </Text>
87
+ {
88
+
89
+ user?.member_types
90
+ ?.map(
91
+ member_type =>
92
+ <Text key={member_type} style={styles.userinfoValue}>
93
+ {t(`user:memberType.${member_type}`)}
94
+ </Text>
95
+ )
96
+ ?? null
97
+ }
98
+
99
+ <Text style={styles.userinfoHeadline}>
100
+ {t('user:organizationalUnits')}
101
+ </Text>
102
+ {
103
+ user?.organizational_units
104
+ ?.map(
105
+ organizational_unit =>
106
+ <Text key={organizational_unit.number} style={styles.userinfoValue}>
107
+ {`${organizational_unit.name}(${organizational_unit.number}|${organizational_unit.short_name})`}
108
+ </Text>
109
+ )
110
+ ?? null
111
+ }
112
+
113
+ <Text style={styles.userinfoHeadline}>
114
+ {t('user:refreshTokenExpiresAt')}
115
+ </Text>
116
+ <Text style={styles.userinfoValue}>
117
+ {refreshTokenExpiresAtDateTime?.toLocaleString(DateTime.DATETIME_FULL_WITH_SECONDS)}
118
+ </Text>
119
+
120
+ <Button
121
+ onPress={() => Alert.alert(
122
+ t('user:logout'),
123
+ t('user:logoutConfirmation'),
124
+ [
125
+ {
126
+ text: t('user:logoutOkButton'),
127
+ onPress: () => logout?.(),
128
+ },
129
+ {
130
+ text: t('user:logoutNoButton'),
131
+ isPreferred: true,
132
+ }
133
+ ]
134
+ )}
135
+ >
136
+ {t('user:logout')}
137
+ </Button>
138
+ </>
139
+ : <>
140
+ <Text>
141
+ Sie sind nicht eingeloogt
142
+ </Text>
143
+ <Button
144
+ onPress={
145
+ () =>
146
+ login
147
+ ? login()
148
+ .catch(
149
+ reason => {
150
+ console.debug(componentName, ':', 'login failed', ':', reason);
151
+ Alert.alert(
152
+ t('user:loginFailed'),
153
+ t('user:tryLoginAgain'),
154
+ );
155
+ }
156
+ )
157
+ : Alert.alert(
158
+ t('user:connectionError'),
159
+ t('user:connectionErrorTryLoginAgain'),
160
+ )
161
+ }
162
+ >
163
+ {t('user:logginButton')}
164
+ </Button>
165
+ </>
166
+ }
167
+ </View>
168
+ </SafeAreaView>
169
+ );
170
+ }
@@ -0,0 +1,17 @@
1
+ export default function (theme) {
2
+ return {
3
+ userinfoGreeting: {
4
+ textAlign: 'center',
5
+ fontSize: theme.fontSizes.l,
6
+ },
7
+ userinfoHeadline: {
8
+ paddingLeft: '5%',
9
+ fontWeight: 'bold',
10
+ fontSize: theme.fontSizes.l,
11
+ },
12
+ userinfoValue: {
13
+ paddingLeft: '10%',
14
+ fontSize: theme.fontSizes.l,
15
+ },
16
+ }
17
+ }