Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2022-04-15 14:55:19 +0300
committerJohn Molakvoæ <skjnldsv@protonmail.com>2022-04-21 10:31:07 +0300
commit9ea72b10104ceb482be33b4626c3603a788a687f (patch)
treec617c4419d160467b587ca02be81c4b65ebef91b /apps/theming/src
parent69d1d1a84e5e8937046d30714f11036b680cc04a (diff)
Migrating themes to Theming app
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/theming/src')
-rw-r--r--apps/theming/src/UserThemes.vue175
-rw-r--r--apps/theming/src/components/ItemPreview.vue121
-rw-r--r--apps/theming/src/settings.js32
3 files changed, 328 insertions, 0 deletions
diff --git a/apps/theming/src/UserThemes.vue b/apps/theming/src/UserThemes.vue
new file mode 100644
index 00000000000..78115021412
--- /dev/null
+++ b/apps/theming/src/UserThemes.vue
@@ -0,0 +1,175 @@
+<template>
+ <SettingsSection class="theming" :title="t('themes', 'Appaerance and accessibility')">
+ <p v-html="description" />
+ <p v-html="descriptionDetail" />
+
+ <div class="theming__preview-list">
+ <ItemPreview v-for="theme in themes"
+ :key="theme.id"
+ :theme="theme"
+ :selected="selectedTheme.id === theme.id"
+ :themes="themes"
+ type="theme"
+ @change="changeTheme" />
+ <ItemPreview v-for="theme in fonts"
+ :key="theme.id"
+ :theme="theme"
+ :selected="theme.enabled"
+ :themes="fonts"
+ 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', [])
+
+console.debug('Available themes', availableThemes)
+
+export default {
+ name: 'UserThemes',
+ components: {
+ ItemPreview,
+ SettingsSection,
+ },
+
+ data() {
+ return {
+ availableThemes,
+ }
+ },
+
+ 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 {
+ display: flex;
+ flex-direction: column;
+ max-width: 800px;
+ }
+}
+
+</style>
diff --git a/apps/theming/src/components/ItemPreview.vue b/apps/theming/src/components/ItemPreview.vue
new file mode 100644
index 00000000000..997d66a037e
--- /dev/null
+++ b/apps/theming/src/components/ItemPreview.vue
@@ -0,0 +1,121 @@
+<template>
+ <div class="theming__preview">
+ <div class="theming__preview-image" :style="{ backgroundImage: 'url(' + img + ')' }" />
+ <div class="theming__preview-description">
+ <h3>{{ theme.title }}</h3>
+ <p>{{ theme.description }}</p>
+ <CheckboxRadioSwitch class="theming__preview-toggle"
+ :checked.sync="checked"
+ :name="name"
+ :type="switchType">
+ {{ theme.enableLabel }}
+ </CheckboxRadioSwitch>
+ </div>
+ </div>
+</template>
+
+<script>
+import { generateFilePath} from '@nextcloud/router'
+import CheckboxRadioSwitch from '@nextcloud/vue/dist/Components/CheckboxRadioSwitch'
+
+export default {
+ name: 'ItemPreview',
+ components: {
+ CheckboxRadioSwitch,
+ },
+ props: {
+ theme: {
+ type: Object,
+ required: true,
+ },
+ selected: {
+ type: Boolean,
+ default: false,
+ },
+ type: {
+ type: String,
+ default: '',
+ },
+ themes: {
+ type: Array,
+ default: () => [],
+ },
+ },
+ computed: {
+ switchType() {
+ return this.themes.length === 1 ? 'switch' : 'radio'
+ },
+
+ name() {
+ return this.switchType === 'radio' ? this.type : null
+ },
+
+ img() {
+ return generateFilePath('theming', 'img', this.theme.id + '.jpg')
+ },
+
+ checked: {
+ get() {
+ return this.selected
+ },
+ set(checked) {
+ console.debug('Selecting theme', this.theme, checked)
+
+ // If this is a radio, we can only enable
+ if (this.switchType === 'radio') {
+ this.$emit('change', { enabled: true, id: this.theme.id })
+ return
+ }
+
+ // If this is a switch, we can disable the theme
+ this.$emit('change', { enabled: checked === true, id: this.theme.id })
+ },
+ },
+ },
+}
+</script>
+<style lang="scss" scoped>
+
+.theming__preview {
+ position: relative;
+ display: flex;
+ justify-content: flex-start;
+ height: 140px;
+ margin-top: 3em;
+
+ &,
+ * {
+ user-select: none;
+ }
+
+ &-image {
+ flex-basis: 200px;
+ flex-shrink: 0;
+ margin-right: 30px;
+ border-radius: var(--border-radius);
+ background-repeat: no-repeat;
+ background-position: top left;
+ background-size: cover;
+ }
+
+ &-description {
+ display: flex;
+ flex-direction: column;
+
+ label {
+ padding: 12px 0;
+ }
+ }
+}
+
+@media (max-width: (1024 / 2)) {
+ .theming__preview {
+ display: unset;
+
+ &-image {
+ height: 150px;
+ }
+ }
+}
+
+</style>
diff --git a/apps/theming/src/settings.js b/apps/theming/src/settings.js
new file mode 100644
index 00000000000..94ae6fd6314
--- /dev/null
+++ b/apps/theming/src/settings.js
@@ -0,0 +1,32 @@
+/**
+ * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import Vue from 'vue'
+import App from './UserThemes.vue'
+
+// bind to window
+Vue.prototype.OC = OC
+Vue.prototype.t = t
+
+const View = Vue.extend(App)
+const accessibility = new View()
+accessibility.$mount('#theming')