generated from hyoo-ru/template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitmo.view.ts
165 lines (138 loc) · 4.27 KB
/
itmo.view.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
namespace $.$$ {
export class $my_itmo extends $.$my_itmo {
@ $mol_mem
data() {
return $my_itmo_data( this.$.$mol_fetch.json( 'my/itmo/itmo_data.json' ) as any )
}
@ $mol_mem
buildings_data() {
const data = Object.fromEntries(
Object.values( this.data().flow )
.flatMap( flow => flow.variants )
.map( les => [ les.bld_id, {
id: les.bld_id,
name: les.building,
main_bld_id: les.main_bld_id,
code: '💻',
} ] )
)
const codes = [ 'БА', 'КА', 'ЧА', 'ЛА', 'ЛБ', 'ЛЕ', 'ЛМ', 'ОЛ' ] // '¹²³⁴⁵⁶⁷⁸⁹'
Object.values( data ).forEach( ( bld: any, i )=> {
bld.name = ( bld.code = codes[ i ] ) + ': ' + ( bld.name ?? 'Онлайн' )
} )
return data
}
@ $mol_mem
buildings() {
return Object.keys( this.buildings_data() ).map( id => this.Building( id ) )
}
building_title( id: string ) {
return this.buildings_data()[ id ].name
}
@ $mol_mem
slots_data() {
return $mol_array_groups(
Object.values( this.data().flow ),
flow => ( flow.variants[0]?.date ?? '' ) + 'T' + ( flow.variants[0]?.time_start ?? '' )
)
}
@ $mol_mem
days_data() {
return $mol_array_groups( Object.keys( this.slots_data() ).sort(), slot => slot.slice( 0, 10 ) )
}
@ $mol_mem
days() {
return Object.keys( this.days_data() ).sort().flatMap( day => day === 'T' ? [] : [ this.Day( day ) ] )
}
@ $mol_mem_key
day_title( day: string ) {
return new $mol_time_moment( day ).toString( 'DD Mon' )
}
@ $mol_mem_key
day_slots( day: string ) {
return this.days_data()[ day ]!.map( slot => this.Slot( slot ) )
}
@ $mol_mem
slots() {
return Object.keys( this.slots_data() ).map( slot => this.Slot( slot ) )
}
@ $mol_mem_key
slot_descr( slot: string ) {
return new $mol_time_moment( slot ).toString( 'hh:mm' )
+ ' ' + ( this.data().flow[ this.slot_value( slot ) ]?.variants[0].room ?? '' )
}
@ $mol_mem_key
slot_options( slot: string ) {
const options = Object.fromEntries( this.slots_data()[ slot ]!.map(
les => [
les.discipline_id,
( this.discipline_slot( les.discipline_id + '' ) ? '✅' : '💤' )
+ ' ' + this.buildings_data()[ les.variants[0].bld_id + '' ].code
+ ': ' + this.data().discipline[ les.discipline_id ].name,
]
) )
options[''] = '💤'
return options
}
@ $mol_mem
local() {
return this.$.$mol_store_local.sub( '$my_itmo_schedule', new $mol_store( {} as Record< string, string | null > ) )
}
slot_value( slot: string, next?: string ) {
if( next !== undefined ) {
const old = this.discipline_slot( next )
if( old ) this.local().value( old, null )
}
return this.local().value( slot, next ) ?? ''
}
@ $mol_mem
disciplines_slot() {
return Object.fromEntries( Object.keys( this.slots_data() ).map( slot => [ this.slot_value( slot ) ?? '', slot ] ) )
}
@ $mol_mem
disciplines_rows() {
return Object.keys( this.data().discipline )
.filter( $mol_match_text( this.disciplines_query(), id => [ this.discipline_title( id ) ]) )
.map( id => this.Discipline( id ) )
}
discipline_title( id: string ) {
return this.data().discipline[ id ].name
}
discipline_descr( id: string ) {
return this.data().discipline[ id ].description
}
discipline_arg( id: string ) {
return { discipline: id }
}
discipline_slot( id: string, next?: string ) {
if( next !== undefined ) this.slot_value( next, id )
return this.disciplines_slot()[ id ] ?? ''
}
@ $mol_mem_key
discipline_slot_options( id: string ) {
const data = this.data()
const slots = data.discipline[ id ].variants
.map( flow_id => data.flow[ flow_id ].variants[0] )
.map( les => ( les.date ?? '' ) + 'T' + ( les.time_start ?? '' ) )
return [ ... new Set( slots ) ].sort()
}
@ $mol_mem_key
discipline_slot_title( slot: string ) {
return ( this.slot_value( slot ) ? '🔵 ' : '🟢 ' )
+ new $mol_time_moment( slot ).toString( 'DD Mon hh:mm' )
}
@ $mol_mem
discipline_current() {
return this.$.$mol_state_arg.value( 'discipline' ) ?? null
}
@ $mol_mem
pages_dynamic() {
return [
... this.discipline_current() ? [ this.Discipline_page( this.discipline_current() ) ] : []
]
}
dump() {
return this.data()
}
}
}