diff --git a/src/main/java/ru/ulstu/fc/project/service/ProjectVariableService.java b/src/main/java/ru/ulstu/fc/project/service/ProjectVariableService.java index 1ad8658..ad8b281 100644 --- a/src/main/java/ru/ulstu/fc/project/service/ProjectVariableService.java +++ b/src/main/java/ru/ulstu/fc/project/service/ProjectVariableService.java @@ -29,13 +29,13 @@ public class ProjectVariableService { if (projectId == null || projectId == 0) { return Collections.emptyList(); } - return variableRepository.findInputByProject(projectService.getById(projectId)); + return variableRepository.getInputByProject(projectService.getById(projectId)); } public List getOutputByProjectId(Integer projectId) { if (projectId == null || projectId == 0) { return Collections.emptyList(); } - return variableRepository.findOutputByProject(projectService.getById(projectId)); + return variableRepository.getOutputByProject(projectService.getById(projectId)); } } diff --git a/src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleController.java b/src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleController.java index 4ae9a30..e13f1c6 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/FuzzyRuleController.java @@ -71,6 +71,22 @@ public class FuzzyRuleController { return variableService.getAllDtoByProject(projectId); } + @ResponseBody + @GetMapping("/getInputVariables/{projectId}") + public List getInputVariables(@PathVariable("projectId") Integer projectId, + final HttpServletResponse response) { + response.addHeader("Cache-Control", "max-age=60, must-revalidate, no-transform"); + return variableService.getInputVariablesDtoByProject(projectId); + } + + @ResponseBody + @GetMapping("/getOutputVariables/{projectId}") + public List getOutputVariables(@PathVariable("projectId") Integer projectId, + final HttpServletResponse response) { + response.addHeader("Cache-Control", "max-age=60, must-revalidate, no-transform"); + return variableService.getOutputVariablesDtoByProject(projectId); + } + @ResponseBody @GetMapping("/getFuzzyTerms/{variableId}") public List getTerms(@PathVariable("variableId") Integer variableId, diff --git a/src/main/java/ru/ulstu/fc/rule/repository/VariableRepository.java b/src/main/java/ru/ulstu/fc/rule/repository/VariableRepository.java index ae56a66..881ce65 100644 --- a/src/main/java/ru/ulstu/fc/rule/repository/VariableRepository.java +++ b/src/main/java/ru/ulstu/fc/rule/repository/VariableRepository.java @@ -15,8 +15,8 @@ public interface VariableRepository extends JpaRepository { List getByProject(Project project); @Query("SELECT v FROM Variable v WHERE v.project = :project AND v.input = true") - List findInputByProject(@Param("project") Project project); + List getInputByProject(@Param("project") Project project); @Query("SELECT v FROM Variable v WHERE v.project = :project AND v.input = false") - List findOutputByProject(@Param("project") Project project); + List getOutputByProject(@Param("project") Project project); } diff --git a/src/main/java/ru/ulstu/fc/rule/service/VariableService.java b/src/main/java/ru/ulstu/fc/rule/service/VariableService.java index 44e94c3..93e3f94 100644 --- a/src/main/java/ru/ulstu/fc/rule/service/VariableService.java +++ b/src/main/java/ru/ulstu/fc/rule/service/VariableService.java @@ -80,4 +80,18 @@ public class VariableService { public void checkIsCurrentUserVariableWithThrow(Variable variable) { projectService.checkIsCurrentUserProjectWithThrow(variable.getProject()); } + + public List getInputVariablesDtoByProject(Integer projectId) { + return variableRepository.getInputByProject(projectService.getById(projectId)) + .stream() + .map(VariableDto::new) + .toList(); + } + + public List getOutputVariablesDtoByProject(Integer projectId) { + return variableRepository.getOutputByProject(projectService.getById(projectId)) + .stream() + .map(VariableDto::new) + .toList(); + } } diff --git a/src/main/resources/public/js/fuzzyRule.js b/src/main/resources/public/js/fuzzyRule.js index 9838bd7..da67636 100644 --- a/src/main/resources/public/js/fuzzyRule.js +++ b/src/main/resources/public/js/fuzzyRule.js @@ -62,15 +62,12 @@ function errorHandler(response, callBack, errorCallBack) { } /* exported getFromRest */ -function getFromRest(url, callBack) { - $.ajax({ +async function getFromRest(url) { + return await $.ajax({ url: url, method: 'get', cache: true, - dataType: 'json', - success: function (response) { - errorHandler(response, callBack); - } + dataType: 'json' }); } @@ -112,60 +109,63 @@ function fillSelect(selectElement, values, selectedVal) { $(selectElement).append($("