Changeset 25 for branches/testa


Ignore:
Timestamp:
Aug 21, 2019 7:44:47 PM (6 years ago)
Author:
anonymous
Message:

use localstorage to store/restore settings

Location:
branches/testa
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • branches/testa/css/menu.css

    r23 r25  
    1515    height: 40px;
    1616    text-align: center;
    17     color: #fff;
     17/*    color: #fff;*/
     18    color: HighlightText;
    1819    font-size: 14px;
    1920    line-height: 2.8;
    20     background: #9fb7d4;
     21/*    background: #9fb7d4;*/
     22    background: #9f9f90;
    2123    text-decoration: none;
    2224    border-right: 1px solid #eee;
     
    2628
    2729.nav > li:hover > a {/*layer-1*/
    28   color: orange;
     30/*  color: orange;
     31  background: #afc6e2;*/
     32  color: MenuText
     33/*  background: Menu*/
    2934  background: #afc6e2;
    3035}
     
    4247    z-index: var(--menu-z-index);
    4348
    44   hight: 30px;
     49/*  hight: 30px; */
    4550}
    4651
  • branches/testa/index.php

    r24 r25  
    1313    <link rel="stylesheet" href="css/style-3.css">
    1414    <link rel="stylesheet" href="css/tab.css">
    15     <link rel="stylesheet" href="css/menu.css">
     15    <link rel="stylesheet" href="css/menu.css?3">
    1616    <link href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" />
    1717    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    1818    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
    1919    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.5/ace.js"></script>
    20     <script src="js/remote.js"></script>
    21     <script src="js/menux.js"></script>
    22     <script src="js/storage.js"></script>
    23     <script src="js/bookmarkmgr.js"></script>
    24     <script src="js/bookmark.js"></script>
     20    <script src="js/storage.js?0"></script>
     21    <script src="js/remote.js?9"></script>
     22    <script src="js/menux.js?9"></script>
     23    <script src="js/bookmark.js?0>"></script>
     24    <script src="js/bookmarkmgr.js?9"></script>
     25    <script src="js/tab.js?9"></script>
     26    <script src="js/topmenu.js?2"></script>
     27    <script src="js/main.js?9"></script>
    2528
    2629    <!--    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.ui-contextmenu/1.18.1/jquery.ui-contextmenu.min.js" integrity="sha256-cI6Q7epHX696CtqUt0dJouTIkNh0w67o5YOhUZygI/s=" crossorigin="anonymous"></script> -->
     
    5659              </ul>
    5760            </li>
     61            <li><a href="#">Bookmark</a>
     62              <ul id="data-bookmark">
     63              </ul>
     64            </li>
    5865            <li><a href="#">Build</a>
    5966              <ul>
     
    6875              </ul>
    6976
    70             <li><a href="#">Bookmark</a>
    71               <ul id="data-bookmark">
     77            <li><a href="#">config</a>
     78              <ul>
     79                <li><a href="#" onclick="save_info_from_globalx()">Save info</a></li>
     80                <li><a href="#" onclick="reset_info()">Reset Info</a></li>
     81                <li><a href="#" onclick="clear_localstorage()">Clear local</a></li>
    7282              </ul>
    7383            </li>
     
    128138     
    129139    </div>
    130     <script src="js/main.js"></script>
    131     <script src="js/tab.js"></script>
    132     <script src="js/topmenu.js"></script>
     140      <script>
     141      main()
     142      </script>
    133143  </body>
    134144</html>
  • branches/testa/js/bookmark.js

    r23 r25  
    33        this.path = path
    44        if( display_name == null ){
    5             this.display_name = path.substr(0, max_display_name_length)
     5            this.display_name = path.substr(-max_display_name_length )
    66        }
    77        else{
    8             this.display_name = display_name
     8            this.display_name = display_name.substr( -max_display_name_length )
    99        }
    1010    }
    11 
    12     display_name() {
    13         return this.display_name
    14     }
    1511}
  • branches/testa/js/bookmarkmgr.js

    r23 r25  
    66    }
    77
    8     add( path , display_name ){
     8    add( path , display_name = null){
    99        let result = this.paths.indexOf( path )
    1010        if( result < 0 ){
     
    2121            delete this.paths[ result ]
    2222        }
     23    }
     24
     25    get( path ){
     26        let ret = null
     27        let result = this.paths.indexOf( path )
     28        if( result >= 0 ){
     29            ret = this.items[ path ]
     30        }
     31        return ret
    2332    }
    2433
     
    4655        return path.substr( -this.max_display_name_length )
    4756    }
     57
     58    get_items() {
     59        return this.items
     60    }
     61
     62    max_display_name_length(){
     63        return this.max_display_name_length
     64    }
    4865}
  • branches/testa/js/main.js

    r24 r25  
    11let Globalx = {};
     2let GlobalxInitValue = {
     3    editor: null,
     4    key_indicate_file: false,
     5    key: '/'
     6};
    27
    38function main() {
    4       Globalx.num = 0;
    5       Globalx.index = 0;
    6       Globalx.parts = ["data", "output", "setting"]
     9    restore_info_to_globalx()
    710
    8       Globalx.parts.map( function( value ){
    9           set_globalx_editor(value)
    10       } )
    11       editor_func("data");
    12       make_ul_for_menu('data' , '#data-side')
    13       menux( "data" )
     11    editor_func("data");
     12    make_ul_for_menu('data' , '#data-side')
     13    menux( "data" )
     14   
     15    editor_func("setting");
     16    make_ul_for_menu("setting" , '#setting-side')
     17   
     18    editor_func("output");
     19    make_ul_for_menu("output" , '#output-side')
    1420
    15       $('#down-download').on('click', {part: "data"}, handleDownload)
    16       $( Globalx['data'].textarea_sel ).val("");
     21    tab_init()
     22    topmenu_init()
    1723
    18       editor_func("setting");
    19       make_ul_for_menu("setting" , '#setting-side')
     24    rebuild_bookmark_menu("data")
    2025
    21       editor_func("output");
    22       make_ul_for_menu("output" , '#output-side')
     26    // LocalStorageにまだ保存していない場合を想定して、ここで保存しておく
     27    console.log("call save_info_from_globalx()")
     28    save_info_from_globalx()
     29
     30    part = "data"
     31    $('#down-download').on('click', {part: part}, handleDownload)
     32    $( Globalx['data'].textarea_sel ).val("");
     33    $( '#bookmark_displayname' ).prop( 'maxlength' , Globalx[part].bookmark_displayname_max_length)
     34    $('#bookmarkDlg').dialog({
     35        autoOpen: false,
     36        modal: true,
     37        buttons: {
     38            "OK": function() {
     39                part = Globalx.parts[ Globalx.index ]
     40                path = $( '#bookmark_path' ).val()
     41                displayname = $( '#bookmark_displayname' ).val()
     42                register_bookmark_( part , path, displayname )
     43                $(this).dialog("close")},
     44            "Cancel": function() {
     45                bookmark_cb.prop('checked', false)
     46                $(this).dialog("close")
     47            }
     48        }
     49    })
     50}
     51
     52function init_globalx() {
     53    Globalx.num = 0;
     54    Globalx.index = 0;
     55    Globalx.parts = ["data", "output", "setting"]
     56   
     57    Globalx.parts.map( function( part ){
     58        console.log("init_globalx part=" + part )
     59        set_globalx_editor(part)
     60    } )
    2361}
    2462
     
    4684      Globalx[part].bookmark_mgr = new BookmarkMgr( Globalx[part].bookmark_displayname_max_length )
    4785
    48       $( '#bookmark_displayname' ).prop( 'maxlength' , Globalx[part].bookmark_displayname_max_length)
    49           $('#bookmarkDlg').dialog({
    50               autoOpen: false,
    51               modal: true,
    52               buttons: {
    53                   "OK": function() {
    54                       part = Globalx.parts[ Globalx.index ]
    55 
    56                       Globalx[part].bookmark_mgr.add( $( '#bookmark_path' ).val() , $( '#bookmark_displayname' ).val() )
    57                       $(this).dialog("close")},
    58                   "Cancel": function() {
    59                       $(this).dislog("close")
    60                   }
    61               }
    62           })
    6386}
    6487
    6588function editor_func(part) {
    66     console.log(`Globalx[#{name}].editor_id=` + Globalx[part].editor_id )
    6789      let editor = ace.edit( Globalx[part].editor_id )
    68     console.log( editor )
    6990      editor.setTheme("ace/theme/monokai");
    7091      editor.setFontSize(14);
     
    7495      Globalx[part].editor = editor;
    7596      let textarea = $( Globalx[part].textarea_sel );
    76     console.log( "textarea=" + textarea )
    7797      Globalx[part].textarea = textarea;
    7898      editor.getSession().on("change", function () {
     
    81101}
    82102
    83 main()
  • branches/testa/js/menux.js

    r23 r25  
    1212
    1313function menu_action( part, item_name , up_flag = false ) {
     14    if( Globalx[part].key != '/' ){
     15       
     16    }
     17
    1418    let realData = get_filelist( Globalx.num )
    1519    Globalx[part].key_indicate_file = false;
     
    121125function bookmark_op(part) {
    122126    if( $( Globalx[part].bookmark_op_sel ).is(':checked') == true ){
    123         console.log( Globalx[part].key +" add_bookmark" )
    124127        add_bookmark(part)
    125128    }
    126129    else{
    127         console.log( Globalx[part].key +" remove_bookmark")
    128130        remove_bookmark(part)
    129131    }
     
    131133
    132134function add_bookmark( part ) {
    133     Globalx[part].bookmark_mgr.add( Globalx[part].key )
    134     rebuild_bookmark_menu( part )
    135135    $( '#bookmark_displayname' ).val( Globalx[part].bookmark_mgr.get_restricted_display_name( Globalx[part].key ) )
    136136    $( '#bookmark_path' ).val( Globalx[part].key )
    137137    $('#bookmarkDlg').dialog("open")
    138    
     138}
     139
     140function register_bookmark_( part , path, displayname ) {
     141    Globalx[part].bookmark_mgr.add( path , displayname )
     142    rebuild_bookmark_menu( part )
    139143}
    140144
     
    162166        return
    163167    }
     168    if(key === Globalx[part].key){
     169        return
     170    }
     171
    164172    let realData = get_filelist( Globalx.num )
    165173    Globalx[part].key = key
     
    176184        });
    177185    }
     186    else{
     187        Globalx[part].key_indicate_file = false
     188        Globalx[part].editor.getSession().setValue( "" );
     189        $( Globalx[part].textarea_sel ).val( "" );
     190    }
    178191    const bookmark_cb = $( Globalx[part].bookmark_op_sel )
    179192    bookmark_cb.prop('checked', true)
     193
     194    $( Globalx[part].menu_sel ).empty()
     195
     196    make_menu_item_list(part, realData)
    180197}
     198
  • branches/testa/js/remote.js

    r23 r25  
    7878
    7979function get_content(path , func) {
    80     console.log( "path:" + path )
    8180    let param_array = [['cmd', 'get_content'], ['num', Globalx.num ], ['path', path]];
    8281    let params = make_url_params( param_array );
     
    8887}
    8988
    90 //
    91 //
    92 function restore_filelist(num, key){
    93     const data = get_filelist(num);
    94     if( data !== null ){
    95 //      display_filelist( data, '#filelist' );
    96 //      console.log( data['/'] );
    97 //      console.log( data['/rtk'] );
    98 //      console.log( data['/rtk/fmp_kernel'] );
    99 //      console.log( data['/rtk/fmp_kernel/data'] );
    100 //      console.log( data['/rtk/fmp_kernel/data/fmp-kernel.md'] );
    101         console.log( data[key] );
    102     }
    103     else{
    104         console.log("null returned!");
    105     }
    106 }
    10789function handleDownload(e) {
    10890    let dl = document.getElementById("down-download")
    10991    if( Globalx[ e.data.part ].key_indicate_file === true ){
    110         console.log("handleDownload-file")
    111         console.log(Globalx[ e.data.part ])
    11292
    11393        get_content( Globalx[ e.data.part ].key , function(content) {
     
    11696            if (window.navigator.msSaveBlob) {
    11797                window.navigator.msSaveBlob(blob, Globalx[ e.data.part ].item_name);
    118                 console.log("handleDownload=" + Globalx[ e.data.part ].item_name)
    11998               
    12099                // msSaveOrOpenBlobの場合はファイルを保存せずに開ける
    121100                window.navigator.msSaveOrOpenBlob(blob, Globalx[ e.data.part ].item_name);
    122101            } else {
    123                 console.log( "handleDownLoad-1-2" )
    124                 console.log("handleDownload=" + Globalx[ e.data.part ].item_name)
    125102                dl.download = Globalx[ e.data.part ].item_name
    126103                dl.href = window.URL.createObjectURL(blob);
     
    130107    else{
    131108        e.preventDefault()
    132         console.log("handleDownload-Not file")
    133109        dl.href = ""
    134110        dl.download = ""
     
    138114function download_cmd(part) {
    139115    if( Globalx[part].key_indicate_file === true ){
    140         console.log("download_cmd filename=" + Globalx[part].filename)
    141 
    142116        let dl = $( Globalx[part].download_sel )
    143 
    144         console.log( dl.attr('download') )
    145117        dl.trigger('click')
    146118    }
  • branches/testa/js/storage.js

    r23 r25  
    11let _globalStorage = {}
     2
     3const _items = ["num", "index", "parts"]
     4
     5function storage_test(){
     6    console.log(_items);
     7}
     8
     9function save_info_from_globalx(){
     10    save_info_from_globalx_with_items(_items)
     11}
     12
     13function convert_to_array_from_bookmark_mgr(mgr){
     14        return {
     15            paths: mgr.get_paths(),
     16            items: mgr_to_array(mgr),
     17            max_display_name_length: mgr.max_display_name_length()
     18        }
     19}
     20
     21function save_info_from_globalx_with_items(items){
     22    let info = {}
     23
     24    copy_object( info, Globalx, items )
     25    /* 
     26        info.num = Globalx.num
     27        info.index = Globalx.index
     28        info.parts = Globalx.parts
     29    */
     30    Globalx.parts.map( function (part) {
     31        save_info_from_globalx_part(info , part)
     32    } )
     33
     34    save_info_to_local_storage(info)
     35}
     36function convert_to_plain_object_from_bookmark_mgr(mgr){
     37//    console.log( "mgr=" + mgr )
     38//    console.log( "mgr.items()=" + mgr.items )
     39    const paths = mgr.get_paths()
     40    const new_bk_items = paths.map( function( path ){
     41        let ret = {
     42            path: "",
     43            display_name: ""
     44        }
     45        item = mgr.get(path)
     46        if( item != null ){
     47            ret.path = path
     48            ret.display_name = item.display_name
     49        }
     50        return ret
     51    } )
     52
     53    return {
     54        max_display_name_length: mgr.max_display_name_length,
     55        items: new_bk_items
     56    }
     57}
     58
     59function save_info_from_globalx_part(info, part){
     60    info[part] = {}
     61    copy_obj_with_part(info, Globalx, part)
     62
     63    info[part].bookmark_mgr = convert_to_plain_object_from_bookmark_mgr(Globalx[part].bookmark_mgr)
     64}
     65
     66function copy_obj_with_part(to_obj, from_obj, part){
     67/*    const items = ["editor_id", "editor", "textarea_sel" , "menu_id", "bookmark_id", "bookmark_op_id", "item_name", "bookmarks", "bookmark_displayname_max_length", "key_indicate_file", "key", "key_sel", "download_sel", "menu_sel", "bookmark_sel", "bookmark_op_sel", "bookmark_mgr" ]*/
     68    const items = ["editor_id", "textarea_sel" , "menu_id", "bookmark_id", "bookmark_op_id", "item_name", "bookmarks", "bookmark_displayname_max_length", "key_sel", "download_sel", "menu_sel", "bookmark_sel", "bookmark_op_sel", "bookmark_mgr" ]
     69    const init_value_items = ["editor", "key_indicate_file", "key"]
     70
     71    if( to_obj[part] === undefined ){
     72        to_obj[part] = {}
     73    }
     74    copy_object( to_obj[part], from_obj[part], items )
     75    copy_object( to_obj[part], GlobalxInitValue, init_value_items )
     76}
     77
     78function copy_object( to_obj, from_obj, items ){
     79    let x = null
     80    items.map( function(item) {
     81        x = from_obj[item]
     82        to_obj[item] = x
     83    } )
     84}
     85
     86function restore_info_to_globalx(){
     87    const info = restore_info()
     88    if( info === undefined ){
     89        console.log("call init_globalx()")
     90        init_globalx()
     91    }
     92    else {
     93        console.log("call restore_info_to_globalx_with_items")
     94        restore_info_to_globalx_with_items(info, _items)
     95    }
     96}
     97
     98function convert_to_bookmark_mgr_from_plain_object(mgr) {
     99    let new_mgr = new BookmarkMgr( mgr.max_display_name_length )
     100   
     101    const bk_items = mgr.items
     102    bk_items.map( function(bk_item) {
     103        return new_mgr.add( bk_item.path , bk_item.display_name)
     104    })
     105    return new_mgr
     106}
     107
     108function restore_info_to_globalx_with_items(info, items){
     109   
     110    copy_object( Globalx, info, items )
     111
     112    info.parts.map( function (part) {
     113        restore_info_to_globalx_part(info , part)
     114    } )
     115}
     116
     117function restore_info_to_globalx_part(info , part){
     118    info[part].bookmark_mgr = convert_to_bookmark_mgr_from_plain_object(info[part].bookmark_mgr)
     119    copy_obj_with_part(Globalx, info, part)
     120}
    2121
    3122function save_info_to_local_storage(info){
     
    18137function get_filelist(num) {
    19138    let num_s = num + ''
    20     if( _globalStorage[num_s] === undefined ){
    21         oldData = localStorage.getItem(num_s)
     139    return restore_from_localstorage(num_s)
     140}
     141
     142
     143function restore_info(){
     144    const item_name = "info"
     145    return restore_from_localstorage(item_name)
     146}
     147
     148function restore_from_localstorage(item_name){
     149   if( _globalStorage[item_name] === undefined ){
     150        oldData = localStorage.getItem(item_name)
    22151        if( oldData ){
    23             _globalStorage[num_s] = JSON.parse(oldData)
     152            _globalStorage[item_name] = JSON.parse(oldData)
    24153        }
    25154    }
    26     return _globalStorage[num_s]
     155    return _globalStorage[item_name]
    27156}
    28157
     158function reset_info(){
     159    let item_name = 'info'
     160    reset_localstorage(item_name)
     161}
     162
     163function reset_localstorage(item_name){
     164    delete _globalStorage[item_name]
     165    localStorage.removeItem(item_name)
     166}
     167
     168function clear_localstorage(){
     169    let keys = Object.keys(_globalStorage)
     170    keys.map( (v) => { delete _globalStorage[v] } )
     171
     172    localStorage.clear()
     173}
  • branches/testa/js/tab.js

    r23 r25  
    1 jQuery(function($){
     1function tab_init(){
    22    $('.tab').click(function(){
    33        $('.is-active').removeClass('is-active');
     
    1010        // クリックしたタブと同じインデックス番号をもつコンテンツを表示
    1111        $('.panel').eq(index).addClass('is-show');
    12     });
    13 });
     12    })
     13}
  • branches/testa/php/content.php

    r23 r25  
    99require_once( dirname(__FILE__) . '/NorthernCross/ns/PathInfo.php');
    1010require_once( dirname(__FILE__) . "/spyc-0.5/spyc.php"); // ★の部分にはspyc.phpを置いたパスを入れます
    11 
    1211
    1312function get_url_data_array()
     
    123122function cmdx(){
    124123    $filelist_filename = "filelist.json";
     124    $setting_filelist_filename = "setting-filelist.json";
    125125    $storage_dir = dirname(__FILE__) . '/../storage';
    126126
     
    132132
    133133            switch ($cmd) {
     134            case 'get_setting_filelist':
     135                $path = ensure_storage_dir( $storage_dir , $num, $setting_filelist_filename );
     136                if( file_exists($path) ){
     137                    $content = input_file( $path );
     138                }
     139                else {
     140                    $content = get_path_info( $num );
     141                    output_file( $path , $content );
     142                }
     143                break;
     144            case 'build':
     145                break;
    134146            case 'get_content':
    135147                if (isset($_GET['path'])) {
     
    146158                $path = ensure_storage_dir( $storage_dir , $num, $filelist_filename );
    147159                if( file_exists($path) ){
    148                     $content = input_file( $filename );
     160                    $content = input_file( $path );
    149161                }
    150162                else {
  • branches/testa/settings.yml

    r23 r25  
    22  url: https://toppers.jp
    33  path: /var/www/vhosts/devconf.northern-cross.info/httpdocs/a/tmp/devconf-guest-4/tmp/md2site-x/_xtest/wtjx/t12/src
     4  setting_path: /var/www/vhosts/devconf.northern-cross.info/httpdocs/a/tmp/devconf-guest-4/tmp/md2site-x/_xtest/wtjx/t12/conf
    45-
    56  url: https://toppers.jp
    67  path: /var/www/vhosts/devconf.northern-cross.info/httpdocs/a/tmp/devconf-guest-4/tmp/md2site-x/_xtest/wtjx/t12/src
     8  setting_path: /var/www/vhosts/devconf.northern-cross.info/httpdocs/a/tmp/devconf-guest-4/tmp/md2site-x/_xtest/wtjx/t12/c
Note: See TracChangeset for help on using the changeset viewer.