Skip to content

Commit

Permalink
都道府県レベルに Pagination を追加, Jumbotron を少し小さくする (#144)
Browse files Browse the repository at this point in the history
* 都道府県レベルに Pagination を追加
* Jumbotron を少し小さくする
  • Loading branch information
igapyon committed Apr 25, 2020
1 parent 16fd6ce commit 003fc91
Show file tree
Hide file tree
Showing 72 changed files with 2,889 additions and 813 deletions.
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;
}
}
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;
}
}
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 src/main/java/jp/igapyon/cityinfojp/thvarmap/ThPaginationUtil.java
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ protected LinkedHashMap<String, Object> buildVarMap() {

result.put("navbar", getNavbarBean(prefNameen));

result.put("pagination", ThPaginationUtil.buildPagination(prefName));

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
result.put("processDateTime", dtf.format(LocalDateTime.now()));
} catch (IOException ex) {
Expand Down
27 changes: 13 additions & 14 deletions src/main/resources/static/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<div>

<li
class="nav-item">

Expand All @@ -42,8 +42,8 @@


</li>
</div>
<div>


<li
class="nav-item dropdown">

Expand Down Expand Up @@ -83,8 +83,8 @@
</div>

</li>
</div>
<div>


<li
class="nav-item">

Expand All @@ -94,8 +94,8 @@


</li>
</div>
<div>


<li
class="nav-item">

Expand All @@ -105,8 +105,8 @@


</li>
</div>
<div>


<li
class="nav-item active dropdown">

Expand All @@ -131,19 +131,18 @@
</div>

</li>
</div>

</ul>
</div>
</nav>


<main role="main">

<div class="jumbotron">
<div class="jumbotron" style="padding:5rem 2rem 1rem 2rem;">
<div class="container">
<br />
<h1 class="display-3">About</h1>
<p>cityinfojp は自治体などの組織による都市情報のファクトを淡々と集積して表示する Webサイトです。
<p>自治体など組織による都市情報ファクトを淡々と集積
<a href="/about.html">
<span style="font-size: 1.5em">

Expand Down Expand Up @@ -243,7 +242,7 @@ <h2>開発言語など</h2>
</main>

<footer class="container">
<p>&copy; cityinfojp 2020 : 2020-04-25 08:43</p>
<p>&copy; cityinfojp 2020 : 2020-04-25 12:03</p>
</footer>

<!-- Bootstrap JavaScript -->
Expand Down
Loading

0 comments on commit 003fc91

Please sign in to comment.