All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xresch.cfw.features.query.commands.CFWQueryCommandDisplay Maven / Gradle / Ivy

package com.xresch.cfw.features.query.commands;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.logging.Logger;

import com.google.gson.JsonObject;
import com.xresch.cfw._main.CFW;
import com.xresch.cfw.features.core.AutocompleteResult;
import com.xresch.cfw.features.query.CFWQuery;
import com.xresch.cfw.features.query.CFWQueryAutocompleteHelper;
import com.xresch.cfw.features.query.CFWQueryCommand;
import com.xresch.cfw.features.query.FeatureQuery;
import com.xresch.cfw.features.query.parse.CFWQueryParser;
import com.xresch.cfw.features.query.parse.QueryPart;
import com.xresch.cfw.features.query.parse.QueryPartAssignment;
import com.xresch.cfw.features.query.parse.QueryPartValue;
import com.xresch.cfw.logging.CFWLog;
import com.xresch.cfw.pipeline.PipelineActionContext;

/************************************************************************************************************
 * 
 * @author Reto Scheiwiller, (c) Copyright 2023 
 * @license MIT-License
 ************************************************************************************************************/
public class CFWQueryCommandDisplay extends CFWQueryCommand {
	
	
	public static final String DESCIRPTION_SYNTAX = " as= [menu=] [pagination=]  [visiblefields=] [titlefields=]"
			+"\n[titleformat=]  [zoom=]";
	
	public static final String DESCRIPTION_SYNTAX_DETAILS = "
    " +"" +"
  • asOption: Defines how the data should be displayed. One of the following options:" +"
      " +"
    • table
    • " +"
    • panels
    • " +"
    • properties
    • " +"
    • cards
    • " +"
    • tiles
    • " +"
    • tileandbar
    • " +"
    • statustiles
    • " +"
    • statuslist
    • " +"
    • statusbar
    • " +"
    • statusbarreverse
    • " +"
    • statusmap
    • " +"
    • title
    • " +"
    • csv
    • " +"
    • json
    • " +"
    • xml
    • " +"
    " +"
  • " +"
  • menu: (Optional) Defines how the menu should be displayed. One of the following options:" +"
      " +"
    • default (or true)
    • " +"
    • button
    • " +"
    • none (or false)
    • " +"
    " +"
  • " +"
  • pagination: (Optional) Defines how the pagination should be displayed. One of the following options:" +"
      " +"
    • both (or true)
    • " +"
    • top
    • " +"
    • bottom
    • " +"
    • none (or false)
    • " +"
    " +"
  • " +"
  • titlefields: (Optional) Array of the fieldnames used for title.
  • " +"
  • titleformat: (Optional) Format of the title. Use '{0}', '{1}'... as placeholders for field values.
  • " +"
  • visiblefields: (Optional) Array of the fieldnames that should be visible.
  • " +"
  • zoomNumber: (Optional) Integer value, zoom in percent to resize the displayed data.
  • " +"
  • sizes: (Optional) An array of page sizes.
  • " +"
  • defaultsize: (Optional) The default selected page size.
  • " +"
  • settings: (Optional) Json Object containing more options for the selected display type.
  • "; public static final String COMMAND_NAME = "display"; private static final Logger logger = CFWLog.getLogger(CFWQueryCommandDisplay.class.getName()); private ArrayList assignmentParts = new ArrayList(); /*********************************************************************************************** * ***********************************************************************************************/ public CFWQueryCommandDisplay(CFWQuery parent) { super(parent); this.isManipulativeCommand(false); } /*********************************************************************************************** * ***********************************************************************************************/ @Override public String[] uniqueNameAndAliases() { return new String[] {COMMAND_NAME}; } /*********************************************************************************************** * ***********************************************************************************************/ @Override public String descriptionShort() { return "Defines how to display the results."; } /*********************************************************************************************** * ***********************************************************************************************/ @Override public String descriptionSyntax() { return COMMAND_NAME+DESCIRPTION_SYNTAX; } /*********************************************************************************************** * ***********************************************************************************************/ @Override public String descriptionSyntaxDetailsHTML() { return DESCRIPTION_SYNTAX_DETAILS ; } /*********************************************************************************************** * ***********************************************************************************************/ @Override public String descriptionHTML() { return CFW.Files.readPackageResource(FeatureQuery.PACKAGE_MANUAL+".commands", "command_"+COMMAND_NAME+".html"); } /*********************************************************************************************** * ***********************************************************************************************/ @Override public void setAndValidateQueryParts(CFWQueryParser parser, ArrayList parts) throws ParseException { //------------------------------------------ // Get Parameters for(int i = 0; i < parts.size(); i++) { QueryPart currentPart = parts.get(i); if(currentPart instanceof QueryPartAssignment) { assignmentParts.add((QueryPartAssignment)currentPart); }else { parser.throwParseException(COMMAND_NAME+": Only parameters(key=value) are allowed.", currentPart); } } } /*********************************************************************************************** * ***********************************************************************************************/ @Override public void autocomplete(AutocompleteResult result, CFWQueryAutocompleteHelper helper) { // keep default } /*********************************************************************************************** * ***********************************************************************************************/ @Override public void initializeAction() throws Exception { //-------------------------------------- // Do this here to make the command removable for command 'mimic' JsonObject displaySettings = this.getParent().getContext().getDisplaySettings(); for(QueryPartAssignment assignment : assignmentParts) { String propertyName = assignment.getLeftSideAsString(null); QueryPartValue valuePart = assignment.getRightSide().determineValue(null); if(valuePart.isString()) { String value = valuePart.getAsString(); value = CFW.Security.sanitizeHTML(value); displaySettings.addProperty(propertyName, value); }else { valuePart.addToJsonObject(propertyName, displaySettings); } } } /*********************************************************************************************** * ***********************************************************************************************/ @Override public void execute(PipelineActionContext context) throws Exception { // Do nothing, inQueue is the same as outQueue this.setDoneIfPreviousDone(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy