AdminTheming.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. <AppMenuSection :default-apps.sync="defaultApps" />
  106. </section>
  107. </template>
  108. <script>
  109. import { loadState } from '@nextcloud/initial-state'
  110. import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
  111. import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
  112. import CheckboxField from './components/admin/CheckboxField.vue'
  113. import ColorPickerField from './components/admin/ColorPickerField.vue'
  114. import FileInputField from './components/admin/FileInputField.vue'
  115. import TextField from './components/admin/TextField.vue'
  116. import AppMenuSection from './components/admin/AppMenuSection.vue'
  117. const {
  118. backgroundMime,
  119. canThemeIcons,
  120. color,
  121. docUrl,
  122. docUrlIcons,
  123. faviconMime,
  124. isThemable,
  125. legalNoticeUrl,
  126. logoheaderMime,
  127. logoMime,
  128. name,
  129. notThemableErrorMessage,
  130. privacyPolicyUrl,
  131. slogan,
  132. url,
  133. userThemingDisabled,
  134. defaultApps,
  135. } = loadState('theming', 'adminThemingParameters')
  136. const textFields = [
  137. {
  138. name: 'name',
  139. value: name,
  140. defaultValue: 'Nextcloud',
  141. type: 'text',
  142. displayName: t('theming', 'Name'),
  143. placeholder: t('theming', 'Name'),
  144. maxlength: 250,
  145. },
  146. {
  147. name: 'url',
  148. value: url,
  149. defaultValue: 'https://nextcloud.com',
  150. type: 'url',
  151. displayName: t('theming', 'Web link'),
  152. placeholder: 'https://…',
  153. maxlength: 500,
  154. },
  155. {
  156. name: 'slogan',
  157. value: slogan,
  158. defaultValue: t('theming', 'a safe home for all your data'),
  159. type: 'text',
  160. displayName: t('theming', 'Slogan'),
  161. placeholder: t('theming', 'Slogan'),
  162. maxlength: 500,
  163. },
  164. ]
  165. const colorPickerField = {
  166. name: 'color',
  167. value: color,
  168. defaultValue: '#0082c9',
  169. displayName: t('theming', 'Color'),
  170. }
  171. const fileInputFields = [
  172. {
  173. name: 'logo',
  174. mimeName: 'logoMime',
  175. mimeValue: logoMime,
  176. defaultMimeValue: '',
  177. displayName: t('theming', 'Logo'),
  178. ariaLabel: t('theming', 'Upload new logo'),
  179. },
  180. {
  181. name: 'background',
  182. mimeName: 'backgroundMime',
  183. mimeValue: backgroundMime,
  184. defaultMimeValue: '',
  185. displayName: t('theming', 'Background and login image'),
  186. ariaLabel: t('theming', 'Upload new background and login image'),
  187. },
  188. ]
  189. const advancedTextFields = [
  190. {
  191. name: 'imprintUrl',
  192. value: legalNoticeUrl,
  193. defaultValue: '',
  194. type: 'url',
  195. displayName: t('theming', 'Legal notice link'),
  196. placeholder: 'https://…',
  197. maxlength: 500,
  198. },
  199. {
  200. name: 'privacyUrl',
  201. value: privacyPolicyUrl,
  202. defaultValue: '',
  203. type: 'url',
  204. displayName: t('theming', 'Privacy policy link'),
  205. placeholder: 'https://…',
  206. maxlength: 500,
  207. },
  208. ]
  209. const advancedFileInputFields = [
  210. {
  211. name: 'logoheader',
  212. mimeName: 'logoheaderMime',
  213. mimeValue: logoheaderMime,
  214. defaultMimeValue: '',
  215. displayName: t('theming', 'Header logo'),
  216. ariaLabel: t('theming', 'Upload new header logo'),
  217. },
  218. {
  219. name: 'favicon',
  220. mimeName: 'faviconMime',
  221. mimeValue: faviconMime,
  222. defaultMimeValue: '',
  223. displayName: t('theming', 'Favicon'),
  224. ariaLabel: t('theming', 'Upload new favicon'),
  225. },
  226. ]
  227. const userThemingField = {
  228. name: 'disable-user-theming',
  229. value: userThemingDisabled,
  230. defaultValue: false,
  231. displayName: t('theming', 'User settings'),
  232. label: t('theming', 'Disable user theming'),
  233. 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.'),
  234. }
  235. export default {
  236. name: 'AdminTheming',
  237. components: {
  238. AppMenuSection,
  239. CheckboxField,
  240. ColorPickerField,
  241. FileInputField,
  242. NcNoteCard,
  243. NcSettingsSection,
  244. TextField,
  245. },
  246. emits: [
  247. 'update:theming',
  248. ],
  249. textFields,
  250. data() {
  251. return {
  252. textFields,
  253. colorPickerField,
  254. fileInputFields,
  255. advancedTextFields,
  256. advancedFileInputFields,
  257. userThemingField,
  258. defaultApps,
  259. canThemeIcons,
  260. docUrl,
  261. docUrlIcons,
  262. isThemable,
  263. notThemableErrorMessage,
  264. }
  265. },
  266. }
  267. </script>
  268. <style lang="scss" scoped>
  269. .admin-theming,
  270. .admin-theming-advanced {
  271. display: flex;
  272. flex-direction: column;
  273. gap: 8px 0;
  274. }
  275. .admin-theming {
  276. &__preview {
  277. width: 230px;
  278. height: 140px;
  279. background-size: cover;
  280. background-position: center;
  281. text-align: center;
  282. margin-top: 10px;
  283. /* This is basically https://github.com/nextcloud/server/blob/master/core/css/guest.css
  284. But without the user variables. That way the admin can preview the render as guest*/
  285. /* As guest, there is no user color color-background-plain */
  286. background-color: var(--color-primary-element-default);
  287. /* As guest, there is no user background (--image-background)
  288. 1. Empty background if defined
  289. 2. Else default background
  290. 3. Finally default gradient (should not happened, the background is always defined anyway) */
  291. background-image: var(--image-background-plain, var(--image-background-default));
  292. &-logo {
  293. width: 20%;
  294. height: 20%;
  295. margin-top: 20px;
  296. display: inline-block;
  297. background-size: contain;
  298. background-position: center;
  299. background-repeat: no-repeat;
  300. background-image: var(--image-logo, url('../../../core/img/logo/logo.svg'));
  301. }
  302. }
  303. }
  304. </style>