html.anubis 3.84 KB
/*
 * Created by PyramIDE.
 * User: フランスのトトロ aka (David RENÉ) 
 * Date: 13/02/2016
 * Time: 11:19
 * © Calexium 
 */

read system/string.anubis
read tools/basis.anubis

read hayamiki_lib/types/hayamiki.anubis
read icons.anubis
read columns.anubis

public define String
  to_HTML_cell_icon
  (
    HK_Model_Column column,
    String          data_name,
    String          general_type_name
  )=
  "icon("+to_Icon(column, data_name, general_type_name)+")".

public define String
  to_HTML_cell_text
  (
    HK_Model_Column column,
    String          data_name,
    String          general_type_name
  )=
  "text("+to_String(column, data_name, general_type_name)+")".
  
public define String
  to_HTML_cell_link
  (
    HK_Model_Column column,
    String          data_name,
    String          general_type_name
  )=
  "link(to_String("+data_name+".id), "+to_String(column, data_name, general_type_name)+")".

public define String
  to_HTML_cell_link
  (
    List(HK_Model_Column) columns,
    String                column_name,
    String                data_name,
    String                general_type_name
  )=
  if get_column_type_from_name(columns, column_name) is
  {
    failure          then "column name "+column_name+"doesn't exist",
    success(column)  then to_HTML_cell_link(column, data_name, general_type_name)
  }.
  


public define String
  to_HTML_cell
  (
    List(HK_Model_Column) columns,
    String                column_name,
    String                data_name,
    String                general_type_name
  )=
  if get_column_type_from_name(columns, column_name) is
  {
    failure          then "column name "+column_name+"doesn't exist",
    success(column)  then 
      since column is hk_column(name, col_type, _, _),
      if col_type is 
      {
        p_key                               then to_HTML_cell_link(column, data_name, general_type_name),
        boolean_field                       then to_HTML_cell_icon(column, data_name, general_type_name),
        date_field(attrs)                   then to_HTML_cell_text(column, data_name, general_type_name),
        time_field(attrs)                   then to_HTML_cell_text(column, data_name, general_type_name),
        datetime_field(attrs)               then to_HTML_cell_text(column, data_name, general_type_name),
        foreign_key(app,foreign_table)      then to_HTML_cell_text(column, data_name, general_type_name),
        integer_field                       then to_HTML_cell_text(column, data_name, general_type_name),
        char_field(Int size)                then to_HTML_cell_text(column, data_name, general_type_name),
        text_field                          then to_HTML_cell_text(column, data_name, general_type_name),
      }
  }.

public define String
  make_list_view_row
  (
    HK_Table      table,      //table to format
    String        data_name,  //name of data
    String        indent,     //indentation string to use
    HK_List_View  list_view   //list view to generate
  )=
  since table   is hk_table(table_name, short, model, _),  //get name and model of the table
  since model   is hk_model( columns, _),     //get all columns of table
//  since display is db_display(views, _),  //
  with current_list_column =  if list_view is 
                              {
                                list_view_all             then to_List_String(columns, false), //generate a list of columns string to view from columns model
                                list_view(v_name, v_col)  then v_col
                              },

  if current_list_column is
  {
    []      then "",
    [h . t] then
      indent+join(",\n"+indent, 
      //Make first column as link
      [to_HTML_cell_link(columns, h, data_name, table_name)] +
      
      //and the other set with list_view
      map((String column_name) |-> to_HTML_cell(columns, column_name, data_name, table_name), t)
    )
  }.