Skip to content

Commit 6c9d5ad

Browse files
committed
refactor: move custom fonts into separate component
Signed-off-by: Elizabeth Danzberger <[email protected]>
1 parent 8dc3cec commit 6c9d5ad

File tree

10 files changed

+310
-46
lines changed

10 files changed

+310
-46
lines changed

cypress/e2e/settings.spec.js

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { User } from '@nextcloud/cypress'
66

77
const usesHttps = Cypress.env('baseUrl').substr(0, 5) === 'https'
88
const collaboraUrl = Cypress.env('collaboraUrl')
9-
const defaultFonts = ['AmaticSC-Regular.ttf']
109

1110
describe('Office admin settings', function() {
1211

@@ -65,16 +64,51 @@ describe('Office admin settings', function() {
6564
.scrollIntoView()
6665
.should('be.visible')
6766

68-
cy.get('#font-settings')
67+
cy.get('.settings-section__name')
68+
.contains('Global Templates')
6969
.scrollIntoView()
7070
.should('be.visible')
71-
defaultFonts.forEach(font => {
72-
cy.get('.settings-entry.font-list-settings').contains(font)
73-
})
71+
})
72+
})
73+
74+
describe('Custom Fonts', function() {
75+
const defaultFonts = ['AmaticSC-Regular.ttf']
76+
77+
beforeEach(function() {
78+
cy.login(new User('admin', 'admin'))
79+
cy.visit('/settings/admin/richdocuments')
7480

7581
cy.get('.settings-section__name')
76-
.contains('Global Templates')
82+
.contains('Custom Fonts')
7783
.scrollIntoView()
7884
.should('be.visible')
7985
})
86+
87+
it('Can delete a font', function() {
88+
cy.intercept({
89+
method: 'DELETE',
90+
url: `**/richdocuments/settings/fonts/${defaultFonts[0]}`,
91+
}).as('deleteFontRequest')
92+
93+
cy.get(`button[aria-label="Delete ${defaultFonts[0]}"]`)
94+
.click({ force: true })
95+
96+
cy.wait('@deleteFontRequest').its('response.statusCode').should('eq', 200)
97+
})
98+
99+
it('Can upload a font file', function() {
100+
cy.intercept({
101+
method: 'POST',
102+
url: '**/richdocuments/settings/fonts',
103+
}).as('uploadFontRequest')
104+
105+
cy.uploadInputFile({
106+
identifier: 'newFontInput',
107+
fixturePath: `fonts/${defaultFonts[0]}`,
108+
fileName: defaultFonts[0],
109+
mimeType: 'font/ttf',
110+
})
111+
112+
cy.wait('@uploadFontRequest').its('response.statusCode').should('eq', 200)
113+
})
80114
})

cypress/e2e/templates.spec.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ describe('Global templates', function() {
1818
})
1919

2020
it('Can be uploaded', function() {
21+
cy.login(new User('admin', 'admin'))
22+
cy.visit('/settings/admin/richdocuments')
23+
2124
cy.intercept('POST', '**/richdocuments/template').as('templateUploadRequest')
22-
cy.uploadSystemTemplate({
25+
cy.uploadInputFile({
26+
identifier: 'newTemplateInput',
2327
fixturePath: 'templates/presentation.otp',
2428
fileName: 'systemtemplate.otp',
2529
mimeType: 'application/vnd.oasis.opendocument.presentation-template',
@@ -33,7 +37,11 @@ describe('Global templates', function() {
3337
})
3438

3539
it('Can prevent uploading a duplicate', function() {
36-
cy.uploadSystemTemplate({
40+
cy.login(new User('admin', 'admin'))
41+
cy.visit('/settings/admin/richdocuments')
42+
43+
cy.uploadInputFile({
44+
identifier: 'newTemplateInput',
3745
fixturePath: 'templates/presentation.otp',
3846
fileName: 'systemtemplate.otp',
3947
mimeType: 'application/vnd.oasis.opendocument.presentation-template',
148 KB
Binary file not shown.

cypress/support/commands.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,28 @@ Cypress.Commands.add('uploadSystemTemplate', ({ fixturePath, fileName, mimeType
301301
cy.login(new User('admin', 'admin'))
302302
cy.visit('/settings/admin/richdocuments')
303303

304-
cy.get('.settings-section__name')
305-
.contains('Global Templates')
304+
cy.get('.settings-section')
305+
.find('input[data-cy="newTemplateInput"')
306+
.as('newTemplateInput')
307+
308+
cy.get('@newTemplateInput')
306309
.scrollIntoView()
307310

308-
cy.get('.settings-section input[type="file"]').selectFile({
311+
cy.get('@newTemplateInput').selectFile({
312+
contents: `cypress/fixtures/${fixturePath}`,
313+
fileName,
314+
mimeType,
315+
}, { force: true })
316+
})
317+
318+
Cypress.Commands.add('uploadInputFile', ({ identifier, fixturePath, fileName, mimeType }) => {
319+
cy.get('.settings-section')
320+
.find(`input[data-cy="${identifier}"]`)
321+
.as('fileInputElement')
322+
323+
cy.get('@fileInputElement').scrollIntoView()
324+
325+
cy.get('@fileInputElement').selectFile({
309326
contents: `cypress/fixtures/${fixturePath}`,
310327
fileName,
311328
mimeType,

lib/Service/FontService.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,13 @@ private function generateFontOverview(ISimpleFile $fontFile): void {
187187
fflush($tmpFontFile);
188188

189189
$im = imagecreatetruecolor(250, 30);
190-
$bg_color = imagecolorallocate($im, 255, 255, 255);
190+
imagealphablending($im, false);
191+
192+
$bg_color = imagecolorallocatealpha($im, 255, 255, 255, 127);
191193
$font_color = imagecolorallocate($im, $color[0], $color[1], $color[2]);
192-
imagefilledrectangle($im, 0, 0, 399, 29, $bg_color);
194+
imagefill($im, 0, 0, $bg_color);
195+
imagesavealpha($im, true);
196+
193197
$ttfResult = imagettftext($im, 20, 0, 0, 22, $font_color, $tmpFontFilePath, $text);
194198
// this happens with invalid ttf fonts
195199
if ($ttfResult === false) {

src/admin.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import './init-shared.js'
66
import Vue from 'vue'
77
import AdminSettings from './components/AdminSettings.vue'
8+
import { createPinia, PiniaVuePlugin } from 'pinia'
89
import '../css/admin.scss'
910

1011
// CSP config for webpack dynamic chunk loading
@@ -21,9 +22,26 @@ Vue.prototype.n = n
2122
Vue.prototype.OC = OC
2223
Vue.prototype.OCA = OCA
2324

25+
Vue.use(PiniaVuePlugin)
26+
27+
const pinia = createPinia()
2428
const element = document.getElementById('admin-vue')
29+
const initialSettings = JSON.parse(element.dataset.initial)
30+
31+
// Hydrate the adminSettings store with the initial settings
32+
// provided by the initial state
33+
pinia.state.value = {
34+
adminSettings: {
35+
fonts: initialSettings.fonts,
36+
},
37+
}
2538

2639
/* eslint-disable-next-line no-new */
2740
new Vue({
28-
render: h => h(AdminSettings, { props: { initial: JSON.parse(element.dataset.initial) } }),
41+
pinia,
42+
render: h => h(
43+
AdminSettings,
44+
{
45+
props: { initial: JSON.parse(element.dataset.initial) },
46+
}),
2947
}).$mount('#admin-vue')

src/components/AdminSettings.vue

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -293,28 +293,7 @@
293293
@update="updateWopiAllowlist" />
294294
</div>
295295

296-
<div v-if="isSetup" id="font-settings" class="section">
297-
<h2>{{ t('richdocuments', 'Custom Fonts') }}</h2>
298-
<SettingsInputFile :label="t('richdocuments', 'Upload font file')"
299-
:button-title="t('richdocuments', 'Upload a font file')"
300-
:uploading="uploadingFont"
301-
:mimetypes="fontMimes"
302-
@change="uploadFont" />
303-
<SettingsFontList :fonts="settings.fonts"
304-
:label="t('richdocuments', 'Available fonts')"
305-
@deleted="onFontDeleted" />
306-
<em>
307-
{{ fontHint }}
308-
</em>
309-
<em>
310-
<pre>
311-
{{ fontXmlHint }}
312-
</pre>
313-
</em>
314-
<em>
315-
{{ t('richdocuments', 'For ideal document compatibility we recommend you to install commonly used fonts. If your users are working with Microsoft Office, installing their proprietary fonts can be done following the documentation.') }} <a :href="fontCustomDocumentUrl" target="_blank">{{ t('richdocuments', 'Custom fonts documentation') }}</a>
316-
</em>
317-
</div>
296+
<CustomFonts />
318297

319298
<div v-if="isSetup" id="secure-view-settings" class="section">
320299
<h2>{{ t('richdocuments', 'Secure View') }}</h2>
@@ -428,9 +407,8 @@ import SettingsCheckbox from './SettingsCheckbox.vue'
428407
import SettingsInputText from './SettingsInputText.vue'
429408
import SettingsSelectGroup from './SettingsSelectGroup.vue'
430409
import SettingsExternalApps from './SettingsExternalApps.vue'
431-
import SettingsInputFile from './SettingsInputFile.vue'
432-
import SettingsFontList from './SettingsFontList.vue'
433410
import GlobalTemplates from './AdminSettings/GlobalTemplates.vue'
411+
import CustomFonts from './AdminSettings/CustomFonts.vue'
434412
import { getCurrentUser } from '@nextcloud/auth'
435413
436414
import { isPublicShare, getSharingToken } from '@nextcloud/sharing/public'
@@ -463,9 +441,8 @@ export default {
463441
NcSelect,
464442
NcSelectTags,
465443
SettingsExternalApps,
466-
SettingsInputFile,
467-
SettingsFontList,
468444
GlobalTemplates,
445+
CustomFonts,
469446
NcModal,
470447
NcNoteCard,
471448
CoolFrame,
@@ -882,12 +859,6 @@ export default {
882859
this.uploadingFont = false
883860
})
884861
},
885-
onFontDeleted(name) {
886-
const index = this.settings.fonts.indexOf(name)
887-
if (index !== -1) {
888-
this.settings.fonts.splice(index, 1)
889-
}
890-
},
891862
},
892863
}
893864
</script>

0 commit comments

Comments
 (0)