Commit 6ce5563e authored by Ubbo Veentjer's avatar Ubbo Veentjer
Browse files

voyant back on shelf. js for syncing aggregator links to shelf when removing...

voyant back on shelf. js for syncing aggregator links to shelf when removing items. empty shelf should not show tools
parent 837724e6
Pipeline #134583 passed with stages
in 8 minutes and 55 seconds
......@@ -58,21 +58,14 @@ public class BasketController {
}
}
/*
List<ViewMode> tools = new ArrayList<ViewMode>();
tools.add(new ViewMode("Voyant v1", "#", false, "digivoy-basket-button"));
tools.add(new ViewMode("Voyant v2", "#", false, "digivoy2-basket-button"));
model.addAttribute("tools", tools);
*/
List<ViewMode> viewmodes = new ArrayList<ViewMode>();
viewmodes.add(new ViewMode(i18n.get("list"), "/shelf?mode=list", false));
viewmodes.add(new ViewMode(i18n.get("gallery"), "/shelf?mode=gallery", false));
model.addAttribute("viewmodes", viewmodes);
model.addAttribute("results", results);
//model.addAttribute("basket", Utils.getBasketItems(renderRequest));
model.addAttribute("aggregatorUrl", tgrepConfig.getTextgridHost()+"/1.0/aggregator");
model.addAttribute("voyantUrl", tgrepConfig.getToolVoyantHost());
model.addAttribute("basketItemString", Utils.getBasketItemsAsString(session));
model.addAttribute("textgridHost", this.tgrepConfig.getTextgridHost());
......
......@@ -48,9 +48,9 @@
.then(cnt => setBasketCount(cnt));
});
function setBasketCount(num) {
[].forEach.call(document.getElementsByClassName("topbox_shelf-count"), function(elem){
elem.textContent = num;
})
document.querySelectorAll('topbox_shelf-count').forEach( elem => {
elem.textContent = num;
})
}
</script>
......
......@@ -12,43 +12,71 @@
$(document).on('click', '.-remove-from-shelf', function(e) {
var $this = $(this);
var tgObjectUri = $this.attr('data-textgrid-targeturi');
$.ajax({
url: "/service/shelf/remove" ,
url: '/service/shelf/remove' ,
type: 'POST',
dataType:'json',
data: {
uri: $this.attr('data-textgrid-targeturi')
uri: tgObjectUri
},
success: function(data) {
$this.closest('li.tgrep.result').remove();
$this.closest('li.tgrep.gallery-item').remove();
$('.tgrep.header_count').html(data);
setBasketCount(data);
removeFromAggregatorItemString(tgObjectUri)
}
});
});
$(document).on('click', '.tgrep.header_button.-clear', function(e) {
var $this = $(this);
$.ajax({
url: "/service/shelf/clear" ,
url: '/service/shelf/clear' ,
type: 'POST',
dataType:'json',
data: {
empty: "empty"
empty: 'empty'
},
success: function(data) {
$('.tgrep.results_list').empty();
$('.tgrep.results_gallery').empty();
$('.tgrep.header_count').html(0);
setBasketCount(data);
removeUselessActionsFromEmptyShelf();
}
});
});
});
// set by jsp
var basketItemString = '${basketItemString}';
// removes the tguri from aggregatorUrl
function removeFromAggregatorItemString(tgObjectUri) {
var basketItemStringOld = basketItemString;
var itemArr = basketItemString.split(',');
itemArr.splice(itemArr.indexOf(tgObjectUri),1);
// are there any objects left on the shelf?
if(itemArr.length > 0) {
basketItemString = itemArr.join(',');
document.querySelectorAll('.aggregator-items').forEach( elem => {
elem.href = elem.href.replace(basketItemStringOld, basketItemString);
});
} else {
removeUselessActionsFromEmptyShelf();
}
}
// dislable download and voyant links if shelf is empty
function removeUselessActionsFromEmptyShelf() {
document.querySelectorAll('.remove_on_shelf_empty').forEach( elem => {
elem.remove();
});
}
</script>
<div class="tgrep wrap">
......@@ -75,21 +103,16 @@
</section>
</c:if>
<c:if test="${tools != null and tools.size() > 0}">
<section class="tgrep sidebar_panel">
<h3 class="tgrep sidebar_subheading">${i18n['tools']}</h3>
<ul class="tgrep sidebar_list">
<c:forEach items="${tools}" var="tool">
<li class="tgrep sidebar_item">
<a href="${tool.url}" rel="noindex nofollow" class="tgrep sidebar_link ${tool.cssClass}">${tool.label}</a>
</li>
</c:forEach>
</ul>
<c:if test="${tools.size() > 6}">
<button class="tgrep sidebar_expand">${i18n['expand']}</button>
</c:if>
</section>
</c:if>
<c:if test="${results.size() > 0}">
<section class="tgrep sidebar_panel remove_on_shelf_empty">
<h3 class="tgrep sidebar_subheading">${i18n['tools']}</h3>
<ul class="tgrep sidebar_list">
<li class="tgrep sidebar_item">
<a class="aggregator-items" href="${voyantUrl}?input=${aggregatorUrl}/zip/${basketItemString}?meta=false&only=text/xml" rel="noindex nofollow" class="tgrep sidebar_link">Voyant</a>
</li>
</ul>
</section>
</c:if>
</aside>
<main class="tgrep main">
......@@ -100,19 +123,21 @@
<div class="tgrep header_info">
${i18n['there-are-currently']} <span class="tgrep header_count">${results.size()}</span> ${i18n['objects-on-your-shelf']}
</div>
<div class="tgrep header_actions">
<button class="tgrep header_button -expand-all">${i18n['expand-all']}</button>
<button class="tgrep header_button -collapse-all">${i18n['collapse-all']}</button>
<button class="tgrep header_button -clear">${i18n['clear']}</button>
<div class="tg dropdown" role="group">
<a class="tg dropdown_toggle">${i18n['download-all']}</a>
<ul class="tg dropdown_menu">
<li class="tg dropdown_item"><a class="tg dropdown_link" href="${aggregatorUrl}/epub/${basketItemString}" data-type="ebook">E-Book</a></li>
<li class="tg dropdown_item"><a class="tg dropdown_link" href="${aggregatorUrl}/zip/${basketItemString}" data-type="zip">ZIP</a></li>
<li class="tg dropdown_item"><a class="tg dropdown_link" href="${aggregatorUrl}/teicorpus/${basketItemString}" data-type="teicorpus">TEI-Corpus</a></li>
</ul>
<c:if test="${results.size() > 0}">
<div class="tgrep header_actions remove_on_shelf_empty">
<button class="tgrep header_button -expand-all">${i18n['expand-all']}</button>
<button class="tgrep header_button -collapse-all ">${i18n['collapse-all']}</button>
<button class="tgrep header_button -clear ">${i18n['clear']}</button>
<div class="tg dropdown" role="group">
<a class="tg dropdown_toggle">${i18n['download-all']}</a>
<ul class="tg dropdown_menu">
<li class="tg dropdown_item"><a class="aggregator-items tg dropdown_link" href="${aggregatorUrl}/epub/${basketItemString}" data-type="ebook">E-Book</a></li>
<li class="tg dropdown_item"><a class="aggregator-items tg dropdown_link" href="${aggregatorUrl}/zip/${basketItemString}" data-type="zip">ZIP</a></li>
<li class="tg dropdown_item"><a class="aggregator-items tg dropdown_link" href="${aggregatorUrl}/teicorpus/${basketItemString}" data-type="teicorpus">TEI-Corpus</a></li>
</ul>
</div>
</div>
</div>
</c:if>
</header>
<c:choose>
......
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