Ejemplo n.º 1
0
        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,
            });
        }
Ejemplo n.º 2
0
        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,
            };
        }
Ejemplo n.º 3
0
        private static HElement Page(MainState state)
        {
            var page = h.Html
                       (
                h.Head(
                    h.Element("title", "NitroBolt.Wui - WebExample. State machine"),
                    h.Css
                    (
                        @"
              .section {min-height:100px;border:1px solid lightgray;margin-bottom:2px;}
              .header {background-color:#E0E0FF;}
            "
                    )
                    ),
                h.Body
                (
                    h.Div
                    (
                        h.@class("section"),
                        h.Div(h.@class("header"), "Клиентский интерфейс"),
                        h.Div
                        (
                            h.data("name", "order"), h.data("id", state.Orders.Count),
                            h.Div("Новый заказ"),
                            h.Div("Опции"),
                            h.Span("\xA0▪ "), h.Span("На указанное время: "),
                            h.Input(h.type("text"), h.data("name", "to-time")), h.Span(h.style("color:darkgray;"), $" Пример(+15с): {DateTime.Now.AddSeconds(15)}"),
                            h.Br(),
                            h.Span("\xA0▪ "), h.Input(h.type("checkbox"), h.data("name", "is-delivery")), h.Span("Доставка"), h.Br(),
                            new[] { "A", "B" }
                            .Select(order =>
                                    h.Input(h.type("button"), new hdata {
                { "command", "new-order" }, { "container", "order" }, { "name", order }
            }, h.value("Сделать заказ типа " + order), h.onclick(";"))
                                    )
                        ),
                        h.Div
                        (
                            h.Div("Заказы"),
                            state.Orders.Where(order => order.Status != OrderStatus.ToTable && order.Status != OrderStatus.Deliveried).Select(order =>
                                                                                                                                              h.Div
                                                                                                                                              (
                                                                                                                                                  h.Span(order.Title), ViewStatus(order.Status), order.Status == OrderStatus.InQueue ? h.Span(string.Format(" Отложен до {0:dd.MM.yy HH:mm}", order.ToTime)) : null,
                                                                                                                                                  order.IsDelivery ? h.Span(h.title("Доставка"), " => ") : null//,

                                                                                                                                              ))
                        )
                    ),
                    h.Div
                    (
                        h.@class("section"),
                        h.Div(h.@class("header"), "Производственный интерфейс"),
                        state.Orders.Where(order => order.Status == OrderStatus.New || order.Status == OrderStatus.Prepare && !order.IsReady).Select(order =>
                                                                                                                                                     h.Div
                                                                                                                                                     (
                                                                                                                                                         h.Div(h.Span("Заказ: "), h.Span(order.Title), ViewStatus(order.Status)),
                                                                                                                                                         order.Products.Select(product =>
                                                                                                                                                                               h.Div
                                                                                                                                                                               (
                                                                                                                                                                                   h.style("padding-left:15px;"),
                                                                                                                                                                                   h.Span("Продукт " + product.Name), ViewStatus(product.Status),
                                                                                                                                                                                   product.Status == ProductStatus.New || product.Status == ProductStatus.Prepare
                           ? h.Input(h.type("button"), new hdata {
                { "command", product.Status == ProductStatus.New ? "product-prepare" : "product-ready" }, { "order", order.Id }, { "product", product.Id }
            }, product.Status == ProductStatus.New ? h.value("Приготовить") : h.value("Готово"), h.onclick(";"))
                           : null
                                                                                                                                                                               )
                                                                                                                                                                               )
                                                                                                                                                     )

                                                                                                                                                     )
                    ),
                    h.Div
                    (
                        h.@class("section"),
                        h.Div(h.@class("header"), "Интерфейс сборщика"),
                        state.Orders.Where(order => order.IsReady).Select(order =>
                                                                          h.Div
                                                                          (
                                                                              h.Span(order.Title),
                                                                              h.Span(" "),
                                                                              h.Input(h.type("button"), new hdata {
                { "command", "order-build" }, { "order", order.Id }
            }, h.value("Собрать"), h.onclick(";"))
                                                                          )

                                                                          )
                    ),
                    h.Div
                    (
                        h.@class("section"),
                        h.Div(h.@class("header"), "Интерфейс официанта"),
                        state.Orders.Where(order => order.Status == OrderStatus.Ready && !order.IsDelivery).Select(order =>
                                                                                                                   h.Div
                                                                                                                   (
                                                                                                                       h.Span(order.Title),
                                                                                                                       h.Span(" "),
                                                                                                                       h.Input(h.type("button"), new hdata {
                { "command", "order-to-table" }, { "order", order.Id }
            }, h.value("Передать клиенту"), h.onclick(";"))
                                                                                                                   )

                                                                                                                   )
                    ),
                    h.Div
                    (
                        h.@class("section"),
                        h.Div(h.@class("header"), "Назначить курьера"),
                        state.Orders.Where(order => order.Status == OrderStatus.Ready && order.IsDelivery).Select(order =>
                                                                                                                  h.Div
                                                                                                                  (
                                                                                                                      h.Span(order.Title),
                                                                                                                      h.Span(" "),
                                                                                                                      new[] { "Иванов П.", "Петров Д.", "Сидоров К." }
                                                                                                                      .Select(courier =>
                                                                                                                              h.Input(h.type("button"), new hdata {
                { "command", "courier" }, { "order", order.Id }, { "courier", courier }
            }, h.value(courier), h.onclick(";"))
                                                                                                                              )
                                                                                                                  )

                                                                                                                  )
                    ),
                    h.Div
                    (
                        h.@class("section"),
                        h.Div(h.@class("header"), "Интерфейс курьера"),
                        state.Orders.Where(order => order.Status == OrderStatus.ToDelivery).Select(order =>
                                                                                                   h.Div
                                                                                                   (
                                                                                                       h.Span(order.Title),
                                                                                                       h.Span(" "),
                                                                                                       h.Input(h.type("button"), new hdata {
                { "command", "order-deliveried" }, { "order", order.Id }
            }, h.value("Передать клиенту"), h.onclick(";"))
                                                                                                   )

                                                                                                   )
                    ),
                    h.Div
                    (
                        h.@class("section"),
                        h.Div(h.@class("header"), "Выполненные заказы"),
                        state.Orders.Where(order => order.Status == OrderStatus.ToTable || order.Status == OrderStatus.Deliveried).Select(order =>
                                                                                                                                          h.Div
                                                                                                                                          (
                                                                                                                                              h.Span(order.Title)
                                                                                                                                          )

                                                                                                                                          )
                    )

                )
                       );

            return(page);
        }
Ejemplo n.º 4
0
        private static HElement Page(MainState state)
        {
            var page = h.Html
            (
              h.Head(
                h.Element("title", "NitroBolt.Wui - WebExample. State machine"),
                h.Css
                (
                  @"
              .section {min-height:100px;border:1px solid lightgray;margin-bottom:2px;}
              .header {background-color:#E0E0FF;}
            "
                )
              ),
              h.Body
              (
                 h.Div
                 (
                   h.@class("section"),
                   h.Div(h.@class("header"), "Клиентский интерфейс"),
                   h.Div
                   (
                     h.data("name", "order"), h.data("id", state.Orders.Count),
                     h.Div("Новый заказ"),
                     h.Div("Опции"),
                     h.Span("\xA0▪ "), h.Span("На указанное время: "),
                     h.Input(h.type("text"), h.data("name", "to-time")), h.Span(h.style("color:darkgray;"), $" Пример(+15с): {DateTime.Now.AddSeconds(15)}"),
                     h.Br(),
                     h.Span("\xA0▪ "), h.Input(h.type("checkbox"), h.data("name", "is-delivery")), h.Span("Доставка"), h.Br(),
                     new[] { "A", "B" }
                      .Select(order =>
                        h.Input(h.type("button"), new hdata { { "command", "new-order" }, { "container", "order" }, { "name", order } }, h.value("Сделать заказ типа " + order), h.onclick(";"))
                      )
                   ),
                   h.Div
                   (
                     h.Div("Заказы"),
                     state.Orders.Where(order => order.Status != OrderStatus.ToTable && order.Status != OrderStatus.Deliveried).Select(order =>
                       h.Div
                       (
                         h.Span(order.Title), ViewStatus(order.Status), order.Status == OrderStatus.InQueue ? h.Span(string.Format(" Отложен до {0:dd.MM.yy HH:mm}", order.ToTime)) : null,
                         order.IsDelivery ? h.Span(h.title("Доставка"), " => ") : null//,

                       ))
                   )
                 ),
                 h.Div
                 (
                   h.@class("section"),
                   h.Div(h.@class("header"), "Производственный интерфейс"),
                   state.Orders.Where(order => order.Status == OrderStatus.New || order.Status == OrderStatus.Prepare && !order.IsReady).Select(order =>
                     h.Div
                     (
                       h.Div(h.Span("Заказ: "), h.Span(order.Title), ViewStatus(order.Status)),
                       order.Products.Select(product =>
                         h.Div
                         (
                           h.style("padding-left:15px;"),
                           h.Span("Продукт " + product.Name), ViewStatus(product.Status),
                           product.Status == ProductStatus.New || product.Status == ProductStatus.Prepare
                           ? h.Input(h.type("button"), new hdata { { "command", product.Status == ProductStatus.New ? "product-prepare" : "product-ready" }, { "order", order.Id }, { "product", product.Id } }, product.Status == ProductStatus.New ? h.value("Приготовить") : h.value("Готово"), h.onclick(";"))
                           : null
                         )
                       )
                     )

                   )
                 ),
                 h.Div
                 (
                   h.@class("section"),
                   h.Div(h.@class("header"), "Интерфейс сборщика"),
                   state.Orders.Where(order => order.IsReady).Select(order =>
                     h.Div
                     (
                       h.Span(order.Title),
                       h.Span(" "),
                       h.Input(h.type("button"), new hdata { { "command", "order-build" }, { "order", order.Id } }, h.value("Собрать"), h.onclick(";"))
                     )

                   )
                 ),
                 h.Div
                 (
                   h.@class("section"),
                   h.Div(h.@class("header"), "Интерфейс официанта"),
                   state.Orders.Where(order => order.Status == OrderStatus.Ready && !order.IsDelivery).Select(order =>
                     h.Div
                     (
                       h.Span(order.Title),
                       h.Span(" "),
                       h.Input(h.type("button"), new hdata { { "command", "order-to-table" }, { "order", order.Id } }, h.value("Передать клиенту"), h.onclick(";"))
                     )

                   )
                 ),
                 h.Div
                 (
                   h.@class("section"),
                   h.Div(h.@class("header"), "Назначить курьера"),
                   state.Orders.Where(order => order.Status == OrderStatus.Ready && order.IsDelivery).Select(order =>
                     h.Div
                     (
                       h.Span(order.Title),
                       h.Span(" "),
                       new[] { "Иванов П.", "Петров Д.", "Сидоров К." }
                       .Select(courier =>
                         h.Input(h.type("button"), new hdata { { "command", "courier" }, { "order", order.Id }, { "courier", courier } }, h.value(courier), h.onclick(";"))
                       )
                     )

                   )
                 ),
                 h.Div
                 (
                   h.@class("section"),
                   h.Div(h.@class("header"), "Интерфейс курьера"),
                   state.Orders.Where(order => order.Status == OrderStatus.ToDelivery).Select(order =>
                     h.Div
                     (
                       h.Span(order.Title),
                       h.Span(" "),
                       h.Input(h.type("button"), new hdata { { "command", "order-deliveried" }, { "order", order.Id } }, h.value("Передать клиенту"), h.onclick(";"))
                     )

                   )
                 ),
                 h.Div
                 (
                   h.@class("section"),
                   h.Div(h.@class("header"), "Выполненные заказы"),
                   state.Orders.Where(order => order.Status == OrderStatus.ToTable || order.Status == OrderStatus.Deliveried).Select(order =>
                     h.Div
                     (
                       h.Span(order.Title)
                     )

                   )
                 )

              )
            );
            return page;
        }