1
1
import Component from '@glimmer/component' ;
2
- import { tracked } from '@glimmer/tracking' ;
2
+ import { cached , tracked } from '@glimmer/tracking' ;
3
3
import { action } from '@ember/object' ;
4
4
import { service } from '@ember/service' ;
5
5
import { DateTime } from 'luxon' ;
6
6
import { validatable , Length , NotBlank } from 'ilios-common/decorators/validation' ;
7
- import { dropTask , restartableTask } from 'ember-concurrency' ;
7
+ import { dropTask } from 'ember-concurrency' ;
8
+ import { TrackedAsyncData } from 'ember-async-data' ;
8
9
9
10
@validatable
10
11
export default class CoursesNewComponent extends Component {
@@ -14,13 +15,29 @@ export default class CoursesNewComponent extends Component {
14
15
15
16
@tracked @NotBlank ( ) selectedYear ;
16
17
@tracked @NotBlank ( ) @Length ( 3 , 200 ) title ;
17
- @tracked academicYearCrossesCalendarYearBoundaries ;
18
18
@tracked years ;
19
19
20
20
constructor ( ) {
21
21
super ( ...arguments ) ;
22
22
const thisYear = DateTime . now ( ) . year ;
23
23
this . years = [ thisYear - 2 , thisYear - 1 , thisYear , thisYear + 1 , thisYear + 2 ] ;
24
+
25
+ if ( this . args . currentYear && this . years . includes ( parseInt ( this . args . currentYear . id , 10 ) ) ) {
26
+ this . setYear ( this . args . currentYear . id ) ;
27
+ }
28
+ }
29
+
30
+ @cached
31
+ get academicYearCrossesCalendarYearBoundariesData ( ) {
32
+ return new TrackedAsyncData (
33
+ this . iliosConfig . itemFromConfig ( 'academicYearCrossesCalendarYearBoundaries' ) ,
34
+ ) ;
35
+ }
36
+
37
+ get academicYearCrossesCalendarYearBoundaries ( ) {
38
+ return this . academicYearCrossesCalendarYearBoundariesData . isResolved
39
+ ? this . academicYearCrossesCalendarYearBoundariesData . value
40
+ : false ;
24
41
}
25
42
26
43
@action
@@ -45,15 +62,6 @@ export default class CoursesNewComponent extends Component {
45
62
}
46
63
}
47
64
48
- load = restartableTask ( async ( ) => {
49
- this . academicYearCrossesCalendarYearBoundaries = await this . iliosConfig . itemFromConfig (
50
- 'academicYearCrossesCalendarYearBoundaries' ,
51
- ) ;
52
- if ( this . args . currentYear && this . years . includes ( parseInt ( this . args . currentYear . id , 10 ) ) ) {
53
- this . setYear ( this . args . currentYear . id ) ;
54
- }
55
- } ) ;
56
-
57
65
saveCourse = dropTask ( async ( ) => {
58
66
this . addErrorDisplayFor ( 'title' ) ;
59
67
const isValid = await this . isValid ( ) ;
0 commit comments