Skip to content

Commit ecbf0bb

Browse files
authored
Merge pull request #29 from windybirth/feature_for_chen
Add skill selector to new page
2 parents dde41ad + fd578a2 commit ecbf0bb

File tree

13 files changed

+222
-101
lines changed

13 files changed

+222
-101
lines changed
Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package jp.wicresoft.controller;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
36
import javax.validation.Valid;
47

58
import org.slf4j.Logger;
@@ -12,33 +15,59 @@
1215
import org.springframework.web.bind.annotation.RequestMethod;
1316

1417
import jp.wicresoft.impl.NewImpl;
18+
import jp.wicresoft.impl.SkillSelectImpl;
1519
import jp.wicresoft.info.IndexViewInfo;
20+
import jp.wicresoft.info.SkillSelectInfo;
1621

1722
@Controller
1823
public class NewController {
1924

2025
@Autowired
2126
NewImpl newImpl;
2227

28+
@Autowired
29+
SkillSelectImpl skillSelectImpl;
30+
2331
Logger logger = LoggerFactory.getLogger(NewController.class);
2432

2533
@RequestMapping(value={"/new"})
2634
public String loadPage(Model model) {
2735
IndexViewInfo indexViewInfo = new IndexViewInfo();
2836
model.addAttribute("indexViewInfo", indexViewInfo);
2937
model.addAttribute("page", "new");
38+
// add skill select
39+
SkillSelectInfo skill = new SkillSelectInfo();
40+
skill.setLsSkill(new ArrayList<String>());
41+
skill.getLsSkill().add("0");
42+
model.addAttribute("skillSelectInfo", skill);
43+
model.addAttribute("skillOptions", skillSelectImpl.getSkillNameList());
3044
return "new";
3145
}
3246

3347
@RequestMapping(value = {"/new_add"}, method = RequestMethod.POST)
34-
public String addInfo(@Valid IndexViewInfo indexViewInfo, BindingResult bindingResult, Model model) {
35-
if (bindingResult.hasErrors()) {
36-
model.addAttribute("indexViewInfo", indexViewInfo);
37-
model.addAttribute("page", "new");
38-
return "new";
48+
public String addInfo(@Valid IndexViewInfo indexViewInfo, BindingResult bindingResult, @Valid SkillSelectInfo skillSelectInfo, Model model) {
49+
if (!bindingResult.hasErrors()) {
50+
logger.info("Add skill : " + skillSelectInfo.getLsSkill());
51+
try {
52+
// convert skill id to integer
53+
List<Integer> skillIdList = new ArrayList<Integer>();
54+
for (String skillIdStr : skillSelectInfo.getLsSkill()) {
55+
skillIdList.add(Integer.parseInt(skillIdStr));
56+
}
57+
logger.info("Add stuff: " + indexViewInfo.getName());
58+
newImpl.addOneStuff(indexViewInfo, skillIdList);
59+
return "redirect:all_stuff";
60+
} catch (Exception e) {
61+
logger.info(e.getLocalizedMessage());
62+
}
63+
3964
}
40-
logger.info("Add stuff: " + indexViewInfo.getName());
41-
newImpl.addOneStuff(indexViewInfo);
42-
return "redirect:all_stuff";
65+
66+
model.addAttribute("indexViewInfo", indexViewInfo);
67+
model.addAttribute("page", "new");
68+
// add skill select
69+
model.addAttribute("skillSelectInfo", skillSelectInfo);
70+
model.addAttribute("skillOptions", skillSelectImpl.getSkillNameList());
71+
return "new";
4372
}
4473
}

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,46 @@
1414
import org.springframework.web.bind.annotation.RequestMethod;
1515
import org.springframework.web.bind.annotation.RequestParam;
1616
import jp.wicresoft.impl.SearchImpl;
17+
import jp.wicresoft.impl.SkillSelectImpl;
1718
import jp.wicresoft.info.IndexViewInfo;
18-
import jp.wicresoft.info.SkillSearchInfo;
19+
import jp.wicresoft.info.SkillSelectInfo;
1920

2021
@Controller
2122
public class SearchController {
2223

2324
@Autowired
2425
SearchImpl searchImpl;
2526

27+
@Autowired
28+
SkillSelectImpl skillSelectImpl;
29+
2630
Logger logger = LoggerFactory.getLogger(NewController.class);
2731

2832
@RequestMapping(value={"/search"}, method=RequestMethod.GET)
2933
public String loadPage(Model model) {
3034
model.addAttribute("page", "search");
31-
SkillSearchInfo skill = new SkillSearchInfo();
35+
SkillSelectInfo skill = new SkillSelectInfo();
3236
skill.setLsSkill(new ArrayList<String>());
3337
skill.getLsSkill().add("0");
34-
model.addAttribute("skillSearchInfo", skill);
35-
model.addAttribute("skillOptions", searchImpl.getSkillNameList());
38+
model.addAttribute("skillSelectInfo", skill);
39+
model.addAttribute("skillOptions", skillSelectImpl.getSkillNameList());
3640
return "search";
3741
}
3842

3943
@RequestMapping(value={"/search"}, method=RequestMethod.POST)
40-
public String loadPage(@Valid SkillSearchInfo skillSearchInfo, Model model) {
41-
logger.info("Search for: " + skillSearchInfo.getLsSkill());
44+
public String loadPage(@Valid SkillSelectInfo skillSelectInfo, Model model) {
45+
logger.info("Search for: " + skillSelectInfo.getLsSkill());
4246
model.addAttribute("page", "search");
43-
if (skillSearchInfo.getLsSkill().isEmpty()) {
47+
if (skillSelectInfo.getLsSkill().isEmpty()) {
4448
// 検索条件がない場合
45-
model.addAttribute("skillSearchInfo", skillSearchInfo);
46-
model.addAttribute("skillOptions", searchImpl.getSkillNameList());
49+
model.addAttribute("skillSelectInfo", skillSelectInfo);
50+
model.addAttribute("skillOptions", skillSelectImpl.getSkillNameList());
4751
return "search";
4852
}
4953

5054
try {
5155
List<Integer> conditionList = new ArrayList<Integer>();
52-
for (String skillIdStr : skillSearchInfo.getLsSkill()) {
56+
for (String skillIdStr : skillSelectInfo.getLsSkill()) {
5357
conditionList.add(Integer.parseInt(skillIdStr));
5458
}
5559
List<IndexViewInfo> indexViewInfos = searchImpl.getSearchResultBySkill(conditionList);
@@ -60,23 +64,23 @@ public String loadPage(@Valid SkillSearchInfo skillSearchInfo, Model model) {
6064
} catch (Exception e) {
6165
logger.info(e.getLocalizedMessage());
6266
}
63-
model.addAttribute("skillSearchInfo", skillSearchInfo);
64-
model.addAttribute("skillOptions", searchImpl.getSkillNameList());
67+
model.addAttribute("skillSelectInfo", skillSelectInfo);
68+
model.addAttribute("skillOptions", skillSelectImpl.getSkillNameList());
6569

6670
return "search";
6771
}
6872

6973
@RequestMapping(value={"/search_addSelect"}, method=RequestMethod.POST)
7074
public String addSelect(@RequestParam(value = "index", required = false) int index, Model model) {
7175
logger.info("Selector have now: " + String.valueOf(index));
72-
SkillSearchInfo skill = new SkillSearchInfo();
76+
SkillSelectInfo skill = new SkillSelectInfo();
7377

7478
skill.setLsSkill(new ArrayList<String>());
7579
skill.getLsSkill().add("0");
76-
model.addAttribute("skillSearchInfo", skill);
80+
model.addAttribute("skillSelectInfo", skill);
7781
// set dynamic index
7882
model.addAttribute("index", index);
79-
model.addAttribute("skillOptions", searchImpl.getSkillNameList());
80-
return "search_subrow";
83+
model.addAttribute("skillOptions", skillSelectImpl.getSkillNameList());
84+
return "skill_select";
8185
}
8286
}
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
package jp.wicresoft.impl;
22

3+
import java.util.List;
4+
5+
import javax.transaction.Transactional;
6+
37
import org.springframework.beans.factory.annotation.Autowired;
48
import org.springframework.stereotype.Component;
59

610
import jp.wicresoft.domain.StuffMeta;
11+
import jp.wicresoft.domain.StuffSkill;
712
import jp.wicresoft.info.IndexViewInfo;
813
import jp.wicresoft.repository.StuffMetaRepository;
14+
import jp.wicresoft.repository.StuffSkillRepository;
915

1016
@Component
1117
public class NewImpl {
1218

1319
@Autowired
1420
StuffMetaRepository stuffMetaRepository;
1521

16-
public void addOneStuff(IndexViewInfo indexViewInfo) {
22+
@Autowired
23+
StuffSkillRepository stuffSkillRepository;
24+
25+
@Transactional
26+
public void addOneStuff(IndexViewInfo indexViewInfo, List<Integer> skillIdList) {
1727
StuffMeta stuffMeta = indexViewInfo.toStuffMeta();
18-
stuffMetaRepository.saveAndFlush(stuffMeta);
28+
StuffMeta result = stuffMetaRepository.saveAndFlush(stuffMeta);
29+
int stuffId = result.getId();
30+
for (Integer skillId : skillIdList) {
31+
stuffSkillRepository.saveAndFlush(new StuffSkill(stuffId, skillId));
32+
}
1933
}
2034
}

skill/src/main/java/jp/wicresoft/impl/SearchImpl.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,20 @@
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.stereotype.Component;
88

9-
import jp.wicresoft.domain.SkillTitleMst;
109
import jp.wicresoft.domain.StuffMeta;
1110
import jp.wicresoft.info.IndexViewInfo;
1211
import jp.wicresoft.jdbc.SkillSearchJdbcTemplate;
13-
import jp.wicresoft.repository.SkillTitleMstRepository;
1412
import jp.wicresoft.repository.StuffMetaRepository;
1513

1614
@Component
1715
public class SearchImpl {
1816

19-
@Autowired
20-
SkillTitleMstRepository skillTitleMstRepository;
21-
2217
@Autowired
2318
StuffMetaRepository stuffMetaRepository;
2419

2520
@Autowired
2621
SkillSearchJdbcTemplate skillSearchJdbcTemplate;
2722

28-
public List<SkillTitleMst> getSkillNameList() {
29-
return skillTitleMstRepository.findAll();
30-
}
31-
3223
public List<IndexViewInfo> getSearchResultBySkill(List<Integer> titleIds) {
3324
List<StuffMeta> stuffMetas = skillSearchJdbcTemplate.findByIds(titleIds);
3425
List<IndexViewInfo> indexViewInfos = new ArrayList<>();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package jp.wicresoft.impl;
2+
3+
import java.util.List;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.stereotype.Component;
7+
8+
import jp.wicresoft.domain.SkillTitleMst;
9+
import jp.wicresoft.repository.SkillTitleMstRepository;
10+
11+
@Component
12+
public class SkillSelectImpl {
13+
14+
@Autowired
15+
SkillTitleMstRepository skillTitleMstRepository;
16+
17+
public List<SkillTitleMst> getSkillNameList() {
18+
return skillTitleMstRepository.findAll();
19+
}
20+
}

skill/src/main/java/jp/wicresoft/info/SkillSearchInfo.java renamed to skill/src/main/java/jp/wicresoft/info/SkillSelectInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import lombok.Data;
66

77
@Data
8-
public class SkillSearchInfo {
8+
public class SkillSelectInfo {
99

1010
List<String> lsSkill;
1111
}

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,42 @@ <h2 class="col-sm-offset-4 col-sm-8">スキル情報新規</h2>
7373
</div>
7474
</div>
7575
</div>
76+
<!-- select area -->
77+
<div class="selectList">
78+
<div class="form-group" th:each="row,rowStat : ${skillSelectInfo.lsSkill}">
79+
<label for="inputName" class="col-sm-4 control-label">スキル</label>
80+
<select id="" th:field="${skillSelectInfo.lsSkill[__${rowStat.index}__]}"
81+
class="selectpicker dynamic-select" data-live-search="true"
82+
title="下記のスキルを選択してください">
83+
<optgroup label="資格">
84+
<option th:each="skill : ${skillOptions}"
85+
th:if="${skill.skillCategory==1}"
86+
th:value="${skill.skillTitleId}" th:text="${skill.titleName}"></option>
87+
</optgroup>
88+
<optgroup label="環境(OS)">
89+
<option th:each="skill : ${skillOptions}"
90+
th:if="${skill.skillCategory==2}"
91+
th:value="${skill.skillTitleId}" th:text="${skill.titleName}"></option>
92+
</optgroup>
93+
<optgroup label="DB">
94+
<option th:each="skill : ${skillOptions}"
95+
th:if="${skill.skillCategory==3}"
96+
th:value="${skill.skillTitleId}" th:text="${skill.titleName}"></option>
97+
</optgroup>
98+
<optgroup label="言語">
99+
<option th:each="skill : ${skillOptions}"
100+
th:if="${skill.skillCategory==4}"
101+
th:value="${skill.skillTitleId}" th:text="${skill.titleName}"></option>
102+
</optgroup>
103+
</select>
104+
</div>
105+
</div>
106+
<div class="form-group">
107+
<label id="addSelector" class="btn btn-primary col-sm-offset-4">
108+
<span class="glyphicon glyphicon-plus"></span> 検索条件追加
109+
</label>
110+
</div>
111+
76112
<div class="form-group">
77113
<div class="col-sm-offset-4 col-sm-4">
78114
<button type="submit" class="btn btn-success">新規</button>
@@ -84,7 +120,38 @@ <h2 class="col-sm-offset-4 col-sm-8">スキル情報新規</h2>
84120
<div th:include="include :: footer"></div>
85121

86122
<script type="text/javascript">
123+
$(document).ready(function() {
124+
// add row
125+
$("#addSelector").on("click",function(){
87126

127+
$.ajax({
128+
type : "POST",
129+
url : "/search_addSelect",
130+
data: {
131+
"index": $("select.dynamic-select").length
132+
},
133+
dataType : 'html',
134+
cache: false,
135+
timeout : 10000,
136+
success : function(data) {
137+
console.log();
138+
var select = $('.selectList:last');
139+
console.log("SUCCESS: ", data);
140+
141+
select.after(data);
142+
$('.selectpicker').selectpicker('render');
143+
},
144+
error : function(e) {
145+
console.log("ERROR: ", e);
146+
alert('サーバーとの通信で問題が発生しました。 後でもう一度お試しください。');
147+
},
148+
done : function(e) {
149+
console.log("DONE");
150+
}
151+
});
152+
153+
});
154+
});
88155
</script>
89156
</body>
90157
</html>

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
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" th:object="${skillSearchInfo}">
27+
<form class="form-horizontal" method="post" action="/search" th:object="${skillSelectInfo}">
2828
<div class="selectList">
29-
<div class="form-group" th:each="row,rowStat : ${skillSearchInfo.lsSkill}">
29+
<div class="form-group" th:each="row,rowStat : ${skillSelectInfo.lsSkill}">
3030
<label for="inputName" class="col-sm-4 control-label">スキル</label>
31-
<select id="" th:field="${skillSearchInfo.lsSkill[__${rowStat.index}__]}"
31+
<select id="" th:field="${skillSelectInfo.lsSkill[__${rowStat.index}__]}"
3232
class="selectpicker dynamic-select" data-live-search="true"
3333
title="下記のスキルを選択してください">
3434
<optgroup label="資格">
@@ -55,7 +55,7 @@ <h2 class="col-sm-offset-4 col-sm-8">スキル情報検索</h2>
5555
</div>
5656
</div>
5757
<div class="form-group">
58-
<label id="addCondition" class="btn btn-primary col-sm-offset-4">
58+
<label id="addSelector" class="btn btn-primary col-sm-offset-4">
5959
<span class="glyphicon glyphicon-plus"></span> 検索条件追加
6060
</label>
6161
</div>
@@ -72,7 +72,7 @@ <h2 class="col-sm-offset-4 col-sm-8">スキル情報検索</h2>
7272
<script type="text/javascript">
7373
$(document).ready(function() {
7474
// add row
75-
$("#addCondition").on("click",function(){
75+
$("#addSelector").on("click",function(){
7676

7777
// $.ajax({
7878
// type : "POST",

skill/src/main/resources/templates/search_subrow.html renamed to skill/src/main/resources/templates/skill_select.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<body>
77
<div class="selectList">
88
<div class="form-group"
9-
th:each="row,rowStat : ${skillSearchInfo.lsSkill}">
9+
th:each="row,rowStat : ${skillSelectInfo.lsSkill}">
1010
<label for="inputName" class="col-sm-4 control-label">スキル</label> <select
11-
th:field="${skillSearchInfo.lsSkill[__${index}__]}"
11+
th:field="${skillSelectInfo.lsSkill[__${index}__]}"
1212
class="selectpicker dynamic-select" data-live-search="true" title="下記のスキルを選択してください">
1313
<optgroup label="資格">
1414
<option th:each="skill : ${skillOptions}"

0 commit comments

Comments
 (0)