Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DARIAH-DE
TextGridRep Portal
Commits
be8c1a88
Commit
be8c1a88
authored
May 11, 2020
by
Ubbo Veentjer
Browse files
shelf works again. closes
#30
parent
3ff35b1c
Pipeline
#134419
passed with stages
in 10 minutes and 12 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/info/textgrid/rep/basket/BasketAjaxController.java
View file @
be8c1a88
...
...
@@ -55,7 +55,7 @@ public class BasketAjaxController {
return
basketCount
(
session
);
}
@GetMapping
(
"/count"
)
//TODO: merge with basketAjaxController?
@GetMapping
(
"/count"
)
public
long
basketCount
(
HttpSession
session
)
{
long
count
;
...
...
src/main/java/info/textgrid/rep/basket/BasketController.java
View file @
be8c1a88
package
info.textgrid.rep.basket
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Locale
;
import
javax.servlet.http.HttpSession
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
info.textgrid.namespaces.middleware.tgsearch.ResultType
;
import
info.textgrid.rep.i18n.I18N
;
import
info.textgrid.rep.i18n.I18NProvider
;
import
info.textgrid.rep.service.tgsearch.TgrepConfigurationService
;
import
info.textgrid.rep.service.tgsearch.TgsearchClientService
;
import
info.textgrid.rep.shared.Utils
;
import
info.textgrid.rep.shared.ViewMode
;
import
info.textgrid.rep.i18n.I18N
;
import
info.textgrid.rep.i18n.I18NProvider
;
@Controller
public
class
BasketController
{
...
...
@@ -61,15 +58,16 @@ 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
/-/shelf/
list"
,
false
));
viewmodes
.
add
(
new
ViewMode
(
i18n
.
get
(
"gallery"
),
"/shelf
/-/shelf/
gallery"
,
false
));
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
);
...
...
src/main/java/info/textgrid/rep/shared/Utils.java
View file @
be8c1a88
...
...
@@ -113,26 +113,11 @@ public class Utils {
}
public
static
String
getBasketItemsAsString
(
HttpSession
session
)
{
// TODO: String.join vom java8
//return String.join(",", getBasketItems(session));
return
join
(
getBasketItems
(
session
),
","
);
}
// http://stackoverflow.com/a/63274
public
static
String
join
(
List
<
String
>
list
,
String
delim
)
{
StringBuilder
sb
=
new
StringBuilder
();
String
loopDelim
=
""
;
if
(
list
!=
null
)
{
for
(
String
s
:
list
)
{
sb
.
append
(
loopDelim
);
sb
.
append
(
s
);
loopDelim
=
delim
;
}
}
return
sb
.
toString
();
String
itemstring
=
""
;
if
(
getBasketItems
(
session
)
!=
null
)
{
itemstring
=
String
.
join
(
","
,
getBasketItems
(
session
));
}
return
itemstring
;
}
public
static
String
urlencode
(
String
string
)
{
...
...
src/main/webapp/WEB-INF/jsp/base/foot.jsp
View file @
be8c1a88
...
...
@@ -40,6 +40,20 @@
<script
src=
"/js/jquery.min.js"
></script>
<script
src=
"/js/theme.js"
></script>
<script
type=
"text/javascript"
>
/* show number of items in basket */
document
.
addEventListener
(
"
DOMContentLoaded
"
,
event
=>
{
fetch
(
"
/service/shelf/count
"
)
.
then
(
response
=>
response
.
text
())
.
then
(
cnt
=>
setBasketCount
(
cnt
));
});
function
setBasketCount
(
num
)
{
[].
forEach
.
call
(
document
.
getElementsByClassName
(
"
topbox_shelf-count
"
),
function
(
elem
){
elem
.
textContent
=
num
;
})
}
</script>
</div>
</body>
</html>
src/main/webapp/WEB-INF/jsp/base/topbox.jsp
View file @
be8c1a88
...
...
@@ -6,7 +6,7 @@
<li>
<a
href=
"/shelf"
class=
"tg topbox_link -shelf"
>
${i18n['shelf']}
<span
class=
"tg topbox_shelf-count"
>
</span>
<span
class=
"tg topbox_shelf-count"
>
0
</span>
</a>
</li>
<!--
...
...
src/main/webapp/WEB-INF/jsp/basket.jsp
View file @
be8c1a88
...
...
@@ -4,13 +4,6 @@
<%@ taglib
uri=
"http://java.sun.com/jsp/jstl/functions"
prefix=
"fn"
%>
<%@ taglib
uri=
"http://textgrid.info/rep/utils"
prefix=
"utils"
%>
<!--
<portlet:defineObjects />
<portlet:resourceURL
id=
"removeFromBasket"
var=
"removeFromBasketUrl"
></portlet:resourceURL>
<portlet:resourceURL
id=
"clearBasket"
var=
"clearBasketUrl"
></portlet:resourceURL>
-->
<%@ include
file=
"base/head.jsp"
%>
<%@ include
file=
"components/js-incl.jsp"
%>
...
...
@@ -21,7 +14,7 @@
var
$this
=
$
(
this
);
$
.
ajax
({
url
:
"
${removeFromBasketUrl}
"
,
url
:
"
/service/shelf/remove
"
,
type
:
'
POST
'
,
dataType
:
'
json
'
,
data
:
{
...
...
@@ -29,8 +22,9 @@
},
success
:
function
(
data
)
{
$this
.
closest
(
'
li.tgrep.result
'
).
remove
();
$
(
'
.tgrep.header_count
'
).
html
(
data
.
basketSize
);
setBasketCount
(
data
.
basketSize
);
// this call needs the basketcount portlet available
$this
.
closest
(
'
li.tgrep.gallery-item
'
).
remove
();
$
(
'
.tgrep.header_count
'
).
html
(
data
);
setBasketCount
(
data
);
}
});
});
...
...
@@ -39,7 +33,7 @@
var
$this
=
$
(
this
);
$
.
ajax
({
url
:
"
${clearBasketUrl}
"
,
url
:
"
/service/shelf/clear
"
,
type
:
'
POST
'
,
dataType
:
'
json
'
,
data
:
{
...
...
@@ -47,52 +41,13 @@
},
success
:
function
(
data
)
{
$
(
'
.tgrep.results_list
'
).
empty
();
$
(
'
.tgrep.results_gallery
'
).
empty
();
$
(
'
.tgrep.header_count
'
).
html
(
0
);
setBasketCount
(
0
);
// this call needs the basketcount portlet available
setBasketCount
(
data
);
}
});
});
/*
* VOYANT
*
*/
//var voyantURL = "https://textgridrep.de/voyant/"
$
(
document
).
on
(
'
click
'
,
'
.digivoy-basket-button
'
,
function
(
e
)
{
var
toolUrl
=
'
https://voyant.de.dariah.eu/voyant
'
;
var
documentLinks
=
[];
var
settings_serialized
=
"
target=
"
+
encodeURIComponent
(
'
${textgridHost}/voyant
'
)
+
"
%2F&e=castList&e=desc&e=figure&e=head&e=note&e=speaker&e=stage&e=title
"
;
$
(
'
.tgrep.result_main
'
).
each
(
function
()
{
var
documentId
=
unescape
(
$
(
this
).
attr
(
'
data-tg-uri
'
));
documentLinks
.
push
(
filteredTGCrudDataLink
(
documentId
,
settings_serialized
));
});
sendToVoyant
(
toolUrl
,
documentLinks
.
join
(
'
\n
'
));
});
$
(
document
).
on
(
'
click
'
,
'
.digivoy2-basket-button
'
,
function
(
e
)
{
var
toolUrl
=
'
https://voyant.de.dariah.eu/voyant2/
'
;
//var toolUrl = 'http://voyant.de.dariah.eu/voyant2';
var
documentLinks
=
[];
var
settings_serialized
=
"
target=
"
+
encodeURIComponent
(
'
${textgridHost}/voyant2
'
)
+
"
%2F&e=castList&e=desc&e=figure&e=head&e=note&e=speaker&e=stage&e=title
"
;
$
(
'
.tgrep.result_main
'
).
each
(
function
()
{
var
documentId
=
unescape
(
$
(
this
).
attr
(
'
data-tg-uri
'
));
documentLinks
.
push
(
filteredTGCrudDataLink
(
documentId
,
settings_serialized
));
});
sendToVoyant2
(
toolUrl
,
documentLinks
.
join
(
'
\n
'
));
});
$
(
document
).
on
(
'
click
'
,
'
.collate-button
'
,
function
(
e
)
{
});
});
</script>
<div
class=
"tgrep wrap"
>
...
...
@@ -102,37 +57,6 @@
</div>
<aside
class=
"tgrep sidebar"
>
<!--
<section class="tgrep sidebar_panel">
<h3 class="tgrep sidebar_subheading">${i18n['views']}<h3>
<ul class="tgrep sidebar_list">
<li class="tgrep sidebar_item">
<a class="tgrep sidebar_link">XML</a>
</li>
<li class="tgrep sidebar_item">
<a class="tgrep sidebar_link">Browse</a>
</li>
<li class="tgrep sidebar_item">
<a class="tgrep sidebar_link">Gallery</a>
</li>
<li class="tgrep sidebar_item">
<a class="tgrep sidebar_link">Digilib</a>
</li>
</ul>
</section>
<section class="tgrep sidebar_panel">
<h3 class="tgrep sidebar_subheading">${i18n['tools']}</h3>
<ul class="tgrep sidebar_list">
<li class="tgrep sidebar_item">
<a class="tgrep sidebar_link voyant-button">Digivoy</a>
</li>
<li class="tgrep sidebar_item">
<a class="tgrep sidebar_link collate-button">CollateX</a>
</li>
</ul>
</section>
-->
<c:if
test=
"
${
viewmodes
!=
null
}
"
>
<section
class=
"tgrep sidebar_panel"
>
...
...
src/main/webapp/WEB-INF/jsp/components/js-incl.jsp
View file @
be8c1a88
...
...
@@ -2,6 +2,7 @@
document
.
addEventListener
(
"
DOMContentLoaded
"
,
function
(
event
)
{
/* the buttons */
$
(
document
).
on
(
'
click
'
,
'
.-add-to-shelf
'
,
function
(
e
)
{
var
$this
=
$
(
this
);
$
.
ajax
({
...
...
@@ -15,7 +16,7 @@
$this
.
removeClass
(
'
-add-to-shelf
'
);
$this
.
addClass
(
'
-remove-from-shelf
'
);
$this
.
html
(
'
${i18n[
'
remove
-
from
-
shelf
'
]}
'
);
setBasketCount
(
data
.
basketSize
);
setBasketCount
(
data
);
}
});
});
...
...
@@ -33,11 +34,12 @@
$this
.
removeClass
(
'
-remove-from-shelf
'
);
$this
.
addClass
(
'
-add-to-shelf
'
);
$this
.
html
(
'
${i18n[
'
add
-
to
-
shelf
'
]}
'
);
setBasketCount
(
data
.
basketSize
);
setBasketCount
(
data
);
}
});
});
});
});
</script>
src/test/java/info/textgrid/rep/search/BasketControllerTest.java
View file @
be8c1a88
package
info.textgrid.rep.search
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
forwardedUrl
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
model
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
view
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
...
...
@@ -15,6 +14,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import
org.springframework.http.MediaType
;
import
org.springframework.mock.web.MockHttpSession
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
;
import
org.springframework.test.web.servlet.request.MockMvcRequestBuilders
;
@SpringBootTest
...
...
@@ -26,8 +26,12 @@ public class BasketControllerTest {
@Test
public
void
showBasket
()
throws
Exception
{
mvc
.
perform
(
MockMvcRequestBuilders
.
get
(
"/shelf"
)
.
accept
(
MediaType
.
TEXT_HTML
))
MockHttpServletRequestBuilder
builder
=
MockMvcRequestBuilders
.
get
(
"/shelf"
)
.
accept
(
MediaType
.
TEXT_HTML
);
mvc
.
perform
(
builder
)
.
andExpect
(
view
().
name
(
"basket"
))
.
andExpect
(
forwardedUrl
(
"/WEB-INF/jsp/basket.jsp"
))
.
andExpect
(
status
().
isOk
());
...
...
@@ -39,27 +43,34 @@ public class BasketControllerTest {
final
MockHttpSession
mockHttpSession
=
new
MockHttpSession
();
// add alice
mvc
.
perform
(
MockMvcRequestBuilders
.
post
(
"/service/shelf/add"
)
MockHttpServletRequestBuilder
builder
=
MockMvcRequestBuilders
.
post
(
"/service/shelf/add"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
mockHttpSession
)
.
param
(
"uri"
,
"textgrid:kv2q.0"
))
// .accept(MediaType.APPLICATION_JSON)
.
param
(
"uri"
,
"textgrid:kv2q.0"
);
mvc
.
perform
(
builder
)
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
string
(
"1"
));
// add another
mvc
.
perform
(
MockMvcRequestBuilders
.
post
(
"/service/shelf/add"
)
builder
=
MockMvcRequestBuilders
.
post
(
"/service/shelf/add"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
mockHttpSession
)
.
param
(
"uri"
,
"textgrid:wfw9.0"
))
// .accept(MediaType.APPLICATION_JSON)
.
param
(
"uri"
,
"textgrid:wfw9.0"
);
mvc
.
perform
(
builder
)
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
string
(
"2"
));
// view html
mvc
.
perform
(
MockMvcRequestBuilders
.
get
(
"/shelf"
)
builder
=
MockMvcRequestBuilders
.
get
(
"/shelf"
)
.
session
(
mockHttpSession
)
.
accept
(
MediaType
.
TEXT_HTML
))
.
accept
(
MediaType
.
TEXT_HTML
);
mvc
.
perform
(
builder
)
.
andExpect
(
view
().
name
(
"basket"
))
.
andExpect
(
forwardedUrl
(
"/WEB-INF/jsp/basket.jsp"
))
.
andExpect
(
status
().
isOk
())
...
...
@@ -68,18 +79,22 @@ public class BasketControllerTest {
//.andExpect(model().attribute("results", containsString("Alice im Wunderland")));
// remove one
mvc
.
perform
(
MockMvcRequestBuilders
.
post
(
"/service/shelf/remove"
)
builder
=
MockMvcRequestBuilders
.
post
(
"/service/shelf/remove"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
mockHttpSession
)
.
param
(
"uri"
,
"textgrid:wfw9.0"
))
// .accept(MediaType.APPLICATION_JSON)
.
param
(
"uri"
,
"textgrid:wfw9.0"
);
mvc
.
perform
(
builder
)
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
string
(
"1"
));
// clear shelf
mvc
.
perform
(
MockMvcRequestBuilders
.
post
(
"/service/shelf/clear"
)
.
session
(
mockHttpSession
))
// .accept(MediaType.APPLICATION_JSON)
builder
=
MockMvcRequestBuilders
.
post
(
"/service/shelf/clear"
)
.
session
(
mockHttpSession
);
mvc
.
perform
(
builder
)
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
string
(
"0"
));
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment