This commit is contained in:
Zyzf 2023-02-20 14:46:21 +04:00
parent af95477935
commit 1b02121e6b
4 changed files with 27 additions and 24 deletions

View File

@ -15,28 +15,29 @@
</div>
<div class="mb-3">
<div class="form-check">
<input class="form-check-input" type="radio" name="radio" id="radioBold" checked>
<label class="form-check-label" for="radioBold">Undercase</label>
<input class="form-check-input" type="radio" name="radio" id="radioUppercase" checked>
<label class="form-check-label" for="radioUppercase">Undercase</label>
</div>
</div>
<div class="mb-3">
<div class="form-check">
<input class="form-check-input" type="radio" name="radio" id="radioCursive">
<label class="form-check-label" for="radioCursive">Lowcase</label>
<input class="form-check-input" type="radio" name="radio" id="radioLowcase">
<label class="form-check-label" for="radioLowcase">Lowcase</label>
</div>
</div>
<div class="mb-3">
<div class="form-check">
<input class="form-check-input" type="radio" name="radio" id="radioUnderline">
<label class="form-check-label" for="radioUnderline">Split</label>
<label for="input" class="form-label">Split by</label>
<input class="form-check-input" type="radio" name="radio" id="radioSplit">
<label class="form-check-label" for="radioSplit">Split</label>
<input type="text" class="form-control" id="inputSplitBy">
</div>
</div>
<div class="mb-3">
<div class="form-check">
<input class="form-check-input" type="radio" name="radio" id="radioCrossed">
<label class="form-check-label" for="radioCrossed">Перечеркнутый</label>
<input class="form-check-input" type="radio" name="radio" id="radioReplace">
<label class="form-check-label" for="radioReplace">Replace</label>
<input type="text" class="form-control" id="inputReplaceOld" maxlength="1">
<input type="text" class="form-control" id="inputReplaceNew" maxlength="1">
</div>
</div>
<button type="submit" class="btn btn-primary">Обработать</button>

View File

@ -15,27 +15,23 @@ document.addEventListener('DOMContentLoaded', function() {
document.getElementsByClassName("needs-validation")[0].addEventListener('submit', function(event) {
event.preventDefault();
if (document.getElementById("radioBold").checked) {
if (document.getElementById("radioUppercase").checked) {
fetch("http://localhost:8080/uppercase?value=" + document.getElementById("input").value)
.then(resp => {return resp.text()})
.then(resBody => {document.getElementById("result").innerHTML = resBody})
}
if (document.getElementById("radioCursive").checked) {
fetch("http://localhost:8080/lovercase?value=" + document.getElementById("input").value)
if (document.getElementById("radioLowcase").checked) {
fetch("http://localhost:8080/lowercase?value=" + document.getElementById("input").value)
.then(resp => {return resp.text()})
.then(resBody => {document.getElementById("result").innerHTML = resBody})
}
if (document.getElementById("radioUnderline").checked) {
if (document.getElementById("radioSplit").checked) {
fetch("http://localhost:8080/split?value=" + document.getElementById("input").value + "&splitBy=" + document.getElementById("inputSplitBy").value)
.then(resp => {return resp.text()})
.then(resBody => {
for (i = 0; i < resBody.length; i++) {
document.getElementById("result").innerHTML += resBody[i]
}
})
.then(resBody => {document.getElementById("result").innerHTML = resBody})
}
if (document.getElementById("radioCrossed").checked) {
fetch("http://localhost:8080/crossed?value=" + document.getElementById("input").value)
if (document.getElementById("radioReplace").checked) {
fetch("http://localhost:8080/replace?value=" + document.getElementById("input").value + "&old=" + document.getElementById("inputReplaceOld").value + "&new=" + document.getElementById("inputReplaceNew").value)
.then(resp => {return resp.text()})
.then(resBody => {document.getElementById("result").innerHTML = resBody})
}

View File

@ -8,8 +8,8 @@ import org.springframework.web.bind.annotation.RestController;
public class ReplaceController {
@GetMapping("/replace")
public String replace(@RequestParam(value = "value", defaultValue = "None") String value,
@RequestParam(value = "old", defaultValue = " ") char oldChar,
@RequestParam(value = "new", defaultValue = " ") char newChar) {
@RequestParam(value = "old", defaultValue = "") char oldChar,
@RequestParam(value = "new", defaultValue = "") char newChar) {
return value.replace(oldChar, newChar);
}
}

View File

@ -7,8 +7,14 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
public class SplitController {
@GetMapping("/split")
public String[] split(@RequestParam(value = "value", defaultValue = "None") String value,
public String split(@RequestParam(value = "value", defaultValue = "None") String value,
@RequestParam(value = "splitBy", defaultValue = " ") String splitBy) {
return value.split(splitBy);
String[] temp = value.split(splitBy);
String res = "";
for (int i = 0; i < temp.length; i++) {
res += temp[i];
res += "; ";
}
return res;
}
}