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 9.0KB

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