mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: add new features about domain (#528)
Co-authored-by: undefined <i@undefined.moe> - Add navigation hint - Update homework/contest filter by assign - Allow empty query for DomainSelectAutoComplete
This commit is contained in:
1 parent
9fb85300e7
commit
3581ccb065
12 files changed
+129
-35
No files matched your search
@@ -72,10 +72,13 @@ ScheduleModel.Worker.addHandler('contest', async (doc) => {
|
||||
export class ContestListHandler extends Handler {
|
||||
@param('rule', Types.Range(contest.RULES), true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, rule = '', page = 1) {
|
||||
@param('all', Types.Boolean)
|
||||
async get(domainId: string, rule = '', page = 1, all = false) {
|
||||
if (rule && contest.RULES[rule].hidden) throw new BadRequestError();
|
||||
const rules = Object.keys(contest.RULES).filter((i) => !contest.RULES[i].hidden);
|
||||
const cursor = contest.getMulti(domainId, rule ? { rule } : { rule: { $in: rules } });
|
||||
if (all && !this.user.hasPerm(PERM.PERM_MOD_BADGE)) all = false;
|
||||
const q = { ...all ? { assign: { $in: [...this.user.group, null] } } : {}, ...rule ? { rule } : { rule: { $in: rules } } };
|
||||
const cursor = contest.getMulti(domainId, q);
|
||||
const qs = rule ? `rule=${rule}` : '';
|
||||
const [tdocs, tpcount] = await paginate<Tdoc>(cursor, page, system.get('pagination.contest'));
|
||||
const tids = [];
|
||||
|
||||
@@ -334,9 +334,14 @@ class DomainJoinHandler extends Handler {
|
||||
}
|
||||
|
||||
class DomainSearchHandler extends Handler {
|
||||
@param('q', Types.Content)
|
||||
async get(domainId: string, q: string) {
|
||||
const ddocs = await domain.getPrefixSearch(q, 20);
|
||||
@param('q', Types.Content, true)
|
||||
async get(domainId: string, q: string = '') {
|
||||
let ddocs: DomainDoc[] = [];
|
||||
if (!q) {
|
||||
const dudict = await domain.getDictUserByDomainId(this.user._id);
|
||||
const dids = Object.keys(dudict);
|
||||
ddocs = await domain.getMulti({ _id: { $in: dids } }).toArray();
|
||||
} else ddocs = await domain.getPrefixSearch(q, 20);
|
||||
for (let i = 0; i < ddocs.length; i++) {
|
||||
ddocs[i].avatarUrl = ddocs[i].avatar ? avatar(ddocs[i].avatar, 64) : '/img/team_avatar.png';
|
||||
}
|
||||
|
||||
@@ -438,6 +438,18 @@ class HomeDomainHandler extends Handler {
|
||||
this.response.template = 'home_domain.html';
|
||||
this.response.body = { ddocs, dudict, canManage };
|
||||
}
|
||||
|
||||
@param('id', Types.String)
|
||||
async postStar(domainId: string, id: string) {
|
||||
await user.setById(this.user._id, { pinnedDomains: this.user.pinnedDomains.concat(id) });
|
||||
this.back({ star: true });
|
||||
}
|
||||
|
||||
@param('id', Types.String)
|
||||
async postUnstar(domainId: string, id: string) {
|
||||
await user.setById(this.user._id, { pinnedDomains: this.user.pinnedDomains.filter((i) => i !== id) });
|
||||
this.back({ star: false });
|
||||
}
|
||||
}
|
||||
|
||||
class HomeDomainCreateHandler extends Handler {
|
||||
@@ -455,8 +467,11 @@ class HomeDomainCreateHandler extends Handler {
|
||||
if (doc) throw new DomainAlreadyExistsError(id);
|
||||
avatar = avatar || this.user.avatar || `gravatar:${this.user.mail}`;
|
||||
const domainId = await domain.add(id, this.user._id, name, bulletin);
|
||||
await domain.edit(domainId, { avatar });
|
||||
await domain.setUserRole(domainId, this.user._id, 'root');
|
||||
await Promise.all([
|
||||
domain.edit(domainId, { avatar }),
|
||||
domain.setUserRole(domainId, this.user._id, 'root'),
|
||||
user.setById(this.user._id, undefined, undefined, { pinnedDomains: [domainId] }),
|
||||
]);
|
||||
this.response.redirect = this.url('domain_dashboard', { domainId });
|
||||
this.response.body = { domainId };
|
||||
}
|
||||
|
||||
@@ -22,8 +22,10 @@ const convertPenaltyRules = validatePenaltyRules;
|
||||
|
||||
class HomeworkMainHandler extends Handler {
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, page = 1) {
|
||||
const cursor = contest.getMulti(domainId, { rule: 'homework' });
|
||||
@param('all', Types.Boolean)
|
||||
async get(domainId: string, page = 1, all = false) {
|
||||
if (all && !this.user.hasPerm(PERM.PERM_MOD_BADGE)) all = false;
|
||||
const cursor = contest.getMulti(domainId, { rule: 'homework', ...all ? { assign: { $in: [...this.user.group, null] } } : {} });
|
||||
const [tdocs, tpcount] = await paginate<Tdoc>(cursor, page, system.get('pagination.contest'));
|
||||
const calendar = [];
|
||||
for (const tdoc of tdocs) {
|
||||
|
||||
Reference in new issue
Block a user