cxm_lib_menu.anubis 3.23 KB
/*
 * Created by PyramIDE.
 * User: フランスのトトロ aka (David RENÉ) 
 * Date: 06/02/2016
 * Time: 15:40
 * © David RENÉ
 */
 
read hayamiki_lib/types/hayamiki.anubis
read tools/basis.anubis
read tools/int.anubis
read system/string.anubis
read system/files.anubis
read tools/streams.anubis
read tools/ISO-8601.anubis

read utils/utils.anubis

define String
  generate_application_menu
  (
    List(HK_App)    apps,
//    List(HK_Table)  tables,  //list of the table model description
    String          indent
  )=
  //   hk_menu_list("111", help_text("222"),
  //   [
  //     hk_menu_item("production_mass_storage",       "view_table", "CURRENT", [("table_name", "production_mass_storage",       ),("view_name", "current")]),

  //calculate then longest table name and add 4 for enclosed quote + coma + final space
  //hence we can make a beautiful formatting
  with max_space = longest_table_name_size(apps, 0) + 4,  
  
  join(",\n",
    map((HK_App  app)  |-> since app is hk_app(app_name, icon, help, tables),
      /*indent+"menu_item("+
        with app_menu_name = if help is { no_help_text        then if app_name ="" then "base" else app_name,
                                          help_text_TAG(tag)  then tag,
                                          help_text(txt)      then txt
                                        },
        to_String(icon)+", "+
        //determine if there is help text for app. If not we use the App name as menu entry

        app_menu_name+",\n"+indent+"[\n"+*/
      join(",\n",
        map_append((HK_Table table)  |-> 
        since table   is hk_table(table_name, short_name, model, display),
        since display is hk_display(list_views, _),
          map((HK_Viewer view ) |-> 
            with view_name = if view is list_view(v_name, _, _, _) then v_name else "default",
            indent+"  "+"menu_item("+
            fill("\""+short_name+(if view_name="default" then "" else " "+view_name)+"\",",max_space)+
            //fill("\""+table_name+"\",",max_space)+
            " controller_action(\"hk_c\", \"view_table\"), "+
            "[(\"table_name\", "+fill("\""+table_name+"\",",max_space)+"),(\"view_name\", \""+view_name+"\")])", list_views), tables))/*+"\n"+indent+"])"*/, apps)).
      
      
public define Maybe(One)
  generate_cxm_lib_menus
  (
    List(HK_App)  apps,  //list of the table model description
    String        dest_dir
  )=

  with file_name        = dest_dir+"web_pages/generated/cxm_lib_apps_menu.anubis",
  
  //create all necessary directories if doesn't exist.
  make_directories(file_name);
  
  //create script file name as new file. Previous file with same name will be erased
  if file(file_name, new) is
  {
    failure       then  println("Can't create menu "+file_name);failure,
    success(fd)   then
      with stream = make_stream(fd),
      
      write_string(stream,
"/*
 * Created by 早見木 (Hayamiki).
 * Date: "+_Int_to_ISO_8601_date(now)+"
 * Time: "+_Int_to_ISO_8601_time(now)+"
 */

transmit xlib/web/making_a_web_site.anubis
transmit xlib/web/widgets/menu.anubis

public define List(Menu_Item)
  applications_cxm_lib_menu
  =" +
/*  hk_menu_list(\"managers\", help_text_TAG(\"APPLICATIONS\"), */
"  [\n"+
    generate_application_menu(apps, "     ")+
"\n
  ].\n"
  )
  }

.