1
1
import { component } from 'vuets'
2
- import { defp , extractMsg , bit_clear_and_set , base64ToBytes , to_int32LE } from 'coreds/lib/util'
2
+ import { defp , extractMsg , bit_clear_and_set } from 'coreds/lib/util'
3
3
import { PojoState , HasState } from 'coreds/lib/types'
4
4
import { diffFieldTo } from 'coreds/lib/diff'
5
5
import { bindFocus , debounce , Keys } from 'coreds-ui/lib/dom_util'
6
- import * as Vue from 'vue'
6
+ import { nextTick } from 'vue'
7
7
import { user } from '../../g/user/'
8
8
const $ = user . BookmarkEntry ,
9
9
M = user . BookmarkEntry . M
10
- const nextTick = Vue . nextTick
11
10
12
11
interface Config {
13
12
url : string
@@ -23,37 +22,12 @@ function $validateNotes() {}*/
23
22
const MAX_TAGS = 4 ,
24
23
SUGGEST_TAGS_LIMIT = 12
25
24
26
- interface Tag {
27
- id : number
28
- name : string
29
- state : number
30
- }
31
-
32
- const enum TagState {
33
- CURRENT = 32
34
- }
35
-
36
- export function toTagArray ( serTags : string , names : string [ ] ) : Tag [ ] {
37
- let list : Tag [ ] = [ ] ,
38
- bytes = base64ToBytes ( serTags )
39
-
40
- for ( let i = 0 , j = 0 , len = bytes . length ; i < len ; i += 4 ) {
41
- let id = to_int32LE ( bytes , i ) ,
42
- name = names [ j ++ ] /*,
43
- color = tag && tag[Tag0.color] ? ('#' + tag[Tag0.color]) : DEFAULT_TAG_COLOR*/
44
-
45
- list . push ( { id, name, state : 0 } )
46
- }
47
-
48
- return list
49
- }
50
-
51
25
interface Entry extends HasState {
52
26
title : string
53
27
notes : string
54
- tags : Tag [ ]
28
+ tags : user . BookmarkTag . M [ ]
55
29
// suggest fields
56
- suggest_tags : Tag [ ]
30
+ suggest_tags : user . BookmarkTag . M [ ]
57
31
tag_idx : number
58
32
tag_name : string
59
33
}
@@ -62,21 +36,13 @@ interface M {
62
36
original : Entry
63
37
}
64
38
65
- function mapTag ( item ) : Tag {
66
- return {
67
- id : item [ '3' ] ,
68
- name : item [ '1' ] ,
69
- state : 0
70
- }
71
- }
72
-
73
- function mapId ( item : Tag ) : number {
74
- return item . id
39
+ function mapId ( item : user . BookmarkTag . M ) : number {
40
+ return item [ user . BookmarkTag . M . $ . id ]
75
41
}
76
42
77
43
function handleKeyEvent ( e : KeyboardEvent , pojo : Entry , self : Home , fn_name : string ) : boolean {
78
- let suggest_tags : Tag [ ] ,
79
- tag : Tag ,
44
+ let suggest_tags : user . BookmarkTag . M [ ] ,
45
+ tag : user . BookmarkTag . M ,
80
46
idx : number
81
47
switch ( e . which ) {
82
48
case Keys . ESCAPE :
@@ -90,12 +56,10 @@ function handleKeyEvent(e: KeyboardEvent, pojo: Entry, self: Home, fn_name: stri
90
56
91
57
if ( idx !== 0 ) {
92
58
tag = suggest_tags [ idx - 1 ]
93
- tag . state ^= TagState . CURRENT
94
59
}
95
60
96
61
tag = suggest_tags [ idx ]
97
- tag . state |= TagState . CURRENT
98
-
62
+ // selected idx
99
63
pojo . tag_idx = idx
100
64
break
101
65
case Keys . UP :
@@ -108,17 +72,13 @@ function handleKeyEvent(e: KeyboardEvent, pojo: Entry, self: Home, fn_name: stri
108
72
// select last
109
73
idx = suggest_tags . length - 1
110
74
tag = suggest_tags [ idx ]
111
- tag . state |= TagState . CURRENT
75
+ // selected idx
112
76
pojo . tag_idx = idx
113
77
break
114
78
}
115
-
116
- tag = suggest_tags [ idx -- ]
117
- tag . state ^= TagState . CURRENT
118
-
119
- tag = suggest_tags [ idx ]
120
- tag . state |= TagState . CURRENT
121
-
79
+
80
+ tag = suggest_tags [ -- idx ]
81
+ // selected idx
122
82
pojo . tag_idx = idx
123
83
break
124
84
case Keys . ENTER :
@@ -176,7 +136,7 @@ export class Home {
176
136
}
177
137
pnew_tag$$F : any
178
138
pnew_tag$$focus : any
179
-
139
+
180
140
m : M
181
141
182
142
static created ( self : Home ) {
@@ -245,7 +205,7 @@ export class Home {
245
205
246
206
let original = array [ 0 ] ,
247
207
pupdate = this . pupdate ,
248
- tags = toTagArray ( original [ $ . $ . serTags ] , original [ M . $ . tags ] ) ,
208
+ tags = original [ M . $ . tags ] ,
249
209
tagCount = tags . length
250
210
251
211
this . m . original = original
@@ -302,9 +262,9 @@ export class Home {
302
262
303
263
this . prepare ( pojo )
304
264
305
- user . BookmarkTag . $NAME ( { "1" : val , "4" : { "1" : false , "2" : SUGGEST_TAGS_LIMIT } } ) . then ( ( data ) => {
265
+ user . BookmarkTag . $NAME ( { "1" : val , "4" : { "1" : false , "2" : SUGGEST_TAGS_LIMIT } } , true ) . then ( ( data ) => {
306
266
let array = data [ '1' ] as any [ ]
307
- pojo . suggest_tags = array && array . length ? array . map ( mapTag ) : [ ]
267
+ pojo . suggest_tags = array || [ ]
308
268
pojo . tag_idx = - 1
309
269
310
270
this . success ( pojo )
@@ -329,8 +289,8 @@ export class Home {
329
289
window . close ( )
330
290
} ) . then ( undefined , this . pnew$$F )
331
291
}
332
- addTag ( tag : Tag ) {
333
- let id = tag . id ,
292
+ addTag ( tag : user . BookmarkTag . M ) {
293
+ let id = mapId ( tag ) ,
334
294
pnew = this . pnew ,
335
295
tags = pnew . tags ,
336
296
i = 0 ,
@@ -340,7 +300,7 @@ export class Home {
340
300
pnew . tag_name = ''
341
301
342
302
for ( ; i < len ; i ++ ) {
343
- if ( id === tags [ i ] . id ) {
303
+ if ( id === mapId ( tags [ i ] ) ) {
344
304
// dup
345
305
nextTick ( this . pnew$$focus_tag )
346
306
return
@@ -351,15 +311,15 @@ export class Home {
351
311
if ( tags . length < MAX_TAGS )
352
312
nextTick ( this . pnew$$focus_tag )
353
313
}
354
- rmTag ( tag : Tag , update ?: boolean ) {
355
- let id = tag . id ,
314
+ rmTag ( tag : user . BookmarkTag . M , update ?: boolean ) {
315
+ let id = mapId ( tag ) ,
356
316
pojo = update ? this . pupdate : this . pnew ,
357
317
tags = pojo . tags ,
358
318
i = 0 ,
359
319
len = tags . length
360
320
361
321
for ( ; i < len ; i ++ ) {
362
- if ( id === tags [ i ] . id ) {
322
+ if ( id === mapId ( tags [ i ] ) ) {
363
323
if ( ! update )
364
324
tags . splice ( i , 1 )
365
325
break
@@ -388,8 +348,8 @@ export class Home {
388
348
389
349
nextTick ( this . pupdate$$focus_tag )
390
350
}
391
- insertTag ( tag : Tag ) {
392
- let id = tag . id ,
351
+ insertTag ( tag : user . BookmarkTag . M ) {
352
+ let id = mapId ( tag ) ,
393
353
pupdate = this . pupdate ,
394
354
tags = pupdate . tags ,
395
355
i = 0 ,
@@ -399,7 +359,7 @@ export class Home {
399
359
pupdate . tag_name = ''
400
360
401
361
for ( ; i < len ; i ++ ) {
402
- if ( id === tags [ i ] . id ) {
362
+ if ( id === mapId ( tags [ i ] ) ) {
403
363
// dup
404
364
nextTick ( this . pupdate$$focus_tag )
405
365
return
@@ -466,8 +426,8 @@ export default component({
466
426
</div>
467
427
<div class="dropdown" :class="{ active: pnew.suggest_tags.length }">
468
428
<ul class="dropdown-menu mfluid">
469
- <li v-for="tag in pnew.suggest_tags" :class="{ current: !!(tag.state & ${ TagState . CURRENT } ) }">
470
- <a @click.prevent="addTag(tag)">{{tag. name}}</a>
429
+ <li v-for="( tag, idx) of pnew.suggest_tags" :class="{ current: idx === pnew.tag_idx }">
430
+ <a @click.prevent="addTag(tag)">{{ tag[' ${ user . BookmarkTag . M . $ . name } '] }}</a>
471
431
</li>
472
432
</ul>
473
433
</div>
@@ -476,8 +436,11 @@ export default component({
476
436
:disabled="!!(pnew.state & ${ PojoState . LOADING } ) || (!!pnew.tag_name && !pnew.tags.length)"><b>Submit</b></button>
477
437
</div>
478
438
<ul class="tags">
479
- <li v-for="tag in pnew.tags">
480
- <a>{{tag.name}}<button class="b" @click.prevent="rmTag(tag, false)">x</button></a>
439
+ <li v-for="tag of pnew.tags">
440
+ <a>
441
+ {{ tag['${ user . BookmarkTag . M . $ . name } '] }}
442
+ <button class="b" @click.prevent="rmTag(tag, false)">x</button>
443
+ </a>
481
444
</li>
482
445
</ul>
483
446
</div>
@@ -499,15 +462,18 @@ export default component({
499
462
</div>
500
463
<div class="dropdown" :class="{ active: pupdate.suggest_tags.length }">
501
464
<ul class="dropdown-menu mfluid">
502
- <li v-for="tag in pupdate.suggest_tags" :class="{ current: !!(tag.state & ${ TagState . CURRENT } ) }">
503
- <a @click.prevent="insertTag(tag)">{{tag. name}}</a>
465
+ <li v-for="( tag, idx) of pupdate.suggest_tags" :class="{ current: idx === pupdate.tag_idx }">
466
+ <a @click.prevent="insertTag(tag)">{{ tag[' ${ user . BookmarkTag . M . $ . name } '] }}</a>
504
467
</li>
505
468
</ul>
506
469
</div>
507
470
<ul class="tags">
508
- <li v-for="tag in pupdate.tags">
509
- <a>{{tag.name}}<button class="b" @click.prevent="rmTag(tag, true)"
510
- :disabled="!!(pupdate.state & ${ PojoState . LOADING } )">x</button></a>
471
+ <li v-for="tag of pupdate.tags">
472
+ <a>
473
+ {{ tag['${ user . BookmarkTag . M . $ . name } '] }}
474
+ <button class="b" @click.prevent="rmTag(tag, true)"
475
+ :disabled="!!(pupdate.state & ${ PojoState . LOADING } )">x</button>
476
+ </a>
511
477
</li>
512
478
</ul>
513
479
</div>
0 commit comments