Skip to content

Commit

Permalink
SAK-45593 Samigo file upload questions appear to wipe out audio respo…
Browse files Browse the repository at this point in the history
…nse on same page (sakaiproject#12094)

Co-authored-by: Earle Nietzel <[email protected]>
  • Loading branch information
kunaljaykam and ern authored Jan 2, 2024
1 parent f3e2890 commit 2e9a5e8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public GradebookInformation getGradebookInformation(final String gradebookUid) {

final Gradebook gradebook = getGradebook(gradebookUid);
if (gradebook == null) {
throw new IllegalArgumentException("Their is no gradbook associated with this Id: " + gradebookUid);
throw new IllegalArgumentException("Their is no gradebook associated with this Id: " + gradebookUid);
}

final GradebookInformation rval = new GradebookInformation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<button class="audio-record"><script>document.write(oEditor.lang.audiorecorder.record)</script></button>
<button class="audio-stop" disabled><script>document.write(oEditor.lang.audiorecorder.stop)</script></button>
<button class="audio-play" disabled><script>document.write(oEditor.lang.audiorecorder.play)</script></button>
<button class="audio-upload" disabled><script>document.write(oEditor.lang.audiorecorder.post)</script></button>
<button class="btn btn-primary text-white audio-upload" disabled><script>document.write(oEditor.lang.audiorecorder.post)</script></button>
<div id="audio-posting" style="display:none"><script>document.write(oEditor.lang.audiorecorder.posting)</script></div>
<div id="audio-finished" style="display:none"><script>document.write(oEditor.lang.audiorecorder.complete)</script></div>
<div id="audio-statusbar" style="display:none"> </div>
Expand Down
8 changes: 8 additions & 0 deletions library/src/webapp/js/sakai-recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@
var audioSrc = $(".audioSrc" + this.vars.questionId);
audioSrc.attr("src", this.vars.deliveryProtocol + "/samigo-app/servlet/ShowMedia?mediaId=" + json.mediaId);
audioSrc.parent()[0].load();

// Triggers AudioActionListener
const buttons = document.getElementsByClassName('audioUploadListenerBtn');
if (buttons.length > 0) {
buttons[0].click();
} else {
console.warn('Audio upload button not found, preventing the invoking of AudioActionListener');
}
}
$("#question" + this.vars.questionId).show();
$(".can_you_hear_" + this.vars.questionId + " a").attr("href", this.vars.deliveryProtocol + "/samigo-app/servlet/ShowMedia?mediaId=" + json.mediaId + "&setMimeType=false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
@Slf4j
public class AudioUploadActionListener implements ActionListener
{
private static ContextUtil cu;

/**
* ACTION. add audio recording to item grading
* @param ae the action event triggering the processAction method
Expand All @@ -66,56 +64,13 @@ public void processAction(ActionEvent ae) throws

try {
// get managed bean
DeliveryBean delivery = (DeliveryBean) cu.lookupBean("delivery");

// look for the correct file upload path information
String audioMediaUploadPath = getAudioMediaUploadPath(ae);
log.info("audioMediaUploadPath: " + audioMediaUploadPath);
DeliveryBean delivery = (DeliveryBean) ContextUtil.lookupBean("delivery");

// now use utility method to fetch the file
delivery.addMediaToItemGrading(audioMediaUploadPath);
log.info("delivery.addMediaToItemGrading(audioMediaUploadPath)");
delivery.saveWork();


} catch (Exception e) {
log.error(e.getMessage(), e);
}
}

/**
* Get audio media upload path from the event's component tree.
* @param ae the event
* @return
*/
private String getAudioMediaUploadPath(FacesEvent ae)
{
String audioMediaUploadPath = null;

// now find what component fired the event
UIComponent component = ae.getComponent();
// get the subview containing the audio question
UIComponent parent = component.getParent();

// get the its peer components from the parent
List peers = parent.getChildren();

// look for the correct file upload path information
// held in the value of the component 'audioMediaUploadPath'
for (int i = 0; i < peers.size(); i++)
{
UIComponent peer = (UIComponent) peers.get(i);

if ("audioMediaUploadPath".equals(peer.getId()) && peer instanceof UIOutput)
{
audioMediaUploadPath = "" + ((UIOutput) peer).getValue();
log.info("FOUND: Component " + i +
" peer.getId(): " + peer.getId()+
" peer.getValue(): " + audioMediaUploadPath );
break;
}
}

return audioMediaUploadPath;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,17 @@ public ShowMediaServlet()
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
doPost(req,res);
handleMediaRequest(req, res);
}

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
handleMediaRequest(req, res);
}

private void handleMediaRequest(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String agentIdString = getAgentString(req, res);
if (agentIdString == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<button class="audio-record"></f:verbatim><h:outputFormat value=" #{deliveryMessages.audio_recorder_record}" /><f:verbatim></button>
<button class="audio-stop" disabled></f:verbatim><h:outputFormat value=" #{deliveryMessages.audio_recorder_stop}" /><f:verbatim></button>
<button class="audio-play" disabled></f:verbatim><h:outputFormat value=" #{deliveryMessages.audio_recorder_play}" /><f:verbatim></button>
<button class="audio-upload" disabled></f:verbatim><h:outputFormat value=" #{deliveryMessages.audio_recorder_post}" /><f:verbatim></button>
<button class="btn btn-primary text-white audio-upload" disabled></f:verbatim><h:outputFormat value=" #{deliveryMessages.audio_recorder_post}" /><f:verbatim></button>
</div>

<%-- SAM-2317 We're going to keep the mic check hidden until more browsers support it --%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,17 @@ should be included in file importing DeliveryMessages
<%-- this invisible text is a trick to get the value set in the component tree
without displaying it; audioMediaUploadPath will get this to the back end
--%>

<%-- delivery action triggered by sakai-recorder js --%>
<h:commandButton id="audioButton" styleClass="audioUploadListenerBtn d-none" value="Upload" type="submit"
rendered="#{delivery.actionString=='takeAssessment'
|| delivery.actionString=='takeAssessmentViaUrl'}">
<f:actionListener
type="org.sakaiproject.tool.assessment.ui.listener.delivery.AudioUploadActionListener" />
</h:commandButton>

<h:outputText escape="false" value="
<input type=\"hidden\" name=\"mediaLocation_#{question.itemData.itemId}\" value=\"jsf/upload_tmp/assessment#{delivery.assessmentId}/question#{question.itemData.itemId}/#{person.eid}/audio_#{delivery.assessmentGrading.assessmentGradingId}.au\"/>" />
<input type=\"hidden\" name=\"mediaLocation_#{question.itemData.itemId}\" value=\"jsf/upload_tmp/assessment#{delivery.assessmentId}/question#{question.itemData.itemId}/#{person.eid}/audio_#{delivery.assessmentGrading.assessmentGradingId}.au\"/>" />

<h:outputText value="#{question.text} " escape="false">
<f:converter converterId="org.sakaiproject.tool.assessment.jsf.convert.SecureContentWrapper" />
Expand Down

0 comments on commit 2e9a5e8

Please sign in to comment.