/* * Created by PyramIDE. * User: フランスのトトロ aka (David RENÉ) * Date: 28/08/2016 * Time: 01:16 * © Calexium */ read hayamiki_lib/types/hayamiki.anubis read tools/basis.anubis read tools/streams.anubis read system/string.anubis read fields.anubis read columns.anubis read html.anubis read edit_view_list_form.anubis read edit_view_table_form.anubis public define Maybe(One) /* Generate */ generate_HK_Form ( Stream stream, //stream file where to write HK_Table table, // HK_Editor edit_view //edit view to generate )= since table is hk_table(table_name, short_name, model, display), since model is hk_model( columns, constraints, _), //since display is db_display(list_view, list_edit), with type_name = to_upper(table_name, 1), //make the first character to upper case and be an Anubis Type. if edit_view is { //generate the form with all entries in list form edit_view_all then generate_edit_view_list_form(stream, table, "default", columns, []), //generate the list form with given columns edit_view_list_form(v_name, cols, lfk) then if get_HK_Model_Column_list_from_name_list(columns, cols) is { failure then println("generate_HK_Form: can't get all specified columns for table \""+table_name+"\" view name \""+v_name+"\" cols["+join(", ",cols)+"]"); failure, success(got_columns) then generate_edit_view_list_form(stream, table, v_name, got_columns, lfk) } form_table(v_name, table_description) then generate_edit_view_table_form(stream, table, v_name, table_description) //generate the table form } . //generate the type of the table that contain all components public define Maybe(One) /* Generate */ _generate_HK_Form ( Stream stream, //stream file where to write HK_Table table, // List(HK_Editor) edit_view, //edit view to generate Bool has_default //set to true if a default view was encountered. )= if edit_view is { [] then //if default view was not generated, we force to generate it if has_default = false then generate_HK_Form(stream, table, edit_view_all) else success(unique), [view . t] then if generate_HK_Form(stream, table, view) is { failure then failure, success(_) then with new_has_default = if has_default = true then //already true, no need to go further true else if view is { edit_view_all then true, //list_view_all is default view edit_view_list_form(view_name, _, _) then //if not we search for view named 'default' if view_name = "default" then true else false form_table(view_name, _) then //if not we search for view named 'default' if view_name = "default" then true else false }, _generate_HK_Form(stream, table, t, new_has_default) } }. public define String /* Generate */ _generate_get_editable_if_else ( String table_name, // List(HK_Editor) edit_view, //edit view to generate String so_far )= if edit_view is { [] then so_far + "\n"+ " _get_editable_"+table_name+"_default("+table_name+", db)\n", [view . t] then with view_name = if view is { edit_view_all then "default", edit_view_list_form(view_name, _, _) then view_name form_table(view_name, _) then view_name }, _generate_get_editable_if_else( table_name, t, so_far + " if editor_view = \""+view_name+"\" then\n"+ " _get_editable_"+table_name+"_"+view_name+"("+table_name+", db)\n"+ " else" ) }. public define Maybe(One) /* Generate the function which get the right editor according to editor name */ generate_get_viewable ( Stream stream, //stream file where to write HK_Table table, // List(HK_Editor) edit_view //list view to generate )= since table is hk_table(table_name, short_name, model, display), if write_string(stream, "public define HK_Form\n"+ " get_editable_"+table_name+"\n"+ " (\n"+ " SQLite3DataBase db,\n"+ " HK_Form_action action,\n"+ " String editor_view\n"+ " )=\n"+ " with "+table_name+" = if action is\n"+ " {\n"+ " new_entry then get_default_"+table_name+"\n"+ " edit_entry(idx) then get_"+table_name+"(db, idx)\n"+ " },\n"+ _generate_get_editable_if_else(table_name, edit_view, "")+ ".\n" ) is //end of the function { failure then println("can't write generate_get_editable "+table_name); failure, success(_) then success(unique) }. public define Maybe(One) generate_VT_all_edit ( Stream stream, HK_Table table )= since table is hk_table(name, short_name, model, display), since model is hk_model( columns, constraints, _), since display is hk_display(_, list_edit), with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. if _generate_HK_Form(stream, table, list_edit, false) is //edit view to generate { failure then failure, success(_) then generate_get_viewable(stream, table, list_edit) }.