Commit 291e3895c2e2e9db694cff91e266a4d756fa5b4d

Authored by totoro
1 parent 0acd0629

add HK_Edit_View in HK_model_display

Showing 1 changed file with 53 additions and 8 deletions   Show diff stats
types/model/display.anubis
... ... @@ -17,8 +17,8 @@ public type HK_List_View:
17 17 public define HK_List_View
18 18 list_view
19 19 (
20   - String view_name,
21   - List(String) columns
  20 + String view_name,
  21 + List(String) columns
22 22 )=
23 23 list_view(view_name, columns, "").
24 24  
... ... @@ -63,20 +63,57 @@ public type HK_Edit_View:
63 63 edit_view_all,
64 64 edit_view(String view_name, List(String) columns).
65 65  
  66 +public define Message
  67 + to_Message
  68 + (
  69 + HK_Edit_View edit_view
  70 + )=
  71 + with _msg = message(_HK_EDIT_VIEW),
  72 + if edit_view is
  73 + {
  74 + edit_view_all then forget(add_string(_msg, "type", "edit_view_all")),
  75 + edit_view(name, columns) then
  76 + forget(add_string(_msg, "type", "list_view"));
  77 + forget(add_string(_msg, "view_name", name));
  78 + map_forget((String column) |-> forget(add_string(_msg, "columns", column)), columns)
  79 + };
  80 + _msg
  81 + .
  82 +
  83 +public define Maybe(HK_Edit_View)
  84 + from_Message
  85 + (
  86 + Message msg
  87 + )=
  88 + if *msg.what = _HK_EDIT_VIEW then
  89 + if find_string(msg, "type") is {failure then failure, success(type) then
  90 + if type = "edit_view_all" then success(edit_view_all) else
  91 + if type = "edit_view" then
  92 + if find_string(msg, "view_name") is {failure then failure, success(view_name) then
  93 + with columns = find_strings(msg, "columns"),
  94 + success(edit_view(view_name, columns))}
  95 + else
  96 + failure
  97 + }
  98 + else
  99 + failure
  100 + .
  101 +
66 102 _HK_MODEL_DISPLAY message format:
67 103 =========================
68 104 The message string name is "hk_display"
69 105 +--------------+---------------+--------------------------------
70 106 | name | type | description
71 107 +--------------+---------------+--------------------------------
72   - | "edits" | List(String) | List of columns for edit panel
  108 + | "list_edits" | List(Message) | List of (edit list) the Message id is _HK_EDIT_VIEW
73 109 | "list_views" | List(Message) | List of (view list) the Message id is _HK_LIST_VIEW
74 110  
75 111  
76 112 public type HK_Display:
77 113 hk_display(List(HK_List_View) list_views,
78   - //List(HK_Edit_View) edit_views
79   - List(String)).
  114 + List(HK_Edit_View) list_edits
  115 + //List(String)
  116 + ).
80 117  
81 118 public define Message
82 119 to_Message
... ... @@ -84,9 +121,10 @@ public define Message
84 121 HK_Display display
85 122 )=
86 123 with hk_display_msg = message(_HK_MODEL_DISPLAY),
87   - since display is hk_display(list_views, list_edit),
  124 + since display is hk_display(list_views, list_edits),
88 125 map_forget((HK_List_View _view) |-> add_message(hk_display_msg, "list_views", to_Message(_view)), list_views);
89   - map_forget((String _str) |-> add_string(hk_display_msg, "edits", _str), list_edit);
  126 + map_forget((HK_Edit_View _edit) |-> add_message(hk_display_msg, "list_edits", to_Message(_edit)), list_edits);
  127 +// map_forget((String _str) |-> add_string(hk_display_msg, "edits", _str), list_edit);
90 128 hk_display_msg
91 129 .
92 130  
... ... @@ -98,10 +136,17 @@ public define Maybe(HK_Display)
98 136 if find_message(msg, "hk_display") is { failure then failure, success(msg_hk_display) then
99 137 if *msg_hk_display.what = _HK_MODEL_DISPLAY then
100 138 with view_list = map_escape((Message _msg) |-> (Maybe(HK_List_View))from_Message(_msg), find_messages(msg_hk_display, "list_views")),
  139 + with edit_list = map_escape((Message _msg) |-> (Maybe(HK_Edit_View))from_Message(_msg), find_messages(msg_hk_display, "list_edits")),
101 140 if view_list is
102 141 {
103 142 failure then failure,
104   - success(list_views) then success(hk_display(list_views, find_strings(msg, "edits")))
  143 + success(list_views) then
  144 + if edit_list is
  145 + {
  146 + failure then failure,
  147 + success(list_edits) then
  148 + success(hk_display(list_views, list_edits))
  149 + }
105 150 }
106 151 else
107 152 failure
... ...