Skip to content

Commit 76175c1

Browse files
authored
Merge pull request #25 from windybirth/feature_for_chen
dynamice search option addtion / basic skill master page
2 parents ab57c4a + 34af163 commit 76175c1

File tree

7 files changed

+128
-52
lines changed

7 files changed

+128
-52
lines changed

skill/src/main/java/jp/wicresoft/controller/NewController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.springframework.ui.Model;
1010
import org.springframework.validation.BindingResult;
1111
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RequestMethod;
1213

1314
import jp.wicresoft.impl.NewImpl;
1415
import jp.wicresoft.info.IndexViewInfo;
@@ -29,7 +30,7 @@ public String loadPage(Model model) {
2930
return "new";
3031
}
3132

32-
@RequestMapping(value={"/new_add"})
33+
@RequestMapping(value = {"/new_add"}, method = RequestMethod.POST)
3334
public String addInfo(@Valid IndexViewInfo indexViewInfo, BindingResult bindingResult, Model model) {
3435
if (bindingResult.hasErrors()) {
3536
model.addAttribute("indexViewInfo", indexViewInfo);

skill/src/main/java/jp/wicresoft/controller/SearchController.java

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import org.springframework.stereotype.Controller;
1212
import org.springframework.ui.Model;
1313
import org.springframework.web.bind.annotation.RequestMapping;
14-
14+
import org.springframework.web.bind.annotation.RequestMethod;
15+
import org.springframework.web.bind.annotation.RequestParam;
1516
import jp.wicresoft.impl.SearchImpl;
1617
import jp.wicresoft.info.IndexViewInfo;
1718
import jp.wicresoft.info.SkillSearchInfo;
@@ -24,7 +25,7 @@ public class SearchController {
2425

2526
Logger logger = LoggerFactory.getLogger(NewController.class);
2627

27-
@RequestMapping(value={"/search"})
28+
@RequestMapping(value={"/search"}, method=RequestMethod.GET)
2829
public String loadPage(Model model) {
2930
model.addAttribute("page", "search");
3031
SkillSearchInfo skill = new SkillSearchInfo();
@@ -35,29 +36,27 @@ public String loadPage(Model model) {
3536
return "search";
3637
}
3738

38-
@RequestMapping(value={"/search_result"})
39+
@RequestMapping(value={"/search"}, method=RequestMethod.POST)
3940
public String loadPage(@Valid SkillSearchInfo skillSearchInfo, Model model) {
4041
logger.info("Search for: " + skillSearchInfo.getLsSkill());
4142
model.addAttribute("page", "search");
43+
if (skillSearchInfo.getLsSkill().isEmpty()) {
44+
// 検索条件がない場合
45+
model.addAttribute("skillSearchInfo", skillSearchInfo);
46+
model.addAttribute("skillOptions", searchImpl.getSkillNameList());
47+
return "search";
48+
}
4249

4350
try {
4451
List<Long> conditionList = new ArrayList<Long>();
4552
for (String skillIdStr : skillSearchInfo.getLsSkill()) {
4653
conditionList.add(Long.parseLong(skillIdStr));
4754
}
48-
if (conditionList.isEmpty()) {
49-
// 検索条件がない場合
50-
model.addAttribute("skillSearchInfo", skillSearchInfo);
51-
model.addAttribute("skillOptions", searchImpl.getSkillNameList());
52-
return "search";
53-
}
5455
List<IndexViewInfo> indexViewInfos = searchImpl.getSearchResultBySkill(conditionList);
55-
if (!indexViewInfos.isEmpty()) {
56-
// 結果を出す
57-
model.addAttribute("stuffMetas", indexViewInfos);
58-
model.addAttribute("category", "検索結果 ");
59-
return "stuff_info";
60-
}
56+
// 結果を出す
57+
model.addAttribute("stuffMetas", indexViewInfos);
58+
model.addAttribute("category", "検索結果 ");
59+
return "stuff_info";
6160
} catch (Exception e) {
6261
logger.info(e.getLocalizedMessage());
6362
}
@@ -66,4 +65,18 @@ public String loadPage(@Valid SkillSearchInfo skillSearchInfo, Model model) {
6665

6766
return "search";
6867
}
68+
69+
@RequestMapping(value={"/search_addSelect"}, method=RequestMethod.POST)
70+
public String addSelect(@RequestParam(value = "index", required = false) int index, Model model) {
71+
logger.info("Selector have now: " + String.valueOf(index));
72+
SkillSearchInfo skill = new SkillSearchInfo();
73+
74+
skill.setLsSkill(new ArrayList<String>());
75+
skill.getLsSkill().add("0");
76+
model.addAttribute("skillSearchInfo", skill);
77+
// set dynamic index
78+
model.addAttribute("index", index);
79+
model.addAttribute("skillOptions", searchImpl.getSkillNameList());
80+
return "search_subrow";
81+
}
6982
}

skill/src/main/java/jp/wicresoft/controller/SkillMasterController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class SkillMasterController {
1515

1616
@RequestMapping(value="/skill")
1717
public String skillView(Model model) {
18+
model.addAttribute("skills", skillMasterImpl.skillView());
1819
model.addAttribute("page", "master");
1920

2021
return "skill_view";
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
package jp.wicresoft.impl;
22

3+
import java.util.List;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
36
import org.springframework.stereotype.Component;
47

8+
import jp.wicresoft.domain.SkillTitleMst;
9+
import jp.wicresoft.repository.SkillTitleMstRepository;
10+
511
@Component
612
public class SkillMasterImpl {
713

8-
public void skillView() {
9-
14+
@Autowired
15+
SkillTitleMstRepository skillTitleMstRepository;
16+
17+
public List<SkillTitleMst> skillView() {
18+
List<SkillTitleMst> stuffMetas = skillTitleMstRepository.findAll();
19+
return stuffMetas;
1020
}
1121
}

skill/src/main/resources/templates/search.html

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
<div class="container">
2525
<h2 class="col-sm-offset-4 col-sm-8">スキル情報検索</h2>
2626

27-
<form class="form-horizontal" method="post" action="/search_result" th:object="${skillSearchInfo}">
27+
<form class="form-horizontal" method="post" action="/search" th:object="${skillSearchInfo}">
2828
<div class="selectList">
2929
<div class="form-group" th:each="row,rowStat : ${skillSearchInfo.lsSkill}">
3030
<label for="inputName" class="col-sm-4 control-label">スキル</label>
31-
<select th:field="${skillSearchInfo.lsSkill[__${rowStat.index}__]}"
32-
class="selectpicker" data-live-search="true"
31+
<select id="" th:field="${skillSearchInfo.lsSkill[__${rowStat.index}__]}"
32+
class="selectpicker dynamic-select" data-live-search="true"
3333
title="下記のスキルを選択してください">
3434
<optgroup label="資格">
3535
<option th:each="skill : ${skillOptions}"
@@ -73,9 +73,55 @@ <h2 class="col-sm-offset-4 col-sm-8">スキル情報検索</h2>
7373
$(document).ready(function() {
7474
// add row
7575
$("#addCondition").on("click",function(){
76-
var iteration = $('.selectList:last');
77-
iteration.clone(true).insertAfter(iteration);
78-
console.log(iteration.html());
76+
77+
// $.ajax({
78+
// type : "POST",
79+
// url : "/search_addSelect",
80+
// dataType : 'html',
81+
// cache: false,
82+
// timeout : 10000,
83+
// success : function(data) {
84+
// console.log();
85+
// var form = $('form');
86+
// console.log("SUCCESS: ", data);
87+
// form.html(data);
88+
// $('.selectpicker').selectpicker('render');
89+
// },
90+
// error : function(e) {
91+
// console.log("ERROR: ", e);
92+
// alert('サーバーとの通信で問題が発生しました。 後でもう一度お試しください。');
93+
// },
94+
// done : function(e) {
95+
// console.log("DONE");
96+
// }
97+
// });
98+
99+
$.ajax({
100+
type : "POST",
101+
url : "/search_addSelect",
102+
data: {
103+
"index": $("select.dynamic-select").length
104+
},
105+
dataType : 'html',
106+
cache: false,
107+
timeout : 10000,
108+
success : function(data) {
109+
console.log();
110+
var select = $('.selectList:last');
111+
console.log("SUCCESS: ", data);
112+
113+
select.after(data);
114+
$('.selectpicker').selectpicker('render');
115+
},
116+
error : function(e) {
117+
console.log("ERROR: ", e);
118+
alert('サーバーとの通信で問題が発生しました。 後でもう一度お試しください。');
119+
},
120+
done : function(e) {
121+
console.log("DONE");
122+
}
123+
});
124+
79125
});
80126
});
81127

skill/src/main/resources/templates/search_subrow.html

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,36 @@
22
<html lang="jp" xmlns:th="http://www.thymeleaf.org">
33
<head>
44
<meta charset="UTF-8">
5-
<title></title>
65
</head>
76
<body>
8-
<select th:field="${skillSearchInfo.lsSkill[__${rowStat.index}__]}"
9-
class="selectpicker" data-live-search="true" title="下記のスキルを選択してください">
10-
<optgroup label="資格">
11-
<option th:each="skill : ${skillOptions}"
12-
th:if="${skill.skillCategory==1}" th:value="${skill.skillTitleId}"
13-
th:text="${skill.titleName}"></option>
14-
</optgroup>
15-
<optgroup label="環境(OS)">
16-
<option th:each="skill : ${skillOptions}"
17-
th:if="${skill.skillCategory==2}" th:value="${skill.skillTitleId}"
18-
th:text="${skill.titleName}"></option>
19-
</optgroup>
20-
<optgroup label="DB">
21-
<option th:each="skill : ${skillOptions}"
22-
th:if="${skill.skillCategory==3}" th:value="${skill.skillTitleId}"
23-
th:text="${skill.titleName}"></option>
24-
</optgroup>
25-
<optgroup label="言語">
26-
<option th:each="skill : ${skillOptions}"
27-
th:if="${skill.skillCategory==4}" th:value="${skill.skillTitleId}"
28-
th:text="${skill.titleName}"></option>
29-
</optgroup>
30-
</select>
7+
<div class="selectList">
8+
<div class="form-group"
9+
th:each="row,rowStat : ${skillSearchInfo.lsSkill}">
10+
<label for="inputName" class="col-sm-4 control-label">スキル</label> <select
11+
th:field="${skillSearchInfo.lsSkill[__${index}__]}"
12+
class="selectpicker dynamic-select" data-live-search="true" title="下記のスキルを選択してください">
13+
<optgroup label="資格">
14+
<option th:each="skill : ${skillOptions}"
15+
th:if="${skill.skillCategory==1}" th:value="${skill.skillTitleId}"
16+
th:text="${skill.titleName}"></option>
17+
</optgroup>
18+
<optgroup label="環境(OS)">
19+
<option th:each="skill : ${skillOptions}"
20+
th:if="${skill.skillCategory==2}" th:value="${skill.skillTitleId}"
21+
th:text="${skill.titleName}"></option>
22+
</optgroup>
23+
<optgroup label="DB">
24+
<option th:each="skill : ${skillOptions}"
25+
th:if="${skill.skillCategory==3}" th:value="${skill.skillTitleId}"
26+
th:text="${skill.titleName}"></option>
27+
</optgroup>
28+
<optgroup label="言語">
29+
<option th:each="skill : ${skillOptions}"
30+
th:if="${skill.skillCategory==4}" th:value="${skill.skillTitleId}"
31+
th:text="${skill.titleName}"></option>
32+
</optgroup>
33+
</select>
34+
</div>
35+
</div>
3136
</body>
3237
</html>

skill/src/main/resources/templates/skill_view.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ <h2 class="col-sm-offset-4 col-sm-8">スキル マスター</h2>
2121
<tr>
2222
<th>#</th>
2323
<th>スキル</th>
24-
<th>詳細情報</th>
24+
<!-- <th>詳細情報</th> -->
2525
<th>操作</th>
2626
</tr>
2727
</thead>
2828
<tbody>
2929
<tr class="openRow" th:each="skill,iterStat : ${skills}">
30-
<th th:text="${skill.id}"></th>
31-
<td th:text="${skill.name}"></td>
32-
<td><a th:href="@{skill_edit} + '/' + ${skill.id}">Edit</a></td>
30+
<th th:text="${skill.skillTitleId}"></th>
31+
<td th:text="${skill.titleName}"></td>
32+
<td><a th:href="@{skill_edit} + '/' + ${skill.skillTitleId}">Edit</a></td>
3333
</tr>
3434
</tbody>
3535
</table>

0 commit comments

Comments
 (0)