Skip to content

Commit 0ebaee5

Browse files
committed
wasync: add support to specify promises
1 parent f9ea7bb commit 0ebaee5

File tree

5 files changed

+48
-15
lines changed

5 files changed

+48
-15
lines changed

app/models/progress.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default DS.Model.extend({
1313
isFeedbackDone: computed('feedbackStatus', function() {
1414
return !(this.feedbackStatus == null);
1515
}),
16+
feedback: DS.attr(),
1617
runAttempt: DS.belongsTo('runAttempt'),
1718
content: DS.belongsTo('content'),
1819
})

app/pods/attempt/content/template.hbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
{{!-- render content outlet and doubts and notes --}}
88
<div>
99
<div>
10-
<ContentFeedback @showFeedback={{true}} />
10+
<WAsync @promise={{this.model.progress}} as |progress|>
11+
<ContentFeedback @progress={{progress}} />
12+
</WAsync>
1113
{{outlet}}
1214
</div>
1315
{{#unless (eq model.contentable 'course-recommend')}}

app/pods/components/content-feedback/component.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@ export default class ContentFeedbackComponent extends Component {
1818
expanded = false
1919
selectedRating = null
2020

21-
@action
22-
toggleExpandedView() {
23-
// this.expanded && this.set('selectedRating', null)
24-
this.toggleProperty('expanded')
25-
}
21+
didReceiveAttrs () {
22+
this._super(...arguments)
23+
this.selectedRating = this.progress
24+
}
2625

2726
@computed('selectedRating')
2827
get expansionType () {
2928
const rating = this.selectedRating
3029
if (rating === 4 || rating === null)
31-
return 'NONE'
30+
return 'NONE'
3231
else if (rating <= 3)
33-
return 'BAD'
34-
else
35-
return 'GOOD'
32+
return 'BAD'
33+
else
34+
return 'GOOD'
3635
}
37-
36+
3837
@computed('expansionType')
3938
get expansionText () {
4039
switch(this.expansionType) {
@@ -43,7 +42,7 @@ export default class ContentFeedbackComponent extends Component {
4342
default: return ''
4443
}
4544
}
46-
45+
4746
@computed('expansionType')
4847
get expansionReasons() {
4948
switch(this.expansionType) {
@@ -52,5 +51,21 @@ export default class ContentFeedbackComponent extends Component {
5251
default: return []
5352
}
5453
}
55-
54+
55+
@action
56+
async updateContentFeedback (reason = '') {
57+
// update everything in progress
58+
const feedback = {
59+
rating: this.selectedRating,
60+
reason
61+
}
62+
this.progress.set('feedback', feedback)
63+
await this.progress.save()
64+
}
65+
66+
@action
67+
toggleExpandedView() {
68+
// this.expanded && this.set('selectedRating', null)
69+
this.toggleProperty('expanded')
70+
}
5671
}

app/pods/components/content-feedback/template.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<label class="radio-container v-align-ma">
2525
<input class="radio" type="radio" name="reason"
2626
checked={{eq this.selectedReason reason}}
27-
onclick={{fn (mut this.selectedReason) reason}} />
27+
onclick={{fn this.updateContentFeedback reason}} />
2828
<span class="checkmark t-smaller"></span>
2929
<span class="font-xs">{{reason}}</span>
3030
</label>

lib/ember-w-pack/addon/components/w-async.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,22 @@ export default class WAsyncComponent extends Component {
77

88
didReceiveAttrs() {
99
this._super(...arguments);
10-
if (this.autoFire) this.task.perform();
10+
if (this.promise) {
11+
this.set('task', {
12+
isRunning: true,
13+
last: {value: null}
14+
})
15+
16+
this.promise.then(resolved => {
17+
this.set('task', {
18+
isRunning: false,
19+
last: {
20+
value: resolved
21+
}
22+
})
23+
})
24+
}
25+
else if (this.autoFire) this.task.perform();
1126
}
1227

1328
@computed('task.{isRunning,last.value}')

0 commit comments

Comments
 (0)