Skip to content

Commit

Permalink
feat: Allow to add, edit and delete a Portlet instance - MEED-6946 - M…
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker committed May 29, 2024
1 parent 3ed4db3 commit 68f4fd1
Show file tree
Hide file tree
Showing 13 changed files with 588 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,28 @@ layout.portletInstance.category.namePlaceholder=Name
layout.portletInstance.category.nameTranslationDrawerTitle=Category name translations
layout.portletInstance.category.icon=Icon

layout.portletInstance.drawerTitie.add=Add an instance
layout.portletInstance.drawerTitie.edit=Edit an instance
layout.portletInstance.name=Name
layout.portletInstance.namePlaceholder=Give a name to your instance
layout.portletInstance.nameTranslationDrawerTitle=Instance name translations
layout.portletInstance.description=Description
layout.portletInstance.descriptionPlaceholder=Add a description to display below preview
layout.portletInstance.descriptionTranslationDrawerTitle=Instance description translations

layout.category=Category
layout.category.placeholder=Select a category
layout.portlet=Portlet
layout.portlet.placeholder=Select a portlet

layout.portlet.allowUsingInSpaceContext=Allow space hosts use it for space apps

layout.portletInstance.add=Add

layout.portletInstanceCategoryCreatedSuccessfully=Portlet Instance Category created successfully
layout.portletInstanceCategoryUpdatedSuccessfully=Portlet Instance Category updated successfully
layout.portletInstanceCreatedSuccessfully=Portlet Instance created successfully
layout.portletInstanceUpdatedSuccessfully=Portlet Instance updated successfully

portlets.portletInstancesList=Instances using {0}
portlets.previewInstance=Preview the instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
:src="illustrationSrc"
class="border-radius"
transition="none"
eager
role="presentation" />
eager />
</div>
</template>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
</v-card>
<portlets-item-instances-drawer />
<portlets-instance-category-drawer />
<portlets-instance-drawer />
<layout-image-illustration-preview />
<layout-analytics application-name="portletsManagement" />
</v-app>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,26 @@
}"
class="border-box-sizing px-1"
@toggle-select="$emit('select-tab', $event)"
@filter-text-input="$emit('portlet-instance-filter', $event)" />
@filter-text-input="$emit('portlet-instance-filter', $event)">
<template v-if="!$root.isMobile" #left>
<v-btn
id="applicationToolbarLeftButton"
:aria-label="$t('layout.portletInstance.add')"
:class="$root.isMobile && 'px-0'"
class="btn btn-primary text-truncate"
@click="$root.$emit('portlet-instance-add')">
<v-icon
size="18">
fa-plus
</v-icon>
<span
v-if="!$root.isMobile"
class="text-truncate text-none ms-2">
{{ $t('layout.portletInstance.add') }}
</span>
</v-btn>
</template>
</application-toolbar>
</template>
<script>
export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,52 +59,14 @@
</div>
</v-subheader>
<v-list-item-group v-model="listItem">
<v-tooltip
v-if="!$root.isMobile"
:disabled="!portletInstance.system"
bottom>
<template #activator="{ on, attrs }">
<div
v-on="on"
v-bind="attrs">
<v-list-item
:href="editLayoutLink"
:disabled="portletInstance.system"
target="_blank"
dense>
<v-icon
:class="portletInstance.system && 'disabled--text'"
size="13">
fa-columns
</v-icon>
<v-list-item-title
:class="portletInstance.system && 'disabled--text'"
class="ps-2">
{{ $t('portlets.label.editLayout') }}
</v-list-item-title>
</v-list-item>
</div>
</template>
<span>{{ $t('portlets.label.system.noEditLayout') }}</span>
</v-tooltip>
<v-list-item
dense
@click="$root.$emit('portlet-instance-drawer-open', portletInstance)">
@click="$root.$emit('portlet-instance-edit', portletInstance)">
<v-icon size="13">
fa-edit
</v-icon>
<v-list-item-title class="ps-2">
{{ $t('portlets.label.editProperties') }}
</v-list-item-title>
</v-list-item>
<v-list-item
dense
@click="$root.$emit('portlet-instance-drawer-open', portletInstance, true)">
<v-icon size="13">
fa-copy
</v-icon>
<v-list-item-title class="ps-2">
{{ $t('portlets.label.duplicate') }}
{{ $t('portlets.label.edit') }}
</v-list-item-title>
</v-list-item>
<v-tooltip :disabled="!portletInstance.system" bottom>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
ref="drawer"
id="portletInstanceCategoryDrawer"
v-model="drawer"
:loading="saving"
allow-expand
right>
<template #title>
Expand Down Expand Up @@ -82,6 +83,7 @@ export default {
title: null,
titleTranslations: {},
maxTitleLength: 100,
saving: false,
isNew: false,
}),
created() {
Expand All @@ -94,6 +96,7 @@ export default {
},
methods: {
open(category) {
this.$root.$emit('close-alert-message');
this.isNew = !category;
this.categoryId = category?.id || null;
this.title = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
<!--

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>
<exo-drawer
ref="drawer"
id="portletInstanceDrawer"
v-model="drawer"
:loading="saving"
allow-expand
right>
<template #title>
<span class="text-wrap">{{ isNew && $t('layout.portletInstance.drawerTitie.add') || $t('layout.portletInstance.drawerTitie.edit') }}</span>
</template>
<template v-if="drawer" #content>
<div class="pa-4" flat>
<translation-text-field
ref="title"
id="pageTemplateTitle"
v-model="titleTranslations"
:field-value.sync="title"
:placeholder="$t('layout.portletInstance.namePlaceholder')"
:maxlength="maxTitleLength"
:object-id="instanceId"
object-type="portletInstance"
field-name="title"
drawer-title="layout.portletInstance.nameTranslationDrawerTitle"
class="width-auto flex-grow-1 pb-1"
back-icon
required>
<template #title>
<div class="text-subtitle-1">
{{ $t('layout.portletInstance.name') }}
</div>
</template>
</translation-text-field>
<translation-text-field
ref="descriptionTranslation"
v-model="descriptionTranslations"
:field-value.sync="description"
:maxlength="maxDescriptionLength"
:object-id="instanceId"
object-type="portletInstance"
field-name="description"
drawer-title="layout.portletInstance.descriptionTranslationDrawerTitle"
class="ma-1px mt-4"
back-icon
rich-editor>
<template #title>
<div class="text-subtitle-1">
{{ $t('layout.portletInstance.description') }}
</div>
</template>
<rich-editor
id="portletInstanceDescription"
ref="portletInstanceDescriptionEditor"
v-model="descriptionTranslations[lang]"
:placeholder="$t('layout.portletInstance.descriptionTranslationDrawerTitle')"
:max-length="maxDescriptionLength"
:tag-enabled="false"
ck-editor-type="portletInstanceDescription"
@ready="checkCKEdtiorDisplay" />
</translation-text-field>
<portlets-instance-category-input
v-model="categoryId"
class="mt-4" />
<portlets-instance-portlet-input
v-model="contentId"
:disabled="!isNew"
class="mt-4" />
<div class="d-flex align-center mt-4">
<v-switch
v-model="spaceApplication"
:aria-label="$t('layout.portlet.allowUsingInSpaceContext')"
class="mt-1 me-2 width-fit-content" />
<div>{{ $t('layout.portlet.allowUsingInSpaceContext') }}</div>
</div>
<portlets-instance-preview
ref="portletInstancePreview"
v-model="illustrationUploadId"
:instance-id="instanceId" />
</div>
</template>
<template #footer>
<div class="d-flex me-2">
<v-spacer />
<v-btn
class="btn mx-1"
@click="close">
{{ $t('layout.cancel') }}
</v-btn>
<v-btn
:loading="saving"
class="btn btn-primary"
@click="save">
{{ $t('layout.save') }}
</v-btn>
</div>
</template>
</exo-drawer>
</template>
<script>
export default {
data: () => ({
drawer: false,
instance: null,
instanceId: null,
categoryId: null,
contentId: null,
title: null,
titleTranslations: {},
description: null,
descriptionTranslations: {},
maxTitleLength: 250,
maxDescriptionLength: 1000,
illustrationUploadId: null,
lang: eXo.env.portal.language,
spaceApplication: false,
saving: false,
isNew: false,
}),
watch: {
description() {
if (this.$refs.descriptionTranslation) {
this.$refs.descriptionTranslation.setValue(this.description);
}
this.checkCKEdtiorDisplay();
},
},
created() {
this.$root.$on('portlet-instance-add', this.open);
this.$root.$on('portlet-instance-edit', this.open);
},
beforeDestroy() {
this.$root.$off('portlet-instance-add', this.open);
this.$root.$off('portlet-instance-edit', this.open);
},
methods: {
open(instance) {
this.$root.$emit('close-alert-message');
this.isNew = !instance;
this.instance = instance || {};
this.instanceId = instance?.id || null;
this.categoryId = instance?.categoryId || null;
this.contentId = instance?.contentId || null;
this.spaceApplication = instance?.spaceApplication || false;
this.titleTranslations = {};
this.descriptionTranslations = {};

this.$nextTick().then(() => this.$refs.drawer.open());
},
close() {
this.$refs.drawer.close();
},
save() {
this.saving = true;
let message = null;
const saveInstanceRequest =
this.instanceId ?
this.$portletInstanceService.getPortletInstance(this.instanceId)
.then(instance => {
instance.categoryId = this.categoryId;
instance.spaceApplication = this.spaceApplication;
return this.$portletInstanceService.updatePortletInstance(instance)
.then(() => {
this.$root.$emit('portlet-instance-updated', instance);
message = this.$t('layout.portletInstanceUpdatedSuccessfully');
return instance;
});
})
: this.$portletInstanceService.createPortletInstance({
categoryId: this.categoryId,
contentId: this.contentId,
spaceApplication: this.spaceApplication,
})
.then(instance => {
this.$root.$emit('portlet-instance-created', instance);
message = this.$t('layout.portletInstanceCreatedSuccessfully');
return instance;
});
return saveInstanceRequest
.then(instance => {
if (instance) {
this.instanceId = instance.id;
return this.$nextTick();
}
})
.then(() => this.$translationService.saveTranslations('portletInstance', this.instanceId, 'title', this.titleTranslations))
.then(() => this.$translationService.saveTranslations('portletInstance', this.instanceId, 'description', this.descriptionTranslations))
.then(() => this.$refs?.portletInstancePreview?.save())
.then(() => {
this.$root.$emit('portlet-instance-saved', this.instanceId);
this.$root.$emit('alert-message', message, 'success');
this.close();
})
.finally(() => this.saving = false);
},
checkCKEdtiorDisplay() {
if (this.$refs.portletInstanceDescriptionEditor?.editor
&& this.description !== this.$refs.portletInstanceDescriptionEditor.inputVal) {
this.$refs.portletInstanceDescriptionEditor.editor.setData(this.description);
}
},
},
};
</script>
Loading

0 comments on commit 68f4fd1

Please sign in to comment.