Commit e25f49b4 authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

rename basket to shelf in code

parent 4d792f07
Pipeline #140982 passed with stages
in 8 minutes and 53 seconds
package info.textgrid.rep.basket;
package info.textgrid.rep.shelf;
import java.util.ArrayList;
import java.util.List;
public class Basket {
public class Shelf {
private List<String> items = new ArrayList<String>();
......
package info.textgrid.rep.basket;
package info.textgrid.rep.shelf;
import java.io.IOException;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -11,43 +11,43 @@ import org.springframework.web.bind.annotation.SessionAttributes;
@RestController
@SessionAttributes("basket")
@SessionAttributes("shelf")
@RequestMapping("/service/shelf")
public class BasketAjaxController {
public class ShelfAjaxController {
@ModelAttribute("basket")
public Basket getBasket() {
return new Basket();
@ModelAttribute("shelf")
public Shelf getShelf() {
return new Shelf();
}
@PostMapping("/add")
public int addToBasket(
@ModelAttribute Basket basket,
public int addToShelf(
@ModelAttribute Shelf shelf,
@RequestParam("uri") String textgridUri
) throws IOException {
return basket.addItem(textgridUri);
return shelf.addItem(textgridUri);
}
@PostMapping("/remove")
public long removeFromBasket(
@ModelAttribute Basket basket,
@ModelAttribute Shelf shelf,
@RequestParam("uri") String textgridUri
) throws IOException {
return basket.remove(textgridUri);
return shelf.remove(textgridUri);
}
@PostMapping("/clear")
public long clearBasket(@ModelAttribute Basket basket) {
return basket.clear();
public long clearShelf(@ModelAttribute Shelf shelf) {
return shelf.clear();
}
@GetMapping("/count")
public long basketCount(@ModelAttribute Basket basket) {
return basket.size();
public long shelfCount(@ModelAttribute Shelf shelf) {
return shelf.size();
}
}
package info.textgrid.rep.basket;
package info.textgrid.rep.shelf;
import java.util.ArrayList;
import java.util.List;
......@@ -19,30 +19,30 @@ import info.textgrid.rep.service.TgsearchClientService;
import info.textgrid.rep.shared.ToolLink;
@Controller
@SessionAttributes("basket")
public class BasketController {
@SessionAttributes("shelf")
public class ShelfController {
private TgsearchClientService tgsearchClientService;
private I18NProvider i18nProvider;
private static final Log log = LogFactory.getLog(BasketController.class);
private static final Log log = LogFactory.getLog(ShelfController.class);
@Autowired
public BasketController(TgsearchClientService tgsearchClientService, I18NProvider i18nProvider) {
public ShelfController(TgsearchClientService tgsearchClientService, I18NProvider i18nProvider) {
this.tgsearchClientService = tgsearchClientService;
this.i18nProvider = i18nProvider;
}
@ModelAttribute("basket")
public Basket getBasket() {
return new Basket();
@ModelAttribute("shelf")
public Shelf getShelf() {
return new Shelf();
}
@GetMapping("/shelf")
public String render(
Model model,
Locale locale,
@ModelAttribute Basket basket,
@ModelAttribute Shelf shelf,
@RequestParam(value="mode", required=false) String mode) {
I18N i18n = i18nProvider.getI18N(locale);
......@@ -51,8 +51,8 @@ public class BasketController {
List<ResultType> results = new ArrayList<ResultType>();
if(basket != null) {
for(String textgridUri : basket.getItems()) {
if(shelf != null) {
for(String textgridUri : shelf.getItems()) {
ResultType res = tgsearchClientService.getMetadata(textgridUri);
results.add(res);
}
......@@ -64,9 +64,9 @@ public class BasketController {
model.addAttribute("viewmodes", viewmodes);
model.addAttribute("results", results);
model.addAttribute("basketItemString", basket.getItemsAsString());
model.addAttribute("shelfItemString", shelf.getItemsAsString());
return "basket";
return "shelf";
}
......
......@@ -6,7 +6,7 @@ import { setShelfCount, setupShelf, setupShelfButtons } from './shelf.js';
document.addEventListener("DOMContentLoaded", function(event) {
/* setup for all pages */
/* retrieve number of basket items on page load to set number display */
/* retrieve number of shelf items on page load to set number display */
$.ajax("/service/shelf/count").done(response => setShelfCount(response));
setupTheme();
......@@ -15,7 +15,7 @@ document.addEventListener("DOMContentLoaded", function(event) {
the body should have a class with this info
*/
const bodyClasses = document.querySelector('body').classList;
if(bodyClasses.contains('basket')) {
if(bodyClasses.contains('shelf')) {
setupShelf();
}
if(bodyClasses.contains('browse')) {
......
......@@ -84,26 +84,24 @@ export function setupShelf() {
});
});
if(document.querySelector('#basketItemString') !== null) {
basketItemString = document.querySelector('#basketItemString').dataset.value;
}
shelfItemString = document.querySelector('#shelfItemString').dataset.value;
}
//set by jsp
var basketItemString;
var shelfItemString;
// removes the tguri from aggregatorUrl
function removeFromAggregatorItemString(tgObjectUri) {
var basketItemStringOld = basketItemString;
var itemArr = basketItemString.split(',');
var shelfItemStringOld = shelfItemString;
var itemArr = shelfItemString.split(',');
itemArr.splice(itemArr.indexOf(tgObjectUri),1);
// are there any objects left on the shelf?
if(itemArr.length > 0) {
basketItemString = itemArr.join(',');
shelfItemString = itemArr.join(',');
$('.aggregator-items').each((id, elem) => {
elem.href = elem.href.replace(basketItemStringOld, basketItemString);
elem.href = elem.href.replace(shelfItemStringOld, shelfItemString);
});
} else {
removeUselessActionsFromEmptyShelf();
......
......@@ -61,7 +61,7 @@ filter=Filter
active-filters=Aktive Filter
remove-filter=Diesen Filter entfernen
# basket.jsp, shares some strings with singleResult.jsp
# shelf.jsp, shares some strings with singleResult.jsp
show-sidebar=Seitenleiste anzeigen
hide-sidebar=Seitenleiste verbergen
expand=Alle anzeigen
......
......@@ -61,7 +61,7 @@ filter=Filter
active-filters=Active filters
remove-filter=Remove this filter
# basket.jsp, shares some strings with singleResult.jsp
# shelf.jsp, shares some strings with singleResult.jsp
show-sidebar=Show sidebar
hide-sidebar=Hide sidebar
expand=Show all
......
......@@ -23,7 +23,7 @@
<div class="tgrep gallery-item_actions">
<ul>
<li><c:choose>
<c:when test="${basket.contains(result.object.generic.generated.textgridUri.value)}">
<c:when test="${shelf.contains(result.object.generic.generated.textgridUri.value)}">
<button class="tgrep gallery-item_button -remove-from-shelf" data-textgrid-targeturi="${result.object.generic.generated.textgridUri.value}">
${i18n['remove-from-shelf']}</button>
</c:when>
......
......@@ -55,7 +55,7 @@
<ul>
<li>
<c:choose>
<c:when test="${basket.contains(result.object.generic.generated.textgridUri.value)}">
<c:when test="${shelf.contains(result.object.generic.generated.textgridUri.value)}">
<button
class="tgrep result_button -remove-from-shelf"
data-textgrid-targeturi="${result.object.generic.generated.textgridUri.value}">
......
......@@ -4,10 +4,10 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://textgrid.info/rep/utils" prefix="utils" %>
<c:set var="pagename" value="basket" />
<c:set var="pagename" value="shelf" />
<%@ include file="base/head.jsp" %>
<span hidden="true" id="basketItemString" data-value="${basketItemString}"></span>
<span hidden="true" id="shelfItemString" data-value="${shelfItemString}"></span>
<div class="tgrep wrap">
<div class="tgrep sidebar-toggle">
......@@ -38,7 +38,7 @@
<h3 class="tgrep sidebar_subheading">${i18n['tools']}</h3>
<ul class="tgrep sidebar_list">
<li class="tgrep sidebar_item">
<a class="aggregator-items" href="${config.voyantHost}?input=${config.aggregatorUrl}/zip/${basketItemString}?meta=false&only=text/xml" rel="noindex nofollow" class="tgrep sidebar_link">Voyant</a>
<a class="aggregator-items" href="${config.voyantHost}?input=${config.aggregatorUrl}/zip/${shelfItemString}?meta=false&only=text/xml" rel="noindex nofollow" class="tgrep sidebar_link">Voyant</a>
<a href ="/docs/voyant" class=""><icon class="info-link"></a>
</li>
</ul>
......@@ -62,10 +62,10 @@
<div class="tg dropdown" role="group">
<a href ="/docs/download"><icon class="info-link -large"></a> <a class="tg dropdown_toggle -download">${i18n['download-all']}</a>
<ul class="tg dropdown_menu">
<li class="tg dropdown_item"><a class="aggregator-items tg dropdown_link" href="${config.aggregatorUrl}/epub/${basketItemString}" data-type="ebook">E-Book</a></li>
<li class="tg dropdown_item"><a class="aggregator-items tg dropdown_link" href="${config.aggregatorUrl}/zip/${basketItemString}" data-type="zip">ZIP</a></li>
<li class="tg dropdown_item"><a class="aggregator-items tg dropdown_link" href="${config.aggregatorUrl}/zip/${basketItemString}?transform=text&meta=false&only=text/xml&dirnames=" data-type="zip">${i18n['download-text-only-zip']}</a></li>
<li class="tg dropdown_item"><a class="aggregator-items tg dropdown_link" href="${config.aggregatorUrl}/teicorpus/${basketItemString}" data-type="teicorpus">TEI-Corpus</a></li>
<li class="tg dropdown_item"><a class="aggregator-items tg dropdown_link" href="${config.aggregatorUrl}/epub/${shelfItemString}" data-type="ebook">E-Book</a></li>
<li class="tg dropdown_item"><a class="aggregator-items tg dropdown_link" href="${config.aggregatorUrl}/zip/${shelfItemString}" data-type="zip">ZIP</a></li>
<li class="tg dropdown_item"><a class="aggregator-items tg dropdown_link" href="${config.aggregatorUrl}/zip/${shelfItemString}?transform=text&meta=false&only=text/xml&dirnames=" data-type="zip">${i18n['download-text-only-zip']}</a></li>
<li class="tg dropdown_item"><a class="aggregator-items tg dropdown_link" href="${config.aggregatorUrl}/teicorpus/${shelfItemString}" data-type="teicorpus">TEI-Corpus</a></li>
</ul>
</div>
</div>
......
......@@ -19,26 +19,26 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
@SpringBootTest
@AutoConfigureMockMvc
public class BasketControllerTest {
public class ShelfControllerTest {
@Autowired
private MockMvc mvc;
@Test
public void showBasket() throws Exception {
public void showShelf() throws Exception {
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders
.get("/shelf")
.accept(MediaType.TEXT_HTML);
mvc.perform(builder)
.andExpect(view().name("basket"))
.andExpect(forwardedUrl("/WEB-INF/jsp/basket.jsp"))
.andExpect(view().name("shelf"))
.andExpect(forwardedUrl("/WEB-INF/jsp/shelf.jsp"))
.andExpect(status().isOk());
}
@Test
public void addToBasket() throws Exception {
public void addToShelf() throws Exception {
final MockHttpSession mockHttpSession = new MockHttpSession();
......@@ -71,11 +71,11 @@ public class BasketControllerTest {
.accept(MediaType.TEXT_HTML);
mvc.perform(builder)
.andExpect(view().name("basket"))
.andExpect(forwardedUrl("/WEB-INF/jsp/basket.jsp"))
.andExpect(view().name("shelf"))
.andExpect(forwardedUrl("/WEB-INF/jsp/shelf.jsp"))
.andExpect(status().isOk())
.andExpect(model().attribute("results", hasSize(2)))
.andExpect(model().attribute("basketItemString", is("textgrid:kv2q.0,textgrid:wfw9.0")));
.andExpect(model().attribute("shelfItemString", is("textgrid:kv2q.0,textgrid:wfw9.0")));
//.andExpect(model().attribute("results", containsString("Alice im Wunderland")));
// remove one
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment