Ignore:
Timestamp:
Aug 26, 2019 6:15:44 PM (6 years ago)
Author:
anonymous
Message:

hide unused menu by css

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/testa-single-bookmark/js/storagex.js

    r29 r36  
    22    constructor () {
    33        this._globalStorage = {}
    4         this._items = ["num", "index", "parts"]
     4        this._items = GlobalxItems
    55    }
    66
     
    3636        this.copy_obj_with_part(info, Globalx, part)
    3737       
    38         info[part].bookmark_mgr = this.convert_to_plain_object_from_bookmark_mgr(Globalx[part].bookmark_mgr)
     38        info.bookmark_mgr = this.convert_to_plain_object_from_bookmark_mgr(Globalx.bookmark_mgr)
    3939    }
    4040
     
    4242        this._globalStorage[key] = obj
    4343        localStorage.setItem(key , JSON.stringify(obj) )
     44    }
     45
     46    change_cache_x( obj ){
     47        this._globalStorage[key] = obj
     48//      localStorage.setItem(key , JSON.stringify(this._globalStorage[key]) )
    4449    }
    4550
     
    5055    }
    5156
    52     convert_to_array_from_bookmark_mgr(mgr){
    53         return {
    54             paths: mgr.get_paths(),
    55             items: mgr_to_array(mgr),
    56             max_display_name_length: mgr.max_display_name_length()
    57         }
     57    async convert_mgr_object_async( mgr, array ){
     58        return await array.map( (path) => {
     59            const item = mgr.get(part , path)
     60            return {
     61                part: part,
     62                path: item.path,
     63                display_name: item.display_name
     64            }
     65        })
    5866    }
    5967
    6068    convert_to_plain_object_from_bookmark_mgr(mgr){
    61         const paths = mgr.get_paths()
    62         const new_bk_items = paths.map( ( path ) => {
    63             let ret = {
    64                 path: "",
    65                 display_name: ""
    66             }
    67             item = mgr.get(path)
    68             if( item != null ){
    69                 ret.path = path
    70                 ret.display_name = item.display_name
    71             }
    72             return ret
    73         } )
    74        
    75         return {
    76             max_display_name_length: mgr.max_display_name_length,
    77             items: new_bk_items
    78         }
     69        let obj = {}
     70        obj.bms = {}
     71
     72        Object.entries( mgr.paths ).map( ([part, array]) => {
     73            obj.bms[part] = this.convert_mgr_object_async(mgr, array)
     74        } )
     75
     76        obj.max_display_name_length = mgr.max_display_name_length
     77        obj.parts = mgr.parts
     78
     79        return obj
     80    }
     81
     82    convert_to_plain_object_from_bookmark_mgr0(mgr){
     83        let obj = {}
     84        obj.bms = Object.fromEntries( Object.entries( mgr.paths ).map( ([part, array]) => {
     85            const bk_items = this.convert_mgr_object_async(mgr, array)
     86
     87            ([part, bk_items])
     88        } ) )
     89        obj.max_display_name_length = mgr.max_display_name_length
     90        obj.parts = mgr.parts
     91
     92        return obj
    7993    }
    8094
    8195    copy_obj_with_part(to_obj, from_obj, part){
    82         const items = ["editor_id", "textarea_sel" , "menu_id", "bookmark_id", "bookmark_op_id", "item_name", "bookmarks", "key_sel", "download_sel", "menu_sel", "bookmark_sel", "bookmark_op_sel", "bookmark_mgr" ]
    83         const init_value_items = ["editor", "key_indicate_file", "key"]
    84        
     96        const items = [
     97            "editor_id",
     98            "textarea_sel" ,
     99            "menu_id",
     100            "bookmark_id",
     101            "bookmark_op_id",
     102            "item_name",
     103            "bookmarks",
     104            "key",
     105            "key_sel",
     106            "download_sel",
     107            "download_url_sel",
     108            "download_partial_url_sel",
     109            "menu_sel" ,
     110            "bookmark_mgr" ,
     111            "bookmark_op_sel"
     112        ]
    85113        if( to_obj[part] === undefined ){
    86114            to_obj[part] = {}
    87115        }
    88116        this.copy_object( to_obj[part], from_obj[part], items )
    89         this.copy_object( to_obj[part], GlobalxInitValue, init_value_items )
     117        this.copy_object( to_obj[part], GlobalxInitValue, GlobalxInitValueItems )
    90118    }
    91119
     
    115143        if( str ){
    116144            ret = this._globalStorage[key] = JSON.parse(str)
    117 //          console.log("rfl 1 key=" + key + " str=" + str)
     145//          console.log("### rfl 1 key=" + key + " str=" + str)
    118146        }
    119147        else{
     
    122150            }
    123151            ret = this._globalStorage[key]
    124             console.log("rfl 2 key=" + key + " undefined")
     152//          console.log("### rfl 2 key=" + key + " undefined")
    125153        }
    126154
     
    132160        const info = this.restore_info()
    133161        if( info !== undefined && info !== null ){
    134             this.restore_info_to_globalx_with_items(info, this._items)
     162            need_to_save = this.restore_info_to_globalx_with_items(info, this._items)
    135163        }
    136164        else{
     
    142170
    143171    convert_to_bookmark_mgr_from_plain_object(mgr) {
    144         let new_mgr = new BookmarkMgr( mgr.max_display_name_length )
    145        
    146         const bk_items = mgr.items
    147         bk_items.map( (bk_item) => {
    148             return new_mgr.add( bk_item.path , bk_item.display_name)
    149         })
     172        let new_mgr = new BookmarkMgr( mgr.max_display_name_length , mgr.parts)
     173       
     174        const bk_items = mgr.bms
     175        Object.entries( ([part, bk_items]) => {
     176            new_bk_items = bk_items.map( (bk_item) => {
     177                return new_mgr.add( bk_item.part , bk_item.path , bk_item.display_name)
     178            } )
     179            [part, new_bk_items]
     180        } )
     181       
    150182        return new_mgr
    151183    }
    152184
    153185    restore_info_to_globalx_with_items(info, items){
     186        let need_to_save = true
     187
    154188        this.copy_object( Globalx, info, items )
    155        
    156         info.parts.map( (part) => {
    157             this.restore_globalx_from_info_part(info , part)
    158         } )
     189
     190        if( info.bookmark_mgr !== undefined ){
     191            info.bookmark_mgr = this.convert_to_bookmark_mgr_from_plain_object(info.bookmark_mgr)
     192       
     193            if( info.parts !== undefined ){
     194                info.parts.map( (part) => {
     195                    this.restore_globalx_from_info_part(info , part)
     196                } )
     197                need_to_save = false
     198            }
     199        }
     200        else{
     201            Globalx.bookmark_mgr = null
     202        }
     203        return need_to_save
    159204    }
    160205
    161206    restore_globalx_from_info_part(info , part){
    162         info[part].bookmark_mgr = this.convert_to_bookmark_mgr_from_plain_object(info[part].bookmark_mgr)
    163207        this.copy_obj_with_part(Globalx, info, part)
    164208    }
     
    168212    }
    169213
    170 
     214    get_output_url() {
     215        return this._globalStorage.output_url
     216    }
    171217
    172218    reset_info = () => {
     
    186232        localStorage.clear()
    187233    }
     234
    188235    show_localstorage() {
    189236        window.open('local_storage.html', '_blank')
Note: See TracChangeset for help on using the changeset viewer.