Commit 74cdeb0f authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Adding new application framework

parent 70f088840997
......@@ -16,7 +16,7 @@ let make = _children => {
self.send(Framework.GoTo(Framework.path_to_str(url.path)));
},
initialState: () => {
let registry = Defaults.defaultRegistry();
let registry = Defaults.defaultRegistry;
Framework.States.initial_state(registry);
},
reducer: Framework.States.reduce,
......
let renderRoot =
(self: ReasonReact.self(_, _, _), goto, schema: Hypermedia.schemaRoot) =>
<div>
<h1> (ReasonReact.string(schema.title)) </h1>
(
schema.links
|> List.map((link: Hypermedia.schemaLink) => {
let link_href =
switch (link.href) {
| Some(x) => x
| None => ""
};
let title =
switch (link.title) {
| Some(x) => x
| None => ""
};
<li>
<a
href=link_href
onClick=(
self.handle((event, self) => goto(event, self, link_href))
)>
(ReasonReact.string(title))
</a>
</li>;
})
|> Array.of_list
|> ReasonReact.array
)
</div>;
let renderCollection =
(
self: ReasonReact.self(_, _, _),
goto,
schema: Hypermedia.schemaArrayType,
data: list(Hypermedia.entityValue),
) => {
let schema_title =
switch (schema.title) {
| Some(x) => x
| None => ""
};
let schema_items =
switch (schema.items) {
| ObjectType(t) => t
| _ => {links: [], properties: [], title: None}
};
let link_href =
switch (List.nth(schema_items.links, 0).href) {
| Some(x) => x
| None => "{id}"
};
<div>
<h1> (ReasonReact.string(schema_title)) </h1>
(
data
|> List.map((entity: Hypermedia.entityValue) => {
let obj = Hypermedia.Entity.as_object(entity);
let link_target = Hypermedia.Utils.produce(link_href, obj);
let title =
Hypermedia.Entity.as_string(
Hypermedia.Entity.get(obj, "title"),
);
<li>
<a
href=link_target
onClick=(
self.handle((event, self) => goto(event, self, link_target))
)>
(ReasonReact.string(title))
</a>
</li>;
})
|> Array.of_list
|> ReasonReact.array
)
</div>;
};
let renderEntity =
(
self: ReasonReact.self(_, _, _),
goto,
schema: Hypermedia.schemaObjectType,
data: Hypermedia.entity,
) => {
let schema_title =
switch (schema.title) {
| Some(x) => x
| None => ""
};
<div>
<h1> (ReasonReact.string(schema_title)) </h1>
<div>
(
data.properties
|> List.map((property: Hypermedia.entityProperty) => {
let value = Hypermedia.Entity.as_string(property.value);
<div>
<div> (ReasonReact.string(property.name)) </div>
<div> (ReasonReact.string(value)) </div>
</div>;
})
|> Array.of_list
|> ReasonReact.array
)
</div>
</div>;
};
\ No newline at end of file
let renderLoading =
(
self: ReasonReact.self(Framework.appState, _, Framework.appAction),
state: Framework.appState,
_self: ReasonReact.self(Framework.appState, _, Framework.appAction),
_state: Framework.appState,
) =>
<div> (ReasonReact.string("Loading")) </div>;
let renderFailed =
(
self: ReasonReact.self(Framework.appState, _, Framework.appAction),
state: Framework.appState,
_self: ReasonReact.self(Framework.appState, _, Framework.appAction),
_state: Framework.appState,
) =>
<div> (ReasonReact.string("Failed")) </div>;
......@@ -56,17 +56,87 @@ let renderCollection =
(
self: ReasonReact.self(Framework.appState, _, Framework.appAction),
state: Framework.appState,
) =>
<div> (ReasonReact.string("Collection")) </div>;
) => {
let resource = Framework.States.root_resource(state);
let schema = Hypermedia.Schema.as_array(Framework.schema_of(resource));
let data = Hypermedia.Entity.as_array(Framework.data_of(resource));
let schema_title =
switch (schema.title) {
| Some(x) => x
| None => ""
};
let schema_items =
switch (schema.items) {
| ObjectType(t) => t
| _ => {links: [], properties: [], title: None}
};
let link_href =
switch (List.nth(schema_items.links, 0).href) {
| Some(x) => x
| None => "{id}"
};
<div>
<h1> (ReasonReact.string(schema_title)) </h1>
(
data
|> List.map((entity: Hypermedia.entityValue) => {
let obj = Hypermedia.Entity.as_object(entity);
let link_target = Hypermedia.Utils.produce(link_href, obj);
let title =
Hypermedia.Entity.as_string(
Hypermedia.Entity.get(obj, "title"),
);
<li>
<a
href=link_target
onClick=(
self.handle((_event, _self) =>
Framework.follow_link(link_target)
)
)>
(ReasonReact.string(title))
</a>
</li>;
})
|> Array.of_list
|> ReasonReact.array
)
</div>;
};
let renderEntity =
(
self: ReasonReact.self(Framework.appState, _, Framework.appAction),
_self: ReasonReact.self(Framework.appState, _, Framework.appAction),
state: Framework.appState,
) =>
<div> (ReasonReact.string("Entity")) </div>;
) => {
let resource = Framework.States.root_resource(state);
let schema = Hypermedia.Schema.as_object(Framework.schema_of(resource));
let data = Hypermedia.Entity.as_object(Framework.data_of(resource));
let schema_title =
switch (schema.title) {
| Some(x) => x
| None => ""
};
<div>
<h1> (ReasonReact.string(schema_title)) </h1>
<div>
(
data.properties
|> List.map((property: Hypermedia.entityProperty) => {
let value = Hypermedia.Entity.as_string(property.value);
<div>
<div> (ReasonReact.string(property.name)) </div>
<div> (ReasonReact.string(value)) </div>
</div>;
})
|> Array.of_list
|> ReasonReact.array
)
</div>
</div>;
};
let defaultRegistry = () : Framework.viewRegistry =>
let defaultRegistry =
Framework.Create.registry([
Framework.Create.view(
"::defaults::Loading",
......
......@@ -86,6 +86,11 @@ module Entity = struct
match entityValue with
| ValueObject x -> x
| _ -> {properties= [];}
let as_array entityValue =
match entityValue with
| ValueArray x -> x
| _ -> []
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment