Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/admin/fiori-service.cds
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ annotate AdminService.Books with @(UI : {
},
{
// TODO: should work dynamically
@UI.Hidden,
$Type : 'UI.ReferenceFacet',
Label : '{i18n>Contents}',
Target : 'contents/@UI.PresentationVariant'
Target : 'contents/@UI.PresentationVariant',
![@UI.Hidden] : contentsHidden
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we can also refer to a Singleton entity here.


}
],
FieldGroup #General : {Data : [
Expand Down
1 change: 1 addition & 0 deletions db/books.cds
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ entity Books : cuid, managed {
on reviews.book = $self;
isReviewable : TechnicalBooleanFlag not null default true;
contents : Composition of many Contents on contents.book = $self @odata.contained:false;
virtual contentsHidden : Boolean default false;
}

entity Authors : cuid, managed {
Expand Down
38 changes: 38 additions & 0 deletions srv/src/main/java/my/bookshop/handlers/SetHiddenHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package my.bookshop.handlers;


import java.util.List;
import java.util.Map;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import com.sap.cds.services.EventContext;
import com.sap.cds.services.handler.EventHandler;
import com.sap.cds.services.handler.annotations.After;
import com.sap.cds.services.handler.annotations.On;
import com.sap.cds.services.handler.annotations.ServiceName;

import cds.gen.adminservice.AdminService_;
import cds.gen.adminservice.Books_;

@Component
@ServiceName(AdminService_.CDS_NAME)
/**
* Example of a custom handler for nextSiblingAction
*/
@Profile("hybrid")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in other areas we are using cloud

public class SetHiddenHandler implements EventHandler {

@After(entity = Books_.CDS_NAME)
void removeUIHidden(EventContext context){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should be able to use Result in the method signature.

Object result = context.get("result");
if (result instanceof Map row) {
row.put("contentsHidden", true);
} else if (result instanceof List rows && rows.size() == 1) {
((Map)rows.get(0)).put("contentsHidden", true);
}
}
}