Changeset 36 for branches/testa-single-bookmark/js/storagex.js
- Timestamp:
- Aug 26, 2019 6:15:44 PM (6 years ago)
- File:
-
- 1 edited
-
branches/testa-single-bookmark/js/storagex.js (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/testa-single-bookmark/js/storagex.js
r29 r36 2 2 constructor () { 3 3 this._globalStorage = {} 4 this._items = ["num", "index", "parts"]4 this._items = GlobalxItems 5 5 } 6 6 … … 36 36 this.copy_obj_with_part(info, Globalx, part) 37 37 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) 39 39 } 40 40 … … 42 42 this._globalStorage[key] = obj 43 43 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]) ) 44 49 } 45 50 … … 50 55 } 51 56 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 }) 58 66 } 59 67 60 68 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 79 93 } 80 94 81 95 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 ] 85 113 if( to_obj[part] === undefined ){ 86 114 to_obj[part] = {} 87 115 } 88 116 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 ) 90 118 } 91 119 … … 115 143 if( str ){ 116 144 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) 118 146 } 119 147 else{ … … 122 150 } 123 151 ret = this._globalStorage[key] 124 console.log("rfl 2 key=" + key + " undefined")152 // console.log("### rfl 2 key=" + key + " undefined") 125 153 } 126 154 … … 132 160 const info = this.restore_info() 133 161 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) 135 163 } 136 164 else{ … … 142 170 143 171 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 150 182 return new_mgr 151 183 } 152 184 153 185 restore_info_to_globalx_with_items(info, items){ 186 let need_to_save = true 187 154 188 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 159 204 } 160 205 161 206 restore_globalx_from_info_part(info , part){ 162 info[part].bookmark_mgr = this.convert_to_bookmark_mgr_from_plain_object(info[part].bookmark_mgr)163 207 this.copy_obj_with_part(Globalx, info, part) 164 208 } … … 168 212 } 169 213 170 214 get_output_url() { 215 return this._globalStorage.output_url 216 } 171 217 172 218 reset_info = () => { … … 186 232 localStorage.clear() 187 233 } 234 188 235 show_localstorage() { 189 236 window.open('local_storage.html', '_blank')
Note: See TracChangeset
for help on using the changeset viewer.
![(trac.ini の [header_logo] セクションを設定してください)](/python/trac/Flist/chrome/common/trac_logo_mini.png)