Skip to content

Commit

Permalink
feat: Allow to change Site or Page icon - MEED-7838 - Meeds-io/MIPs#159
Browse files Browse the repository at this point in the history
… (#4200)

Allow to select a specific icon when adding a site or a page.
  • Loading branch information
boubaker committed Nov 23, 2024
1 parent b9e31b8 commit f8d52e8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ public static SidebarItem resolveProperties(NavigationService navigationService,
Long.parseLong(nodeId),
locale));
item.setTarget(node.getState().getTarget());
if (node.getState() != null && node.getState().getIcon() != null) {
item.setIcon(node.getState().getIcon());
}
SiteKey siteKey = node.getState().getSiteKey();
PortalConfig site = layoutService.getPortalConfig(siteKey);
if (site != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,35 +128,29 @@ public SidebarItem resolveProperties(SidebarItem item, String username, Locale l
.get(SITE_TYPE_PROP_NAME),
item.getProperties()
.get(SITE_NAME_PROP_NAME)));
if (rootNode != null && rootNode.getSize() > 0) {
NodeContext<NodeContext<Object>> firstNode = rootNode.get(0);
if (firstNode.getData() != null
&& firstNode.getData().getState() != null
&& firstNode.getData().getState().getIcon() != null) {
item.setIcon(firstNode.getData().getState().getIcon());
}
if (StringUtils.equals(item.getProperties().get(SITE_EXPAND_PAGES_PROP_NAME), "true")) {
Collection<NodeContext<Object>> nodes = rootNode.getNodes();
item.setItems(new ArrayList<>());
nodes.forEach(node -> {
if (node.getData() != null
&& node.getData().getState() != null
&& isVisibilityEligible(node.getData().getState())) {
SidebarItem pageItem = new SidebarItem(SidebarItemType.PAGE);
pageItem.setProperties(Collections.singletonMap(NODE_ID_PROP_NAME, node.getData().getId()));
pageItem.setUrl(node.getData().getName());
PageSidebarPlugin.resolveProperties(navigationService,
layoutService,
translationService,
descriptionService,
resourceBundleManager,
localeConfigService,
pageItem,
locale);
item.getItems().add(pageItem);
}
});
}
if (rootNode != null
&& rootNode.getSize() > 0
&& StringUtils.equals(item.getProperties().get(SITE_EXPAND_PAGES_PROP_NAME), "true")) {
Collection<NodeContext<Object>> nodes = rootNode.getNodes();
item.setItems(new ArrayList<>());
nodes.forEach(node -> {
if (node.getData() != null
&& node.getData().getState() != null
&& isVisibilityEligible(node.getData().getState())) {
SidebarItem pageItem = new SidebarItem(SidebarItemType.PAGE);
pageItem.setProperties(Collections.singletonMap(NODE_ID_PROP_NAME, node.getData().getId()));
pageItem.setUrl(node.getData().getName());
PageSidebarPlugin.resolveProperties(navigationService,
layoutService,
translationService,
descriptionService,
resourceBundleManager,
localeConfigService,
pageItem,
locale);
item.getItems().add(pageItem);
}
});
}
return item;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ generalSettings.sidebar.spacesNamesPlaceHolder=Menu item name
generalSettings.sidebar.spacesNamesDrawerTitle=Add Menu item translations
generalSettings.sidebar.spacesSelectLimit=Select number of items to list
generalSettings.sidebar.linkName=Name
generalSettings.sidebar.linkDescription=Description
generalSettings.sidebar.linkDescription=Tooltip
generalSettings.sidebar.linkLabel=Link
generalSettings.sidebar.linkIcon=Update the icon
generalSettings.sidebar.linkTarget=Opens in same tab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
outlined
dense />
</template>
<font-icon-input
v-model="icon"
:label="$t('generalSettings.sidebar.linkIcon')"
class="mt-4 mb-2" />
</div>
</template>
<template #footer>
Expand Down Expand Up @@ -127,7 +131,9 @@ export default {
settings: null,
option: null,
item: null,
icon: null,
siteId: null,
nodeId: null,
sites: null,
isNew: true,
excludeSpaceSites: true,
Expand Down Expand Up @@ -155,7 +161,13 @@ export default {
return this.site?.siteType;
},
siteIcon() {
return this.site?.siteNavigations && this.getFirstIcon(this.site.siteNavigations) || null;
return !this.loading
&& this.site?.siteNavigations
&& this.getFirstIcon(this.site.siteNavigations)
|| null;
},
pageIcon() {
return this.nodeId && this.page?.icon || null;
},
modified() {
return this.isNew
Expand Down Expand Up @@ -183,7 +195,7 @@ export default {
}
},
page() {
return this.pages?.find?.(p => p.id === this.nodeId);
return this.pages?.find?.(p => Number(p.id) === Number(this.nodeId));
},
},
watch: {
Expand All @@ -205,6 +217,16 @@ export default {
this.retrieveSite();
}
},
siteIcon() {
if (this.drawer && this.isSiteOption) {
this.icon = this.siteIcon || this.icon || 'fa-project-diagram';
}
},
pageIcon() {
if (this.drawer && this.isPageOption) {
this.icon = this.pageIcon || this.icon || 'fa-project-diagram';
}
},
},
created() {
this.$root.$on('sidebar-item-add-site', this.open);
Expand All @@ -228,6 +250,7 @@ export default {
properties: {},
};
this.isNew = !item;
this.icon = this.item.icon || 'fa-project-diagram';
this.initialized = false;
if (!this.item.properties) {
this.item.properties = {};
Expand Down Expand Up @@ -264,11 +287,10 @@ export default {
this.saving = true;
try {
await this.retrieveSite();
const siteIcon = this.site?.siteNavigations && this.getFirstIcon(this.site.siteNavigations) || null;
this.item.name = this.isPageOption ? this.page.label : this.site.displayName;
this.item.url = this.isPageOption ? `/portal/${this.siteName}/${this.page.uri}` : `/portal/${this.siteName}`;
this.item.target = this.isPageOption ? this.page.target : null;
this.item.icon = this.isPageOption ? this.page.icon : siteIcon;
this.item.icon = this.icon;
this.item.type = this.isPageOption ? 'PAGE' : 'SITE';
this.item.properties = this.isPageOption ? {
siteId: this.siteId,
Expand Down

0 comments on commit f8d52e8

Please sign in to comment.