use of com.axelor.meta.schema.actions.ActionView in project axelor-open-suite by axelor.
the class MenuBuilderController method showMenuBuilderRecords.
public void showMenuBuilderRecords(ActionRequest request, ActionResponse response) {
MenuBuilder menuBuilder = request.getContext().asType(MenuBuilder.class);
if (menuBuilder.getMetaMenu() == null || menuBuilder.getMetaMenu().getAction() == null) {
return;
}
try {
MetaAction metaAction = menuBuilder.getMetaMenu().getAction();
ObjectViews objectViews = XMLViews.fromXML(metaAction.getXml());
ActionView actionView = (ActionView) objectViews.getActions().get(0);
ActionViewBuilder actionViewBuilder = ActionView.define(I18n.get(actionView.getTitle()));
actionViewBuilder.model(actionView.getModel());
actionViewBuilder.icon(actionView.getIcon());
actionViewBuilder.domain(actionView.getDomain());
actionViewBuilder.context("jsonModel", menuBuilder.getActionBuilder().getModel());
actionView.getViews().forEach(view -> actionViewBuilder.add(view.getType(), view.getName()));
if (ObjectUtils.notEmpty(actionView.getParams())) {
actionView.getParams().forEach(param -> actionViewBuilder.param(param.getName(), param.getValue()));
}
response.setView(actionViewBuilder.map());
} catch (Exception e) {
}
}
use of com.axelor.meta.schema.actions.ActionView 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();
}
use of com.axelor.meta.schema.actions.ActionView in project axelor-open-suite by axelor.
the class CalendarConfigurationService method createMetaAction.
public MetaAction createMetaAction(String name, String title) {
String module = "axelor-base";
String type = "action-view";
String expr = String.format("eval: __repo__(CalendarConfiguration).all().filter('self.metaAction.name = :name').bind('name', '%s').fetchOne().calendarSet.collect{ it.id }", name);
ActionView actionView = ActionView.define(title).name(name).model("com.axelor.apps.base.db.ICalendarEvent").add("calendar", "calendar-event-all").add("grid", "calendar-event-grid").add("form", "calandar-event-form").domain("self.calendar.id in (:_calendarIdList)").context("_calendarIdList", expr).get();
return MetaActionTool.actionToMetaAction(actionView, name, type, module);
}
Aggregations