forked from facebookresearch/ParlAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor MTurk html to make it more modular
- Loading branch information
Will Feng
committed
Jul 6, 2017
1 parent
c5fd1eb
commit 2b413f2
Showing
12 changed files
with
467 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<!-- | ||
Copyright (c) 2017-present, Facebook, Inc. | ||
All rights reserved. | ||
This source code is licensed under the BSD-style license found in the | ||
LICENSE file in the root directory of this source tree. An additional grant | ||
of patent rights can be found in the PATENTS file in the same directory. | ||
--> | ||
{% extends "core.html" %} | ||
|
||
{% block right_pane %} | ||
<div id="right-pane" style="min-height: 100%; display: flex; flex-direction: column; justify-content: space-between;"> | ||
<div id="right-top-pane" style="width: 100%; height: 570px; padding-top: 60px; padding-left: 20px; padding-right: 20px; padding-bottom: 20px; overflow:scroll; "> | ||
<div id="message_thread" style="width: 100%"> | ||
</div> | ||
</div> | ||
|
||
<div id="right-bottom-pane" style="width: 100%; background-color: #eee"> | ||
<div id="approval" style="padding-left: 35px; padding-top: 30px; padding-bottom: 30px; padding-right: 35px; float: left"> | ||
<div id="approval-prompt-text" style="width: 100%; display: block; float: left"> | ||
<span class="prompt-text" style="width: 100%; float: left; font-size: 16px">Do you approve this work?</span> | ||
</div> | ||
<div id="approval-buttons-group" style="width: 100%; display: block; float: left; margin-top: 30px;"> | ||
<button id="approve-button" type="button" class="btn btn-primary btn-lg" style="width: 200px"> | ||
<span class="glyphicon glyphicon-ok" aria-hidden="true"></span> Approve | ||
</button> | ||
<button id="reject-button" type="button" class="btn btn-danger btn-lg" style="margin-left: 20px; width: 200px"> | ||
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Reject | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block handle_new_messages %} | ||
<script type="text/javascript"> | ||
function handle_new_messages(new_messages) { | ||
for (var i = 0; i < new_messages.length; i++) { | ||
var message = new_messages[i]; | ||
var agent_id = message['id']; | ||
var message_id = parseInt(message['message_id']); | ||
var message_text = message['text'].replace(/(?:\r\n|\r|\n)/g, '<br />'); | ||
var reward = null; | ||
var received_message_from_other_agents = false; | ||
if ('reward' in message) { | ||
reward = message['reward'] | ||
} | ||
|
||
if (!(message_id in messages_shown)) { | ||
if ($.inArray(agent_id, mturk_agent_ids) == -1) { | ||
$('div#message_thread').append(` | ||
<div class="row" style="margin-left: 0; margin-right: 0"> | ||
<div class="alert alert-warning" role="alert" style="float: left; display:table"> | ||
<span style="font-size: 16px"><b>`+agent_id+`</b>: `+message_text+`</span> | ||
</div> | ||
</div> | ||
`); | ||
received_message_from_other_agents = true; | ||
} else { | ||
if (reward) { | ||
var reward_text = reward; | ||
if (reward > 0) { | ||
reward_text = '+' + reward_text; | ||
} | ||
$('div#message_thread').append(` | ||
<div class="row" style="margin-left: 0; margin-right: 0"> | ||
<div class="alert alert-info" role="alert" style="float: right; display:table"> | ||
<span style="font-size: 16px"><b>`+agent_id+`</b>: `+reward_text+`</span> | ||
</div> | ||
</div> | ||
`); | ||
} else { | ||
$('div#message_thread').append(` | ||
<div class="row" style="margin-left: 0; margin-right: 0"> | ||
<div class="alert alert-info" role="alert" style="float: right; display:table"> | ||
<span style="font-size: 16px"><b>`+agent_id+`</b>: `+message_text+`</span> | ||
</div> | ||
</div> | ||
`); | ||
} | ||
} | ||
messages_shown[message_id] = true; | ||
} | ||
} | ||
if (new_messages.length > 0) { | ||
$("div#message_thread").css("display", ""); | ||
scroll_conversation_to_bottom(); | ||
} | ||
} | ||
</script> | ||
{% endblock %} | ||
|
||
{% block additional_scripts %} | ||
<script type="text/javascript"> | ||
function send_approval_and_update_UI(action) { | ||
$("div#message_thread").css("display", "none"); | ||
$("div#approval-prompt-text span.prompt-text").text("Submitting to MTurk..."); | ||
$("div#approval-buttons-group").css("display", "none"); | ||
|
||
var post_data_dict = { | ||
requester_key: get_url_parameter('requester_key'), | ||
task_group_id: task_group_id, | ||
conversation_id: conversation_id, | ||
action: action | ||
}; | ||
post_data_dict['method_name'] = 'review_hit'; | ||
$.ajax({ | ||
url: '/prod/json', | ||
type: "POST", | ||
data: JSON.stringify(post_data_dict), | ||
contentType: "application/json", | ||
success: function(data){ | ||
if (verbose_log) console.log(data); | ||
|
||
$("div#approval-prompt-text span.prompt-text").text("Do you approve this work?"); | ||
$("div#approval-buttons-group").css("display", ""); | ||
|
||
hit_index = parseInt(hit_index); | ||
assignment_index = parseInt(assignment_index); | ||
|
||
if (assignment_index < num_assignments) { | ||
window.location.href = window.location.href.replace('hit_index='+hit_index+'&assignment_index='+assignment_index, 'hit_index='+hit_index+'&assignment_index='+(assignment_index+1)); | ||
} else if (hit_index < num_hits) { | ||
window.location.href = window.location.href.replace('hit_index='+hit_index+'&assignment_index='+assignment_index, 'hit_index='+(hit_index+1)+'&assignment_index=1'); | ||
} else { | ||
$("div#message_thread").css("display", "none"); | ||
$("div#approval-prompt-text span.prompt-text").text("All done! Please feel free to close the window."); | ||
$("div#approval-buttons-group").css("display", "none"); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
$("button#approve-button").click(function() { | ||
send_approval_and_update_UI('approve'); | ||
}); | ||
|
||
$("button#reject-button").click(function() { | ||
send_approval_and_update_UI('reject'); | ||
}); | ||
</script> | ||
{% endblock %} | ||
|
||
{% block additional_init_scripts %} | ||
<script type="text/javascript"> | ||
function init_additional() { | ||
$("div#left-pane").css("min-height", $(window).height()); | ||
} | ||
</script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- | ||
Copyright (c) 2017-present, Facebook, Inc. | ||
All rights reserved. | ||
This source code is licensed under the BSD-style license found in the | ||
LICENSE file in the root directory of this source tree. An additional grant | ||
of patent rights can be found in the PATENTS file in the same directory. | ||
--> | ||
{% extends "approval_core.html" %} |
Oops, something went wrong.