Skip to content

Commit d852247

Browse files
committed
feat: Export Portlets Instances - MEED-8399 - Meeds-io/MIPs#180 (#353)
This PR will implement a new feature to export portlet instances.
1 parent b86977f commit d852247

4 files changed

Lines changed: 115 additions & 15 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* This file is part of the Meeds project (https://meeds.io/).
3+
*
4+
* Copyright (C) 2020 - 2025 Meeds Association contact@meeds.io
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
package io.meeds.layout.plugin;
20+
21+
import io.meeds.layout.model.PortletInstancePreference;
22+
import io.meeds.layout.service.PortletInstanceService;
23+
import io.meeds.layout.util.JsonUtils;
24+
import io.meeds.social.databind.plugin.DatabindPreferencePlugin;
25+
import io.meeds.social.databind.service.DatabindService;
26+
import jakarta.annotation.PostConstruct;
27+
import org.exoplatform.commons.exception.ObjectNotFoundException;
28+
import org.exoplatform.services.log.ExoLogger;
29+
import org.exoplatform.services.log.Log;
30+
import org.springframework.beans.factory.annotation.Autowired;
31+
import org.springframework.core.Ordered;
32+
import org.springframework.core.annotation.Order;
33+
import org.springframework.stereotype.Component;
34+
35+
import java.io.File;
36+
import java.io.FileWriter;
37+
import java.io.IOException;
38+
import java.util.List;
39+
40+
@Component
41+
@Order(Ordered.HIGHEST_PRECEDENCE)
42+
public class PortletInstanceDatabindPreferencePlugin implements DatabindPreferencePlugin {
43+
44+
private static final Log LOG = ExoLogger.getExoLogger(PortletInstanceDatabindPreferencePlugin.class);
45+
46+
@Autowired
47+
private PortletInstanceService portletInstanceService;
48+
49+
@Autowired
50+
private DatabindService databindService;
51+
52+
@Override
53+
public String getDataType() {
54+
return "PortletInstance";
55+
}
56+
57+
@PostConstruct
58+
public void init() {
59+
databindService.addDataPreferencePlugin(this);
60+
}
61+
62+
@Override
63+
public void serialize(String objectId, File zipFile, String username) throws ObjectNotFoundException, IllegalAccessException {
64+
List<PortletInstancePreference> preferences = portletInstanceService.getPortletInstancePreferences(Long.parseLong(objectId),
65+
username);
66+
String jsonData = JsonUtils.toJsonString(preferences);
67+
try (FileWriter writer = new FileWriter(zipFile)) {
68+
writer.write(jsonData);
69+
} catch (IOException e) {
70+
LOG.warn("Fail to serialize portlet instance with id", objectId, e);
71+
}
72+
}
73+
}

layout-webapp/src/main/resources/locale/portlet/LayoutEditor_en.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,13 @@ portlets.contentManagers=Content Managers
316316
portlets.spaceHost=Space Admin
317317
portletInstance.label.preview=Preview of {0}
318318

319+
portletInstance.label.exportInstance=Export Instance
320+
portletInstance.label.export=Export
321+
portletInstance.label.exportInstance.part1=Export the Instance for use on another platform.
322+
portletInstance.label.exportInstance.part2=The following items will be included for reuse:
323+
portletInstance.label.exportInstance.part3=- Characteristics (name, description, image preview)
324+
portletInstance.label.exportInstance.part4=- App Preferences
325+
319326
layout.editPortletInstance=Edit portlet instance {0}
320327
layout.uploadBackgroundImageTitle=Upload a background image
321328
layout.deleteBackgroundImageTitle=Delete the background image

layout-webapp/src/main/webapp/vue-app/portlets/components/PortletsManagement.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@
4242
<portlets-instance-drawer />
4343
<layout-image-illustration-preview />
4444
<layout-analytics application-name="portletsManagement" />
45+
<serialize-drawer>
46+
<template #title>{{ $t('portletInstance.label.exportInstance') }}</template>
47+
<template #content>
48+
<v-card-text class="pb-0">{{ $t('portletInstance.label.exportInstance.part1') }}</v-card-text>
49+
<v-card-text class="pb-0">{{ $t('portletInstance.label.exportInstance.part2') }}</v-card-text>
50+
<v-card-text class="pb-0">{{ $t('portletInstance.label.exportInstance.part3') }}</v-card-text>
51+
<v-card-text class="pb-0">{{ $t('portletInstance.label.exportInstance.part4') }}</v-card-text>
52+
</template>
53+
</serialize-drawer>
4554
</v-app>
4655
</template>
4756
<script>

layout-webapp/src/main/webapp/vue-app/portlets/components/instances/Menu.vue

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,33 @@
4848
target="_blank"
4949
rel="opener"
5050
dense>
51-
<v-icon size="13">
52-
fa-edit
53-
</v-icon>
54-
<v-list-item-title class="ps-2">
51+
<v-list-item-icon class="me-auto">
52+
<v-icon size="13">fa-edit</v-icon>
53+
</v-list-item-icon>
54+
<v-list-item-title>
5555
{{ $t('portlets.label.editInstance') }}
5656
</v-list-item-title>
5757
</v-list-item>
5858
<v-list-item
5959
dense
6060
@click="$root.$emit('portlet-instance-edit', portletInstance)">
61-
<v-icon size="13">
62-
fa-edit
63-
</v-icon>
64-
<v-list-item-title class="ps-2">
61+
<v-list-item-icon class="me-auto">
62+
<v-icon size="13">fa-edit</v-icon>
63+
</v-list-item-icon>
64+
<v-list-item-title>
6565
{{ $t('portlets.label.editProperties') }}
6666
</v-list-item-title>
6767
</v-list-item>
68+
<v-list-item
69+
dense
70+
@click="$root.$emit('serialize-drawer-open', 'PortletInstance', portletInstanceId)">
71+
<v-list-item-icon class="me-auto">
72+
<v-icon size="13">fa-download</v-icon>
73+
</v-list-item-icon>
74+
<v-list-item-title>
75+
{{ $t('portletInstance.label.export') }}
76+
</v-list-item-title>
77+
</v-list-item>
6878
<v-tooltip :disabled="!portletInstance.system" bottom>
6979
<template #activator="{ on, attrs }">
7080
<div
@@ -74,14 +84,15 @@
7484
:disabled="portletInstance.system"
7585
dense
7686
@click="$root.$emit('portlet-instance-delete', portletInstance)">
77-
<v-icon
78-
:class="!portletInstance.system && 'error--text' || 'disabled--text'"
79-
size="13">
80-
fa-trash
81-
</v-icon>
87+
<v-list-item-icon class="me-auto">
88+
<v-icon
89+
:class="!portletInstance.system && 'error--text' || 'disabled--text'"
90+
size="13">
91+
fa-trash
92+
</v-icon>
93+
</v-list-item-icon>
8294
<v-list-item-title
83-
:class="!portletInstance.system && 'error--text' || 'disabled--text'"
84-
class="ps-2">
95+
:class="!portletInstance.system && 'error--text' || 'disabled--text'">
8596
{{ $t('portlets.label.delete') }}
8697
</v-list-item-title>
8798
</v-list-item>

0 commit comments

Comments
 (0)