Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil-Nandagopal committed Aug 21, 2020
2 parents b184197 + 5756e6b commit 112e907
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.appsmith.server.acl.AclPermission;
import com.appsmith.server.domains.Application;
import com.appsmith.server.domains.Page;
import com.mongodb.client.result.UpdateResult;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand All @@ -21,6 +20,8 @@ public interface CustomApplicationRepository extends AppsmithRepository<Applicat

Flux<Application> findByClonedFromApplicationId(String applicationId, AclPermission permission);

Mono<UpdateResult> addPageToApplication(Application application, Page page, boolean isDefault);
Mono<UpdateResult> addPageToApplication(String applicationId, String pageId, boolean isDefault);

Mono<UpdateResult> setDefaultPage(String applicationId, String pageId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.appsmith.server.constants.FieldName;
import com.appsmith.server.domains.Application;
import com.appsmith.server.domains.ApplicationPage;
import com.appsmith.server.domains.Page;
import com.appsmith.server.domains.QApplication;
import com.mongodb.client.result.UpdateResult;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
import org.springframework.data.mongodb.core.convert.MongoConverter;
Expand Down Expand Up @@ -73,13 +73,30 @@ public Flux<Application> findByClonedFromApplicationId(String applicationId, Acl
}

@Override
public Mono<UpdateResult> addPageToApplication(Application application, Page page, boolean isDefault) {
final ApplicationPage applicationPage = new ApplicationPage(page.getId(), isDefault);
public Mono<UpdateResult> addPageToApplication(String applicationId, String pageId, boolean isDefault) {
final ApplicationPage applicationPage = new ApplicationPage(pageId, isDefault);
return mongoOperations.updateFirst(
Query.query(getIdCriteria(application.getId())),
Query.query(getIdCriteria(applicationId)),
new Update().addToSet(FieldName.PAGES, applicationPage),
Application.class
);
}

@Override
public Mono<UpdateResult> setDefaultPage(String applicationId, String pageId) {
final Mono<UpdateResult> setAllAsNonDefaultMono = mongoOperations.updateFirst(
Query.query(getIdCriteria(applicationId)).addCriteria(Criteria.where("pages.isDefault").is(true)),
new Update().set("pages.$.isDefault", false),
Application.class
);

final Mono<UpdateResult> setDefaultMono = mongoOperations.updateFirst(
Query.query(getIdCriteria(applicationId)).addCriteria(Criteria.where("pages._id").is(new ObjectId(pageId))),
new Update().set("pages.$.isDefault", true),
Application.class
);

return setAllAsNonDefaultMono.then(setDefaultMono);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public Mono<Page> createPage(Page page) {
*/
@Override
public Mono<UpdateResult> addPageToApplication(Application application, Page page, Boolean isDefault) {
return applicationRepository.addPageToApplication(application, page, isDefault)
return applicationRepository.addPageToApplication(application.getId(), page.getId(), isDefault)
.doOnSuccess(result -> {
if (result.getModifiedCount() != 1) {
log.error("Add page to application didn't update anything, probably because application wasn't found.");
Expand Down Expand Up @@ -195,14 +195,11 @@ public Mono<Application> makePageDefault(String applicationId, String pageId) {
})
.then(applicationService.findById(applicationId))
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.APPLICATION_ID, applicationId)))
.flatMap(application -> {
List<ApplicationPage> pages = application.getPages();

// We are guaranteed to find the pageId in this list.
pages.forEach(page -> page.setIsDefault(page.getId().equals(pageId)));

return applicationService.save(application);
});
.flatMap(application ->
applicationRepository
.setDefaultPage(applicationId, pageId)
.then(applicationService.getById(applicationId))
);
}

@Override
Expand Down
Binary file modified static/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 112e907

Please sign in to comment.