-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
184 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,64 @@ | ||
const url = "https://skynet.cs.vt.edu/peml-live/api/parse"; | ||
|
||
// 获取 PEML 数据 | ||
// Fetch the PEML data from a local file. | ||
fetch('/data/s7.peml') | ||
.then(response => { | ||
// Convert the response to text format. | ||
return response.text(); | ||
}) | ||
.then(pemlText => { | ||
// Construct the payload to send in the POST request. | ||
const payload = { | ||
"peml": pemlText, | ||
"output_format": "json", | ||
"render_to_html": "true" | ||
"peml": pemlText, // The PEML data as text. | ||
"output_format": "json", // Specify the output format as JSON. | ||
"render_to_html": "true" // Request HTML rendering. | ||
}; | ||
|
||
// 发送 POST 请求进行解析 | ||
// Send a POST request to the server to parse the PEML text. | ||
$.post(url, payload, function(data, status) { | ||
console.log('Post status:', status); | ||
console.log('Post data:', data); | ||
console.log('Post status:', status); // Log the status of the POST request. | ||
console.log('Post data:', data); // Log the data received from the POST request. | ||
|
||
// 检查服务器响应数据是否包含所需字段 | ||
// Check if the server's response contains the necessary fields. | ||
if (data && data.title && data.instructions && data.assets && data.assets.code && data.assets.code.starter && data.assets.code.starter.files && data.assets.code.starter.files[0] && data.assets.code.starter.files[0].content) { | ||
// 获取你需要的字段 | ||
var title = data.title.split(" -- ")[0]; | ||
var instructions = data.instructions; | ||
var initialArray = data.assets.code.starter.files[0].content.map(item => item.code.split('\\n')); | ||
// Extract the required fields from the response. | ||
var title = data.title.split(" -- ")[0]; // Get the title and clean it. | ||
var instructions = data.instructions; // Get the instructions directly. | ||
var initialArray = data.assets.code.starter.files[0].content.map(item => item.code.split('\\n')); // Process the initial array of code. | ||
|
||
// 在这里使用你获取的字段 | ||
document.getElementById("title").innerHTML = title; | ||
document.getElementById("instructions").innerHTML = instructions; | ||
// Use the extracted fields in your application. | ||
document.getElementById("title").innerHTML = title; // Display the title. | ||
document.getElementById("instructions").innerHTML = instructions; // Display the instructions. | ||
|
||
var parson = new ParsonsWidget(); | ||
parson.init(initialArray); | ||
parson.shuffleLines(); | ||
var parson = new ParsonsWidget(); // Create a new ParsonsWidget instance. | ||
parson.init(initialArray); // Initialize the widget with the initial array. | ||
parson.shuffleLines(); // Shuffle the lines initially. | ||
|
||
// Add an event listener for creating a new instance of the shuffled lines. | ||
$("#newInstanceLink").click(function(event) { | ||
event.preventDefault(); | ||
parson.shuffleLines(); | ||
}); | ||
|
||
// Add an event listener for providing feedback. | ||
$("#feedbackLink").click(function(event) { | ||
event.preventDefault(); | ||
var fb = parson.getFeedback(); | ||
$("#feedback").html(fb.feedback); | ||
$("#feedback").html(fb.feedback); // Display the feedback. | ||
if (fb.success) { | ||
score = 50; | ||
score = 50; // Set score on success. | ||
} else { | ||
score = 0; | ||
score = 0; // Reset score on failure. | ||
} | ||
updateScore(score); | ||
updateScore(score); // Update the score display. | ||
}); | ||
|
||
function updateScore(score) { | ||
// 更新分数的代码 | ||
// Implement the logic to update the score in the UI or backend. | ||
} | ||
} else { | ||
console.error('服务器响应数据不完整或格式不正确'); | ||
// 在这里处理服务器响应数据不完整或格式不正确的情况 | ||
console.error('Incomplete or incorrect server response data.'); | ||
// Handle cases where server response data is incomplete or incorrect. | ||
} | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.