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.console.freemarker.*; 022import org.apache.juneau.console.views.*; 023import org.apache.juneau.console.views.RowAction.*; 024import org.apache.juneau.console.views.TableSpec.*; 025 026/** 027 * Builder twin of the Orders page (P5, {@code orders.ftlh}). 028 * 029 * <h5 class='section'>Example:</h5> 030 * <p class='bjava'> 031 * <jk>return</jk> <jsm>twin</jsm>(<jv>req</jv>, OrdersPageBuilders.<jsm>orders</jsm>()); 032 * </p> 033 */ 034@SuppressWarnings({ 035 "java:S1192" // Page-definition ids and labels repeat as inline literals by design. 036}) 037public final class OrdersPageBuilders { 038 039 private OrdersPageBuilders() {} 040 041 /** 042 * P5 Orders. 043 * 044 * @return The page spec. 045 */ 046 public static PageSpec orders() { 047 return PageSpec.create().tab("orders").toolkit("views") 048 .table(TableSpec.create("orders").rowType("Order").dataMode(DataMode.SERVER).dataUrl("/console/orders/query").urlState("day", "window") 049 .columnConfig(Map.of("tabs", List.of("columns", "sort"))) 050 .defaultOrder("id", Sort.ASC) 051 .columns( 052 Column.create("id").label("Id"), 053 Column.create("petId").label("Pet").href("/console/pets/{petId}/summary"), 054 Column.create("shipDate").label("Ship date").render("date"), 055 Column.create("status").label("Status").render("pill")) 056 .ribbon( 057 RibbonItem.optionGroup("status", 058 RibbonItem.option("placed").title("Placed").column("status").value("$eq(PLACED)"), 059 RibbonItem.option("approved").title("Approved").column("status").value("$eq(APPROVED)"), 060 RibbonItem.option("delivered").title("Delivered").column("status").value("$eq(DELIVERED)")) 061 .title("Order status").deselectable(true), 062 RibbonItem.dialog("new-order").title("+ New order").symbol("plus") 063 .form("/console/orders/new-form").endpoint("/console/orders").method(Method.POST).onSuccess(OnSuccess.REDRAW), 064 RibbonItem.export("copy", "csv").optional("excel", "pdf"), 065 RibbonItem.refresh()) 066 .rowActions( 067 RowAction.create("approve").label("Approve").endpoint("/console/orders/{id}/approve").method(Method.POST).onSuccess(OnSuccess.REDRAW) 068 .visibleWhen(VisibilityRule.when("status").eq("PLACED")), 069 RowAction.create("deliver").label("Deliver").endpoint("/console/orders/{id}/deliver").method(Method.POST).onSuccess(OnSuccess.REDRAW) 070 .visibleWhen(VisibilityRule.when("status").eq("APPROVED")), 071 RowAction.create("cancel").label("Cancel").form("/console/orders/{id}/cancel-form").present(Present.DIALOG) 072 .endpoint("/console/orders/{id}").method(Method.DELETE).onSuccess(OnSuccess.REDRAW), 073 RowAction.create("delete").label("Delete").endpoint("/console/orders/{id}").method(Method.DELETE) 074 .confirm("Delete order '{id}'?").confirmLabel("Delete").tone(Tone.DANGER).confirmRenderer("typed").onSuccess(OnSuccess.REDRAW)), 075 "Orders"); 076 } 077}