Skip to content

Commit 8e7176d

Browse files
author
th37rose
committed
Sort applications by position in bundle
1 parent 46aeb3c commit 8e7176d

File tree

7 files changed

+38
-19
lines changed

7 files changed

+38
-19
lines changed

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/bundle/service/BundleElementRelationServiceImpl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import reactor.core.publisher.Mono;
99

1010
import java.util.List;
11+
import java.util.Objects;
1112

1213
import static org.lowcoder.infra.birelation.BiRelationBizType.BUNDLE_ELEMENT;
1314

@@ -29,7 +30,17 @@ public Mono<Boolean> deleteByElementId(String elementId) {
2930

3031
@Override
3132
public Mono<Void> create(String bundleId, String elementId) {
32-
return biRelationService.addBiRelation(BUNDLE_ELEMENT, bundleId, elementId, null, null)
33+
return biRelationService.getBySourceId(BUNDLE_ELEMENT, bundleId)
34+
.mapNotNull(rel -> {
35+
try {
36+
return Integer.parseInt(rel.getExtParam1());
37+
} catch (NumberFormatException e) {
38+
return null;
39+
}
40+
})
41+
.reduce(Integer::max)
42+
.switchIfEmpty(Mono.just(0))
43+
.flatMap(maxVal -> biRelationService.addBiRelation(BUNDLE_ELEMENT, bundleId, elementId, null, null, String.valueOf(maxVal + 1)))
3344
.then();
3445
}
3546

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/bundle/service/BundleServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public Mono<Bundle> findById(String id) {
3838
}
3939

4040
return repository.findById(id)
41-
.switchIfEmpty(Mono.error(new BizException(BizError.NO_RESOURCE_FOUND, "FOLDER_NOT_FOUND", id)));
41+
.switchIfEmpty(Mono.error(new BizException(BizError.NO_RESOURCE_FOUND, "BUNDLE_NOT_FOUND", id)));
4242
}
4343

4444
@Override
45-
public Mono<Bundle> create(Bundle folder) {
46-
return repository.save(folder);
45+
public Mono<Bundle> create(Bundle bundle) {
46+
return repository.save(bundle);
4747
}
4848

4949
@Override

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/application/view/ApplicationInfoView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class ApplicationInfoView {
3636
private final boolean publicToAll;
3737
private final boolean publicToMarketplace;
3838
private final boolean agencyProfile;
39+
private final int bundlePosition;
3940

4041
public long getLastViewTime() {
4142
return lastViewTime == null ? 0 : lastViewTime.toEpochMilli();

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/BundleApiServiceImpl.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class BundleApiServiceImpl implements BundleApiService {
5555
// compare by last view time reversed.
5656
Comparator.comparingLong((ToLongFunction<Node<ApplicationInfoView, BundleInfoView>>) node -> {
5757
if (node instanceof ElementNode<ApplicationInfoView, BundleInfoView> elementNode) {
58-
return elementNode.getSelf().getLastViewTime();
58+
return elementNode.getSelf().getBundlePosition();
5959
}
6060
return ((BundleNode<ApplicationInfoView, BundleInfoView>) node).getSelf().getCreateTime();
6161
})
@@ -123,13 +123,12 @@ private Mono<Void> checkBundleNameUnique(String name, String userId) {
123123
}
124124

125125
/**
126-
* only org admin and bundle creator can delete a bundle, when bundle is deleted,
127-
* all sub bundles will be deleted, all sub files will be moved to root bundle
126+
* only org admin and bundle creator can delete a bundle
128127
*/
129128
@Override
130129
public Mono<Bundle> delete(@Nonnull String bundleId) {
131130
return checkManagePermission(bundleId)
132-
.flatMap(orgMember -> buildBundleTree(orgMember.getOrgId()))
131+
.flatMap(orgMember -> buildBundleTree(orgMember.getUserId()))
133132
.flatMap(tree -> {
134133
BundleNode<Object, Bundle> bundleNode = tree.get(bundleId);
135134
if (bundleNode == null) {
@@ -217,11 +216,8 @@ public Flux<?> getElements(@Nullable String bundleId, @Nullable ApplicationType
217216
return;
218217
}
219218
bundleInfoView.setManageable(orgMember.isAdmin() || orgMember.isSuperAdmin() || orgMember.getUserId().equals(bundleInfoView.getCreateBy()));
220-
221-
List<BundleInfoView> bundleInfoViews = bundleNode.getBundleChildren().stream().filter(BundleInfoView::isVisible).toList();
222-
bundleInfoView.setSubBundles(bundleInfoViews);
223219
bundleInfoView.setSubApplications(bundleNode.getElementChildren());
224-
bundleInfoView.setVisible(devOrAdmin || isNotEmpty(bundleInfoViews) || isNotEmpty(bundleInfoView.getSubApplications()));
220+
bundleInfoView.setVisible(devOrAdmin || isNotEmpty(bundleInfoView.getSubApplications()));
225221
}
226222
});
227223
})

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/BundleEndpoints.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public interface BundleEndpoints
5656
tags = TAG_BUNDLE_MANAGEMENT,
5757
operationId = "listBundleContents",
5858
summary = "Get Bundle contents",
59-
description = "Retrieve the contents of an Application Bundle within Lowcoder, including Applications and Subbundles."
59+
description = "Retrieve the contents of an Application Bundle within Lowcoder, including Applications."
6060
)
6161
@GetMapping("/elements")
6262
public Mono<ResponseView<List<?>>> getElements(@RequestParam(value = "id", required = false) String bundleId,

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/BundleInfoView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class BundleInfoView {
2828
private boolean isVisible;
2929
private boolean isManageable;
3030

31-
private List<BundleInfoView> subBundles;
3231
private List<ApplicationInfoView> subApplications;
3332

3433
private final Instant createTime;

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/home/UserHomeApiServiceImpl.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.lowcoder.domain.application.model.ApplicationStatus;
1414
import org.lowcoder.domain.application.model.ApplicationType;
1515
import org.lowcoder.domain.application.service.ApplicationService;
16+
import org.lowcoder.domain.bundle.model.BundleElement;
17+
import org.lowcoder.domain.bundle.service.BundleElementRelationServiceImpl;
1618
import org.lowcoder.domain.interaction.UserApplicationInteraction;
1719
import org.lowcoder.domain.interaction.UserApplicationInteractionService;
1820
import org.lowcoder.domain.organization.model.OrgMember;
@@ -59,6 +61,7 @@ public class UserHomeApiServiceImpl implements UserHomeApiService {
5961
private final FolderApiService folderApiService;
6062
private final UserApplicationInteractionService userApplicationInteractionService;
6163
private final CommonConfig config;
64+
private final BundleElementRelationServiceImpl bundleElementRelationServiceImpl;
6265

6366
@Override
6467
public Mono<UserProfileView> buildUserProfileView(User user, ServerWebExchange exchange) {
@@ -225,15 +228,23 @@ public Flux<ApplicationInfoView> getAllAuthorisedApplications4CurrentOrgMember(@
225228
Map<String, ResourcePermission> resourcePermissionMap = tuple.getT2();
226229
return resourcePermissionMap.containsKey(application.getId());
227230
})
228-
.map(tuple -> {
231+
.flatMap(tuple -> {
229232
// build view
230233
Application application = tuple.getT1();
231234
Map<String, ResourcePermission> resourcePermissionMap = tuple.getT2();
232235
Map<String, User> userMap = tuple.getT3();
233236
Map<String, Instant> applicationLastViewTimeMap = tuple.getT4();
234-
ResourceRole resourceRole = resourcePermissionMap.get(application.getId()).getResourceRole();
235-
return buildView(application, resourceRole, userMap, applicationLastViewTimeMap.get(application.getId()),
236-
withContainerSize);
237+
238+
return bundleElementRelationServiceImpl.getByElementIds(List.of(Objects.requireNonNull(application.getId())))
239+
.mapNotNull(BundleElement::position)
240+
.defaultIfEmpty(0)
241+
.collectList()
242+
.flatMap(positions -> {
243+
int position = positions.isEmpty() ? 0 : positions.get(0);
244+
ResourceRole resourceRole = resourcePermissionMap.get(application.getId()).getResourceRole();
245+
return Mono.just(buildView(application, resourceRole, userMap, applicationLastViewTimeMap.get(application.getId()),
246+
position, withContainerSize));
247+
});
237248
});
238249
});
239250
}
@@ -365,7 +376,7 @@ public Flux<MarketplaceApplicationInfoView> getAllAgencyProfileApplications(@Nul
365376
}
366377

367378
private ApplicationInfoView buildView(Application application, ResourceRole maxRole, Map<String, User> userMap, @Nullable Instant lastViewTime,
368-
boolean withContainerSize) {
379+
Integer bundlePosition, boolean withContainerSize) {
369380
ApplicationInfoViewBuilder applicationInfoViewBuilder = ApplicationInfoView.builder()
370381
.applicationId(application.getId())
371382
.orgId(application.getOrganizationId())
@@ -379,6 +390,7 @@ private ApplicationInfoView buildView(Application application, ResourceRole maxR
379390
.applicationStatus(application.getApplicationStatus())
380391
.lastModifyTime(application.getUpdatedAt())
381392
.lastViewTime(lastViewTime)
393+
.bundlePosition(bundlePosition)
382394
.publicToAll(application.isPublicToAll())
383395
.publicToMarketplace(application.isPublicToMarketplace())
384396
.agencyProfile(application.agencyProfile());

0 commit comments

Comments
 (0)