Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Riina Antikainen
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 602bcc35
authored
Dec 12, 2014
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajax stuff for queue management
1 parent
17e0fb65
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
107 additions
and
15 deletions
code/moya-beans/ejbModule/fi/codecrew/moya/beans/QueueBean.java
code/moya-web/WebContent/neomap/view.xhtml
code/moya-web/src/main/java/fi/codecrew/moya/rest/placemap/v1/PlacemapRestViewV1.java
code/moya-web/src/main/java/fi/codecrew/moya/rest/pojo/placemap/IntegerRoot.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/QueueBean.java
View file @
602bcc3
...
...
@@ -47,7 +47,7 @@ public class QueueBean implements QueueBeanLocal {
private
final
Map
<
Integer
,
MapQueue
>
mapqueues
;
private
int
reservingSize
=
2
;
private
int
reservingSize
=
1
;
private
class
MapQueue
{
// private final Set<MapReservationQueueEntry> reserving = new HashSet<>();
...
...
@@ -94,6 +94,16 @@ public class QueueBean implements QueueBeanLocal {
public
boolean
isReserving
(
EventUser
e
)
{
// Check queue size and add entry to queue
checkReservingEntry
();
MapReservationQueueEntry
que
=
queEntries
.
get
(
e
);
if
(
que
!=
null
)
{
que
.
setSeenTime
(
new
Date
());
}
return
reserving
.
contains
(
e
);
}
private
void
checkReservingEntry
()
{
if
(
reserving
.
size
()
<
reservingSize
)
{
synchronized
(
queue
)
{
if
(
reserving
.
size
()
<
reservingSize
)
{
...
...
@@ -104,12 +114,6 @@ public class QueueBean implements QueueBeanLocal {
}
}
}
MapReservationQueueEntry
que
=
queEntries
.
get
(
e
);
if
(
que
!=
null
)
{
que
.
setSeenTime
(
new
Date
());
}
return
reserving
.
contains
(
e
);
}
public
MapReservationQueueEntry
remove
(
EventUser
user
)
...
...
@@ -124,6 +128,7 @@ public class QueueBean implements QueueBeanLocal {
logger
.
info
(
"Removed user {} from queue"
);
}
ret
=
queEntries
.
remove
(
user
);
checkReservingEntry
();
}
return
ret
;
}
...
...
@@ -132,10 +137,16 @@ public class QueueBean implements QueueBeanLocal {
MapReservationQueueEntry
ret
=
null
;
synchronized
(
queue
)
{
if
(!
reserving
.
contains
(
user
)
&&
!
queue
.
contains
(
user
))
{
ret
=
new
MapReservationQueueEntry
();
queEntries
.
put
(
user
,
ret
);
boolean
queStat
=
queue
.
offer
(
user
);
logger
.
info
(
"User {} not in queue, offer state {}"
,
user
,
queStat
);
if
(
reserving
.
size
()
<
reservingSize
)
{
boolean
resStat
=
reserving
.
add
(
user
);
logger
.
info
(
"User {} not in queue and reserving smaller than size Entering directly: Success: {}"
,
user
,
resStat
);
}
else
{
boolean
queStat
=
queue
.
offer
(
user
);
logger
.
info
(
"User {} not in queue, offer state {}"
,
user
,
queStat
);
}
}
else
{
ret
=
queEntries
.
get
(
user
);
logger
.
info
(
"User {} already in queue. Not entering again {}"
,
user
,
ret
);
...
...
@@ -286,4 +297,7 @@ public class QueueBean implements QueueBeanLocal {
return
ret
;
}
}
code/moya-web/WebContent/neomap/view.xhtml
View file @
602bcc3
...
...
@@ -22,7 +22,8 @@
action="#{ajaxMapView.placeClicked()}" />
</h:form>
-->
<p:dialog
rendered=
"#{ajaxMapView.isMgmtPermission()}"
visible=
"#{!empty ajaxMapView.place}"
id=
"fbdiag"
>
<p:dialog
rendered=
"#{ajaxMapView.isMgmtPermission()}"
visible=
"#{!empty ajaxMapView.place}"
id=
"fbdiag"
>
Clicked place name : #{ajaxMapView.place.name};
<h:link
rendered=
"#{!empty ajaxMapView.place}"
outcome=
"/place/edit"
>
<f:param
name=
"placeid"
value=
"#{ajaxMapView.place.id}"
/>
...
...
@@ -43,10 +44,13 @@
action=
"#{ajaxMapView.buySelectedPlaces()}"
ajax=
"false"
/>
</h:form>
</div>
<p:outputPanel
rendered=
"#{ajaxMapView.queueEnabled}"
>
<h:form>
<p:commandButton
value=
"#{i18n['mapView.enterQueue']}"
action=
"#{ajaxMapView.enterQueue()}"
ajax=
"false"
/>
<p:commandButton
value=
"#{i18n['mapView.check']}"
action=
"#{ajaxMapView.checkReserving()}"
/>
<p:commandButton
value=
"#{i18n['mapView.enterQueue']}"
action=
"#{ajaxMapView.enterQueue()}"
ajax=
"false"
/>
<p:commandButton
value=
"#{i18n['mapView.check']}"
action=
"#{ajaxMapView.checkReserving()}"
ajax=
"false"
/>
</h:form>
queueEntry #{ajaxMapView.queueEntry}
<br
/>
QueuePosition: #{ajaxMapView.queuePosition}
<br
/>
...
...
@@ -54,14 +58,37 @@
isReserving #{ajaxMapView.reserving}
<br
/>
</p:outputPanel>
<svg
id=
"seatmap"
style=
"margin: auto; border: 1px solid black;"
width=
"#{ajaxMapView.map.width}px"
height=
"#{ajaxMapView.map.height}px"
/>
<svg
id=
"seatmap"
style=
"margin: auto; border: 1px solid black;"
width=
"#{ajaxMapView.map.width}px"
height=
"#{ajaxMapView.map.height}px"
/>
<script
type=
"text/javascript"
>
px
=
placemap
({
function
updateQueue
(
data
)
{
if
(
data
.
value
===
undefined
)
{
alert
(
'not in queue'
);
}
else
if
(
data
.
value
==
0
)
{
alert
(
"Reserving"
);
}
else
{
alert
(
"Quue position "
+
data
.
value
);
}
}
function
updateMap
()
{
px
.
update
();
$
.
getJSON
(
"#{request.contextPath}/rest/placemap/v1/queue/#{ajaxMapView.map.id}/#{ajaxMapView.eventuser.id}"
)
.
done
(
function
(
data
){
updateQueue
(
data
);
}
);
}
px
=
placemap
({
element
:
document
.
getElementById
(
"seatmap"
),
moyaurl
:
"#{request.contextPath}"
,
map_id
:
#
{
ajaxMapView
.
map
.
id
},
onclick
:
function
(
d
)
{
px
.
update
();
//
px.update();
//alert(d);
// #{ajaxMapView.isMgmtPermission()?'placeClicker([{name: \'placeId\', value: d}])':''}
return
false
;
...
...
@@ -72,6 +99,8 @@
// px.enable_edit();
// });
//px.enable_edit();
setInterval
(
function
()
{
updateMap
()
},
5000
);
</script>
<h:panelGrid
columns=
"3"
cellpadding=
"10"
>
...
...
code/moya-web/src/main/java/fi/codecrew/moya/rest/placemap/v1/PlacemapRestViewV1.java
View file @
602bcc3
...
...
@@ -23,9 +23,12 @@ import org.slf4j.LoggerFactory;
import
fi.codecrew.moya.beans.PermissionBeanLocal
;
import
fi.codecrew.moya.beans.PlaceBeanLocal
;
import
fi.codecrew.moya.beans.QueueBeanLocal
;
import
fi.codecrew.moya.beans.UserBeanLocal
;
import
fi.codecrew.moya.model.EventMap
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.Place
;
import
fi.codecrew.moya.model.User
;
import
fi.codecrew.moya.rest.pojo.placemap.IntegerRoot
;
import
fi.codecrew.moya.rest.pojo.placemap.PlacemapMapRootPojo
;
import
fi.codecrew.moya.rest.pojo.placemap.SimplePlacePojo
;
import
fi.codecrew.moya.rest.pojo.placemap.SimplePlacelistRoot
;
...
...
@@ -50,6 +53,8 @@ public class PlacemapRestViewV1 {
@EJB
private
QueueBeanLocal
quebean
;
@EJB
private
UserBeanLocal
userbean
;
// @GET
// @Path("/maps")
...
...
@@ -110,6 +115,29 @@ public class PlacemapRestViewV1 {
return
SimplePlacelistRoot
.
wrap
(
thisplace
,
permbean
.
getCurrentUser
());
}
@GET
@Path
(
"/queue/{mapid}/{userid}"
)
public
IntegerRoot
getQueue
(
@PathParam
(
"mapid"
)
Integer
mapid
,
@PathParam
(
"userid"
)
Integer
userid
)
{
EventUser
user
=
null
;
if
(
userid
!=
null
)
{
// We might not have permission to create user.. It should exist if we are querying this, but
// there is no guarantees of that
user
=
userbean
.
findByEventUserId
(
userid
);
}
else
{
user
=
permbean
.
getCurrentUser
();
}
if
(
user
==
null
)
{
return
null
;
}
EventMap
map
=
placebean
.
findMap
(
mapid
);
IntegerRoot
root
=
new
IntegerRoot
();
root
.
setValue
(
quebean
.
getQueuePosition
(
map
,
user
));
return
root
;
}
@POST
@Path
(
"/place/{place}"
)
public
Response
togglePlaceReservation
(
@PathParam
(
"place"
)
Integer
placeId
)
...
...
code/moya-web/src/main/java/fi/codecrew/moya/rest/pojo/placemap/IntegerRoot.java
0 → 100644
View file @
602bcc3
package
fi
.
codecrew
.
moya
.
rest
.
pojo
.
placemap
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlRootElement
;
@XmlRootElement
public
class
IntegerRoot
{
private
Integer
value
=
-
1
;
@XmlElement
(
name
=
"value"
)
public
Integer
getValue
()
{
return
value
;
}
public
void
setValue
(
Integer
value
)
{
this
.
value
=
value
;
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment