| 1 | class BookmarkMgr { |
|---|
| 2 | constructor( max_display_name_length , parts ) { |
|---|
| 3 | this.paths = {} |
|---|
| 4 | |
|---|
| 5 | this.parts = parts |
|---|
| 6 | this.parts.map( (part) => { |
|---|
| 7 | this.paths[part] = [] |
|---|
| 8 | } ) |
|---|
| 9 | this.items = {} |
|---|
| 10 | this.parts.map( (part) => { |
|---|
| 11 | this.items[part] = {} |
|---|
| 12 | } ) |
|---|
| 13 | this.max_display_name_length = max_display_name_length |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | add( part, path , display_name = null){ |
|---|
| 17 | console.log("BookmarkMgr add part=" + part + " path="+ path) |
|---|
| 18 | let result = this.paths[part].indexOf( path ) |
|---|
| 19 | if( result < 0 ){ |
|---|
| 20 | this.paths[part].push( path ) |
|---|
| 21 | this.items[part][ path ] = new Bookmark( path , this.max_display_name_length , display_name ) |
|---|
| 22 | } |
|---|
| 23 | return this.items[part][ path ] |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | remove( part, path ){ |
|---|
| 27 | let result = this.paths[part].indexOf( path ) |
|---|
| 28 | if( result >= 0 ){ |
|---|
| 29 | delete this.items[part][ path ] |
|---|
| 30 | delete this.paths[part][ result ] |
|---|
| 31 | } |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | get( part, path ){ |
|---|
| 35 | let ret = null |
|---|
| 36 | let result = this.paths[part].indexOf( path ) |
|---|
| 37 | if( result >= 0 ){ |
|---|
| 38 | ret = this.items[part][ path ] |
|---|
| 39 | } |
|---|
| 40 | return ret |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | display_name( part, path ){ |
|---|
| 44 | let result = this.paths[part].indexOf( path ) |
|---|
| 45 | let disp = null |
|---|
| 46 | if( result >= 0 ){ |
|---|
| 47 | disp = this.items[part][ path ].display_name |
|---|
| 48 | } |
|---|
| 49 | return disp |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | get_paths(part){ |
|---|
| 53 | return this.paths[part] |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | get_display_names(part, path){ |
|---|
| 57 | const array = thils.paths[part] |
|---|
| 58 | return array.map( function( path ){ |
|---|
| 59 | return this.items[part][ path ].display_name |
|---|
| 60 | } ) |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | get_restricted_display_name( path ){ |
|---|
| 64 | return path.substr( -(this.max_display_name_length) ) |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | get_items(part) { |
|---|
| 68 | return this.items[part] |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | max_display_name_length(){ |
|---|
| 72 | return this.max_display_name_length |
|---|
| 73 | } |
|---|
| 74 | } |
|---|