Skip to content

Commit f7166cd

Browse files
committed
integrate tagghether tags
1 parent 7bcb62c commit f7166cd

File tree

6 files changed

+40
-27
lines changed

6 files changed

+40
-27
lines changed

app/pods/components/contest/contest-content-list/component.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export default class ContentList extends Component {
1212
@restartableTask fetchContentsTask = function *() {
1313
try {
1414
return yield this.store.query('content', {
15-
filter: this.filter,
15+
filter: this.filter,
16+
filterRelationships: this.filterRelationships,
1617
page: this.page,
1718
contest_id: this.contest.id
1819
})

app/pods/components/practice-filter-component/component.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,20 @@ import { alias } from '@ember/object/computed';
77

88
export default class PracticeFilterComponent extends Component {
99
@service store
10+
@service api
1011

1112
@alias('searchTagsTask.lastSuccessful.value') availableTags
1213

1314
@computed('tags')
1415
get selectedTags() {
15-
if (this.tags.length) {
16-
return this.store.query('tag', {
17-
filter: {
18-
id: {
19-
$in: this.tags
20-
}
21-
}
22-
})
16+
if (this.tags.length && (this.allTags && this.allTags.length)) {
17+
return this.get('allTags').filter(tag => this.tags.includes(tag.id))
2318
}
2419
}
2520

26-
didReceiveAttrs() {
27-
this.searchTagsTask.perform()
21+
async didReceiveAttrs() {
22+
const allTags = await this.searchTagsTask.perform()
23+
this.set('allTags', allTags)
2824
}
2925

3026
@action
@@ -51,10 +47,11 @@ export default class PracticeFilterComponent extends Component {
5147

5248
@restartableTask searchTagsTask = function *(query = '') {
5349
yield timeout(500)
54-
return yield this.store.query('tag', {
55-
filter: {
56-
name: {
57-
$iLike: `%${query}%`
50+
return yield this.api.request('/tags', {
51+
data: {
52+
filter: {
53+
"name like": `%${query}%`,
54+
"is_active =": true
5855
}
5956
}
6057
})

app/pods/contests/contest/index/controller.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,23 @@ export default class IndexController extends Controller {
2828
difficulty: {
2929
$in: this.difficulty
3030
},
31-
tags: {
32-
id: {
33-
$in: this.tags
34-
}
35-
},
3631
name: {
3732
$iLike: `%${this.q}%`
3833
}
3934
}
4035
}
36+
37+
@computed('status','difficulty','tags', 'q')
38+
get filterRelationships() {
39+
return {
40+
content_tags: {
41+
tagId: {
42+
$in: this.tags
43+
}
44+
}
45+
}
46+
}
47+
4148
@computed('contest.currentAttempt')
4249
get nextRoute() {
4350
return 'contests.contest.attempt'

app/pods/contests/contest/index/template.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
@contest={{contest}}
6262
@page={{page}}
6363
@route='contests.contest.content'
64-
@filter={{filter}} as |contents|>
64+
@filter={{filter}}
65+
@filterRelationships={{filterRelationships}} as |contents|>
6566
<PaginationPill
6667
@pagination={{contents.meta.pagination}}
6768
@setOffset={{action (mut offset)}} />

app/pods/practice/contest/index/controller.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,22 @@ export default class ContestController extends Controller {
2727
difficulty: {
2828
$in: this.difficulty
2929
},
30-
tags: {
31-
id: {
32-
$in: this.tags
33-
}
34-
},
3530
name: {
3631
$iLike: `%${this.q}%`
3732
}
3833
}
3934
}
35+
36+
@computed('status','difficulty','tags', 'q')
37+
get filterRelationships() {
38+
return {
39+
content_tags: {
40+
tagId: {
41+
$in: this.tags
42+
}
43+
}
44+
}
45+
}
4046

4147
@action
4248
setOffset(offset) {

app/pods/practice/contest/index/template.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
@contest={{contest}}
3939
@page={{page}}
4040
@route='practice.contest.content'
41-
@filter={{filter}} as |contents|>
41+
@filter={{filter}}
42+
@filterRelationships={{filterRelationships}} as |contents|>
4243
<PaginationPill
4344
@pagination={{contents.meta.pagination}}
4445
@setOffset={{action (mut offset)}} />

0 commit comments

Comments
 (0)