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 org.apache.juneau.commons.beanquery.*; 020import org.apache.juneau.console.freemarker.*; 021import org.apache.juneau.console.views.*; 022import org.apache.juneau.console.views.RowAction.*; 023import org.apache.juneau.console.views.TableSpec.*; 024 025/** 026 * Builder twin of the Users page (P11, {@code users.ftlh}). 027 * 028 * <h2 class='section'>Example:</h2> 029 * <p class='bjava'> 030 * <jk>return</jk> <jsm>twin</jsm>(<jv>req</jv>, UsersPageBuilders.<jsm>users</jsm>()); 031 * </p> 032 */ 033@SuppressWarnings({ 034 "java:S1192" // Page-definition ids and labels repeat as inline literals by design. 035}) 036public final class UsersPageBuilders { 037 038 private UsersPageBuilders() {} 039 040 /** 041 * P11 Users. 042 * 043 * @return The page spec. 044 */ 045 public static PageSpec users() { 046 return PageSpec.create().tab("users").toolkit("views", "datatables-buttons", "datatables-export") 047 .table(TableSpec.create("users").rowType("User").dataMode(DataMode.SERVER).dataUrl("/console/users/query") 048 .operators(SearchOperatorSet.standard()) 049 .defaultOrder("username", Sort.ASC) 050 .rowIdField("username") 051 .detail(RowDetails.user()) 052 .columns( 053 Column.create("username").label("Username").searchType(SearchType.TEXT), 054 Column.create("firstName").label("First name").searchType(SearchType.TEXT), 055 Column.create("lastName").label("Last name").searchType(SearchType.TEXT), 056 Column.create("userStatus").label("Status").render(PillRenders.userStatus()).searchType(SearchType.ENUM)) 057 .columnConfig(true) 058 .ribbon(Ribbons.standard() 059 .create(RibbonItem.dialog("add-user").title("+ Add user").symbol("plus") 060 .form("/console/users/form").endpoint("/console/users").method(Method.POST).onSuccess(OnSuccess.REDRAW)) 061 .filter(RibbonItem.optionGroup("userStatus", 062 RibbonItem.option("active").title("Active").symbol("user_check").column("userStatus").value("$eq(ACTIVE)"), 063 RibbonItem.option("inactive").title("Inactive").symbol("user_x").column("userStatus").value("$eq(INACTIVE)")) 064 .title("User status").deselectable(true)) 065 .export("excel", "pdf") 066 .build()) 067 .rowActions( 068 RowAction.create("edit").label("Edit").form("/console/users/form?username={username}").present(Present.DIALOG) 069 .endpoint("/console/users/{username}").method(Method.PUT).onSuccess(OnSuccess.REDRAW), 070 RowAction.create("delete").label("Delete").endpoint("/console/users/{username}").method(Method.DELETE) 071 .confirm("Delete user '{username}'?").confirmLabel("Delete").tone(Tone.DANGER).onSuccess(OnSuccess.REDRAW)), 072 "Users"); 073 } 074}