static HElement View(QNode node, IDictionary <Guid, QCalculator.Function> functionIndex) { var functionId = ConvertHlp.ToGuid(node.C(0).P_("function-id", "*").AsString()); var f = functionId.Maybe(_ => functionIndex.Find(functionId.Value)); return(h.Div ( h.@class("q"), h.Span(h.@class("q-type"), $" ({TypeToString(node.C(0).P("type").QValue().FirstOrDefault())}) "), h.Span(node.RawValue()), h.Span(h.@class("q-inter-type"), $" ({node.P_s(0, "inter-type", "*").Select(interType => TypeToString(interType)).JoinToString(", ")}) "), functionId.Maybe(_ => h.A(h.style("font-size:75%"), h.href($"#f-{_}"), "f-" + f?.Index, h.title(FunctionFullName(f.RawDescription)))), node.Nodes().OrEmpty().Skip(1).Select(n => View(n, functionIndex)) )); }
public static NitroBolt.Wui.HtmlResult <HElement> HView(MainState state, JsonData[] jsons, HttpRequestMessage request) { foreach (var json in jsons.OrEmpty()) { switch (json.JPath("data", "command")?.ToString()) { case "new-order": { var name = json.JPath("data", "name")?.ToString() ?? "C"; var isDelivery = json.JPath("data", "is-delivery")?.ToString() == "True"; var toTime = ToTime(json.JPath("data", "to-time")?.ToString()); var status = toTime == null ? ProductStatus.New : ProductStatus.InQueue; var products = name == "B" ? new[] { new Product("K", status) } : new[] { new Product("M", status), new Product("P", status) }; state = state.With(orders: state.Orders.Add(new Order(name: name, isDelivery: isDelivery, status: toTime == null ? OrderStatus.New : OrderStatus.InQueue, products: ImmutableArray.Create(products), toTime: toTime))); } break; case "product-prepare": { var orderId = ConvertHlp.ToGuid(json.JPath("data", "order")); var productId = ConvertHlp.ToGuid(json.JPath("data", "product")); var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId); var product = order?.Products.OrEmpty().FirstOrDefault(_product => _product.Id == productId); if (product != null && product.Status != ProductStatus.New) { product = null; } if (product != null) { state = state.With(orders: state.Orders.Replace(order, order.With(products: order.Products.Replace(product, product.With(status: ProductStatus.Prepare))))); } } break; case "product-ready": { var orderId = ConvertHlp.ToGuid(json.JPath("data", "order")); var productId = ConvertHlp.ToGuid(json.JPath("data", "product")); var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId); var product = order?.Products.OrEmpty().FirstOrDefault(_product => _product.Id == productId); if (product != null && product.Status != ProductStatus.Prepare) { product = null; } if (product != null) { state = state.With(orders: state.Orders.Replace(order, order.With(products: order.Products.Replace(product, product.With(status: ProductStatus.Ready))))); } } break; case "order-build": { var orderId = ConvertHlp.ToGuid(json.JPath("data", "order")); var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId); if (order != null && order.Status != OrderStatus.Prepare && !order.IsReady) { order = null; } if (order != null) { state = state.With(orders: state.Orders.Replace(order, order.With(status: OrderStatus.Ready))); } } break; case "courier": { var orderId = ConvertHlp.ToGuid(json.JPath("data", "order")); var courier = json.JPath("data", "courier")?.ToString(); var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId); if (order != null && order.Status != OrderStatus.Ready && !order.IsDelivery) { order = null; } if (order != null) { state = state.With(orders: state.Orders.Replace(order, order.With(status: OrderStatus.ToDelivery, courier: courier))); } } break; case "order-deliveried": { var orderId = ConvertHlp.ToGuid(json.JPath("data", "order")); var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId); if (order != null && order.Status != OrderStatus.ToDelivery) { order = null; } if (order != null) { state = state.With(orders: state.Orders.Replace(order, order.With(status: OrderStatus.Deliveried))); } } break; case "order-to-table": { var orderId = ConvertHlp.ToGuid(json.JPath("data", "order")); var order = state.Orders.FirstOrDefault(_order => _order.Id == orderId); if (order != null && order.Status != OrderStatus.Ready && order.IsDelivery) { order = null; } if (order != null) { state = state.With(orders: state.Orders.Replace(order, order.With(status: OrderStatus.ToTable))); } } break; default: break; } } state = state.With(orders: DeQueue(state.Orders, DateTime.Now)); var page = Page(state); return(new NitroBolt.Wui.HtmlResult <HElement> { Html = page, State = state, }); }