-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lamps.view.ts
208 lines (166 loc) · 3.78 KB
/
lamps.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
namespace $.$$ {
export class $hyoo_lamps extends $.$hyoo_lamps {
@ $mol_mem
lamps_all() {
return $mol_csv_parse( $mol_fetch.text( 'https://lamptest.ru/led.php' ), ';' )
}
@ $mol_mem
lamps2() {
return $mol_fetch.text( '//lamptest.ru/led.php' )
}
@ $mol_mem
lamps() {
return this.lamps_all().filter(
$mol_match_text(
this.filter() ,
( lamp : any )=> {
return Object.keys( lamp ).map( field => lamp[ field ] )
} ,
)
)
}
@ $mol_mem
lamps_dict() {
const dict = {} as { [ key : string ] : any }
this.lamps_all().forEach( lamp => {
dict[ lamp[ 'no' ] ] = lamp
} )
return dict
}
@ $mol_mem
lamp_rows() {
return [
this.Filter(),
... this.lamps().map( lamp => this.Lamp_row( lamp[ 'no' ] ) )
]
}
lamp_title( id : string ) {
const row = this.lamps_dict()[ id ]
const brand = row[ 'brand' ]
if( brand === 'noname' ) return row[ 'model' ]
return `${ row[ 'brand' ] } ${ row[ 'model' ] }`
}
@ $mol_mem
filter( next? : string , force? : $mol_mem_force ) : string {
if( next === undefined ) return $mol_state_arg.value( 'filter' ) || ''
return $mol_state_arg.value( 'filter' , next ) ?? ''
}
lamp_arg( id : string ) {
return { 'lamp' : id }
}
id( next? : string | null ) {
return $mol_state_arg.value( 'lamp' , next ) ?? ''
}
lamp() {
return this.lamps_dict()[ this.id() ] || null
}
pages() {
let sub : $mol_view[] = []
sub.push( this.Addon_page() )
if( this.lamp() !== null ) sub.push( this.Main_page( this.lamp() ) )
return sub
}
Placeholder() {
return this.lamp() ? null as any : super.Placeholder()
}
@ $mol_mem
menu_scroll_top( next? : number ) {
this.filter()
return next || 0
}
title() {
const id = this.id()
if( !id ) return 'LampTest.ru'
return this.lamp_title( id )
}
cri() {
return `${ this.lamp()[ 'cri' ] }%`
}
angle() {
return `${ this.lamp()[ 'angle' ] }°`
}
shape() {
return `${ this.lamp()[ 'shape' ] }`
}
base() {
return `${ this.lamp()[ 'base' ] }`
}
type() {
return `${ this.lamp()[ 'type' ] }`
}
temp() {
return `${ this.lamp()[ 'color_l' ] }`
}
wattage() {
return `${ this.lamp()[ 'power_l' ] }W`
}
matt() {
return this.lamp()[ 'matt' ] == 1
}
ripple() {
return `${ this.lamp()[ 'flicker' ] }%`
}
rating_cri() {
const cri = this.lamp()[ 'cri' ]
if( cri >= 90 ) return 5
if( cri >= 85 ) return 4.5
if( cri >= 80 ) return 4
if( cri >= 75 ) return 3.5
if( cri >= 70 ) return 3
if( cri >= 60 ) return 2
return 1
}
rating() {
return Math.min( this.rating_cri() )
}
slug( id : string ) {
const trans = {
'а' : 'a' ,
'б' : 'b' ,
'в' : 'v' ,
'г' : 'g' ,
'д' : 'd' ,
'е' : 'e' ,
'ё' : 'yo' ,
'ж' : 'zh' ,
'з' : 'z' ,
'и' : 'i' ,
'й' : 'y' ,
'к' : 'k' ,
'л' : 'l' ,
'м' : 'm' ,
'н' : 'n' ,
'о' : 'o' ,
'п' : 'p' ,
'р' : 'r' ,
'с' : 's' ,
'т' : 't' ,
'у' : 'u' ,
'ф' : 'f' ,
'х' : 'h' ,
'ц' : 'ts' ,
'ч' : 'ch' ,
'ш' : 'sh' ,
'щ' : 'sch' ,
'ъ' : '\'' ,
'ы' : 'yi' ,
'ь' : '' ,
'э' : 'e' ,
'ю' : 'yu' ,
'я' : 'ya' ,
}
const prefix = '0'.repeat(5 - id.length) + id + '-'
return prefix + this.lamp_title( id )
.replace( /[ \/]/g , '-' )
.replace( /[.,]/g , '' )
.toLowerCase()
.replace( /[а-я]/g , ( letter : keyof typeof trans )=> trans[ letter ] )
}
photo() {
return `http://lamptest.ru/images/photo/${ this.slug( this.id() ) }.jpg`
}
thumb( id : string ) {
return `http://lamptest.ru/images/photo/${ this.slug( id ) }-med.jpg`
}
}
}