Skip to content

Commit

Permalink
Merge pull request TFcis#81 from tobiichi3227/feat/misc
Browse files Browse the repository at this point in the history
feat/misc
  • Loading branch information
LifeAdventurer authored Jun 24, 2024
2 parents a9db218 + 6ea98a1 commit 90113b8
Show file tree
Hide file tree
Showing 23 changed files with 289 additions and 254 deletions.
3 changes: 2 additions & 1 deletion src/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from redis import asyncio as aioredis

from services.user import UserService
import utils.htmlgen


class RequestHandler(tornado.web.RequestHandler):
Expand Down Expand Up @@ -42,7 +43,7 @@ def default(self, obj):
return json.JSONEncoder.default(self, obj)

from services.user import UserConst

kwargs['htmlgen'] = utils.htmlgen
if not self.acct.is_guest():
kwargs['acct_id'] = self.acct.acct_id

Expand Down
2 changes: 1 addition & 1 deletion src/services/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def list_log(self, off, num, log_type=None):

async def get_log_type(self):
async with self.db.acquire() as con:
result = await con.fetch('SELECT DISTINCT "type" FROM "log"')
result = await con.fetch('SELECT DISTINCT "type" FROM "log" ORDER BY "type"')

log_type = [type['type'] for type in result]

Expand Down
23 changes: 10 additions & 13 deletions src/static/templ/acct-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
new URL(photo);
} catch {
if (photo != "") {
alert("Photo url is invalid");
index.show_notify_dialog("Photo url is invalid", index.DIALOG_TYPE.error);
return;
}
}
Expand All @@ -27,7 +27,7 @@
new URL(cover);
} catch {
if (cover != "") {
alert("Cover url is invalid");
index.show_notify_dialog("Cover url is invalid", index.DIALOG_TYPE.error);
return;
}
}
Expand All @@ -41,21 +41,20 @@
}, function(res) {
let msg = 'Unknown';

if(res[0] == 'E') {
if(res == 'Enamemin') {
if (res[0] == 'E') {
dialog_type = index.DIALOG_TYPE.error;
if (res == 'Enamemin') {
msg = 'Name length < min';
} else if (res == 'Enamemax') {
msg = 'Name length > max';
}

j_profile.find('div.print').print(res);

index.show_notify_dialog(msg, index.DIALOG_TYPE.error);
} else {
j_profile.find('div.print').print('Success', true);
index.show_notify_dialog('Update Successfully', index.DIALOG_TYPE.success);
index.reload();
}
});

});

j_reset.find('button.submit').on('click', function(e) {
Expand All @@ -64,7 +63,7 @@
let repeat = j_reset.find('input.repeat').val();

if (pw != repeat) {
j_reset.find('div.print').print('Repeat incorrect');
index.show_notify_dialog('Repeat incorrect', index.DIALOG_TYPE.error);
return;
}

Expand All @@ -85,9 +84,9 @@
msg = 'Previous incorrect';
}

j_reset.find('div.print').print(msg);
index.show_notify_dialog(msg, index.DIALOG_TYPE.error);
} else {
j_reset.find('div.print').print('Success', true);
index.show_notify_dialog('Update Password Successfully', index.DIALOG_TYPE.success);
j_reset.find('input').val('');
}
});
Expand Down Expand Up @@ -138,7 +137,6 @@ <h1>Edit User <a href="/oj/acct/{{ acct.acct_id }}/">{{ acct.name }}</a></h1>
</div>

<button type="button" class="btn btn-primary submit">更新</button>
<div class="print"></div>
</form>
{% end %}

Expand All @@ -162,7 +160,6 @@ <h3>更改密碼</h3>
</div>

<button type="button" class="btn btn-warning submit">確認</button>
<div class="print"></div>
</form>
{% end %}
</div>
Expand Down
5 changes: 1 addition & 4 deletions src/static/templ/chal.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
} else {
function update_state_data(chal_state_data) {
var states = document.querySelectorAll('tr.states');
let print = document.querySelector('div.print');
states.forEach(function(element, idx, arr) {
let state = element.querySelector('td.state');
state.innerHTML = state_map[chal_state_data[idx]['state']];
Expand Down Expand Up @@ -55,7 +54,7 @@
}, function(res) {
if (res[0] == 'E') {
if (res == 'Ejudge') {
$("div.print").print('All Judge Server Offline');
index.show_notify_dialog('All Judge Server Offline!!!', index.DIALOG_TYPE.warning);
}
} else {
index.reload();
Expand Down Expand Up @@ -126,10 +125,8 @@

{% if rechal == True and chal['code'] == True %}
<button id="rechal" class="btn btn-warning">Rechallenge</button>
<div class="print"></div>
{% elif chal['code'] == True %}
<button id="report_pro_button" class="btn btn-warning">Report Problem</button>
<div class="print"></div>
{% end %}
</div>

Expand Down
20 changes: 10 additions & 10 deletions src/static/templ/challist.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@
j_filter.find('input, select').keypress(function(e) {

if (e.keyCode == 13) {
//KeyCode 13 means Enter
// KeyCode 13 means Enter
let proid = j_filter.find('#proid').val();
let acctid = j_filter.find('#acctid').val();
let state = j_filter.find('#state').val();
let compiler_type = j_filter.find("#compiler").val();
let url = '/oj/chal/?';

if (re.test(proid) || re.test(acctid)) {
alert('請輸入數字、逗號與空白做查詢,範例:1, 2, 3')
j_filter.find('input.proid').val('')
j_filter.find('input.acctid').val('')
return
j_filter.find('#proid').val('');
j_filter.find('#acctid').val('');
index.show_notify_dialog("請輸入數字、逗號與空白做查詢,範例:1, 2, 3", index.DIALOG_TYPE.warning);
return;
}

if (proid != '') {
Expand Down Expand Up @@ -70,14 +70,14 @@
let url = '/oj/chal/?';

if (re.test(proid) || re.test(acctid)) {
alert('請輸入數字、逗號與空白做查詢,範例:1, 2, 3')
j_filter.find('input.proid').val('')
j_filter.find('input.acctid').val('')
return
j_filter.find('#proid').val('');
j_filter.find('#acctid').val('');
index.show_notify_dialog("請輸入數字、逗號與空白做查詢,範例:1, 2, 3", index.DIALOG_TYPE.warning);
return;
}

if (proid != '') {
url += `&proid=${proid}`
url += `&proid=${proid}`;
}

if (acctid != '') {
Expand Down
1 change: 1 addition & 0 deletions src/static/templ/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<link
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"
rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"
integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="
Expand Down
1 change: 0 additions & 1 deletion src/static/templ/manage/acct/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ <h3>{{ acct.acct_id }} / {{ acct.name }}</h3>

<button type="button" class="btn btn-primary submit">Update</button>
<button type="button" class="btn btn-secondary cancel">Cancel</button>
<div class="print"></div>
</form>
</div>
{% end %}
77 changes: 58 additions & 19 deletions src/static/templ/manage/board/add.html
Original file line number Diff line number Diff line change
@@ -1,54 +1,83 @@
{% extends '../manage.html' %}
{% block head %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@eonasdan/[email protected]/dist/css/tempus-dominus.min.css" crossorigin="anonymous">

<style>
.svg-inline--fa {
display: var(--fa-display, inline-block);
height: 1em;
}
</style>

<script type="text/javascript">
function init() {
var start_date_picker = null;
var end_date_picker = null;
$.getScript('https://cdn.jsdelivr.net/npm/@eonasdan/[email protected]/dist/js/tempus-dominus.min.js', () => {
const options = {
display: {
calendarWeeks: true,
},

localization: {
locale: 'zh-tw',
format: 'yyyy/MM/dd HH:mm',
},
};
start_date_picker = new tempusDominus.TempusDominus(document.getElementById('datepickerStart'), options);
end_date_picker = new tempusDominus.TempusDominus(document.getElementById('datepickerEnd'), options);
});

let j_form = $("#form");
let re = /[^0-9,\ ]/;

j_form.find("#add").on('click', (event) => {
let start_time = null, end_time = null;
let name = j_form.find("#name").val();
let status = j_form.find("#status").val();
let start = j_form.find("#start").val();
let end = j_form.find("#end").val();
let pro_list = j_form.find("#pro_list").val();
let acct_list = j_form.find("#acct_list").val();

if (start != '' && start != '-1') {
start = new Date(start + ' +0000').toISOString();
} else if (start == '-1') {
start = new Date('1970/01/01 00:00 +0000').toISOString();
start_time = start_date_picker.viewDate;
if (start_time == '') {
index.show_notify_dialog("開始時間不可為空", index.DIALOG_TYPE.warning);
return;
}

if (end != '' && end != '-1') {
end = new Date(end + ' +0000').toISOString();
} else if (end == '-1') {
end = new Date('2100/01/01 00:00 +0000').toISOString();
end_time = end_date_picker.viewDate;
if (end_time == '') {
index.show_notify_dialog("結束時間不可為空", index.DIALOG_TYPE.warning);
return;
}

if (start_time >= end_time) {
index.show_notify_dialog("結束時間必須大於開始時間", index.DIALOG_TYPE.warning);
return;
}

if (re.test(pro_list)) {
alert("Problem List錯誤,請輸入數字、逗號與空白設定,範例:1, 2, 3");
index.show_notify_dialog("Problem List錯誤,請輸入數字、逗號與空白設定,範例:1, 2, 3", index.DIALOG_TYPE.warning);
return;
}

if (re.test(acct_list)) {
alert("Account List錯誤,請輸入數字、逗號與空白設定,範例:1, 2, 3");
index.show_notify_dialog("Account List錯誤,請輸入數字、逗號與空白設定,範例:1, 2, 3", index.DIALOG_TYPE.warning);
return;
}

$.post('/oj/be/manage/board/add', {
reqtype: 'add',
name: name,
status: status,
start: start,
end: end,
start: start_time.toISOString(),
end: end_time.toISOString(),
pro_list: pro_list,
acct_list: acct_list,
}, function(res) {
if (res[0] == 'E') {

} else {
index.go("/oj/manage/board/")
index.go("/oj/manage/board/");
}
});
});
Expand Down Expand Up @@ -76,11 +105,21 @@
</div>

<div class="mb-1">
<label for="#start" class="form-label">Start</label>
<input type="text" class="form-control" id="start" placeholder="[Year / Month / Day Hour : Minute]">
<label for="#datepickerStartInput" class="form-label">Start Time</label>
<div id="datepickerStart" class="input-group">
<input id="datepickerStartInput" type="text" class="form-control">
<span class="input-group-text" data-td-target="#datepickerStart" data-td-toggle="datepickerStart">
<svg class="svg-inline--fa fa-calendar" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="calendar" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" data-fa-i2svg=""><path fill="currentColor" d="M96 32V64H48C21.5 64 0 85.5 0 112v48H448V112c0-26.5-21.5-48-48-48H352V32c0-17.7-14.3-32-32-32s-32 14.3-32 32V64H160V32c0-17.7-14.3-32-32-32S96 14.3 96 32zM448 192H0V464c0 26.5 21.5 48 48 48H400c26.5 0 48-21.5 48-48V192z"></path></svg><!-- <span class="fa-solid fa-calendar"></span> Font Awesome fontawesome.com -->
</span>
</div>

<label for="#end" class="form-label">End</label>
<input type="text" class="form-control" id="end" placeholder="[Year / Month / Day Hour : Minute]">
<label for="#datepickerEnd" class="form-label">End Time</label>
<div id="datepickerEnd" class="input-group">
<input id="datepickerEndInput" type="text" class="form-control">
<span class="input-group-text" data-td-target="#datepickerEnd" data-td-toggle="datepickerEnd">
<svg class="svg-inline--fa fa-calendar" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="calendar" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" data-fa-i2svg=""><path fill="currentColor" d="M96 32V64H48C21.5 64 0 85.5 0 112v48H448V112c0-26.5-21.5-48-48-48H352V32c0-17.7-14.3-32-32-32s-32 14.3-32 32V64H160V32c0-17.7-14.3-32-32-32S96 14.3 96 32zM448 192H0V464c0 26.5 21.5 48 48 48H400c26.5 0 48-21.5 48-48V192z"></path></svg><!-- <span class="fa-solid fa-calendar"></span> Font Awesome fontawesome.com -->
</span>
</div>
</div>

<div class="mb-1">
Expand Down
Loading

0 comments on commit 90113b8

Please sign in to comment.