001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.petstore.console.pages; 018 019import java.util.*; 020 021import org.apache.juneau.commons.beanquery.*; 022import org.apache.juneau.console.freemarker.*; 023import org.apache.juneau.console.views.*; 024import org.apache.juneau.console.views.RowAction.*; 025import org.apache.juneau.console.views.TableSpec.*; 026 027/** 028 * Builder twin of the Orders page (P5, {@code orders.ftlh}). 029 * 030 * <h2 class='section'>Example:</h2> 031 * <p class='bjava'> 032 * <jk>return</jk> <jsm>twin</jsm>(<jv>req</jv>, OrdersPageBuilders.<jsm>orders</jsm>()); 033 * </p> 034 */ 035@SuppressWarnings({ 036 "java:S1192" // Page-definition ids and labels repeat as inline literals by design. 037}) 038public final class OrdersPageBuilders { 039 040 private OrdersPageBuilders() {} 041 042 /** 043 * P5 Orders. 044 * 045 * @return The page spec. 046 */ 047 public static PageSpec orders() { 048 return PageSpec.create().tab("orders").toolkit("views", "datatables-buttons", "datatables-export") 049 .table(TableSpec.create("orders").rowType("Order").dataMode(DataMode.SERVER).dataUrl("/console/orders/query").urlState("day", "window") 050 .operators(SearchOperatorSet.standard()) 051 .columnConfig(Map.of("tabs", List.of("columns", "sort"))) 052 .defaultOrder("id", Sort.ASC) 053 .detail(RowDetails.order()) 054 .columns( 055 Column.create("id").label("Id").searchType(SearchType.NUMERIC), 056 Column.create("petId").label("Pet").href("/console/pets/{petId}/summary").searchType(SearchType.NUMERIC), 057 Column.create("shipDate").label("Ship date").render("date").searchType(SearchType.TEXT), 058 Column.create("status").label("Status").render(PillRenders.orderStatus()).searchType(SearchType.ENUM)) 059 .ribbon(Ribbons.standard() 060 .create(RibbonItem.dialog("new-order").title("+ New order").symbol("plus") 061 .form("/console/orders/new-form").endpoint("/console/orders").method(Method.POST).onSuccess(OnSuccess.REDRAW)) 062 .filter(RibbonItem.optionGroup("status", 063 RibbonItem.option("placed").title("Placed").symbol("shopping_cart").column("status").value("$eq(PLACED)"), 064 RibbonItem.option("approved").title("Approved").symbol("badge_check").column("status").value("$eq(APPROVED)"), 065 RibbonItem.option("delivered").title("Delivered").symbol("truck").column("status").value("$eq(DELIVERED)")) 066 .title("Order status").deselectable(true)) 067 .export("excel", "pdf") 068 .build()) 069 .rowActions( 070 RowAction.create("approve").label("Approve").endpoint("/console/orders/{id}/approve").method(Method.POST).onSuccess(OnSuccess.REDRAW) 071 .visibleWhen(VisibilityRule.when("status").eq("PLACED")), 072 RowAction.create("deliver").label("Deliver").endpoint("/console/orders/{id}/deliver").method(Method.POST).onSuccess(OnSuccess.REDRAW) 073 .visibleWhen(VisibilityRule.when("status").eq("APPROVED")), 074 RowAction.create("cancel").label("Cancel").form("/console/orders/{id}/cancel-form").present(Present.DIALOG) 075 .endpoint("/console/orders/{id}").method(Method.DELETE).onSuccess(OnSuccess.REDRAW), 076 RowAction.create("delete").label("Delete").endpoint("/console/orders/{id}").method(Method.DELETE) 077 .confirm("Delete order '{id}'?").confirmLabel("Delete").tone(Tone.DANGER).confirmRenderer("typed").onSuccess(OnSuccess.REDRAW)), 078 "Orders"); 079 } 080}