You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AdminTheming.vue 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <!--
  2. - @copyright 2022 Christopher Ng <chrng8@gmail.com>
  3. -
  4. - @author Christopher Ng <chrng8@gmail.com>
  5. -
  6. - @license AGPL-3.0-or-later
  7. -
  8. - This program is free software: you can redistribute it and/or modify
  9. - it under the terms of the GNU Affero General Public License as
  10. - published by the Free Software Foundation, either version 3 of the
  11. - License, or (at your option) any later version.
  12. -
  13. - This program is distributed in the hope that it will be useful,
  14. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. - GNU Affero General Public License for more details.
  17. -
  18. - You should have received a copy of the GNU Affero General Public License
  19. - along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. -
  21. -->
  22. <template>
  23. <section>
  24. <NcSettingsSection :title="t('theming', 'Theming')"
  25. :description="t('theming', 'Theming makes it possible to easily customize the look and feel of your instance and supported clients. This will be visible for all users.')"
  26. :doc-url="docUrl">
  27. <div class="admin-theming">
  28. <NcNoteCard v-if="!isThemable"
  29. type="error"
  30. :show-alert="true">
  31. <p>{{ notThemableErrorMessage }}</p>
  32. </NcNoteCard>
  33. <TextField v-for="field in textFields"
  34. :key="field.name"
  35. :name="field.name"
  36. :value.sync="field.value"
  37. :default-value="field.defaultValue"
  38. :type="field.type"
  39. :display-name="field.displayName"
  40. :placeholder="field.placeholder"
  41. :maxlength="field.maxlength"
  42. @update:theming="$emit('update:theming')" />
  43. <ColorPickerField :name="colorPickerField.name"
  44. :value.sync="colorPickerField.value"
  45. :default-value="colorPickerField.defaultValue"
  46. :display-name="colorPickerField.displayName"
  47. @update:theming="$emit('update:theming')" />
  48. <FileInputField v-for="field in fileInputFields"
  49. :key="field.name"
  50. :name="field.name"
  51. :mime-name="field.mimeName"
  52. :mime-value.sync="field.mimeValue"
  53. :default-mime-value="field.defaultMimeValue"
  54. :display-name="field.displayName"
  55. :aria-label="field.ariaLabel"
  56. @update:theming="$emit('update:theming')" />
  57. <div class="admin-theming__preview">
  58. <div class="admin-theming__preview-logo" />
  59. </div>
  60. </div>
  61. </NcSettingsSection>
  62. <NcSettingsSection :title="t('theming', 'Advanced options')">
  63. <div class="admin-theming-advanced">
  64. <TextField v-for="field in advancedTextFields"
  65. :key="field.name"
  66. :name="field.name"
  67. :value.sync="field.value"
  68. :default-value="field.defaultValue"
  69. :type="field.type"
  70. :display-name="field.displayName"
  71. :placeholder="field.placeholder"
  72. :maxlength="field.maxlength"
  73. @update:theming="$emit('update:theming')" />
  74. <FileInputField v-for="field in advancedFileInputFields"
  75. :key="field.name"
  76. :name="field.name"
  77. :mime-name="field.mimeName"
  78. :mime-value.sync="field.mimeValue"
  79. :default-mime-value="field.defaultMimeValue"
  80. :display-name="field.displayName"
  81. :aria-label="field.ariaLabel"
  82. @update:theming="$emit('update:theming')" />
  83. <CheckboxField :name="userThemingField.name"
  84. :value="userThemingField.value"
  85. :default-value="userThemingField.defaultValue"
  86. :display-name="userThemingField.displayName"
  87. :label="userThemingField.label"
  88. :description="userThemingField.description"
  89. @update:theming="$emit('update:theming')" />
  90. <a v-if="!canThemeIcons"
  91. :href="docUrlIcons"
  92. rel="noreferrer noopener">
  93. <em>{{ t('theming', 'Install the ImageMagick PHP extension with support for SVG images to automatically generate favicons based on the uploaded logo and color.') }}</em>
  94. </a>
  95. </div>
  96. </NcSettingsSection>
  97. </section>
  98. </template>
  99. <script>
  100. import { loadState } from '@nextcloud/initial-state'
  101. import {
  102. NcNoteCard,
  103. NcSettingsSection,
  104. } from '@nextcloud/vue'
  105. import CheckboxField from './components/admin/CheckboxField.vue'
  106. import ColorPickerField from './components/admin/ColorPickerField.vue'
  107. import FileInputField from './components/admin/FileInputField.vue'
  108. import TextField from './components/admin/TextField.vue'
  109. const {
  110. backgroundMime,
  111. canThemeIcons,
  112. color,
  113. docUrl,
  114. docUrlIcons,
  115. faviconMime,
  116. isThemable,
  117. legalNoticeUrl,
  118. logoheaderMime,
  119. logoMime,
  120. name,
  121. notThemableErrorMessage,
  122. privacyPolicyUrl,
  123. slogan,
  124. url,
  125. userThemingDisabled,
  126. } = loadState('theming', 'adminThemingParameters')
  127. const textFields = [
  128. {
  129. name: 'name',
  130. value: name,
  131. defaultValue: 'Nextcloud',
  132. type: 'text',
  133. displayName: t('theming', 'Name'),
  134. placeholder: t('theming', 'Name'),
  135. maxlength: 250,
  136. },
  137. {
  138. name: 'url',
  139. value: url,
  140. defaultValue: 'https://nextcloud.com',
  141. type: 'url',
  142. displayName: t('theming', 'Web link'),
  143. placeholder: 'https://…',
  144. maxlength: 500,
  145. },
  146. {
  147. name: 'slogan',
  148. value: slogan,
  149. defaultValue: t('theming', 'a safe home for all your data'),
  150. type: 'text',
  151. displayName: t('theming', 'Slogan'),
  152. placeholder: t('theming', 'Slogan'),
  153. maxlength: 500,
  154. },
  155. ]
  156. const colorPickerField = {
  157. name: 'color',
  158. value: color,
  159. defaultValue: '#0082c9',
  160. displayName: t('theming', 'Color'),
  161. }
  162. const fileInputFields = [
  163. {
  164. name: 'logo',
  165. mimeName: 'logoMime',
  166. mimeValue: logoMime,
  167. defaultMimeValue: '',
  168. displayName: t('theming', 'Logo'),
  169. ariaLabel: t('theming', 'Upload new logo'),
  170. },
  171. {
  172. name: 'background',
  173. mimeName: 'backgroundMime',
  174. mimeValue: backgroundMime,
  175. defaultMimeValue: '',
  176. displayName: t('theming', 'Background and login image'),
  177. ariaLabel: t('theming', 'Upload new background and login image'),
  178. },
  179. ]
  180. const advancedTextFields = [
  181. {
  182. name: 'imprintUrl',
  183. value: legalNoticeUrl,
  184. defaultValue: '',
  185. type: 'url',
  186. displayName: t('theming', 'Legal notice link'),
  187. placeholder: 'https://…',
  188. maxlength: 500,
  189. },
  190. {
  191. name: 'privacyUrl',
  192. value: privacyPolicyUrl,
  193. defaultValue: '',
  194. type: 'url',
  195. displayName: t('theming', 'Privacy policy link'),
  196. placeholder: 'https://…',
  197. maxlength: 500,
  198. },
  199. ]
  200. const advancedFileInputFields = [
  201. {
  202. name: 'logoheader',
  203. mimeName: 'logoheaderMime',
  204. mimeValue: logoheaderMime,
  205. defaultMimeValue: '',
  206. displayName: t('theming', 'Header logo'),
  207. ariaLabel: t('theming', 'Upload new header logo'),
  208. },
  209. {
  210. name: 'favicon',
  211. mimeName: 'faviconMime',
  212. mimeValue: faviconMime,
  213. defaultMimeValue: '',
  214. displayName: t('theming', 'Favicon'),
  215. ariaLabel: t('theming', 'Upload new favicon'),
  216. },
  217. ]
  218. const userThemingField = {
  219. name: 'disable-user-theming',
  220. value: userThemingDisabled,
  221. defaultValue: false,
  222. displayName: t('theming', 'User settings'),
  223. label: t('theming', 'Disable user theming'),
  224. description: t('theming', 'Although you can select and customize your instance, users can change their background and colors. If you want to enforce your customization, you can toggle this on.'),
  225. }
  226. export default {
  227. name: 'AdminTheming',
  228. components: {
  229. CheckboxField,
  230. ColorPickerField,
  231. FileInputField,
  232. NcNoteCard,
  233. NcSettingsSection,
  234. TextField,
  235. },
  236. emits: [
  237. 'update:theming',
  238. ],
  239. data() {
  240. return {
  241. textFields,
  242. colorPickerField,
  243. fileInputFields,
  244. advancedTextFields,
  245. advancedFileInputFields,
  246. userThemingField,
  247. canThemeIcons,
  248. docUrl,
  249. docUrlIcons,
  250. isThemable,
  251. notThemableErrorMessage,
  252. }
  253. },
  254. }
  255. </script>
  256. <style lang="scss" scoped>
  257. .admin-theming,
  258. .admin-theming-advanced {
  259. display: flex;
  260. flex-direction: column;
  261. gap: 8px 0;
  262. }
  263. .admin-theming {
  264. &__preview {
  265. width: 230px;
  266. height: 140px;
  267. background-size: cover;
  268. background-position: center;
  269. text-align: center;
  270. margin-top: 10px;
  271. /* This is basically https://github.com/nextcloud/server/blob/master/core/css/guest.css
  272. But without the user variables. That way the admin can preview the render as guest*/
  273. /* As guest, there is no user color color-background-plain */
  274. background-color: var(--color-primary-default, #0082c9);
  275. /* As guest, there is no user background (--image-background)
  276. 1. Empty background if defined
  277. 2. Else default background
  278. 3. Finally default gradient (should not happened, the background is always defined anyway) */
  279. background-image: var(--image-background-plain, var(--image-background-default, linear-gradient(40deg, #0082c9 0%, #30b6ff 100%)));
  280. &-logo {
  281. width: 20%;
  282. height: 20%;
  283. margin-top: 20px;
  284. display: inline-block;
  285. background-size: contain;
  286. background-position: center;
  287. background-repeat: no-repeat;
  288. background-image: var(--image-logo, url('../../../core/img/logo/logo.svg'));
  289. }
  290. }
  291. }
  292. </style>