Browse Source

Add search problem to home page

pull/6/head
Menci 8 years ago
parent
commit
4662823a70
  1. 2
      modules/api_v2.js
  2. 24
      views/index.ejs

2
modules/api_v2.js

@ -43,7 +43,7 @@ app.get('/api/v2/search/problem/:keyword*?', async (req, res) => {
}
});
result = result.map(x => ({ name: `#${x.id}. ${x.title}`, value: x.id }));
result = result.map(x => ({ name: `#${x.id}. ${x.title}`, value: x.id, url: syzoj.utils.makeUrl(['problem', x.id]) }));
res.send({ success: true, results: result });
} catch (e) {
syzoj.log(e);

24
views/index.ejs

@ -103,6 +103,16 @@
</div>
</div>
<% } %>
<h4 class="ui top attached block header">搜索题目</h4>
<div class="ui bottom attached segment">
<div class="ui search" style="width: 100%; ">
<div class="ui left icon input" style="width: 100%; ">
<input class="prompt" style="width: 100%; " type="text" placeholder="ID / 题目名 …">
<i class="search icon"></i>
</div>
<div class="results" style="width: 100%; "></div>
</div>
</div>
<h4 class="ui top attached block header">近期比赛</h4>
<div class="ui bottom attached <% if (!contests || !contests.length) { %>center aligned <% } %>segment">
<% if (!contests || !contests.length) { %>
@ -148,4 +158,18 @@
</div>
</div>
</div>
<script>
$(function () {
$('.ui.search').search({
debug: true,
apiSettings: {
url: '/api/v2/search/problem/{query}',
cache: false
},
fields: {
title: 'name'
}
});
});
</script>
<% include footer %>

Loading…
Cancel
Save