-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
都道府県レベルに Pagination を追加, Jumbotron を少し小さくする (#144)
* 都道府県レベルに Pagination を追加 * Jumbotron を少し小さくする
- Loading branch information
Showing
72 changed files
with
2,889 additions
and
813 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/main/java/jp/igapyon/cityinfojp/fragment/pagination/PaginationBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2020 Toshiki Iga | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package jp.igapyon.cityinfojp.fragment.pagination; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Thymeleaf + Bootstrap の Pagination Fragment のための Bean. | ||
* | ||
* @author Toshiki Iga | ||
*/ | ||
public class PaginationBean { | ||
private PaginationItemBean prevItem; | ||
private PaginationItemBean nextItem; | ||
|
||
private List<PaginationItemBean> itemList = new ArrayList<>(); | ||
|
||
public boolean hasPrev() { | ||
return prevItem != null; | ||
} | ||
|
||
public boolean hasNext() { | ||
return nextItem != null; | ||
} | ||
|
||
public PaginationItemBean getPrevItem() { | ||
return prevItem; | ||
} | ||
|
||
public void setPrevItem(PaginationItemBean prevItem) { | ||
this.prevItem = prevItem; | ||
} | ||
|
||
public PaginationItemBean getNextItem() { | ||
return nextItem; | ||
} | ||
|
||
public void setNextItem(PaginationItemBean nextItem) { | ||
this.nextItem = nextItem; | ||
} | ||
|
||
public List<PaginationItemBean> getItemList() { | ||
return itemList; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/jp/igapyon/cityinfojp/fragment/pagination/PaginationItemBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2020 Toshiki Iga | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package jp.igapyon.cityinfojp.fragment.pagination; | ||
|
||
/** | ||
* Thymeleaf + Bootstrap の Pagination Fragment のアイテムのための Bean. | ||
* | ||
* @author Toshiki Iga | ||
*/ | ||
public class PaginationItemBean { | ||
private String title = "ページN"; | ||
private String url = "https://example.org/"; | ||
/** | ||
* カレントアイテムの場合のみtrue。trueだと押せなくなる。 | ||
*/ | ||
private boolean current = false; | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public void setUrl(String url) { | ||
this.url = url; | ||
} | ||
|
||
public boolean isCurrent() { | ||
return current; | ||
} | ||
|
||
public void setCurrent(boolean current) { | ||
this.current = current; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/jp/igapyon/cityinfojp/fragment/pagination/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Thymeleaf + Bootstrap の Pagination Fragment を処理する機能。 | ||
*/ | ||
package jp.igapyon.cityinfojp.fragment.pagination; |
112 changes: 112 additions & 0 deletions
112
src/main/java/jp/igapyon/cityinfojp/thvarmap/ThPaginationUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright 2020 Toshiki Iga | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package jp.igapyon.cityinfojp.thvarmap; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import jp.igapyon.cityinfojp.fragment.pagination.PaginationBean; | ||
import jp.igapyon.cityinfojp.fragment.pagination.PaginationItemBean; | ||
import jp.igapyon.cityinfojp.json.JsonPrefEntry; | ||
import jp.igapyon.cityinfojp.json.JsonPrefEntryUtil; | ||
|
||
/** | ||
* このサイト用の Pagination を構築するためのユーティリィ。 | ||
* | ||
* @author Toshiki Iga | ||
*/ | ||
public class ThPaginationUtil { | ||
public static PaginationBean buildPagination(String pref) throws IOException { | ||
PaginationBean pagination = new PaginationBean(); | ||
|
||
// すべての都道府県情報 | ||
List<JsonPrefEntry> prefList = JsonPrefEntryUtil.readEntryListFromClasspath(); | ||
|
||
// とりあえず全てを登録してみる。 | ||
for (JsonPrefEntry lookup : prefList) { | ||
PaginationItemBean item = new PaginationItemBean(); | ||
pagination.getItemList().add(item); | ||
item.setTitle(lookup.getName()); | ||
item.setUrl("/pref/" + lookup.getNameen().toLowerCase() + ".html"); | ||
if (lookup.getName().equals(pref)) { | ||
item.setCurrent(true); | ||
} | ||
} | ||
|
||
int currentIndex = -1; | ||
for (int index = 0; index < pagination.getItemList().size(); index++) { | ||
if (pagination.getItemList().get(index).isCurrent()) { | ||
currentIndex = index; | ||
break; | ||
} | ||
} | ||
|
||
int fromIndex = -1; | ||
if (currentIndex < 2) { | ||
fromIndex = 0; | ||
} else { | ||
if (currentIndex > pagination.getItemList().size() - 3) { | ||
fromIndex = pagination.getItemList().size() - 5; | ||
} else { | ||
fromIndex = currentIndex - 2; | ||
} | ||
} | ||
|
||
int toIndex = -1; | ||
if (currentIndex > pagination.getItemList().size() - 3) { | ||
toIndex = pagination.getItemList().size(); | ||
} else { | ||
if (currentIndex < 2) { | ||
toIndex = 4; | ||
} else { | ||
toIndex = currentIndex + 2; | ||
} | ||
} | ||
|
||
{ | ||
// prev | ||
if (currentIndex != 0) { | ||
int prevIndex = currentIndex - 4; | ||
if (prevIndex < 0) { | ||
prevIndex = 0; | ||
} | ||
pagination.setPrevItem(pagination.getItemList().get(prevIndex)); | ||
} | ||
} | ||
{ | ||
// next | ||
if (currentIndex != pagination.getItemList().size() - 1) { | ||
int nextIndex = currentIndex + 4; | ||
if (nextIndex > pagination.getItemList().size() - 1) { | ||
nextIndex = pagination.getItemList().size() - 1; | ||
} | ||
pagination.setNextItem(pagination.getItemList().get(nextIndex)); | ||
} | ||
} | ||
|
||
// 余分な部分を除去。先に後ろの方から除去。 | ||
for (int pointer = pagination.getItemList().size() - 1; pointer > toIndex; pointer--) { | ||
pagination.getItemList().remove(pointer); | ||
} | ||
|
||
// 余分な部分を除去。後に最初の方から除去。 | ||
for (int counter = fromIndex; counter > 0; counter--) { | ||
pagination.getItemList().remove(0); | ||
} | ||
|
||
return pagination; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.