diff --git a/src/main/java/de/thm/arsnova/cache/CacheBuster.java b/src/main/java/de/thm/arsnova/cache/CacheBuster.java index 5291d6ee9f3def6b8c5850e5694a642d4f959e88..78e9cc75e42e94247aafc43e464de96cb4a1fe07 100644 --- a/src/main/java/de/thm/arsnova/cache/CacheBuster.java +++ b/src/main/java/de/thm/arsnova/cache/CacheBuster.java @@ -125,4 +125,7 @@ public class CacheBuster implements ICacheBuster, NovaEventVisitor { @Override public void visit(LockFeedbackEvent lockFeedbackEvent) { } + @Override + public void visit(FlipFlashcardsEvent flipFlashcardsEvent) { } + } diff --git a/src/main/java/de/thm/arsnova/controller/SessionController.java b/src/main/java/de/thm/arsnova/controller/SessionController.java index 1ee9bcdd3b552d7315038b788735b61afde96461..6787596c7b99414fe0577f56efce50afea453581 100644 --- a/src/main/java/de/thm/arsnova/controller/SessionController.java +++ b/src/main/java/de/thm/arsnova/controller/SessionController.java @@ -376,6 +376,17 @@ public class SessionController extends PaginationController { ) { return sessionService.lockFeedbackInput(sessionkey, lock); } + + @RequestMapping(value = "/{sessionkey}/flipflashcards", method = RequestMethod.POST) + @ApiOperation(value = "flip all flashcards in session", + nickname = "lockFeedbackInput") + public boolean flipFlashcards( + @ApiParam(value = "session-key from current session", required = true) @PathVariable final String sessionkey, + @ApiParam(value = "flip", required = true) @RequestParam(required = true) final Boolean flip, + @ApiParam(value = "http servlet response", required = true) final HttpServletResponse response + ) { + return sessionService.flipFlashcards(sessionkey, flip); + } /* internal redirections */ diff --git a/src/main/java/de/thm/arsnova/domain/LearningProgressFactory.java b/src/main/java/de/thm/arsnova/domain/LearningProgressFactory.java index 3d67580f4a990f05f5fb5a488a6e29a27828e157..28d1132b209c9e0fdb4884d8917821c6b0b9bf9a 100644 --- a/src/main/java/de/thm/arsnova/domain/LearningProgressFactory.java +++ b/src/main/java/de/thm/arsnova/domain/LearningProgressFactory.java @@ -184,4 +184,7 @@ public class LearningProgressFactory implements NovaEventVisitor, ILearningProgr @Override public void visit(LockFeedbackEvent lockFeedbackEvent) { } + @Override + public void visit(FlipFlashcardsEvent flipFlashcardsEvent) { } + } diff --git a/src/main/java/de/thm/arsnova/entities/Session.java b/src/main/java/de/thm/arsnova/entities/Session.java index 6250806da1e299021019b6e852c7a67eab7f5942..e0f22a0009d436bf51cb7ffaee3cdf3992ee0661 100644 --- a/src/main/java/de/thm/arsnova/entities/Session.java +++ b/src/main/java/de/thm/arsnova/entities/Session.java @@ -57,6 +57,7 @@ public class Session implements Serializable { private String ppLevel; private String sessionType; private boolean feedbackLock; + private boolean flipFlashcards; private String _id; private String _rev; @@ -92,6 +93,7 @@ public class Session implements Serializable { copy.ppLevel = original.ppLevel; copy.sessionType = original.sessionType; copy.feedbackLock = original.feedbackLock; + copy.flipFlashcards = original.flipFlashcards; copy._id = original._id; copy._rev = original._rev; @@ -339,6 +341,15 @@ public class Session implements Serializable { public void setFeedbackLock(Boolean lock) { this.feedbackLock = lock; } + + @ApiModelProperty(required = true, value = "the flashcard flip condition") + public boolean getFlipFlashcards() { + return flipFlashcards; + } + + public void setFlipFlashcards(Boolean flip) { + this.flipFlashcards = flip; + } @Override public String toString() { diff --git a/src/main/java/de/thm/arsnova/events/FlipFlashcardsEvent.java b/src/main/java/de/thm/arsnova/events/FlipFlashcardsEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..332124988aa1bf316abe2ceac2ed95352badc8ca --- /dev/null +++ b/src/main/java/de/thm/arsnova/events/FlipFlashcardsEvent.java @@ -0,0 +1,37 @@ +/* + * This file is part of ARSnova Backend. + * Copyright (C) 2012-2016 The ARSnova Team + * + * ARSnova Backend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ARSnova Backend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package de.thm.arsnova.events; + +import de.thm.arsnova.entities.Session; + +/** + * Fires whenever voting on a question is disabled. + */ +public class FlipFlashcardsEvent extends SessionEvent { + + private static final long serialVersionUID = 1L; + + public FlipFlashcardsEvent(Object source, Session session) { + super(source, session); + } + + @Override + public void accept(NovaEventVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/main/java/de/thm/arsnova/events/NovaEventVisitor.java b/src/main/java/de/thm/arsnova/events/NovaEventVisitor.java index 13fccdce39eb7faa801c6d54d855c01fcc295725..0626f7bf29dba3ba4f1074f34f06cd317b56074a 100644 --- a/src/main/java/de/thm/arsnova/events/NovaEventVisitor.java +++ b/src/main/java/de/thm/arsnova/events/NovaEventVisitor.java @@ -81,4 +81,6 @@ public interface NovaEventVisitor { void visit(FeatureChangeEvent featureChangeEvent); void visit(LockFeedbackEvent lockFeedbackEvent); + + void visit(FlipFlashcardsEvent flipFlashcardsEvent); } diff --git a/src/main/java/de/thm/arsnova/services/ISessionService.java b/src/main/java/de/thm/arsnova/services/ISessionService.java index 368305dd940658002d07a5c47d0022f11e3af421..0e95e24738c9d3a1610a4a91d195cf46775e38c3 100644 --- a/src/main/java/de/thm/arsnova/services/ISessionService.java +++ b/src/main/java/de/thm/arsnova/services/ISessionService.java @@ -83,4 +83,6 @@ public interface ISessionService { SessionFeature changeSessionFeatures(String sessionkey, SessionFeature features); boolean lockFeedbackInput(String sessionkey, Boolean lock); + + boolean flipFlashcards(String sessionkey, Boolean flip); } diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java index dd3ea57316b2fdc042787b655b245de762d9b066..67038d0b57c5f341226b976759bd1162415ca24f 100644 --- a/src/main/java/de/thm/arsnova/services/SessionService.java +++ b/src/main/java/de/thm/arsnova/services/SessionService.java @@ -33,6 +33,7 @@ import de.thm.arsnova.entities.transport.ImportExportSession; import de.thm.arsnova.entities.transport.LearningProgressValues; import de.thm.arsnova.events.DeleteSessionEvent; import de.thm.arsnova.events.FeatureChangeEvent; +import de.thm.arsnova.events.FlipFlashcardsEvent; import de.thm.arsnova.events.LockFeedbackEvent; import de.thm.arsnova.events.NewSessionEvent; import de.thm.arsnova.events.StatusSessionEvent; @@ -457,6 +458,18 @@ public class SessionService implements ISessionService, ApplicationEventPublishe this.publisher.publishEvent(new LockFeedbackEvent(this, session)); return databaseDao.updateSession(session).getFeedbackLock(); } + + @Override + public boolean flipFlashcards(String sessionkey, Boolean flip) { + final Session session = databaseDao.getSessionFromKeyword(sessionkey); + final User user = userService.getCurrentUser(); + if (!session.isCreator(user)) { + throw new UnauthorizedException(); + } + session.setFlipFlashcards(flip); + this.publisher.publishEvent(new FlipFlashcardsEvent(this, session)); + return databaseDao.updateSession(session).getFlipFlashcards(); + } /** * diff --git a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java index 7c6da91214321e75ffaf6cdf3e9264ed4558292f..495040a55ec78a772e7c92ca06fd0b49c4a25493 100644 --- a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java +++ b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java @@ -355,15 +355,22 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { */ public void reportSessionDataToClient(final String sessionKey, final User user, final SocketIOClient client) { final de.thm.arsnova.entities.Session session = sessionService.getSessionInternal(sessionKey, user); + final de.thm.arsnova.entities.SessionFeature features = sessionService.getSessionFeatures(sessionKey); + client.sendEvent("unansweredLecturerQuestions", questionService.getUnAnsweredLectureQuestionIds(sessionKey, user)); client.sendEvent("unansweredPreparationQuestions", questionService.getUnAnsweredPreparationQuestionIds(sessionKey, user)); client.sendEvent("countLectureQuestionAnswers", questionService.countLectureQuestionAnswersInternal(sessionKey)); client.sendEvent("countPreparationQuestionAnswers", questionService.countPreparationQuestionAnswersInternal(sessionKey)); - client.sendEvent("countFlashcards", questionService.countFlashcardsForUserInternal(sessionKey)); client.sendEvent("activeUserCountData", sessionService.activeUsers(sessionKey)); client.sendEvent("learningProgressOptions", session.getLearningProgressOptions()); final de.thm.arsnova.entities.Feedback fb = feedbackService.getFeedback(sessionKey); client.sendEvent("feedbackData", fb.getValues()); + + if (features.isFlashcard() || features.isFlashcardFeature()) { + client.sendEvent("countFlashcards", questionService.countFlashcardsForUserInternal(sessionKey)); + client.sendEvent("flipFlashcards", session.getFlipFlashcards()); + } + try { final long averageFeedback = feedbackService.getAverageFeedbackRounded(sessionKey); client.sendEvent("feedbackDataRoundedAverage", averageFeedback); @@ -579,13 +586,24 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { @Override public void visit(FeatureChangeEvent event) { final String sessionKey = event.getSession().getKeyword(); - broadcastInSession(sessionKey, "featureChange", event.getSession().getFeatures()); + final de.thm.arsnova.entities.SessionFeature features = event.getSession().getFeatures(); + broadcastInSession(sessionKey, "featureChange", features); + + if (features.isFlashcard() || features.isFlashcardFeature()) { + broadcastInSession(sessionKey, "countFlashcards", questionService.countFlashcardsForUserInternal(sessionKey)); + broadcastInSession(sessionKey, "flipFlashcards", event.getSession().getFlipFlashcards()); + } } @Override public void visit(LockFeedbackEvent event) { broadcastInSession(event.getSession().getKeyword(), "lockFeedback", event.getSession().getFeedbackLock()); } + + @Override + public void visit(FlipFlashcardsEvent event) { + broadcastInSession(event.getSession().getKeyword(), "flipFlashcards", event.getSession().getFlipFlashcards()); + } @Override public void visit(DeleteQuestionEvent deleteQuestionEvent) {