[sword-svn] r172 - in trunk: . web
Sun Feb 28 17:15:43 EST 2021
Author:
Date: 2021-02-28 17:15:43 -0500 (Sun, 28 Feb 2021)
New Revision: 172
Added:
trunk/web/
trunk/web/clear.jsp
trunk/web/getLessons.jsp
trunk/web/getWord.jsp
trunk/web/index.jsp
trunk/web/quiz.jsp
Log:
added web interface
Added: trunk/web/clear.jsp
===================================================================
--- trunk/web/clear.jsp (rev 0)
+++ trunk/web/clear.jsp 2021-02-28 22:15:43 UTC (rev 172)
@@ -0,0 +1,6 @@
+<%
+session.setAttribute("fcquizer", null);
+session.setAttribute("fcword", null);
+session.setAttribute("fcanswers", null);
+session.setAttribute("fcwrong", null);
+%>
Added: trunk/web/getLessons.jsp
===================================================================
--- trunk/web/getLessons.jsp (rev 0)
+++ trunk/web/getLessons.jsp 2021-02-28 22:15:43 UTC (rev 172)
@@ -0,0 +1,18 @@
+<%@ page import="org.crosswire.flashcards.LessonManager" %>
+<%@ page import="org.crosswire.flashcards.LessonSet" %>
+<%@ page import="org.crosswire.flashcards.Lesson" %>
+<%
+LessonManager mgr = (LessonManager)session.getAttribute("fcmgr");
+String l = request.getParameter("l");
+if (mgr == null) return;
+if (l == null) return;
+LessonSet ls = mgr.getLessonSet(l);
+if (ls == null) return;
+for (Object o : ls.getLessons()) {
+ Lesson lesson = (Lesson)o;
+%>
+ <option value="<%=lesson.getDescription()%>"><%=lesson.getDescription()%></option>
+<%
+}
+%>
+
Added: trunk/web/getWord.jsp
===================================================================
--- trunk/web/getWord.jsp (rev 0)
+++ trunk/web/getWord.jsp 2021-02-28 22:15:43 UTC (rev 172)
@@ -0,0 +1,83 @@
+<%@ page
+ language="java"
+ contentType="text/html;charset=utf-8"
+%>
+<%@ page import="java.util.Vector" %>
+<%@ page import="org.crosswire.flashcards.LessonManager" %>
+<%@ page import="org.crosswire.flashcards.LessonSet" %>
+<%@ page import="org.crosswire.flashcards.Lesson" %>
+<%@ page import="org.crosswire.flashcards.FlashCard" %>
+<%@ page import="org.crosswire.flashcards.Quizer" %>
+<%
+Quizer quizer = (Quizer)session.getAttribute("fcquizer");
+if (quizer == null) return;
+
+FlashCard currentWord = (FlashCard)session.getAttribute("fcword");
+Vector answers = (Vector)session.getAttribute("fcanswers");
+Integer w = (Integer)session.getAttribute("fcwrong");
+int wrong = -1;
+if (w != null) wrong = w.intValue();
+String status = "Begin";
+
+String c = request.getParameter("c");
+if (currentWord != null) {
+ boolean correct = false;
+ try { correct = answers.elementAt(Integer.parseInt(c)).equals(currentWord.getBack()); } catch (Exception e) {}
+
+ if (correct) {
+ status = "Correct";
+ currentWord = null;
+ }
+ else {
+ status = "Try again";
+ session.setAttribute("fcwrong", new Integer(++wrong));
+ }
+}
+
+if ((currentWord == null || answers == null)) {
+ currentWord = quizer.getRandomWord(wrong);
+ answers = quizer.getRandomAnswers(7);
+ session.setAttribute("fcword", currentWord);
+ session.setAttribute("fcanswers", answers);
+ session.setAttribute("fcwrong", new Integer(0));
+ c = null;
+}
+if (currentWord != null) {
+%>
+
+<div id="word">
+<%= currentWord.getFront() %>
+</div>
+<hr/>
+<div id="answers">
+<form>
+<%
+for (int i = 0; i < answers.size(); i++) {
+ String answer = (String)answers.elementAt(i);
+ if (answer.length() > 50) answer = answer.substring(0, 50);
+%>
+<input type="radio" name="c" onclick="getWord(this);" value="<%=i%>" <%=answer.equals(c)?"checked=\"checked\"":""%>><%=answer%></input><br/>
+<%
+}
+%>
+</form>
+</div>
+<hr/>
+<div id="status">
+ <%=status%> | <%=Integer.toString(quizer.getNotLearnedCount())%> | <%=Integer.toString(quizer.getTotalAsked() - quizer.getTotalWrong())%>/<%=Integer.toString(quizer.getTotalAsked())%> | <%=quizer.getPercentage()%>%
+</div>
+
+<%
+}
+else {
+%>
+<br/>
+<br/>
+<h2>-=+* Great Job *+=-</h2>
+<br/>
+<br/>
+<%
+ session.setAttribute("fcquizer", null);
+}
+%>
+
Added: trunk/web/index.jsp
===================================================================
--- trunk/web/index.jsp (rev 0)
+++ trunk/web/index.jsp 2021-02-28 22:15:43 UTC (rev 172)
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN"
+ "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd" >
+
+<%@ page import="org.crosswire.flashcards.LessonManager" %>
+<%@ page import="org.crosswire.flashcards.LessonSet" %>
+<%
+final String SKEL_PATH ="/home/crosswire/bin/fcskel";
+final String LESSONS_PATH="/home/crosswire/html/fc/g/packages";
+String lessonDir = request.getParameter("l");
+lessonDir = (lessonDir == null) ? (SKEL_PATH+"/target/install")
+ : (LESSONS_PATH+"/"+lessonDir);
+
+LessonManager mgr = (LessonManager)session.getAttribute("fcmgr");
+String oldLessonDir = (String)session.getAttribute("fclessdir");
+if (!lessonDir.equals(oldLessonDir)) mgr = null;
+if (mgr == null) {
+ session.setAttribute("fcmgr", new LessonManager(lessonDir));
+ session.setAttribute("fclessdir", lessonDir);
+}
+mgr = (LessonManager)session.getAttribute("fcmgr");
+%>
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
+
+<head profile="http://www.w3.org/2000/08/w3c-synd/#">
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Flashcards Web Quizer</title>
+<script type="text/javascript" src="//www.google.com/jsapi"></script>
+<script type="text/javascript">
+// <!--
+google.load("prototype", "1.6.0.2");
+function lschange(ls) {
+ d = document.getElementById('lessons');
+ d.innerHTML='';
+ new Ajax.Request('getLessons.jsp?l='+ls.value, {
+ method: 'get',
+ onSuccess: function(transport) {
+ d = document.getElementById('lessons');
+ d.innerHTML = transport.responseText;
+ }
+ });
+}
+
+function lessonchange(l) {
+ return;
+ var lessons='';
+ for (var i=0; i<l.options.length; i++) {
+ if (l.options[i].selected) {
+ lessons+=((lessons.length>0)?'&':'?');
+ lessons+='l='+escape(l.options[i].value);
+ }
+ }
+}
+
+function quiz() {
+ new Ajax.Request('clear.jsp?t='+new Date().getTime(), {
+ method: 'get',
+ onSuccess: function(transport) {
+ d = document.getElementById('setup');
+ d.submit();
+ }
+ });
+}
+// -->
+</script>
+</head>
+<body>
+<form id="setup" action="quiz.jsp" method="get">
+<fieldset>
+<select name="ls" onchange="lschange(this)" size="10">
+<%
+for (Object o : mgr.getLessonSets()) {
+LessonSet ls = (LessonSet)o;
+if (!"images".equals(ls.getDescription())) {
+%>
+<option value="<%=ls.getDescription()%>"><%=ls.getDescription()%></option>
+<%
+}
+}
+%>
+</select>
+<select id="lessons" name="l" onchange="lessonchange(this)" size="10" multiple="multiple">
+<option> </option>
+</select>
+<button onclick="quiz(); return false;">Quiz</button>
+</fieldset>
+</form>
+</body>
+</html>
Added: trunk/web/quiz.jsp
===================================================================
--- trunk/web/quiz.jsp (rev 0)
+++ trunk/web/quiz.jsp 2021-02-28 22:15:43 UTC (rev 172)
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
+<%@ page
+ language="java"
+ contentType="text/html;charset=utf-8"
+%>
+<%@ page import="org.crosswire.flashcards.LessonManager" %>
+<%@ page import="org.crosswire.flashcards.LessonSet" %>
+<%@ page import="org.crosswire.flashcards.Lesson" %>
+<%@ page import="org.crosswire.flashcards.Quizer" %>
+<%
+Quizer quizer = (Quizer)session.getAttribute("fcquizer");
+if (quizer == null) {
+ LessonManager mgr = (LessonManager)session.getAttribute("fcmgr");
+ String ls = request.getParameter("ls");
+ String l[] = request.getParameterValues("l");
+ if (mgr == null) return;
+ if (ls == null) return;
+ if (l == null) return;
+ if (l.length == 0) return;
+ LessonSet leset = mgr.getLessonSet(ls);
+ if (leset == null) return;
+ quizer = new Quizer();
+ for (String o : l) {
+ Lesson lesson = leset.getLesson(o);
+ if (lesson != null) {
+ quizer.loadLesson(lesson);
+ }
+ }
+ session.setAttribute("fcquizer", quizer);
+}
+%>
+<head profile="http://www.w3.org/2000/08/w3c-synd/#">
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<script type="text/javascript" src="//www.google.com/jsapi"></script>
+<script language="JavaScript">
+google.load("prototype", "1.6.0.2");
+
+function getWord(choice) {
+ s = document.getElementById('status');
+ if (s) s.innerHTML = '';
+ options = document.getElementsByTagName('input');
+ for (i = 0; i < options.length; i++) {
+ var o = options[i];
+ o.disabled = true;
+ }
+ var u = 'getWord.jsp'
+ if (choice) u += '?c='+escape(choice.value);
+ new Ajax.Request(u, {
+ method: 'get',
+ onSuccess: function(transport) {
+ d = document.getElementById('wordItem');
+ d.innerHTML = transport.responseText;
+ }
+ });
+}
+
+function loaded() {
+ getWord();
+}
+</script>
+<style>
+#word {
+ font-size: 300%;
+}
+</style>
+</head>
+<body onload="loaded();">
+<div id="wordItem">
+</div>
+</body>
+</html>
More information about the sword-cvs
mailing list