commit 7f644dea33b8c7157b8df1d0fc68274251f518b0
Author: mlinha <mlinha@students.zcu.cz>
Date:   Sat May 2 22:38:39 2020 +0200

    re #7981 re #7979 re #7974 default table name added, assembly order implemented, parameter order in configuration implemented

diff --git a/src/main/java/vldc/aswi/dao/AssemblyRepository.java b/src/main/java/vldc/aswi/dao/AssemblyRepository.java
index e3661ae4..c89f624d 100644
--- a/src/main/java/vldc/aswi/dao/AssemblyRepository.java
+++ b/src/main/java/vldc/aswi/dao/AssemblyRepository.java
@@ -4,6 +4,8 @@ import org.springframework.data.repository.CrudRepository;
 import org.springframework.stereotype.Repository;
 import vldc.aswi.domain.Assembly;
 
+import java.util.List;
+
 /**
  * Repository for domain Assembly.
  */
@@ -23,4 +25,10 @@ public interface AssemblyRepository extends CrudRepository<Assembly, Long> {
      * @return Assembly with highest order.
      */
     Assembly findFirst1ByOrderByAssemblyOrder();
+
+    /**
+     * Find assemblies order by order
+     * @return ordered assemblies
+     */
+    List<Assembly> getByOrderByAssemblyOrderAsc();
 }
diff --git a/src/main/java/vldc/aswi/service/AssemblyManager.java b/src/main/java/vldc/aswi/service/AssemblyManager.java
index 177522e0..67528712 100644
--- a/src/main/java/vldc/aswi/service/AssemblyManager.java
+++ b/src/main/java/vldc/aswi/service/AssemblyManager.java
@@ -17,6 +17,12 @@ public interface AssemblyManager {
      */
     List<Assembly> getAssemblies();
 
+    /**
+     * Get all Assemblies from database by order.
+     * @return List of assemblies.
+     */
+    List<Assembly> getAssembliesOrdered();
+
     /**
      * Get assembly by id.
      * @param id - ID of assembly.
@@ -32,11 +38,10 @@ public interface AssemblyManager {
     Long updateAssembly(Assembly updatedAssemblyValues);
 
     /**
-     * Update assembly's order.
-     * @param id - ID of assembly.
-     * @param order - Assembly's order.
+     * Update assembly order.
+     * @param data - sorted IDs.
      */
-    void updateAssemblyOrder(Long id, int order);
+    void updateAssemblyOrder(String data);
 
     /**
      * Create new assembly.
diff --git a/src/main/java/vldc/aswi/service/AssemblyManagerImpl.java b/src/main/java/vldc/aswi/service/AssemblyManagerImpl.java
index 7f21b880..47be775f 100644
--- a/src/main/java/vldc/aswi/service/AssemblyManagerImpl.java
+++ b/src/main/java/vldc/aswi/service/AssemblyManagerImpl.java
@@ -68,6 +68,15 @@ public class AssemblyManagerImpl implements AssemblyManager {
         return retVal;
     }
 
+    /**
+     * Get all Assemblies from database ordered.
+     * @return List of assemblies.
+     */
+    @Override
+    public List<Assembly> getAssembliesOrdered() {
+        return this.assemblyRepository.getByOrderByAssemblyOrderAsc();
+    }
+
     /**
      * Get assembly by id.
      * @param id - ID of assembly.
@@ -81,15 +90,17 @@ public class AssemblyManagerImpl implements AssemblyManager {
     }
 
     /**
-     * Update assembly's order.
-     * @param id - ID of assembly.
-     * @param order - Assembly's order.
+     * Update assembly order.
+     * @param data - sorted IDs.
      */
     @Override
-    public void updateAssemblyOrder(Long id, int order) {
-        Assembly assembly = getAssemblyById(id);
-        assembly.setAssemblyOrder(order);
-        this.assemblyRepository.save(assembly);
+    public void updateAssemblyOrder(String data) {
+        String[] idOrder = data.split(",");
+        for (int i = 0; i < idOrder.length; i++) {
+            Assembly assembly = getAssemblyById(Long.valueOf(idOrder[i]));
+            assembly.setAssemblyOrder(i + 1);
+            this.assemblyRepository.save(assembly);
+        }
     }
 
     /**
diff --git a/src/main/java/vldc/aswi/service/ConfigurationManagerImpl.java b/src/main/java/vldc/aswi/service/ConfigurationManagerImpl.java
index 0ecf4a4f..260d151d 100644
--- a/src/main/java/vldc/aswi/service/ConfigurationManagerImpl.java
+++ b/src/main/java/vldc/aswi/service/ConfigurationManagerImpl.java
@@ -170,13 +170,16 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
         for(int i = 0; i < newConfiguration.getParametersInConfiguration().size(); i++) {
             ParameterInConfiguration parameterInConfiguration = new ParameterInConfiguration();
             parameterInConfiguration.setParameter(assembly.getParameters().get(i));
-            parameterInConfiguration.setColumnName(newConfiguration.getParametersInConfiguration().get(i).getColumnName());
             parameterInConfiguration.setConfiguration(savedConfiguration);
             parameterInConfiguration.setOperatorValue(newConfiguration.getParametersInConfiguration().get(i).getOperatorValue());
             parameterInConfiguration.setColumnName(assembly.getParameters().get(i).getName());
+            if(newConfiguration.getParametersInConfiguration().get(i).getColumnName() != null &&
+                    !newConfiguration.getParametersInConfiguration().get(i).getColumnName().equals("")) {
+                parameterInConfiguration.setColumnName(newConfiguration.getParametersInConfiguration().get(i).getColumnName());
+            }
             if(newConfiguration.getParametersInConfiguration().get(i).getLocation() != null) {
-                parameterInConfiguration.setLocation(locationRepository.getByName(
-                        newConfiguration.getParametersInConfiguration().get(i).getLocation().getName()));
+                parameterInConfiguration.setLocation(locationRepository.getById(
+                        newConfiguration.getParametersInConfiguration().get(i).getLocation().getId()));
             }
             if(newConfiguration.getParametersInConfiguration().get(i).getOperator() != null) {
                 parameterInConfiguration.setOperator(operatorRepository.getByName(
@@ -211,12 +214,16 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
         for(int i = 0; i < configuration.getParametersInConfiguration().size(); i++) {
             ParameterInConfiguration parameterInConfiguration = configuration.getParametersInConfiguration().get(i);
             parameterInConfiguration.setOperatorValue(newConfiguration.getParametersInConfiguration().get(i).getOperatorValue());
-            if(newConfiguration.getParametersInConfiguration().get(i).getColumnName() != null) {
+            if(newConfiguration.getParametersInConfiguration().get(i).getColumnName() != null &&
+                    !newConfiguration.getParametersInConfiguration().get(i).getColumnName().equals("")) {
                 parameterInConfiguration.setColumnName(newConfiguration.getParametersInConfiguration().get(i).getColumnName());
             }
             if(newConfiguration.getParametersInConfiguration().get(i).getLocation() != null) {
-                parameterInConfiguration.setLocation(locationRepository.getByName(
-                        newConfiguration.getParametersInConfiguration().get(i).getLocation().getName()));
+                parameterInConfiguration.setLocation(locationRepository.getById(
+                        newConfiguration.getParametersInConfiguration().get(i).getLocation().getId()));
+            }
+            else {
+                parameterInConfiguration.setLocation(null);
             }
             if(newConfiguration.getParametersInConfiguration().get(i).getOperator() != null) {
                 parameterInConfiguration.setOperator(operatorRepository.getByName(
diff --git a/src/main/java/vldc/aswi/web/controller/AssemblyController.java b/src/main/java/vldc/aswi/web/controller/AssemblyController.java
index f96f8e39..b244a6ec 100644
--- a/src/main/java/vldc/aswi/web/controller/AssemblyController.java
+++ b/src/main/java/vldc/aswi/web/controller/AssemblyController.java
@@ -106,6 +106,7 @@ public class AssemblyController extends BasicController {
         Configuration configuration = new Configuration();
 
         configuration.setAssembly(assembly);
+        configuration.setTableName(assembly.getName());
         configuration.setParametersInConfiguration(new ArrayList<>());
         for(Parameter parameter : assembly.getParameters()) {
             ParameterInConfiguration parameterInConfiguration = new ParameterInConfiguration();
@@ -117,7 +118,6 @@ public class AssemblyController extends BasicController {
         }
 
         modelMap.addAttribute("configuration", configuration);
-        modelMap.addAttribute("isAssembly", false);
 
         return modelAndView;
     }
diff --git a/src/main/java/vldc/aswi/web/controller/ConfigurationController.java b/src/main/java/vldc/aswi/web/controller/ConfigurationController.java
index 61219097..607a0af2 100644
--- a/src/main/java/vldc/aswi/web/controller/ConfigurationController.java
+++ b/src/main/java/vldc/aswi/web/controller/ConfigurationController.java
@@ -45,7 +45,6 @@ public class ConfigurationController extends BasicController{
         initializeFields(configuration);
 
         modelMap.addAttribute("configuration", configuration);
-        modelMap.addAttribute("isAssembly", "0");
 
         return modelAndView;
     }
diff --git a/src/main/java/vldc/aswi/web/controller/IndexController.java b/src/main/java/vldc/aswi/web/controller/IndexController.java
index 6da9ba6b..5a744493 100644
--- a/src/main/java/vldc/aswi/web/controller/IndexController.java
+++ b/src/main/java/vldc/aswi/web/controller/IndexController.java
@@ -54,7 +54,7 @@ public class IndexController extends BasicController {
 
 		ModelMap modelMap = modelAndView.getModelMap();
 
-		List<Assembly> assemblies = assemblyManager.getAssemblies();
+		List<Assembly> assemblies = assemblyManager.getAssembliesOrdered();
 
 
 		modelMap.addAttribute("assemblies", assemblies);
@@ -101,11 +101,11 @@ public class IndexController extends BasicController {
 
 		return attributes;
 	}
+
 	@ResponseBody
 	@RequestMapping("/saveOrder")
 	public String saveOrder(@RequestBody String data) {
-		// seřazený idčka záznamů
-		System.out.println(data);
+		assemblyManager.updateAssemblyOrder(data);
 
 		return "Ok";
 	}
diff --git a/src/main/webapp/WEB-INF/templates/assembly.html b/src/main/webapp/WEB-INF/templates/assembly.html
index 4d299d8b..2f72d78c 100644
--- a/src/main/webapp/WEB-INF/templates/assembly.html
+++ b/src/main/webapp/WEB-INF/templates/assembly.html
@@ -65,24 +65,24 @@
                             </td>
                             <td class="select-action-buttons">
                                 <optional th:each="location : ${parameterInConfiguration.parameter.locations}">
-                                <span th:if="${location.name?.equals('Řádek')}"
+                                    <span th:if="${location.name?.equals('Řádek')}"
                                       th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].location.name}"
                                       class="select-action-padding select-action-button select-input-action-margin-collapse unselectable row-button"
                                       th:classappend="(${configuration.parametersInConfiguration[__${itemStat.index}__].location.name?.equals('Řádek')}) ? select-action-headlight"  >
-                                  <i class="fas fa-align-justify"></i>
-                                </span>
+                                        <i class="fas fa-align-justify"></i>
+                                    </span>
                                     <span th:if="${location.name?.equals('Sloupec')}"
                                           th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].location.name}"
                                           class="select-action-padding select-action-button select-input-action-margin-collapse unselectable column-button"
                                           th:classappend="(${configuration.parametersInConfiguration[__${itemStat.index}__].location.name?.equals('Sloupec')}) ? select-action-headlight">
-                                  <i class="fas fa-align-justify transform"></i>
-                                </span>
+                                        <i class="fas fa-align-justify transform"></i>
+                                    </span>
                                     <span th:if="${location.name?.equals('Hodnota')}"
                                           th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].location.name}"
                                           class="select-action-padding select-action-button select-input-action-margin-collapse unselectable value-button"
                                           th:classappend="(${configuration.parametersInConfiguration[__${itemStat.index}__].location.name?.equals('Hodnota')}) ? select-action-headlight">
-                                    <i class="fas fa-heading"></i>
-                                </span>
+                                        <i class="fas fa-heading"></i>
+                                    </span>
                                 </optional>
                             </td>
                             <td class="s">
@@ -124,7 +124,8 @@
                             </thead>
                             <tbody id="row-wrapper" class="sortable">
                             <tr th:each="parameterInConfiguration, itemStat : ${configuration.parametersInConfiguration}" th:if="${parameterInConfiguration.location.name?.equals('Řádek')}" class="row-parameter parameter">
-                                <input type="hidden" th:field="${configuration.parametersInConfiguration[__${i.index}__].locations}">
+                                <input type="hidden" th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].location.id}" value="1">
+                                <input type="hidden" th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].order}">
                                 <td>
                                     <span class="parameter-name" th:text="${parameterInConfiguration.parameter.name}"></span>
                                 </td>
@@ -156,7 +157,7 @@
                             <tbody id="column-wrapper" class="sortable">
                             <tr th:each="parameterInConfiguration, itemStat : ${configuration.parametersInConfiguration}" th:if="${parameterInConfiguration.location.name?.equals('Sloupec')}" class="column-parameter parameter">
                                 <input type="hidden" th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].location.id}" value="2">
-
+                                <input type="hidden" th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].order}">
                                 <td>
                                     <span class="parameter-name" th:text="${parameterInConfiguration.parameter.name}"></span>
                                 </td>
@@ -186,8 +187,8 @@
                             </thead>
                             <tbody id="value-wrapper">
                             <tr th:each="parameterInConfiguration, itemStat : ${configuration.parametersInConfiguration}" th:if="${parameterInConfiguration.location.name?.equals('Hodnota')}" class="value-parameter parameter">
-                                <input type="hidden" th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].location.id}">
-
+                                <input type="hidden" th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].location.id}" value="3">
+                                <input type="hidden" th:field="${configuration.parametersInConfiguration[__${itemStat.index}__].order}">
                                 <td>
                                     <span class="parameter-name" th:text="${parameterInConfiguration.parameter.name}"></span>
                                 </td>
