Search in sources :

Example 6 with ActionBuilder

use of com.axelor.studio.db.ActionBuilder in project axelor-open-suite by axelor.

the class ActionBuilderController method setViews.

public void setViews(ActionRequest request, ActionResponse response) {
    inflector = Inflector.getInstance();
    ActionBuilder builder = request.getContext().asType(ActionBuilder.class);
    String model = builder.getModel();
    boolean isJson = false;
    if (builder.getIsJson() != null) {
        isJson = builder.getIsJson();
    }
    if (builder.getTypeSelect() == ActionBuilderRepository.TYPE_SELECT_VIEW && model != null) {
        if (!isJson) {
            model = model.substring(model.lastIndexOf('.') + 1);
            model = inflector.dasherize(model);
        }
        List<ActionBuilderView> views = new ArrayList<>();
        addActionBuilderView(views, model, "grid", isJson, 0);
        addActionBuilderView(views, model, "form", isJson, 1);
        response.setValue("actionBuilderViews", views);
    }
}
Also used : ActionBuilder(com.axelor.studio.db.ActionBuilder) ArrayList(java.util.ArrayList) ActionBuilderView(com.axelor.studio.db.ActionBuilderView)

Example 7 with ActionBuilder

use of com.axelor.studio.db.ActionBuilder in project axelor-open-suite by axelor.

the class MenuBuilderService method createActionBuilder.

@SuppressWarnings("unchecked")
public Optional<ActionBuilder> createActionBuilder(MetaAction metaAction) {
    try {
        ObjectViews objectViews = XMLViews.fromXML(metaAction.getXml());
        List<Action> actions = objectViews.getActions();
        if (actions != null && !actions.isEmpty()) {
            ActionView action = (ActionView) actions.get(0);
            if (action.getModel() != null && action.getModel().contentEquals(MetaJsonRecord.class.getName())) {
                return Optional.empty();
            }
            ActionBuilder actionBuilder = new ActionBuilder(action.getName());
            actionBuilder.setTitle(action.getTitle());
            actionBuilder.setModel(action.getModel());
            actionBuilder.setTypeSelect(ActionBuilderRepository.TYPE_SELECT_VIEW);
            String domain = action.getDomain();
            actionBuilder.setDomainCondition(domain);
            for (ActionView.View view : action.getViews()) {
                ActionBuilderView builderView = new ActionBuilderView();
                builderView.setViewType(view.getType());
                builderView.setViewName(view.getName());
                actionBuilder.addActionBuilderView(builderView);
            }
            if (action.getParams() != null) {
                for (ActionView.Param param : action.getParams()) {
                    ActionBuilderLine paramLine = new ActionBuilderLine();
                    paramLine.setName(param.getName());
                    paramLine.setValue(param.getValue());
                    actionBuilder.addViewParam(paramLine);
                }
            }
            if (action.getContext() != null) {
                for (ActionView.Context ctx : (List<ActionView.Context>) action.getContext()) {
                    ActionBuilderLine ctxLine = new ActionBuilderLine();
                    ctxLine.setName(ctx.getName());
                    if (ctx.getName().contentEquals("jsonModel") && domain != null && domain.contains("self.jsonModel = :jsonModel")) {
                        actionBuilder.setIsJson(true);
                        actionBuilder.setModel(ctx.getExpression());
                    }
                    ctxLine.setValue(ctx.getExpression());
                    actionBuilder.addLine(ctxLine);
                }
            }
            return Optional.of(actionBuilder);
        }
    } catch (JAXBException e) {
        TraceBackService.trace(e);
    }
    return Optional.empty();
}
Also used : MetaAction(com.axelor.meta.db.MetaAction) Action(com.axelor.meta.schema.actions.Action) ActionBuilder(com.axelor.studio.db.ActionBuilder) ActionBuilderLine(com.axelor.studio.db.ActionBuilderLine) JAXBException(javax.xml.bind.JAXBException) ActionView(com.axelor.meta.schema.actions.ActionView) ObjectViews(com.axelor.meta.schema.ObjectViews) ActionBuilderView(com.axelor.studio.db.ActionBuilderView) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ActionBuilder (com.axelor.studio.db.ActionBuilder)7 ActionBuilderView (com.axelor.studio.db.ActionBuilderView)3 MetaMenu (com.axelor.meta.db.MetaMenu)2 ActionBuilderLine (com.axelor.studio.db.ActionBuilderLine)2 Transactional (com.google.inject.persist.Transactional)2 ArrayList (java.util.ArrayList)2 MetaAction (com.axelor.meta.db.MetaAction)1 ObjectViews (com.axelor.meta.schema.ObjectViews)1 Action (com.axelor.meta.schema.actions.Action)1 ActionView (com.axelor.meta.schema.actions.ActionView)1 MenuBuilderRepo (com.axelor.studio.db.repo.MenuBuilderRepo)1 List (java.util.List)1 JAXBException (javax.xml.bind.JAXBException)1