columns.anubis 2.7 KB
/*
 * Created by PyramIDE.
 * User: フランスのトトロ aka (David RENÉ) 
 * Date: 13/02/2016
 * Time: 10:07
 * © David RENÉ
 */

read tools/basis.anubis

transmit help.anubis
transmit fields.anubis
transmit xlib/web/json.anubis
transmit hayamiki_lib/model/types/hk_model_column.anubis
transmit hayamiki_lib/model/types/hk_model_attr.anubis
transmit hayamiki_lib/model/types/hk_help_text.anubis

public define JsonValue
  to_JSON
  (    
    HK_Model_Attr hk_model_attr
  )=
  with members = 
    if hk_model_attr is
    {
      unique           then  [ json_member("hk_column_attr", json_string("unique")) ],

//      indexed          then  [ json_member("hk_column_attr", json_string("indexed")) ],

      default(value)   then  [ json_member("hk_column_attr", json_string("default")),
                               json_member("value",          json_string(value))
                             ],
                             
      not_null         then  [ json_member("hk_column_attr", json_string("not_null")) ]
    },
  
  json_object("_HK_COLUMN_ATTRIBUTES", members).
  
   'HK_Model_Column' (describing a column in a table). 
   Description of a column:

             
 /****** DEFAULT CONSTRUCTOR HELPER - part *******/
 
public define HK_Model_Column
/* Constructor helper for hk_column without help attribute.
 the real type constructor will be called with the attribute no_help_text 
*/
  hk_column
  (
    String              name,
    HK_Model_Field      type,
    List(HK_Model_Attr) attributes,
  )=
  hk_column(name, type, attributes, no_help_text).
  
public define HK_Model_Column
  hk_column
  (
    String          name,
    HK_Model_Field  type   
  )=
  hk_column(name, type, [], no_help_text).
  
             
  _HK_COLUMN message format:
  ==========================
  
  +--------------+---------------+--------------------------
  |  name        |  type         |      description
  +--------------+---------------+--------------------------------
  | "name"       | String        | Name of the column in table
  | "field_type" | Message       | computation String to be shown to summarize row content. This string is Anubis source code
  | "attributes" | List(Message) | List of attributes of the table Message id is _HK_COLUMN_ATTRIBUTES
  | "text"       | Message       | help text to use during  edit screen



public define JsonValue
  to_JSON
  (
    HK_Model_Column hk_column
  )=
  json_object("_HK_COLUMN",
  [
    json_member("name",       json_string(hk_column.name)),
    json_member("field_type", to_JSON(hk_column.type)),  
    json_member("attributes", json_array(map((HK_Model_Attr attribute) |-> to_JSON(attribute), hk_column.attributes))),
    json_member("text",       to_JSON(hk_column.help))
  ]).