Skip to content

Commit

Permalink
feat: Add CTAs to create instance from Portlets Tab - MEED-6919 - Mee…
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker committed May 30, 2024
1 parent 93f0cbb commit 0038e21
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ layout.portletInstanceUpdatedSuccessfully=Portlet Instance updated successfully

portlets.portletInstancesList=Instances using {0}
portlets.previewInstance=Preview the instance
portlets.noPortletInstancesYet=No instance is using this portlet for now
portlets.noPortletInstancesYet=Create your first instance using this portlet
portlets.instancePreview=Preview
portlets.uploadPreviewTitle=Upload an illustration for portlet instance
portlets.label.createInstance=Create instance
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
flat>
<portlets-toolbar
ref="toolbar"
:tab-name="tabName"
class="card-border-radius overflow-hidden"
@portlet-instance-filter="keyword = $event"
@select-tab="tabName = $event" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<application-toolbar
id="portletsApplication"
:center-button-toggle="{
selected: 'instances',
selected: tabName,
buttons: [{
value: 'instances',
text: $t('portlets.instances'),
Expand All @@ -41,7 +41,7 @@
class="border-box-sizing px-1"
@toggle-select="$emit('select-tab', $event)"
@filter-text-input="$emit('portlet-instance-filter', $event)">
<template v-if="!$root.isMobile" #left>
<template v-if="!$root.isMobile && tabName === 'instances'" #left>
<v-btn
id="applicationToolbarLeftButton"
:aria-label="$t('layout.portletInstance.add')"
Expand All @@ -63,9 +63,14 @@
</template>
<script>
export default {
props: {
tabName: {
type: String,
default: null,
}
},
data: () => ({
portlets: null,
tabName: 'instances',
}),
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
id="portletInstanceDrawer"
v-model="drawer"
:loading="saving"
:go-back-button="goBackButton"
allow-expand
right>
<template #title>
Expand Down Expand Up @@ -83,7 +84,7 @@
class="mt-4" />
<portlets-instance-portlet-input
v-model="contentId"
:disabled="!isNew"
:disabled="!isNew || disableSelectedPortlet"
class="mt-4" />
<div class="d-flex align-center mt-4">
<v-switch
Expand Down Expand Up @@ -134,6 +135,8 @@ export default {
illustrationUploadId: null,
lang: eXo.env.portal.language,
spaceApplication: false,
goBackButton: false,
disableSelectedPortlet: false,
saving: false,
isNew: false,
}),
Expand All @@ -159,13 +162,19 @@ export default {
this.$root.$off('portlet-instance-edit', this.open);
},
methods: {
open(instance) {
open(instance, goBackButton, contentId) {
this.$root.$emit('close-alert-message');
this.isNew = !instance;
this.goBackButton = goBackButton;
this.disableSelectedPortlet = !!contentId;
this.instance = instance || {};
this.instanceId = instance?.id || null;
this.categoryId = instance?.categoryId || null;
this.contentId = instance?.contentId || null;
if (instance) {
this.categoryId = instance.categoryId || null;
} else {
this.categoryId = this.$root?.selectedCategoryId;
}
this.contentId = instance?.contentId || contentId;
this.spaceApplication = instance?.spaceApplication || false;
this.title = instance?.name || null;
this.titleTranslations = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<span class="text-font-size text-color">{{ instancesCount }}</span>
</v-btn>
</td>
<td v-if="!$root.isMobile" align="center">
<portlets-item-menu :portlet="portlet" />
</td>
</tr>
</template>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ export default {
class: 'portlet-instances-header',
width: '75px'
},
{
text: this.$t('portlets.label.actions'),
value: 'actions',
align: 'center',
sortable: false,
class: 'portlet-actions-header',
width: '75px'
},
]) || [
{
text: '',
Expand Down Expand Up @@ -130,6 +138,14 @@ export default {
class: 'portlet-instances-header',
width: '75px'
},
{
text: this.$t('portlets.label.actions'),
value: 'actions',
align: 'center',
sortable: false,
class: 'portlet-actions-header',
width: '75px'
},
];
},
noEmptyPortlets() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<!--

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>
<v-menu
v-model="menu"
:left="!$vuetify.rtl"
:right="$vuetify.rtl"
:content-class="menuId"
offset-y>
<template #activator="{ on, attrs }">
<v-btn
:aria-label="$t('portlets.menu.open')"
icon
small
class="mx-auto"
v-bind="attrs"
v-on="on">
<v-icon size="16" class="icon-default-color">fas fa-ellipsis-v</v-icon>
</v-btn>
</template>
<v-hover v-if="menu" @input="hoverMenu = $event">
<v-list
class="pa-0"
dense
@mouseout="menu = false"
@focusout="menu = false">
<v-list-item-group v-model="listItem">
<v-list-item
dense
@click="$root.$emit('portlet-instance-add', null, false, portlet.contentId)">
<v-icon size="13">
fa-plus
</v-icon>
<v-list-item-title class="ps-2">
{{ $t('portlets.label.createInstance') }}
</v-list-item-title>
</v-list-item>
</v-list-item-group>
</v-list>
</v-hover>
</v-menu>
</template>
<script>
export default {
props: {
portlet: {
type: Object,
default: null,
},
},
data: () => ({
menu: false,
hoverMenu: false,
listItem: null,
menuId: `PortletMenu${parseInt(Math.random() * 10000)}`,
}),
computed: {
portletId() {
return this.portlet?.id;
},
name() {
return this.$te(this.portlet?.name) ? this.$t(this.portlet?.name) : this.portlet?.name;
},
editLayoutLink() {
return `/portal/administration/layout-editor?portletContentId=${this.portletId}`;
},
},
watch: {
listItem() {
if (this.menu) {
this.menu = false;
this.listItem = null;
}
},
menu() {
if (this.menu) {
this.$root.$emit('portlet-menu-opened', this.portletId);
} else {
this.$root.$emit('portlet-menu-closed', this.portletId);
}
},
hoverMenu() {
if (!this.hoverMenu) {
window.setTimeout(() => {
if (!this.hoverMenu) {
this.menu = false;
}
}, 200);
}
},
},
created() {
this.$root.$on('portlet-menu-opened', this.checkMenuStatus);
document.addEventListener('click', this.closeMenuOnClick);
},
beforeDestroy() {
this.$root.$off('portlet-menu-opened', this.checkMenuStatus);
document.removeEventListener('click', this.closeMenuOnClick);
},
methods: {
closeMenuOnClick(e) {
if (e.target && !e.target.closest(`.${this.menuId}`)) {
this.menu = false;
}
},
checkMenuStatus(portletId) {
if (this.menu && portletId !== this.portlet.id) {
this.menu = false;
}
},
},
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
</template>
<template v-if="drawer" #content>
<div v-if="applications.length" class="my-4">
<v-btn
:aria-label="$t('layout.portletInstance.add')"
:class="$root.isMobile && 'px-0'"
class="btn btn-primary text-truncate mb-6 mx-4"
@click="$root.$emit('portlet-instance-add', null, true, contentId)">
{{ $t('layout.portletInstance.add') }}
</v-btn>
<v-list-item
v-for="application in applications"
:key="application.id"
Expand Down Expand Up @@ -63,8 +70,16 @@
</v-list-item-action>
</v-list-item>
</div>
<div v-else class="d-flex align-center justify-center pa-4 subtitle-1">
{{ $t('portlets.noPortletInstancesYet') }}
<div v-else class="d-flex flex-column align-center justify-center pa-4 subtitle-1">
<v-icon size="40" class="icon-default-color">fa-braille</v-icon>
<span class="text-sub-title my-4">{{ $t('portlets.noPortletInstancesYet') }}</span>
<v-btn
:aria-label="$t('layout.portletInstance.add')"
:class="$root.isMobile && 'px-0'"
class="btn btn-primary text-truncate"
@click="$root.$emit('portlet-instance-add', null, true, contentId)">
{{ $t('layout.portletInstance.add') }}
</v-btn>
</div>
</template>
</exo-drawer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import PortletInput from './components/instances/form/PortletInput.vue';

import PortletList from './components/portlets/List.vue';
import PortletItem from './components/portlets/Item.vue';
import PortletMenu from './components/portlets/Menu.vue';

import PortletInstancesDrawer from './components/portlets/drawer/InstancesDrawer.vue';

Expand All @@ -66,6 +67,7 @@ const components = {

'portlets-list': PortletList,
'portlets-item': PortletItem,
'portlets-item-menu': PortletMenu,
'portlets-item-instances-drawer': PortletInstancesDrawer,
};

Expand Down
6 changes: 6 additions & 0 deletions layout-webapp/src/main/webapp/vue-app/portlets/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function init() {
portlets: [],
portletInstances: [],
portletInstanceCategories: [],
selectedCategoryId: null,
loading: 0,
collator: new Intl.Collator(eXo.env.portal.language, {numeric: true, sensitivity: 'base'}),
}),
Expand Down Expand Up @@ -74,12 +75,17 @@ export function init() {
this.$root.$on('portlet-instance-deleted', this.refreshPortletInstances);
this.$root.$on('portlet-instance-category-saved', this.refreshPortletInstanceCategories);
this.$root.$on('portlet-instance-category-deleted', this.refreshPortletInstanceCategories);
this.$root.$on('portlet-instance-category-deleted', this.refreshPortletInstances);
this.$root.$on('portlet-instance-category-selected', this.selectCategory);

this.refreshPortlets();
this.refreshPortletInstances();
this.refreshPortletInstanceCategories();
},
methods: {
selectCategory(categoryId) {
this.selectedCategoryId = categoryId;
},
refreshPortlets() {
this.loading++;
return this.$portletService.getPortlets()
Expand Down

0 comments on commit 0038e21

Please sign in to comment.