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
|
<template>
<SettingsSection class="theming" :title="t('themes', 'Appearance and accessibility')">
<p v-html="description" />
<p v-html="descriptionDetail" />
<div class="theming__preview-list">
<ItemPreview v-for="theme in themes"
:key="theme.id"
:enforced="theme.id === enforceTheme"
:selected="selectedTheme.id === theme.id"
:theme="theme"
:unique="themes.length === 1"
type="theme"
@change="changeTheme" />
</div>
<div class="theming__preview-list">
<ItemPreview v-for="theme in fonts"
:key="theme.id"
:selected="theme.enabled"
:theme="theme"
:unique="fonts.length === 1"
type="font"
@change="changeFont" />
</div>
</SettingsSection>
</template>
<script>
import { generateOcsUrl } from '@nextcloud/router'
import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'
import SettingsSection from '@nextcloud/vue/dist/Components/SettingsSection'
import ItemPreview from './components/ItemPreview'
const availableThemes = loadState('theming', 'themes', [])
const enforceTheme = loadState('theming', 'enforceTheme', '')
console.debug('Available themes', availableThemes)
export default {
name: 'UserThemes',
components: {
ItemPreview,
SettingsSection,
},
data() {
return {
availableThemes,
enforceTheme,
}
},
computed: {
themes() {
return this.availableThemes.filter(theme => theme.type === 1)
},
fonts() {
return this.availableThemes.filter(theme => theme.type === 2)
},
// Selected theme, fallback on first (default) if none
selectedTheme() {
return this.themes.find(theme => theme.enabled === true) || this.themes[0]
},
description() {
// using the `t` replace method escape html, we have to do it manually :/
return t(
'theming',
'Universal access is very important to us. We follow web standards and check to make everything usable also without mouse, and assistive software such as screenreaders. We aim to be compliant with the {guidelines}Web Content Accessibility Guidelines{linkend} 2.1 on AA level, with the high contrast theme even on AAA level.'
)
.replace('{guidelines}', this.guidelinesLink)
.replace('{linkend}', '</a>')
},
guidelinesLink() {
return '<a target="_blank" href="https://www.w3.org/WAI/standards-guidelines/wcag/" rel="noreferrer nofollow">'
},
descriptionDetail() {
return t(
'theming',
'If you find any issues, don’t hesitate to report them on {issuetracker}our issue tracker{linkend}. And if you want to get involved, come join {designteam}our design team{linkend}!'
)
.replace('{issuetracker}', this.issuetrackerLink)
.replace('{designteam}', this.designteamLink)
.replace(/\{linkend\}/g, '</a>')
},
issuetrackerLink() {
return '<a target="_blank" href="https://github.com/nextcloud/server/issues/" rel="noreferrer nofollow">'
},
designteamLink() {
return '<a target="_blank" href="https://nextcloud.com/design" rel="noreferrer nofollow">'
},
},
methods: {
changeTheme({ enabled, id }) {
// Reset selected and select new one
this.themes.forEach(theme => {
if (theme.id === id && enabled) {
theme.enabled = true
document.body.setAttribute(`data-theme-${theme.id}`, true)
return
}
theme.enabled = false
document.body.removeAttribute(`data-theme-${theme.id}`)
})
this.selectItem(enabled, id)
},
changeFont({ enabled, id }) {
// Reset selected and select new one
this.fonts.forEach(font => {
if (font.id === id && enabled) {
font.enabled = true
document.body.setAttribute(`data-theme-${font.id}`, true)
return
}
font.enabled = false
document.body.removeAttribute(`data-theme-${font.id}`)
})
this.selectItem(enabled, id)
},
/**
* Commit a change and force reload css
* Fetching the file again will trigger the server update
*
* @param {boolean} enabled the theme state
* @param {string} themeId the theme ID to change
*/
async selectItem(enabled, themeId) {
try {
if (enabled) {
await axios({
url: generateOcsUrl('apps/theming/api/v1/theme/{themeId}/enable', { themeId }),
method: 'PUT',
})
} else {
await axios({
url: generateOcsUrl('apps/theming/api/v1/theme/{themeId}', { themeId }),
method: 'DELETE',
})
}
} catch (err) {
console.error(err, err.response)
OC.Notification.showTemporary(t('theming', err.response.data.ocs.meta.message + '. Unable to apply the setting.'))
}
},
},
}
</script>
<style lang="scss" scoped>
.theming {
// Limit width of settings sections for readability
p {
max-width: 800px;
}
// Proper highlight for links and focus feedback
&::v-deep a {
font-weight: bold;
&:hover,
&:focus {
text-decoration: underline;
}
}
&__preview-list {
--gap: 30px;
display: grid;
margin-top: var(--gap);
column-gap: var(--gap);
row-gap: var(--gap);
grid-template-columns: 1fr 1fr;
}
}
@media (max-width: 1440px) {
.theming__preview-list {
display: flex;
flex-direction: column;
}
}
</style>
|