Skip to content

Commit

Permalink
Merged PR 30491: Add configurable icon for static pages
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimnielandt committed Dec 12, 2023
2 parents 8b501ac + 8a710fe commit 31f221e
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 9 deletions.
13 changes: 12 additions & 1 deletion domain/src/main/java/org/fao/geonet/domain/page/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ public class Page extends GeonetEntity implements Serializable {
private PageStatus status;

private String label;
private String icon;

public Page() {

}

public Page(PageIdentity pageIdentity, byte[] data, String link, PageFormat format, List<PageSection> sections, PageStatus status, String label) {
public Page(PageIdentity pageIdentity, byte[] data, String link, PageFormat format, List<PageSection> sections, PageStatus status, String label, String icon) {
super();
this.pageIdentity = pageIdentity;
this.data = data;
Expand All @@ -72,6 +73,7 @@ public Page(PageIdentity pageIdentity, byte[] data, String link, PageFormat form
this.sections = sections;
this.status = status;
this.label = label;
this.icon = icon;
}

public enum PageStatus {
Expand Down Expand Up @@ -139,6 +141,11 @@ public String getLabel() {
return label;
}

@Column
public String getIcon() {
return icon;
}

public void setPageIdentity(PageIdentity pageIdentity) {
this.pageIdentity = pageIdentity;
}
Expand Down Expand Up @@ -167,6 +174,10 @@ public void setLabel(String label) {
this.label = label;
}

public void setIcon(String icon) {
this.icon = icon;
}

@Override
public String toString() {
return String.format("Entity of type %s with id: %s", this.getClass().getName(), getPageIdentity().getLinkText());
Expand Down
10 changes: 10 additions & 0 deletions liquibase/changesets/00041-page-icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.20.xsd">
<changeSet id="00041-page-icon" author="joachim">
<addColumn tableName="spg_page">
<column name="icon" type="varchar"/>
</addColumn>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class PageProperties implements Serializable {
private String link;
private String content;
private String label;
private String icon;
private Page.PageFormat format;
private Page page;

Expand All @@ -34,6 +35,7 @@ public PageProperties(Page p) {
sections = p.getSections();
status = p.getStatus();
label = p.getLabel();
icon = p.getIcon();
}

@Override
Expand Down Expand Up @@ -104,4 +106,12 @@ public String getLabel() {
public void setLabel(String label) {
this.label = label;
}

public String getIcon() {
return icon;
}

public void setIcon(String icon) {
this.icon = icon;
}
}
19 changes: 11 additions & 8 deletions services/src/main/java/org/fao/geonet/api/pages/PagesAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ private ResponseEntity<String> createPage(PageProperties pageProperties,

Optional<Page> page = pageRepository.findById(new PageIdentity(language, pageId));

if (!page.isPresent()) {
Page newPage = getEmptyHiddenDraftPage(pageProperties.getLanguage(), pageProperties.getPageId(), pageProperties.getLabel(), format);
if (page.isEmpty()) {
Page newPage = getEmptyHiddenDraftPage(pageProperties.getLanguage(), pageProperties.getPageId(), pageProperties.getLabel(), pageProperties.getIcon(), format);
fillContent(data, link, content, newPage);

if (section != null) {
Expand Down Expand Up @@ -201,6 +201,7 @@ private ResponseEntity<Void> updatePageInternal(@NotNull String language,
String newPageId = pageProperties.getPageId();
Page.PageFormat format = pageProperties.getFormat();
String newLabel = pageProperties.getLabel();
String newIcon = pageProperties.getIcon();

checkValidLanguage(language);

Expand All @@ -214,7 +215,7 @@ private ResponseEntity<Void> updatePageInternal(@NotNull String language,

Optional<Page> page = pageRepository.findById(new PageIdentity(language, pageId));

if (!page.isPresent()) {
if (page.isEmpty()) {
throw new ResourceNotFoundException("Can't update non existing page " + pageId + ".");
}
Page pageToUpdate = page.get();
Expand All @@ -238,7 +239,8 @@ private ResponseEntity<Void> updatePageInternal(@NotNull String language,
format != null ? format : pageToUpdate.getFormat(),
pageProperties.getSections() != null ? pageProperties.getSections() : pageToUpdate.getSections(),
pageProperties.getStatus() != null ? pageProperties.getStatus() : pageToUpdate.getStatus(),
newLabel != null ? newLabel : pageToUpdate.getLabel());
newLabel != null ? newLabel : pageToUpdate.getLabel(),
newIcon != null ? newIcon : pageToUpdate.getIcon());

pageRepository.save(pageCopy);
pageRepository.delete(pageToUpdate);
Expand All @@ -248,6 +250,7 @@ private ResponseEntity<Void> updatePageInternal(@NotNull String language,
pageToUpdate.setSections(pageProperties.getSections() != null ? pageProperties.getSections() : pageToUpdate.getSections());
pageToUpdate.setStatus(pageProperties.getStatus() != null ? pageProperties.getStatus() : pageToUpdate.getStatus());
pageToUpdate.setLabel(newLabel);
pageToUpdate.setIcon(newIcon);
pageRepository.save(pageToUpdate);
}

Expand Down Expand Up @@ -339,7 +342,7 @@ public ResponseEntity<String> getPageContent(

final Optional<Page> page = pageRepository.findById(new PageIdentity(language, pageId));

if (!page.isPresent()) {
if (page.isEmpty()) {
return ResponseEntity.notFound().build();
}

Expand Down Expand Up @@ -522,7 +525,7 @@ private Page searchPage(final String language, final String pageId, final PageRe
throws ResourceNotFoundException {
final Optional<Page> page = pageRepository.findById(new PageIdentity(language, pageId));

if (!page.isPresent()) {
if (page.isEmpty()) {
throw new ResourceNotFoundException("Page " + pageId + " not found");
}
return page.get();
Expand All @@ -531,9 +534,9 @@ private Page searchPage(final String language, final String pageId, final PageRe
/**
* @return An empty hidden draft Page
*/
protected Page getEmptyHiddenDraftPage(final String language, final String pageId, final String label, final Page.PageFormat format) {
protected Page getEmptyHiddenDraftPage(final String language, final String pageId, final String label, final String icon, final Page.PageFormat format) {
final List<Page.PageSection> sections = new ArrayList<>();
return new Page(new PageIdentity(language, pageId), null, null, format, sections, Page.PageStatus.HIDDEN, label);
return new Page(new PageIdentity(language, pageId), null, null, format, sections, Page.PageStatus.HIDDEN, label, icon);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void putPage() throws Exception {
newPage.setPageId(pageId);
newPage.setLink(link + "updated");
newPage.setLabel(pageId + "updated");
newPage.setIcon("dummy-icon");
newPage.getSections().add(Page.PageSection.FOOTER);
MockHttpServletRequestBuilder updatePageBuilder = put("/srv/api/pages/eng/license")
.content(gson.toJson(newPage))
Expand All @@ -123,6 +124,7 @@ public void putPage() throws Exception {
Assert.assertTrue(page.isPresent());
Assert.assertEquals(link + "updated", page.get().getLink());
Assert.assertEquals(pageId + "updated", page.get().getLabel());
Assert.assertEquals("dummy-icon", page.get().getIcon());
Assert.assertTrue(page.get().getSections().contains(Page.PageSection.TOP));
Assert.assertTrue(page.get().getSections().contains(Page.PageSection.FOOTER));

Expand Down
5 changes: 5 additions & 0 deletions vlaanderen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [8.1.9-SNAPSHOT]

### vlaanderen

### core-geonetwork
- Configurable icon for static pages - [pr](https://agiv.visualstudio.com/Metadata/_git/MetadataGeonetwork/pullrequest/30491) / [pr-core](https://github.com/geonetwork/core-geonetwork/pull/7536)

## [8.1.8] - 2023-12-08
- Added custom mailing to workflow notifications - [pr1](https://agiv.visualstudio.com/Metadata/_git/MetadataGeonetwork/pullrequest/30315) / [pr2](https://agiv.visualstudio.com/Metadata/_git/MetadataGeonetwork/pullrequest/30496)
- Header/footer improvements, responsiveness - [pr](https://agiv.visualstudio.com/DefaultCollection/Metadata/_git/MetadataGeonetwork/pullrequest/29987)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
aria-haspopup="true"
aria-expanded="true"
>
<span
data-ng-show="page.icon && page.icon.length > 0"
class="fa fa-fw {{page.icon}}"
></span>
<span>{{page.label}}</span>
<span class="caret hidden-xs"></span>
</a>
Expand All @@ -23,6 +27,10 @@
href="{{page.link}}"
target="{{page.link.indexOf('http') === 0 ? '_blank' : '_self'}}"
>
<span
data-ng-show="page.icon && page.icon.length > 0"
class="fa fa-fw {{page.icon}}"
></span>
<span>{{page.label}}</span>
</a>
<a
Expand All @@ -31,6 +39,10 @@
title="{{page.pageId}}"
data-ng-click="changePage($event)"
>
<span
data-ng-show="page.icon && page.icon.length > 0"
class="fa fa-fw {{page.icon}}"
></span>
<span>{{page.label}}</span>
</a>
</li>
Expand All @@ -42,6 +54,10 @@
href="{{page.link}}"
target="_blank"
>
<span
data-ng-show="page.icon && page.icon.length > 0"
class="fa fa-fw {{page.icon}}"
></span>
<span>{{page.label}}</span>
</a>
<a
Expand All @@ -51,6 +67,10 @@
title="{{page.pageId}}"
data-ng-click="changePage($event)"
>
<span
data-ng-show="page.icon && page.icon.length > 0"
class="fa fa-fw {{page.icon}}"
></span>
<span>{{page.label}}</span>
</a>
</li>
2 changes: 2 additions & 0 deletions web-ui/src/main/resources/catalog/locales/en-custom.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@
"---below-to-be-transifexed---": "all labels are pending to be either incorporated into the core or to be deleted at some point",
"approvedRecord": "Approved record",
"measureDate": "Date",
"pageIcon": "Page icon",
"pageIcon-help": "Optionally, define a <a target='_blank' href='https://fontawesome.com/v4/icons/'>font-awesome icon</a>. Example: 'fa-wrench'.",
"---end-of-file---": ""
}
2 changes: 2 additions & 0 deletions web-ui/src/main/resources/catalog/locales/en-v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@
"pageContent": "Page content",
"pageContentFile": "Page content file",
"pageLabel": "Page label",
"pageIcon": "Page icon",
"pageIcon-help": "Optionally, define a <a target='_blank' href='https://fontawesome.com/v4/icons/'>font-awesome icon</a>. Example: 'fa-wrench'.",
"pageSection": "Page section",
"pageApiLink": "Page API link",
"uiRestorePrevious": "Restore last saved",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,23 @@
</div>
</div>

<div class="form-group">
<label class="control-label col-sm-3" data-translate="">pageIcon</label>

<div class="col-sm-9">
<input
type="text"
name="label"
class="form-control"
data-ng-model="staticPageSelected.icon"
/>
</div>

<div class="col-sm-9 col-sm-offset-3">
<p class="help-block ng-scope" data-translate="">pageIcon-help</p>
</div>
</div>

<div class="form-group">
<label class="control-label col-sm-3" data-translate="">format</label>

Expand Down

0 comments on commit 31f221e

Please sign in to comment.