Commit 3b5ddc53 authored by oleg.pahhomov's avatar oleg.pahhomov

SA0140-537 | fix order for my widgets

parent 8c208338
......@@ -16,6 +16,8 @@ public interface UserWidgetRepository extends JpaRepository<UserWidget, Long> {
List<UserWidget> findByAppUserAndDashboardAndWidget(Long user, Long dashboard, Long widget);
List<UserWidget> findByAppUserAndDashboard(Long user, Long dashboard);
Optional<UserWidget> findByWidgetDomainAndAppUser(Long widgetDomain, Long user);
List<UserWidget> findAllByWidgetDomainIn(List<Long> widgetDomain);
......
......@@ -58,8 +58,7 @@ public class WidgetCustomRepositoryImpl implements WidgetCustomRepository {
return entityManager.createNativeQuery("" +
"SELECT w.* from widget w\n" +
"join dashboard_widget dw on w.id = dw.widget\n" +
"where dw.dashboard = :dashboard \n" +
"order by dw.id desc", Widget.class)
"where dw.dashboard = :dashboard \n", Widget.class)
.setParameter("dashboard", dashboard)
.getResultList();
}
......
......@@ -31,8 +31,8 @@ public class UserWidgetCopyService {
private UserLegendRepository userLegendRepository;
private UserLegendValueRepository userLegendValueRepository;
public void saveAsCopy(UserWidget userWidget, Dashboard myDashboard, DashboardWidget dashboardWidget) {
UserWidget newUserWidget = copy(userWidget, myDashboard, dashboardWidget);
public void saveAsCopy(UserWidget userWidget, Dashboard myDashboard, DashboardWidget dashboardWidget, int order) {
UserWidget newUserWidget = copy(userWidget, myDashboard, dashboardWidget, order);
List<UserGraphType> userGraphTypes = userGraphTypeRepository.findAllByUserWidget(userWidget.getId());
for (UserGraphType userGraphType : userGraphTypes) {
UserGraphType newUserGraph = copy(userGraphType, newUserWidget);
......@@ -51,13 +51,14 @@ public class UserWidgetCopyService {
}
}
private UserWidget copy(UserWidget existing, Dashboard reference, DashboardWidget dashboardWidget) {
private UserWidget copy(UserWidget existing, Dashboard reference, DashboardWidget dashboardWidget, int order) {
UserWidget newItem = new UserWidget();
BeanUtils.copyProperties(existing, newItem);
newItem.setId(null);
newItem.setDashboard(reference.getId());
newItem.setWidgetDomain(null);
newItem.setDashboardWidget(dashboardWidget.getId());
newItem.setOrderNr(order);
return userWidgetRepository.save(newItem);
}
......
......@@ -86,7 +86,8 @@ public class WidgetSaveService {
if (CollectionUtils.isEmpty(myDashboardUserWidgets)) {
List<UserWidget> userWidgetsOfPrevDashboard = userWidgetRepository.findByAppUserAndDashboardAndWidget(user.getId(), dashboard.getId(), widget.getId());
if (CollectionUtils.isNotEmpty(userWidgetsOfPrevDashboard)) {
userWidgetCopyService.saveAsCopy(first(userWidgetsOfPrevDashboard), myDashboard, dashboardWidget);
List<UserWidget> currentNrOfWidgets = userWidgetRepository.findByAppUserAndDashboard(user.getId(), myDashboard.getId());
userWidgetCopyService.saveAsCopy(first(userWidgetsOfPrevDashboard), myDashboard, dashboardWidget, currentNrOfWidgets.size() * -1);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment