diff --git a/comm/server/adcclilib.py b/comm/server/adcclilib.py index a413e64396dbd3ce537a3dd71d013107113485c3..fb03db34b7bf8148f0a26f4a642c203c20353d31 100644 --- a/comm/server/adcclilib.py +++ b/comm/server/adcclilib.py @@ -7,8 +7,10 @@ ADCCLI = "/home/pi/adc2018/conmgr/client/adccli" def _exec_adccli(cmd): exec_cmd = "{} {} {}".format(PYTHON2, ADCCLI, cmd).strip() + print("ADCCLI: {}".format(exec_cmd)) p = subprocess.run(exec_cmd, stdout=subprocess.PIPE, shell=True) res = p.stdout.decode().strip() + print(res) return res def login(url, username, password): @@ -35,10 +37,17 @@ def get_q_all(outpath): cmd = "get-q" question_list = _exec_adccli(cmd).split("\n") + print("--- ADCCLI questions ---") + print(question_list) + for v in question_list: - out_file_path = "{}/NL_Q{:02d}.txt".format(outpath, int(v)) - cmd = "--output {} get-q {}".format(out_file_path, v.rstrip()) - _exec_adccli(cmd) + if v.startswith("Q"): + qnumber = int(v.replace("Q", "")) + out_file_path = "{}/NL_Q{:02d}.txt".format(outpath, qnumber) + cmd = "--output {} get-q {}".format(out_file_path, qnumber) + r = _exec_adccli(cmd) + + return question_list def put_a(qnum, filepath): cmd = "put-a {} {}".format(qnum, filepath) diff --git a/comm/server/main.py b/comm/server/main.py index 2b097e810b8962a7eddd07b8d5f921bee1dc80fc..68157a4bdcef71640336aba841d9c5378f451665 100644 --- a/comm/server/main.py +++ b/comm/server/main.py @@ -473,6 +473,45 @@ def adccli_whoami(): res = {'message': r, 'status': r == d['username']} return json.dumps(res) +@app.route("/adccli-get-all-q") +def adccli_get_all_q(): + global app_args + + out_abspath = os.path.abspath(app_args['question']) + r = adcclilib.get_q_all(out_abspath) + + load_questions() + + res = {'message': r} + return json.dumps(res) + +@app.route("/adccli-put-a", methods=["POST"]) +def adccli_put_a(): + global app_args + global questions + + qname = request.form["qname"] + + if not "best_json" in questions[qname]: + res = {'message': "Required to 'save' before submission"} + else: + out_path = "{}/{}".format(app_args['out'], "submit") + qnumber = qname.replace("NL_Q", "").replace(".txt", "") + ans_file_path = "{}/T01_A{}.txt".format(out_path, qnumber) + ans_file_abspath = os.path.abspath(ans_file_path) + + r = adcclilib.put_a(qnumber, ans_file_abspath) + mes = r + "\n" + + json_name = questions[qname]['best_json'] + data = questions[qname]['answers'][json_name] + r = adcclilib.put_a_info(qnumber, data['cputime'], "0", "Test") + mes += r + + res = {'message': mes} + + return json.dumps(res) + @app.route("/board-viewer", methods=["GET"]) def show_board_viewer(): diff --git a/comm/server/static/js/pynq-manager.js b/comm/server/static/js/pynq-manager.js index fa801c1f763fba9bc7d2415fea225c4d109f0206..995d93ca348f7431e90838ad183f351b16e38e39 100644 --- a/comm/server/static/js/pynq-manager.js +++ b/comm/server/static/js/pynq-manager.js @@ -146,29 +146,26 @@ $(function(){ $("#client-control-pane").html(""); $("#client-control-pane").html(d); - $("#adccli-login-button").click(function(){ - var $obj = $(this); + var button_action_with_ajax = function($obj, url){ $obj.prop("disabled", "disabled"); $.ajax({ type: "GET", - url: "/adccli-login", + url: url, dataType: "json", }).done((data)=>{ $obj.prop("disabled", false); alert(data['message']); }); + }; + + $("#adccli-login-button").click(function(){ + button_action_with_ajax($(this), "/adccli-login"); }); $("#adccli-logout-button").click(function(){ - var $obj = $(this); - $obj.prop("disabled", "disabled"); - $.ajax({ - type: "GET", - url: "/adccli-logout", - dataType: "json", - }).done((data)=>{ - $obj.prop("disabled", false); - alert(data['message']); - }); + button_action_with_ajax($(this), "/adccli-logout"); + }); + $("#adccli-get-all-q").click(function(){ + button_action_with_ajax($(this), "/adccli-get-all-q"); }); $.ajax({ @@ -214,6 +211,17 @@ $(function(){ alert(data['status']); }); }); + $("#client-control-pane").find(".submit-button").eq(0).click(function(){ + var qname = $(this).data("qname"); + $.ajax({ + type: "POST", + dataType: "json", + url: "/adccli-put-a", + data: {qname: qname} + }).done((data) => { + alert(data['message']); + }); + }); $(".answer-detail-row td").click(function(){ var json_name = $(this).parent("tr").data("json"); diff --git a/comm/server/templates/part_client_table.html b/comm/server/templates/part_client_table.html index af8fe2e3ae691f56e1a6b4d911183f4d3367594f..7386b49fabcd3f66e5f4b18208e50f950b937557 100644 --- a/comm/server/templates/part_client_table.html +++ b/comm/server/templates/part_client_table.html @@ -13,6 +13,8 @@ Viewer Mode +
+

クライアント

diff --git a/comm/server/templates/part_question_status.html b/comm/server/templates/part_question_status.html index 225e00ec2829eb14717cbe0e2357dd759521938f..a6f634cd7df0708d1510b6629e52078ecfc9b7f8 100644 --- a/comm/server/templates/part_question_status.html +++ b/comm/server/templates/part_question_status.html @@ -3,8 +3,11 @@

【{{qname}}】

-
+ +

+

+