Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
二牛 committed Apr 29, 2022
1 parent 7465978 commit 497be3a
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hhwyz.orderedtasklist.controller;

import com.alibaba.fastjson.JSON;
import com.hhwyz.orderedtasklist.dto.TaskDTO;
import com.hhwyz.orderedtasklist.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -34,9 +35,14 @@ public void fav() {

}

@PostMapping("/killTask")
public void killTask(String taskUuid) {
taskService.killTask(taskUuid);
}

@PostMapping("/addTaskToBufferedList")
public void addTaskToBufferedList(@RequestBody String task) {
taskService.addTaskToBufferedList(task);
taskService.addTaskToBufferedList(JSON.parseObject(task, String.class));
}

@GetMapping("/getTwoToCompare")
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/hhwyz/orderedtasklist/dto/TaskDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import lombok.Data;

import java.util.UUID;

/**
* @author erniu.wzh
* @date 2022/4/28 17:42
*/
@Data
public class TaskDTO {
private String taskContent;
private String taskUuid;

public TaskDTO(String taskContent) {
this.taskContent = taskContent;
}

public TaskDTO() {
this.taskUuid = UUID.randomUUID().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface TaskService {
void setCompare(int flag);

void clear();

void killTask(String taskUuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,29 @@ public void clear() {
taskServiceDTO.setTaskOrderedList(new ArrayList<>());
taskServiceDTO.setTaskBufferedList(new ArrayList<>());
}

@Override
public void killTask(String taskUuid) {
List<TaskDTO> bufferedList = taskServiceDTO.getTaskBufferedList();
killFromList(taskUuid, bufferedList);
List<TaskDTO> orderedList = taskServiceDTO.getTaskOrderedList();
killFromList(taskUuid, orderedList);
}

private void killFromList(String taskUuid, List<TaskDTO> list) {
int killIndex = -1;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getTaskUuid().equals(taskUuid)) {
killIndex = i;
break;
}
}
if (killIndex != -1) {
list.remove(killIndex);
taskServiceDTO.setTaskAIndex(-1);
taskServiceDTO.setTaskBIndex(-1);
taskServiceDTO.setLeftIndex(0);
taskServiceDTO.setRightIndex(taskServiceDTO.getTaskOrderedList().size() - 1);
}
}
}
5 changes: 5 additions & 0 deletions src/main/resources/static/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.myBorder {
border: 1px solid #187543;
/*padding:14px;*/
/*border-radius: 16px;*/
}
150 changes: 24 additions & 126 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,140 +2,38 @@
<html lang="zh">

<head>
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet">
<meta charset="utf-8" content="user-scalable=no, width=device-width, initial-scale=1.0" name="viewport"/>
<title>我的空间</title>
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet">
<link href="index.css" rel="stylesheet">
<meta charset="utf-8" content="user-scalable=no, width=device-width, initial-scale=1.0" name="viewport"/>
<title>我的空间</title>
</head>

<body>
<div class="container">
<div class="row">
<div class="col">
<input autofocus id="newTask">
<div class="container border">
<div class="row justify-content-center border">
<div class="col">
<input autofocus id="newTask">
</div>
<div class="col">
<button class="btn btn-outline-dark" id="submitTask" type="button">submitTask</button>
</div>
<div class="col">
<button class="btn btn-outline-dark" id="clear" type="button">clear</button>
</div>
</div>
<div class="col">
<button id="submitTask">submitTask</button>
<div class="row justify-content-center border" id="compare"></div>
<div class="row justify-content-center border">
<div class="col">
<dl id="ordered"></dl>
</div>
<div class="col">
<dl id="buffered"></dl>
</div>
</div>
<div class="col">
<button id="clear">clear</button>
</div>
</div>
<div class="row" id="compare">
</div>
<div class="row">
<div class="col">
<dl id="ordered"></dl>
</div>
<div class="col">
<dl id="buffered"></dl>
</div>
</div>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
<script>
function init() {
$.ajax({
url: "/getTwoToCompare",
type: "GET",
async: false,
success: function (data) {
if (data) {
$('#compare').empty()
.append("<div class=\"col\">\n" +
" <button id=\"taskA\">" + data[0].taskContent + "</button>\n" +
" </div>")
.append("<div class=\"col\">\n" +
" <button id=\"taskB\">" + data[1].taskContent + "</button>\n" +
" </div>");
}
}
});
$.ajax({
url: "/getOrderedTaskList",
type: "GET",
success: function (data) {
if (data) {
data.forEach(element => {
$("#ordered").append("<dt>" + element.taskContent + "</dt>")
});
}
}
});
$.ajax({
url: "/getBufferedTaskList",
type: "GET",
success: function (data) {
if (data) {
data.forEach(element => {
$("#buffered").append("<dt>" + element.taskContent + "</dt>")
});
}
}
});

}

$(document).ready(init());
$('#submitTask').click(function () {
$.ajax({
url: "/addTaskToBufferedList",
type: "POST",
async: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify($("#newTask").val())
});
window.location.reload();
});

$('#clear').click(function () {
$.ajax({
url: "/clear",
type: "GET",
async: false
});
window.location.reload();
});

$(document).on('click', '#taskA', function () {
$.ajax({
url: "/setCompare",
type: "POST",
async: false,
data: {
flag: 0
}
});
window.location.reload();
});

$(document).on('click', '#taskB', function () {
$.ajax({
url: "/setCompare",
type: "POST",
async: false,
data: {
flag: 1
}
});
window.location.reload();
});

document.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
$('#submitTask').click();
}
if (event.key === "ArrowLeft") {
$('#taskA').click();
}
if (event.key === "ArrowRight") {
$('#taskB').click();
}
});


</script>
<script src="index.js"></script>
</body>

</html>
89 changes: 89 additions & 0 deletions src/main/resources/static/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
function init() {
$.ajax({
url: "/getTwoToCompare", type: "GET", async: false, success: function (data) {
if (data) {
$('#compare').empty()
.append("<div class=\"col\">\n" + " <button class=\"btn btn-outline-dark\" type=\"button\" id=\"taskA\">" + data[0].taskContent + "</button>\n" + " </div>")
.append("<div class=\"col\">\n" + " <button class=\"btn btn-outline-dark\" type=\"button\" id=\"taskB\">" + data[1].taskContent + "</button>\n" + " </div>");
}
}
});
$.ajax({
url: "/getOrderedTaskList", type: "GET", success: function (data) {
if (data) {
data.forEach(element => {
$("#ordered").append("<dt><button class=\"btn btn-outline-dark\" type=\"button\" id='kill' name='" + element.taskUuid + "'>X</button>" + element.taskContent + "</dt>")
});
}
}
});
$.ajax({
url: "/getBufferedTaskList", type: "GET", success: function (data) {
if (data) {
data.forEach(element => {
$("#buffered").append("<dt><button class=\"btn btn-outline-dark\" type=\"button\" id='kill' name='" + element.taskUuid + "'>X</button>" + element.taskContent + "</dt>")
});
}
}
});

}

$(document).ready(init());
$('#submitTask').click(function () {
$.ajax({
url: "/addTaskToBufferedList",
type: "POST",
async: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify($("#newTask").val())
});
window.location.reload();
});

$('#clear').click(function () {
$.ajax({
url: "/clear", type: "GET", async: false
});
window.location.reload();
});

$(document).on("click", "#kill", function () {
$.ajax({
url: "/killTask", type: "POST", async: false, data: {
taskUuid: $(this).attr("name")
}
});
window.location.reload();
})

$(document).on('click', '#taskA', function () {
$.ajax({
url: "/setCompare", type: "POST", async: false, data: {
flag: 0
}
});
window.location.reload();
});

$(document).on('click', '#taskB', function () {
$.ajax({
url: "/setCompare", type: "POST", async: false, data: {
flag: 1
}
});
window.location.reload();
});

document.addEventListener("keydown", function (event) {
if (event.keyCode === 13) {
$('#submitTask').click();
}
if (event.key === "ArrowLeft") {
$('#taskA').click();
}
if (event.key === "ArrowRight") {
$('#taskB').click();
}
});

0 comments on commit 497be3a

Please sign in to comment.