plugin.anubis 4.62 KB
/*
 * Created by PyramIDE.
 * User: フランスのトトロ aka (David RENÉ) 
 * Date: 30/07/2017
 * Time: 01:33
 * © David RENÉ
 */

read system/logger.anubis
//read app/app_constants.anubis
read xlib/web/widgets/left_menu.anubis
transmit xlib/web/types/making_a_web_site.anubis
transmit xlib/web/types/controllers_web_site.anubis
 read xlib/web/widgets/menu.anubis
read hayamiki_lib/model/database.anubis
read hayamiki_lib/view/view_table_manager_types.anubis

public type WEB_Plugin:
  web_plugin(
    String  app_name,     //application name
    String  space_name,   //space name
    String  version,
    String  date,
    //version
    (SQLite3DataBase db, HK_Database hk_db, VTM _vtm, (LogLevel, String) -> One   logger) -> List(WEB_Controller) get_controller,
    (SQLite3DataBase db, WEB_Session, String type) -> Maybe(HTML) get_typed_content
//    (One dummy) -> Plugin_Left_Menu                                     get_plugin_left_menu
//    (One dummy) -> Message                                              get_API,
//    (Message message) ->  Message                                       call_API

  )
.


public define Maybe(WEB_Plugin)
  load_plugin
  (
    String                      file_name,
    (LogLevel, String) -> One   logger
  )=
  if (LoadAdm(WEB_Plugin))load_adm(file_name) is 
  {
    file_not_found               then logger(logError, "File '"+file_name+"' not found.\n\n");failure,
    read_error                   then logger(logError, "Error reading file '"+file_name+"'.\n\n");failure, 
    timeout                      then logger(logError, "Timeout when loading '"+file_name+"'.\n\n");failure, 
    file_damaged                 then logger(logError, "File '"+file_name+"' is damaged.\n\n");failure, 
    bad_version(expected,found)  then logger(logError, "Secondary module '"+file_name+"' doesn't have the same\n"+
                                           "  version ("+found+") as primary module ("+expected+").\n\n");failure, 
    wrong_type(expected,found)   then logger(logError, "Secondary module '"+file_name+"' has different type as expected by primary module\n");failure, 
    ok(web_plugin)               then logger(logInfo, "web plugin loaded: APP ["+web_plugin.app_name+"] SPACE ["+web_plugin.space_name+"] version: "+web_plugin.version+" date: "+web_plugin.date+" loaded ");success(web_plugin)
  }
.

public define Maybe(WEB_Plugin)
  load_plugin
  (
    String                      file_name
  )=
  load_plugin(file_name, (LogLevel lvl, String string) |-> println(to_String(lvl)+" "+string))
.

  
public define List(WEB_Plugin)
  all_plugins
  (
    String                      directory,        //directory where search the plugin file below
    String                      plugin_file_mask, //mask for loading plugin like "my_app_plugin_*.adm"
    (LogLevel, String) -> One   logger            //
  )=
  with files = directory_list(directory, plugin_file_mask),
  map_select(
    (String file_name) |->
      load_plugin(directory+file_name, logger)
    ,
    files
  )
.

public define List(WEB_Plugin)
  all_plugins
  (
    String                      directory,        //directory where search the plugin file below
    String                      plugin_file_mask  //mask for loading plugin like "my_app_plugin_*.adm"
  )=
  all_plugins(directory, plugin_file_mask, (LogLevel lvl, String string) |-> println(to_String(lvl)+" "+string))
.

public define Maybe(WEB_Plugin)
  get_WEB_Plugin
  (
    List(WEB_Plugin)          plugins,
    String                    _app,
    String                    _space,
    (LogLevel, String) -> One logger
  )=
  if plugins is
  {
    []      then  logger(logError, "get_WEB_Plugin for app ["+_app+"] space ["+_space+"] NOT FOUND");failure,
    [h . t] then
      if h.app_name = _app & h.space_name = _space then
        //println("get_WEB_Plugin for app ["+_app+"] space ["+_space+"] OK");
        success(h)
      else
        get_WEB_Plugin(t, _app, _space, logger)
  }
.

public define Maybe(WEB_Plugin)
  get_WEB_Plugin
  (
    List(WEB_Plugin)          plugins,
    String                    _app,
    String                    _space
  )=
  get_WEB_Plugin(plugins, _app, _space, (LogLevel lvl, String string) |-> println(to_String(lvl)+" "+string))
.

 public define World_Left_Menu
  get_left_menu_from_plugins
  (
    List(WEB_Plugin)  plugins,
    World_Left_Menu   current_world
  )=
  if plugins is
  {
    []      then current_world,
    [h . t] then get_left_menu_from_plugins(t, add_to_World_Left_Menu(current_world, h.get_plugin_left_menu(unique)))
  }
.

 public define World_Left_Menu
  get_left_menu_from_plugins
  (
    List(WEB_Plugin) plugins
  )=
  get_left_menu_from_plugins(plugins, world_menu([]))
.