AdminTheming.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 :name="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. data-admin-theming-settings>
  28. <div class="admin-theming">
  29. <NcNoteCard v-if="!isThemable"
  30. type="error"
  31. :show-alert="true">
  32. <p>{{ notThemableErrorMessage }}</p>
  33. </NcNoteCard>
  34. <!-- Name, web link, slogan... fields -->
  35. <TextField v-for="field in textFields"
  36. :key="field.name"
  37. :data-admin-theming-setting-field="field.name"
  38. :default-value="field.defaultValue"
  39. :display-name="field.displayName"
  40. :maxlength="field.maxlength"
  41. :name="field.name"
  42. :placeholder="field.placeholder"
  43. :type="field.type"
  44. :value.sync="field.value"
  45. @update:theming="$emit('update:theming')" />
  46. <!-- Primary color picker -->
  47. <ColorPickerField :name="colorPickerField.name"
  48. :default-value="colorPickerField.defaultValue"
  49. :display-name="colorPickerField.displayName"
  50. :value.sync="colorPickerField.value"
  51. data-admin-theming-setting-primary-color
  52. @update:theming="$emit('update:theming')" />
  53. <!-- Default background picker -->
  54. <FileInputField v-for="field in fileInputFields"
  55. :key="field.name"
  56. :aria-label="field.ariaLabel"
  57. :data-admin-theming-setting-file="field.name"
  58. :default-mime-value="field.defaultMimeValue"
  59. :display-name="field.displayName"
  60. :mime-name="field.mimeName"
  61. :mime-value.sync="field.mimeValue"
  62. :name="field.name"
  63. @update:theming="$emit('update:theming')" />
  64. <div class="admin-theming__preview" data-admin-theming-preview>
  65. <div class="admin-theming__preview-logo" data-admin-theming-preview-logo />
  66. </div>
  67. </div>
  68. </NcSettingsSection>
  69. <NcSettingsSection :name="t('theming', 'Advanced options')">
  70. <div class="admin-theming-advanced">
  71. <TextField v-for="field in advancedTextFields"
  72. :key="field.name"
  73. :name="field.name"
  74. :value.sync="field.value"
  75. :default-value="field.defaultValue"
  76. :type="field.type"
  77. :display-name="field.displayName"
  78. :placeholder="field.placeholder"
  79. :maxlength="field.maxlength"
  80. @update:theming="$emit('update:theming')" />
  81. <FileInputField v-for="field in advancedFileInputFields"
  82. :key="field.name"
  83. :name="field.name"
  84. :mime-name="field.mimeName"
  85. :mime-value.sync="field.mimeValue"
  86. :default-mime-value="field.defaultMimeValue"
  87. :display-name="field.displayName"
  88. :aria-label="field.ariaLabel"
  89. @update:theming="$emit('update:theming')" />
  90. <CheckboxField :name="userThemingField.name"
  91. :value="userThemingField.value"
  92. :default-value="userThemingField.defaultValue"
  93. :display-name="userThemingField.displayName"
  94. :label="userThemingField.label"
  95. :description="userThemingField.description"
  96. data-admin-theming-setting-disable-user-theming
  97. @update:theming="$emit('update:theming')" />
  98. <a v-if="!canThemeIcons"
  99. :href="docUrlIcons"
  100. rel="noreferrer noopener">
  101. <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>
  102. </a>
  103. </div>
  104. </NcSettingsSection>
  105. </section>
  106. </template>
  107. <script>
  108. import { loadState } from '@nextcloud/initial-state'
  109. import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
  110. import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
  111. import CheckboxField from './components/admin/CheckboxField.vue'
  112. import ColorPickerField from './components/admin/ColorPickerField.vue'
  113. import FileInputField from './components/admin/FileInputField.vue'
  114. import TextField from './components/admin/TextField.vue'
  115. const {
  116. backgroundMime,
  117. canThemeIcons,
  118. color,
  119. docUrl,
  120. docUrlIcons,
  121. faviconMime,
  122. isThemable,
  123. legalNoticeUrl,
  124. logoheaderMime,
  125. logoMime,
  126. name,
  127. notThemableErrorMessage,
  128. privacyPolicyUrl,
  129. slogan,
  130. url,
  131. userThemingDisabled,
  132. } = loadState('theming', 'adminThemingParameters')
  133. const textFields = [
  134. {
  135. name: 'name',
  136. value: name,
  137. defaultValue: 'Nextcloud',
  138. type: 'text',
  139. displayName: t('theming', 'Name'),
  140. placeholder: t('theming', 'Name'),
  141. maxlength: 250,
  142. },
  143. {
  144. name: 'url',
  145. value: url,
  146. defaultValue: 'https://nextcloud.com',
  147. type: 'url',
  148. displayName: t('theming', 'Web link'),
  149. placeholder: 'https://…',
  150. maxlength: 500,
  151. },
  152. {
  153. name: 'slogan',
  154. value: slogan,
  155. defaultValue: t('theming', 'a safe home for all your data'),
  156. type: 'text',
  157. displayName: t('theming', 'Slogan'),
  158. placeholder: t('theming', 'Slogan'),
  159. maxlength: 500,
  160. },
  161. ]
  162. const colorPickerField = {
  163. name: 'color',
  164. value: color,
  165. defaultValue: '#0082c9',
  166. displayName: t('theming', 'Color'),
  167. }
  168. const fileInputFields = [
  169. {
  170. name: 'logo',
  171. mimeName: 'logoMime',
  172. mimeValue: logoMime,
  173. defaultMimeValue: '',
  174. displayName: t('theming', 'Logo'),
  175. ariaLabel: t('theming', 'Upload new logo'),
  176. },
  177. {
  178. name: 'background',
  179. mimeName: 'backgroundMime',
  180. mimeValue: backgroundMime,
  181. defaultMimeValue: '',
  182. displayName: t('theming', 'Background and login image'),
  183. ariaLabel: t('theming', 'Upload new background and login image'),
  184. },
  185. ]
  186. const advancedTextFields = [
  187. {
  188. name: 'imprintUrl',
  189. value: legalNoticeUrl,
  190. defaultValue: '',
  191. type: 'url',
  192. displayName: t('theming', 'Legal notice link'),
  193. placeholder: 'https://…',
  194. maxlength: 500,
  195. },
  196. {
  197. name: 'privacyUrl',
  198. value: privacyPolicyUrl,
  199. defaultValue: '',
  200. type: 'url',
  201. displayName: t('theming', 'Privacy policy link'),
  202. placeholder: 'https://…',
  203. maxlength: 500,
  204. },
  205. ]
  206. const advancedFileInputFields = [
  207. {
  208. name: 'logoheader',
  209. mimeName: 'logoheaderMime',
  210. mimeValue: logoheaderMime,
  211. defaultMimeValue: '',
  212. displayName: t('theming', 'Header logo'),
  213. ariaLabel: t('theming', 'Upload new header logo'),
  214. },
  215. {
  216. name: 'favicon',
  217. mimeName: 'faviconMime',
  218. mimeValue: faviconMime,
  219. defaultMimeValue: '',
  220. displayName: t('theming', 'Favicon'),
  221. ariaLabel: t('theming', 'Upload new favicon'),
  222. },
  223. ]
  224. const userThemingField = {
  225. name: 'disable-user-theming',
  226. value: userThemingDisabled,
  227. defaultValue: false,
  228. displayName: t('theming', 'User settings'),
  229. label: t('theming', 'Disable user theming'),
  230. 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.'),
  231. }
  232. export default {
  233. name: 'AdminTheming',
  234. components: {
  235. CheckboxField,
  236. ColorPickerField,
  237. FileInputField,
  238. NcNoteCard,
  239. NcSettingsSection,
  240. TextField,
  241. },
  242. emits: [
  243. 'update:theming',
  244. ],
  245. data() {
  246. return {
  247. textFields,
  248. colorPickerField,
  249. fileInputFields,
  250. advancedTextFields,
  251. advancedFileInputFields,
  252. userThemingField,
  253. canThemeIcons,
  254. docUrl,
  255. docUrlIcons,
  256. isThemable,
  257. notThemableErrorMessage,
  258. }
  259. },
  260. }
  261. </script>
  262. <style lang="scss" scoped>
  263. .admin-theming,
  264. .admin-theming-advanced {
  265. display: flex;
  266. flex-direction: column;
  267. gap: 8px 0;
  268. }
  269. .admin-theming {
  270. &__preview {
  271. width: 230px;
  272. height: 140px;
  273. background-size: cover;
  274. background-position: center;
  275. text-align: center;
  276. margin-top: 10px;
  277. /* This is basically https://github.com/nextcloud/server/blob/master/core/css/guest.css
  278. But without the user variables. That way the admin can preview the render as guest*/
  279. /* As guest, there is no user color color-background-plain */
  280. background-color: var(--color-primary-element-default, #0082c9);
  281. /* As guest, there is no user background (--image-background)
  282. 1. Empty background if defined
  283. 2. Else default background
  284. 3. Finally default gradient (should not happened, the background is always defined anyway) */
  285. background-image: var(--image-background-plain, var(--image-background-default, linear-gradient(40deg, #0082c9 0%, #30b6ff 100%)));
  286. &-logo {
  287. width: 20%;
  288. height: 20%;
  289. margin-top: 20px;
  290. display: inline-block;
  291. background-size: contain;
  292. background-position: center;
  293. background-repeat: no-repeat;
  294. background-image: var(--image-logo, url('../../../core/img/logo/logo.svg'));
  295. }
  296. }
  297. }
  298. </style>