// 詳細表示画面 class StatusView { constructor(selector) { this.container = $(selector); this.problem_key = null; this.request_refresh_timer = null; } // 問題詳細画面を表示 show_problem(problem_key = null){ var _this = this; if(problem_key != null){ this.problem_key = problem_key; } $.ajax({ type: 'GET', dataType: 'html', url: '/part/problem/' + _this.problem_key }).done((d) => { _this.container.empty(); _this.container.html(d); _this.container.find('.start-button').click(()=>{ _this.start_solver(); }); _this.container.find('.solution-detail-row td').click((e) => { var solution_id = $(e.target).parent("tr").data("solution-id"); var problem_name = $(e.target).parent("tr").data("problem"); var viewer_url = "/view/solution#" + problem_name + "/" + solution_id; window.open(viewer_url, "_blank"); }) }); } // 問題を解くのをスタート start_solver(){ var _this = this; $.ajax({ type: "POST", dataType: "json", url: "/api/problem/solve", data: JSON.stringify({ "problem": _this.problem_key }), contentType: 'application/json' }).done((d) => { var request_id = d['request_id']; var timeout = d['timeout']; _this.container.find('#solver-processing-modal').modal({ backdrop: 'static', keyboard: false, show: true }); _this.container.find('#solver-processing-modal').on('hidden.bs.modal', function(e){ // console.log(e); _this.show_problem(); }) _this.container.find('.stop-button').click(()=>{ _this.stop_solver(); }); _this.get_request_status(request_id, timeout); }); } // 強制停止 stop_solver(){ var _this = this; $.ajax({ type: "GET", dataType: "json", url: "/api/stop", }).done((d) => { _this.request_refresh_timer = 'stopped'; alert(d); }); } get_request_status(request_id, timeout){ var _this = this; $.ajax({ type: 'GET', dataType: 'html', url: '/part/request/' + request_id }).done((d) => { _this.container.find('#request-status-container').empty(); _this.container.find('#request-status-container').html(d); status = $(d).find('#request-status-value').text(); // console.log(status); if(status == 'done'){ _this.request_refresh_timer = null; }else if(_this.request_refresh_timer == 'stopped'){ _this.request_refresh_timer = null; }else{ _this.request_refresh_timer = setTimeout(_this.get_request_status(request_id, timeout), 1000); } }); } // システム詳細画面を表示 show_system(){ var _this = this; $.ajax({ type: "GET", dataType: "html", url: "/part/system-summary" }).done((d) => { _this.container.empty(); _this.container.html(d); var button_action_with_ajax = function($obj, url){ $obj.prop("disabled", "disabled"); $.ajax({ type: "GET", 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(){ button_action_with_ajax($(this), "/adccli-logout"); }); $("#adccli-get-all-q").click(function(){ button_action_with_ajax($(this), "/adccli-get-all-q"); }); $.ajax({ type: "GET", url: "/adccli-whoami", dataType: "json", }).done((data)=>{ if(data['status']) $("#adccli-status").text("ログイン中"); else $("#adccli-status").text("ログアウト"); }); }); } } $(function(){ const status_view = new StatusView('#status-container'); var refresh_problems = function(){ $.ajax({ type: "GET", dataType: "html", url: "/part/problems" }).done((d) => { $("#problem-list-container").empty(); $("#problem-list-container").html(d); $(".problem-row td").click(function(){ var $tr = $(this).parent("tr.problem-row"); $(".problem-row").removeClass("q-selected"); $tr.addClass("q-selected"); var qname = $tr.data("qname"); // show_problem_status(qname); location.hash = "#" + qname; return false; }); var hash = location.hash.replace("#", ""); if(hash != ""){ $(".problem-row[data-qname='" + hash + "']").addClass("q-selected"); } }); } $(window).on('hashchange', function(){ var hash = location.hash.replace("#", ""); if(hash == ""){ status_view.show_system(); }else{ status_view.show_problem(hash); } }).trigger('hashchange'); refresh_problems(); });