Skip to content

Commit

Permalink
feat: Add Branding Custom CSS Field UI - MEED-7129 - Meeds-io/MIPs#144 (
Browse files Browse the repository at this point in the history
#3931)

This change will introduce a new Field to allow adding a custom global
CSS. This feature can be enabled using a feature flag.
  • Loading branch information
boubaker committed Jun 26, 2024
1 parent 16ef11a commit 54d9599
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,6 @@ generalSettings.gradientTo=To
generalSettings.uploadBackgroundImageTitle=Upload a background image
generalSettings.deleteBackgroundImageTitle=Delete the background image
generalSettings.errorUploadingPreview=An error occurred while uploading Illustration. Please contact the administrator or try again later.
generalSettings.globalPageFullWindow=Full Window Pages
generalSettings.globalPageFullWindow=Full Window Pages
generalSettings.editCustomStyle=Edit custom style
generalSettings.customStyle=Custom Style
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@
eXo.env.portal.postToNetworkEnabled = <%=featureService.isFeatureActiveForUser("PostToNetwork", userName)%>;
eXo.env.portal.editorAttachImageEnabled = <%=featureService.isFeatureActiveForUser("EditorAttachImage", userName)%>;
eXo.env.portal.attachmentObjectTypes = ['<%=StringUtils.join(supportedAttachmentObjectTypes, "', '")%>'];
eXo.env.portal.customStylesheetEnabled = <%=featureService.isFeatureActiveForUser("customStylesheet", userName)%>;
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ export default {
type: Object,
default: null,
},
customCss: {
type: String,
default: null,
},
},
data: () => ({
companyName: null,
Expand Down Expand Up @@ -265,6 +269,7 @@ export default {
companyName: this.companyName,
...this.backgroundProperties,
pageWidth: this.fullWindow && this.fullWindowWidth || null,
customCss: this.customCss,
});
newBranding.themeStyle.primaryColor = this.primaryColor;
newBranding.themeStyle.secondaryColor = this.secondaryColor;
Expand Down Expand Up @@ -376,17 +381,17 @@ export default {
name: 'background-image',
value: null,
});
if (this.backgroundProperties.pageBackgroundColor
if (this.backgroundProperties.pageBackground?.data) {
this.$root.$emit('refresh-body-style-property', {
name: 'background-image',
value: `url(${this.$utils.convertImageDataAsSrc(this.backgroundProperties.pageBackground?.data)})`,
});
} else if (this.backgroundProperties.pageBackgroundColor
|| (!this.backgroundProperties.pageBackground?.uploadId && !this.backgroundProperties.pageBackground?.fileId)) {
this.$root.$emit('refresh-body-style-property', {
name: '--allPagesBackgroundImage',
value: 'none',
});
} else if (this.backgroundProperties.pageBackground?.data) {
this.$root.$emit('refresh-body-style-property', {
name: 'background-image',
value: `url(${this.$utils.convertImageDataAsSrc(this.backgroundProperties.pageBackground?.data)})`,
});
}
}
},
Expand Down Expand Up @@ -419,6 +424,7 @@ export default {
pageBackgroundPosition: this.backgroundProperties.pageBackgroundPosition || null,
pageBackgroundColor: this.backgroundProperties.pageBackgroundColor || null,
pageWidth: this.fullWindow && this.fullWindowWidth || null,
customCss: this.customCss,
});

this.$root.loading = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
class="pa-0 mb-12 pb-5">
<portal-general-settings-branding-site
:branding="branding"
:custom-css="customStylesheet"
@changed="$emit('changed')"
@saved="$emit('saved')"
@close="$emit('close')" />
Expand All @@ -35,6 +36,10 @@
lg="6"
class="pa-0">
<portal-general-settings-branding-site-preview />
<portal-general-settings-custom-style-input
v-if="customStylesheetEnabled"
v-model="customStylesheet"
class="mt-8" />
</v-col>
</v-row>
</template>
Expand All @@ -46,5 +51,17 @@ export default {
default: null,
},
},
data: () => ({
customStylesheetEnabled: eXo.env.portal.customStylesheetEnabled,
customStylesheet: null,
}),
watch: {
customStylesheet() {
this.$emit('changed');
},
},
created() {
this.customStylesheet = this.branding?.customCss;
},
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<slot name="title"></slot>
</div>
<v-spacer />
<v-tooltip bottom>
<v-tooltip :disabled="disableTooltip" bottom>
<template #activator="{on, attrs}">
<div
v-on="on"
Expand Down Expand Up @@ -72,12 +72,17 @@ export default {
data: () => ({
changed: false,
sendingImage: false,
disableTooltip: false,
uploadId: null,
}),
watch: {
uploadId() {
this.$emit('input', this.uploadId);
},
hasFile() {
this.disableTooltip = true;
window.setTimeout(() => this.disableTooltip = false, 50);
},
},
methods: {
uploadFile(file) {
Expand All @@ -86,24 +91,31 @@ export default {
const thiss = this;
return this.$uploadService.upload(file)
.then(uploadId => {
this.uploadId = uploadId;
const reader = new FileReader();
reader.onload = e => thiss.$emit('image-data-updated', e?.target?.result);
reader.readAsDataURL(file);

return new Promise(resolve => {
const reader = new FileReader();
reader.onload = e => {
thiss.$emit('image-data-updated', e?.target?.result);
resolve(uploadId);
};
reader.readAsDataURL(file);
});
})
.then(uploadId => {
this.changed = true;
this.uploadId = uploadId;
this.sendingImage = false;
this.$emit('refresh');
})
.then(() => this.$emit('refresh'))
.catch(() => {
this.$root.$emit('alert-message', this.$t('generalSettings.errorUploadingPreview'), 'error');
this.sendingImage = false;
});
}
},
reset() {
this.uploadId = null;
this.uploadId = 0;
this.$emit('input', 0);
this.$emit('reset');
this.changed = true;
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
ref="backgroundImage"
:has-file="hasFile"
class="my-auto ms-4"
@image-data-updated="setPageBackgroundData" />
@image-data-updated="setPageBackgroundData"
@reset="deletePageBackground" />
</div>
</v-radio-group>
</v-list-item-content>
Expand Down Expand Up @@ -188,7 +189,7 @@ export default {
enabled() {
if (this.initialized) {
this.branding.pageBackgroundColor = this.enabled && this.defaultBackgroundColor || null;
this.branding.pageBackground = null;
this.branding.pageBackground = {};
this.backgroundImageStyle = null;
}
},
Expand All @@ -213,7 +214,11 @@ export default {
if (this.initialized) {
if (this.choice === 'color') {
this.branding.pageBackgroundColor = this.defaultBackgroundColor;
this.branding.pageBackground = null;
this.branding.pageBackground = {
data: null,
fileId: 0,
uploadId: 0,
};
this.backgroundImageUploadId = 0;
this.backgroundImageStyle = null;
} else if (this.choice === 'image') {
Expand Down Expand Up @@ -243,8 +248,16 @@ export default {
this.$nextTick().then(() => this.initialized = true);
},
methods: {
deletePageBackground() {
this.branding.pageBackground = {
data: null,
fileId: 0,
uploadId: 0,
};
},
setPageBackgroundData(data) {
this.branding.pageBackground.data = data;
this.$emit('input', this.branding);
},
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<!--

This file is part of the Meeds project (https://meeds.io/).

Copyright (C) 2020 - 2024 Meeds Association contact@meeds.io

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

-->
<template>
<div>
<v-btn class="btn" @click="open">
<v-icon class="icon-default-color me-2" size="18">fa-edit</v-icon>
{{ $t('generalSettings.editCustomStyle') }}
</v-btn>
<exo-drawer
ref="drawer"
allow-expand
right>
<template #title>
{{ $t('generalSettings.editCustomStyle') }}
</template>
<template #content>
<div class="full-height pa-5">
<textarea
v-model="customStyle"
:aria-label="$t('generalSettings.customStyle')"
class="full-width full-height"></textarea>
</div>
</template>
<template #footer>
<div class="d-flex justify-end">
<v-btn
:aria-label="$t('generalSettings.cancel')"
:disabled="loading"
class="btn cancel-button me-4"
elevation="0"
@click="close">
{{ $t('generalSettings.cancel') }}
</v-btn>
<v-btn
:aria-label="$t('generalSettings.apply')"
color="primary"
class="btn btn-primary"
elevation="0"
@click="apply">
{{ $t('generalSettings.apply') }}
</v-btn>
</div>
</template>
</exo-drawer>
</div>
</template>
<script>
export default {
props: {
value: {
type: String,
default: null,
},
},
data: () => ({
customStyle: null,
}),
created() {
this.customStyle = this.value;
},
methods: {
open() {
this.customStyle = this.value;
this.$refs.drawer.open();
},
close() {
this.$refs.drawer.close();
},
apply() {
this.$emit('input', this.customStyle);
this.$refs.drawer.close();
},
},
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import LoginBackgroundSelector from './components/branding/form/LoginBackgroundS
import BorderRadiusSelector from './components/branding/form/BorderRadiusSelector.vue';
import BackgroundImageAttachment from './components/branding/form/BackgroundImageAttachment.vue';
import BackgroundInput from './components/branding/form/BackgroundInput.vue';
import CustomStyleInput from './components/branding/form/CustomStyleInput.vue';

import SiteBranding from './components/branding/SiteBranding.vue';
import SiteBrandingWindow from './components/branding/SiteBrandingWindow.vue';
Expand All @@ -49,6 +50,7 @@ const components = {
'portal-general-settings-border-radius': BorderRadiusSelector,
'portal-general-settings-background-image-attachment': BackgroundImageAttachment,
'portal-general-settings-background-input': BackgroundInput,
'portal-general-settings-custom-style-input': CustomStyleInput,
'portal-general-settings-login-background-selector': LoginBackgroundSelector,
'portal-general-settings-hub-access': HubAccess,
'portal-general-settings-default-spaces-drawer': DefaultSpacesDrawer,
Expand Down

0 comments on commit 54d9599

Please sign in to comment.