-
Notifications
You must be signed in to change notification settings - Fork 715
/
index.vue
291 lines (268 loc) · 8.93 KB
/
index.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<template>
<KPageContainer>
<div class="mb">
<h1>{{ $tr('pageHeader') }}</h1>
<p>
{{ $tr('pageDescription') }}
<KExternalLink
v-if="isSuperuser && deviceSettingsUrl"
:text="$tr('deviceSettings')"
:href="deviceSettingsUrl"
/>
</p>
</div>
<template v-if="settings !== null">
<div class="mb">
<h2>{{ coreString('facilityLabel') }}</h2>
<p class="current-facility-name">
{{ coreString('facilityNameWithId', { facilityName: facilityName, id: lastPartId }) }}
<KButton
appearance="basic-link"
:text="coreString('editAction')"
name="edit-facilityname"
@click="showEditFacilityModal = true"
/>
</p>
</div>
<div class="mb">
<div class="settings">
<template v-for="setting in settingsList">
<template
v-if="
setting !== 'learner_can_edit_password' &&
setting !== 'learner_can_login_with_no_password'
"
>
<KCheckbox
:key="setting"
:label="$tr(camelCase(setting))"
:checked="settings[setting]"
@change="toggleSetting(setting)"
/>
</template>
<template v-else-if="setting === 'learner_can_login_with_no_password'">
<KCheckbox
:key="setting"
:label="$tr('learnerNeedPasswordToLogin')"
:checked="!settings['learner_can_login_with_no_password']"
@change="toggleLearnerLoginPassword()"
/>
<KCheckbox
:key="setting + 'learner_can_edit_password'"
:disabled="enableChangePassword"
:label="$tr('learnerCanEditPassword')"
:checked="!settings['learner_can_login_with_no_password']
&& settings['learner_can_edit_password']"
class="checkbox-password"
@change="toggleSetting('learner_can_edit_password')"
/>
</template>
</template>
</div>
<div>
<KButtonGroup style="margin-top: 8px;">
<KButton
:primary="false"
appearance="raised-button"
:text="$tr('resetToDefaultSettings')"
name="reset-settings"
@click="showModal = true"
/>
<KButton
:primary="true"
appearance="raised-button"
:text="coreString('saveChangesAction')"
name="save-settings"
:disabled="!settingsHaveChanged"
@click="saveConfig()"
/>
</KButtonGroup>
</div>
</div>
</template>
<ConfirmResetModal
v-if="showModal"
id="confirm-reset"
@submit="resetToDefaultSettings"
@cancel="showModal = false"
/>
<EditFacilityNameModal
v-if="showEditFacilityModal"
id="edit-facility"
:facilityName="facilityName"
@submit="sendFacilityName"
@cancel="showEditFacilityModal = false"
/>
</KPageContainer>
</template>
<script>
import { crossComponentTranslator } from 'kolibri.utils.i18n';
import { mapActions, mapGetters, mapState } from 'vuex';
import camelCase from 'lodash/camelCase';
import isEqual from 'lodash/isEqual';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import urls from 'kolibri.urls';
import ConfirmResetModal from './ConfirmResetModal';
import EditFacilityNameModal from './EditFacilityNameModal';
// TODO: Notification component is empty and should be removed on 0.15 version
import Notifications from './ConfigPageNotifications';
// See FacilityDataset in core.auth.models for details
const settingsList = [
'learner_can_edit_username',
'learner_can_edit_password',
'learner_can_edit_name',
'learner_can_sign_up',
'learner_can_login_with_no_password',
'show_download_button_in_learn',
];
export default {
name: 'FacilityConfigPage',
metaInfo() {
return {
title: this.$tr('documentTitle'),
};
},
components: {
ConfirmResetModal,
EditFacilityNameModal,
},
mixins: [commonCoreStrings],
data() {
return {
showModal: false,
showEditFacilityModal: false,
settingsCopy: {},
};
},
computed: {
...mapState('facilityConfig', [
'facilityName',
'facilityId',
'settings',
'facilityNameSaved',
'facilityNameError',
]),
...mapGetters(['isSuperuser']),
settingsList: () => settingsList,
settingsHaveChanged() {
return !isEqual(this.settings, this.settingsCopy);
},
deviceSettingsUrl() {
const getUrl = urls['kolibri:kolibri.plugins.device:device_management'];
if (getUrl) {
return getUrl() + '#/settings';
}
return null;
},
lastPartId() {
return this.facilityId.slice(0, 4);
},
enableChangePassword() {
return this.settings['learner_can_login_with_no_password'];
},
NotificationsStrings() {
return crossComponentTranslator(Notifications);
},
},
watch: {
facilityNameSaved(val) {
if (val) {
this.createSnackbar(this.coreString('changesSavedNotification'));
this.$store.commit('facilityConfig/RESET_FACILITY_NAME_STATES');
}
},
facilityNameError(val) {
if (val) {
this.createSnackbar(this.coreString('changesNotSavedNotification'));
this.$store.commit('facilityConfig/RESET_FACILITY_NAME_STATES');
}
},
},
mounted() {
this.copySettings();
},
methods: {
camelCase,
...mapActions('facilityConfig', ['saveFacilityName']),
...mapActions(['createSnackbar']),
toggleSetting(settingName) {
this.$store.commit('facilityConfig/CONFIG_PAGE_MODIFY_SETTING', {
name: settingName,
value: !this.settings[settingName],
});
},
toggleLearnerLoginPassword() {
this.toggleSetting('learner_can_login_with_no_password');
if (
this.settings['learner_can_edit_password'] &&
!this.settings['learner_can_login_with_no_password']
) {
this.toggleSetting('learner_can_edit_password');
}
},
updateSettings(action) {
this.$store
.dispatch(action)
.then(() => {
// eslint-disable-next-line kolibri/vue-no-undefined-string-uses
this.createSnackbar(this.NotificationsStrings.$tr('saveSuccess'));
this.copySettings();
})
.catch(() => {
// eslint-disable-next-line kolibri/vue-no-undefined-string-uses
this.createSnackbar(this.NotificationsStrings.$tr('saveFailure'));
this.$store.commit('facilityConfig/CONFIG_PAGE_UNDO_SETTINGS_CHANGE');
});
},
resetToDefaultSettings() {
this.showModal = false;
this.updateSettings('facilityConfig/resetFacilityConfig');
},
sendFacilityName(name) {
this.showEditFacilityModal = false;
if (name != this.facilityName) this.saveFacilityName({ name: name, id: this.facilityId });
},
saveConfig() {
this.updateSettings('facilityConfig/saveFacilityConfig');
},
copySettings() {
this.settingsCopy = Object.assign({}, this.settings);
},
},
$trs: {
// These are not going to be picked up by the linter because snake cased versions
// are used to get the keys to these strings.
/* eslint-disable kolibri/vue-no-unused-translations */
learnerCanEditName: 'Allow learners to edit their full name',
learnerCanEditPassword: 'Allow learners to edit their password when signed in',
learnerCanEditUsername: 'Allow learners to edit their username',
learnerCanSignUp: 'Allow learners to create accounts',
learnerCanLoginWithNoPassword: 'Allow learners to sign in with no password',
learnerNeedPasswordToLogin: 'Require password for learners',
showDownloadButtonInLearn: "Show 'download' button with resources",
allowGuestAccess: 'Allow users to access resources without signing in',
/* eslint-enable kolibri/vue-no-unused-translations */
pageDescription: {
message: 'Configure facility settings here.',
context: '\nInterpret as "[You can] configure facility settings here"',
},
deviceSettings: 'You can also configure device settings',
pageHeader: 'Facility settings',
resetToDefaultSettings: 'Reset to defaults',
documentTitle: 'Configure Facility',
},
};
</script>
<style lang="scss" scoped>
.mb {
margin-bottom: 2rem;
}
.settings > label {
margin-bottom: 2rem;
font-weight: bold;
cursor: pointer;
}
.checkbox-password {
margin-left: 24px;
}
</style>