@@ -17,7 +17,8 @@ import type {
17
17
SerializedGraph ,
18
18
SerializedDomain ,
19
19
SerializedSubject ,
20
- SerializedLecture
20
+ SerializedLecture ,
21
+ DropdownOption
21
22
} from '$scripts/types'
22
23
23
24
// Exports
@@ -106,7 +107,7 @@ abstract class FieldController {
106
107
abstract unassignParent ( parent : FieldController , mirror ?: boolean ) : void
107
108
abstract unassignChild ( child : FieldController , mirror ?: boolean ) : void
108
109
109
- abstract matchesQuery ( query : string ) : Promise < boolean >
110
+ abstract matchesQuery ( query : string ) : boolean
110
111
}
111
112
112
113
class DomainController extends FieldController {
@@ -407,11 +408,11 @@ class DomainController extends FieldController {
407
408
*/
408
409
409
410
static revive ( cache : ControllerCache , data : SerializedDomain ) : DomainController {
410
- const existing = cache . find ( DomainController , data . id )
411
- if ( existing ) {
412
- if ( ! existing . represents ( data ) ) {
411
+ const domain = cache . find ( DomainController , data . id )
412
+ if ( domain ) {
413
+ if ( ! domain . represents ( data ) )
413
414
throw new Error ( `DomainError: Attempted to revive Domain with ID ${ data . id } , but server data is out of sync with cache` )
414
- }
415
+ return domain
415
416
}
416
417
417
418
return new DomainController ( cache , data . id , data . x , data . y , data . name , data . style , data . graph , data . parents , data . children , data . subjects )
@@ -866,7 +867,7 @@ class DomainController extends FieldController {
866
867
* @returns Whether the domain matches the query
867
868
*/
868
869
869
- async matchesQuery ( query : string ) : Promise < boolean > {
870
+ matchesQuery ( query : string ) : boolean {
870
871
const query_lower = query . toLowerCase ( )
871
872
const name = this . trimmed_name . toLowerCase ( )
872
873
const style = this . style ? styles [ this . style ] . display_name . toLowerCase ( ) : ''
@@ -966,7 +967,7 @@ class SubjectController extends FieldController {
966
967
967
968
// Call API to get the graph data
968
969
this . _pending_graph = this . cache
969
- . fetch ( `/api/subject/${ this . id } /course ` , { method : 'GET' } )
970
+ . fetch ( `/api/subject/${ this . id } /graph ` , { method : 'GET' } )
970
971
. then (
971
972
async response => {
972
973
const data = await response . json ( ) as SerializedGraph
@@ -976,10 +977,10 @@ class SubjectController extends FieldController {
976
977
} ,
977
978
error => {
978
979
this . _pending_graph = undefined
979
- throw new Error ( `APIError (/api/subject/${ this . id } /course GET): ${ error } ` )
980
+ throw new Error ( `APIError (/api/subject/${ this . id } /graph GET): ${ error } ` )
980
981
}
981
982
)
982
-
983
+
983
984
return await this . _pending_graph
984
985
}
985
986
@@ -1025,6 +1026,17 @@ class SubjectController extends FieldController {
1025
1026
return await this . _pending_domain
1026
1027
}
1027
1028
1029
+ async getDomainOptions ( ) : Promise < DropdownOption < number > [ ] > {
1030
+ const domains = await this . getGraph ( )
1031
+ . then ( graph => graph . getDomains ( ) )
1032
+
1033
+ return domains . map ( domain => ( {
1034
+ value : domain . id ,
1035
+ label : domain . name ,
1036
+ validation : ValidationData . success ( )
1037
+ } ) )
1038
+ }
1039
+
1028
1040
/**
1029
1041
* Get the lectures assigned to this subject, from the cache or the API
1030
1042
* @returns The lectures assigned to this subject
@@ -1109,7 +1121,7 @@ class SubjectController extends FieldController {
1109
1121
throw new Error ( `APIError (/api/subject/${ this . id } /parents GET): ${ error } ` )
1110
1122
}
1111
1123
)
1112
-
1124
+
1113
1125
return await this . _pending_parents as SubjectController [ ]
1114
1126
}
1115
1127
@@ -1153,7 +1165,7 @@ class SubjectController extends FieldController {
1153
1165
throw new Error ( `APIError (/api/subject/${ this . id } /children GET): ${ error } ` )
1154
1166
}
1155
1167
)
1156
-
1168
+
1157
1169
return await this . _pending_children as SubjectController [ ]
1158
1170
}
1159
1171
@@ -1208,11 +1220,11 @@ class SubjectController extends FieldController {
1208
1220
*/
1209
1221
1210
1222
static revive ( cache : ControllerCache , data : SerializedSubject ) : SubjectController {
1211
- const existing = cache . find ( SubjectController , data . id )
1212
- if ( existing ) {
1213
- if ( ! existing . represents ( data ) )
1223
+ const subject = cache . find ( SubjectController , data . id )
1224
+ if ( subject ) {
1225
+ if ( ! subject . represents ( data ) )
1214
1226
throw new Error ( `SubjectError: Attempted to revive Subject with ID ${ data . id } , but server data is out of sync with cache` )
1215
- return existing
1227
+ return subject
1216
1228
}
1217
1229
1218
1230
return new SubjectController ( cache , data . id , data . x , data . y , data . name , data . domain , data . graph , data . parents , data . children , data . lectures )
@@ -1659,11 +1671,16 @@ class SubjectController extends FieldController {
1659
1671
* @returns Whether the subject matches the query
1660
1672
*/
1661
1673
1662
- async matchesQuery ( query : string ) : Promise < boolean > {
1674
+ matchesQuery ( query : string ) : boolean {
1663
1675
const query_lower = query . toLowerCase ( )
1664
- const name = this . trimmed_name . toLowerCase ( )
1665
- const domain = await this . getDomain ( ) . then ( domain => domain ?. name . toLowerCase ( ) || '' )
1676
+ const name_lower = this . trimmed_name . toLowerCase ( )
1677
+ if ( this . _domain_id === null ) {
1678
+ return name . includes ( query_lower )
1679
+ }
1680
+
1681
+ const domain = this . cache . find ( DomainController , this . _domain_id )
1682
+ const domain_lower = domain ? domain . trimmed_name . toLowerCase ( ) : ''
1666
1683
1667
- return name . includes ( query_lower ) || domain . includes ( query_lower )
1684
+ return name_lower . includes ( query_lower ) || domain_lower . includes ( query_lower )
1668
1685
}
1669
1686
}
0 commit comments