diff --git a/src/main/java/com/eactive/httpmockserver/ApiManageController.java b/src/main/java/com/eactive/httpmockserver/ApiManageController.java index c7e0dd2..3700125 100644 --- a/src/main/java/com/eactive/httpmockserver/ApiManageController.java +++ b/src/main/java/com/eactive/httpmockserver/ApiManageController.java @@ -4,6 +4,7 @@ import java.util.Optional; import javax.validation.Valid; +import com.eactive.httpmockserver.script.ScriptInfoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpMethod; @@ -21,6 +22,9 @@ public class ApiManageController { @Autowired private ApiService apiService; + @Autowired + private ScriptInfoService scriptInfoService; + @Autowired private ApiServiceKeyService apiKeyService; @@ -47,6 +51,8 @@ public class ApiManageController { model.addAttribute("apiInfo", apiInfo); } + model.addAttribute("scriptInfos", scriptInfoService.findAllScriptInfos()); + return "page/add-edit-api"; } diff --git a/src/main/java/com/eactive/httpmockserver/script/Script.java b/src/main/java/com/eactive/httpmockserver/script/Script.java index c4ce9ad..87a4fb7 100644 --- a/src/main/java/com/eactive/httpmockserver/script/Script.java +++ b/src/main/java/com/eactive/httpmockserver/script/Script.java @@ -2,5 +2,12 @@ package com.eactive.httpmockserver.script; public interface Script { + /** + * Script Process Function + * @param requestMessage 수신 받은 요청 메시지 + * @param responseMessage 정의된 응답 메시지 + * @return 스크립트 수행 후 응답 할 메시지 + * @throws Exception + */ public String postProcess(String requestMessage, String responseMessage) throws Exception; } diff --git a/src/main/resources/basecodes/BaseScript.java.template b/src/main/resources/basecodes/BaseScript.java.template index 14b19e6..dad1a83 100644 --- a/src/main/resources/basecodes/BaseScript.java.template +++ b/src/main/resources/basecodes/BaseScript.java.template @@ -1,8 +1,15 @@ package com.eactive.httpmockserver.script.dynamic; import com.eactive.httpmockserver.script.Script; +//IMPORT 클래스는 여기에 정의해 주세요 public class implements Script{ - @Override + /** + * Script Process Function + * @param requestMessage 수신 받은 요청 메시지 + * @param responseMessage 정의된 응답 메시지 + * @return 스크립트 수행 후 응답 할 메시지 + * @throws Exception + */ public String postProcess(String requestMessage, String responseMessage) throws Exception { return responseMessage; } diff --git a/src/main/resources/templates/page/add-edit-api.html b/src/main/resources/templates/page/add-edit-api.html index 0b403a6..d3253b1 100644 --- a/src/main/resources/templates/page/add-edit-api.html +++ b/src/main/resources/templates/page/add-edit-api.html @@ -159,9 +159,9 @@
- +
@@ -230,6 +230,11 @@ + + + + + @@ -238,6 +243,11 @@ @@ -114,33 +117,65 @@ wrappingIndent: 'none', automaticLayout: true }); - const readonlyRange = new monaco.Range (1, 0, 7, 0) - editor.onKeyDown (e => { - const contains = editor.getSelections().findIndex (range => readonlyRange.intersectRanges (range)) - let currentLineNumber = editor.getPosition().lineNumber - let lineCount = editor.getModel().getLineCount(); - console.log(e.ctrlKey) - if(e.ctrlKey && e.keyCode == 33){ - return - } - switch(e.keyCode){ - case 13: - case 14: - case 15: - case 16: - case 17: - case 18: - case 63: - return - } - const matchTailPart = lineCount == currentLineNumber || lineCount - 1 == currentLineNumber; - if (contains !== -1 || matchTailPart) { - e.stopPropagation () - e.preventDefault () // for Ctrl+C, Ctrl+V - return false; + const constrainedInstance = constrainedEditor(monaco); + constrainedInstance.initializeIn(editor); + const model = editor.getModel(); + let editableLine = 14 + + const linesContent = editor.getModel().getLinesContent(); + for (let i = 0; i < linesContent.length; i++) { + const lineText = linesContent[i].trim(); + + if(lineText.startsWith('public String postProcess')){ + editableLine = i + 2 + break } - }); + } + + const editableLineTextLength = linesContent[editableLine - 1].length + 1; + + constrainedInstance.addRestrictionsTo(model, [{ + // range : [ startLine, startColumn, endLine, endColumn ] + range: [3, 1, 3, 26], // Range of Util Variable name + label: 'import', + allowMultiline: true + }, { + range: [editableLine, 1, editableLine, editableLineTextLength], // Range of Function definition + allowMultiline: true, + label: 'funcDefinition' + }]); + model.toggleHighlightOfEditableAreas(); + + + + // const readonlyRange = new monaco.Range (1, 0, 7, 0) + // editor.onKeyDown (e => { + // const contains = editor.getSelections().findIndex (range => readonlyRange.intersectRanges (range)) + // let currentLineNumber = editor.getPosition().lineNumber + // let lineCount = editor.getModel().getLineCount(); + // console.log(e.ctrlKey) + // if(e.ctrlKey && e.keyCode == 33){ + // return + // } + // switch(e.keyCode){ + // case 13: + // case 14: + // case 15: + // case 16: + // case 17: + // case 18: + // case 63: + // return + // } + // + // const matchTailPart = lineCount == currentLineNumber || lineCount - 1 == currentLineNumber; + // if (contains !== -1 || matchTailPart) { + // e.stopPropagation () + // e.preventDefault () // for Ctrl+C, Ctrl+V + // return false; + // } + // }); $('#form').submit(function(eventObj) { $('#scriptName').prop( "disabled", false );