Save separate appLayout for edit/view and sync on publish (#3245)

This commit is contained in:
Shrikant Sharat Kandula 2021-02-26 16:18:04 +05:30 committed by GitHub
parent 1f7fc9c0ed
commit a1d027bb59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 4 deletions

View File

@ -53,7 +53,11 @@ public class Application extends BaseDomain {
String icon;
AppLayout appLayout;
@JsonIgnore
AppLayout unpublishedAppLayout;
@JsonIgnore
AppLayout publishedAppLayout;
// This constructor is used during clone application. It only deeply copies selected fields. The rest are either
// initialized newly or is left up to the calling function to set.
@ -65,14 +69,28 @@ public class Application extends BaseDomain {
this.clonedFromApplicationId = application.getId();
this.color = application.getColor();
this.icon = application.getIcon();
this.appLayout = application.getAppLayout() == null ? null
: new AppLayout(application.getAppLayout().type, application.getAppLayout().getWidth());
this.unpublishedAppLayout = application.getUnpublishedAppLayout() == null ? null
: new AppLayout(application.getUnpublishedAppLayout().type, application.getUnpublishedAppLayout().getWidth());
this.publishedAppLayout = application.getPublishedAppLayout() == null ? null
: new AppLayout(application.getPublishedAppLayout().type, application.getPublishedAppLayout().getWidth());
}
public List<ApplicationPage> getPages() {
return Boolean.TRUE.equals(viewMode) ? publishedPages : pages;
}
public AppLayout getAppLayout() {
return Boolean.TRUE.equals(viewMode) ? publishedAppLayout : unpublishedAppLayout;
}
public void setAppLayout(AppLayout appLayout) {
if (Boolean.TRUE.equals(viewMode)) {
publishedAppLayout = appLayout;
} else {
unpublishedAppLayout = appLayout;
}
}
@Data
@NoArgsConstructor
@AllArgsConstructor

View File

@ -451,7 +451,7 @@ public class ApplicationPageServiceImpl implements ApplicationPageService {
// Create a new clone application object without the pages using the parametrized Application constructor
Application newApplication = new Application(sourceApplication);
newApplication.setName(newName);
Mono<User> userMono = sessionUserService.getCurrentUser().cache();
// First set the correct policies for the new cloned application
return setApplicationPolicies(userMono, sourceApplication.getOrganizationId(), newApplication)
@ -602,6 +602,8 @@ public class ApplicationPageServiceImpl implements ApplicationPageService {
application.setPublishedPages(pages);
application.setPublishedAppLayout(application.getUnpublishedAppLayout());
// Archive the deleted pages and save the application changes and then return the pages so that
// the pages can also be published
return Mono.zip(archivePageListMono, applicationService.save(application))

View File

@ -697,6 +697,7 @@ public class ApplicationServiceTest {
Application testApplication = new Application();
String appName = "ApplicationServiceTest Publish Application";
testApplication.setName(appName);
testApplication.setAppLayout(new Application.AppLayout(Application.AppLayout.Type.FIXED, 1024));
Mono<Application> applicationMono = applicationPageService.createApplication(testApplication, orgId)
.flatMap(application -> applicationPageService.publish(application.getId()))
.then(applicationService.findByName(appName, MANAGE_APPLICATIONS))
@ -726,6 +727,8 @@ public class ApplicationServiceTest {
assertThat(newPage.getUnpublishedPage().getName()).isEqualTo(newPage.getPublishedPage().getName());
assertThat(newPage.getUnpublishedPage().getLayouts().get(0).getId()).isEqualTo(newPage.getPublishedPage().getLayouts().get(0).getId());
assertThat(newPage.getUnpublishedPage().getLayouts().get(0).getDsl()).isEqualTo(newPage.getPublishedPage().getLayouts().get(0).getDsl());
assertThat(application.getPublishedAppLayout()).isEqualTo(application.getUnpublishedAppLayout());
})
.verifyComplete();
}