Search in sources :

Example 16 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class StudioMetaService method removeMetaActions.

/**
 * Removes MetaActions from comma separated names in string.
 *
 * @param actionNames Comma separated string of action names.
 */
@Transactional
public void removeMetaActions(String xmlIds) {
    log.debug("Removing actions: {}", xmlIds);
    if (xmlIds == null) {
        return;
    }
    List<MetaAction> metaActions = metaActionRepo.all().filter("self.xmlId in ?1 OR self.name in ?1 ", Arrays.asList(xmlIds.split(","))).fetch();
    for (MetaAction action : metaActions) {
        List<MetaMenu> menus = metaMenuRepo.all().filter("self.action = ?1", action).fetch();
        for (MetaMenu metaMenu : menus) {
            metaMenu.setAction(null);
            metaMenuRepo.save(metaMenu);
        }
        metaActionRepo.remove(action);
    }
}
Also used : MetaMenu(com.axelor.meta.db.MetaMenu) MetaAction(com.axelor.meta.db.MetaAction) Transactional(com.google.inject.persist.Transactional)

Example 17 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class StudioMetaService method createMenu.

public MetaMenu createMenu(MenuBuilder builder) {
    // String xmlId = XML_ID_PREFIX + builder.getName();
    String xmlId = builder.getXmlId();
    MetaMenu menu = builder.getMetaMenu();
    if (menu == null) {
        menu = metaMenuRepo.findByID(xmlId);
    } else {
        menu.setXmlId(xmlId);
    }
    if (menu == null) {
        menu = new MetaMenu(builder.getName());
        menu.setXmlId(xmlId);
        Integer priority = getPriority(MetaMenu.class.getSimpleName(), menu.getName());
        menu.setPriority(priority);
        menu.setTitle(builder.getTitle());
        menu = metaMenuRepo.save(menu);
    }
    menu.setTitle(builder.getTitle());
    menu.setIcon(builder.getIcon());
    menu.setIconBackground(builder.getIconBackground());
    menu.setOrder(builder.getOrder());
    menu.setParent(builder.getParentMenu());
    if (builder.getGroups() != null) {
        Set<Group> groups = new HashSet<>();
        groups.addAll(builder.getGroups());
        menu.setGroups(groups);
    }
    if (builder.getRoles() != null) {
        Set<Role> roles = new HashSet<>();
        roles.addAll(builder.getRoles());
        menu.setRoles(roles);
    }
    String condition = builder.getConditionToCheck();
    if (builder.getAppBuilder() != null) {
        if (condition != null) {
            condition = "__config__.app.isApp('" + builder.getAppBuilder().getCode() + "') && (" + condition + ")";
        } else {
            condition = "__config__.app.isApp('" + builder.getAppBuilder().getCode() + "')";
        }
    }
    menu.setConditionToCheck(condition);
    menu.setModuleToCheck(builder.getModuleToCheck());
    menu.setLeft(builder.getLeft());
    menu.setTop(builder.getTop());
    menu.setHidden(builder.getHidden());
    menu.setMobile(builder.getMobile());
    menu.setTag(builder.getTag());
    menu.setTagCount(builder.getTagCount());
    menu.setTagGet(builder.getTagGet());
    menu.setTagStyle(builder.getTagStyle());
    menu.setLink(builder.getLink());
    if (builder.getMetaModule() != null) {
        menu.setModule(builder.getMetaModule().getName());
    }
    return menu;
}
Also used : Role(com.axelor.auth.db.Role) Group(com.axelor.auth.db.Group) MetaMenu(com.axelor.meta.db.MetaMenu) HashSet(java.util.HashSet)

Example 18 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class CalendarConfigurationService method createMetaMenu.

public MetaMenu createMetaMenu(String name, String title, MetaAction metaAction, MetaMenu parentMenu) {
    MetaMenu metaMenu = new MetaMenu();
    metaMenu.setName(name);
    metaMenu.setAction(metaAction);
    metaMenu.setModule("axelor-base");
    metaMenu.setTitle(title);
    metaMenu.setParent(parentMenu);
    return metaMenu;
}
Also used : MetaMenu(com.axelor.meta.db.MetaMenu)

Example 19 with MetaMenu

use of com.axelor.meta.db.MetaMenu in project axelor-open-suite by axelor.

the class XmlHandler method generateMenuGraph.

private void generateMenuGraph(List<? extends MetaMenu> menuList) {
    // log.debug("Checking menu list: {}",menuList);
    for (MetaMenu menu : menuList) {
        String model = menu.getAction() != null ? menu.getAction().getModel() : null;
        // log.debug("Action model: ",model);
        if (model != null && !objectList.contains(model)) {
            updateFieldData(menu.getAction());
        }
        // List<? extends MetaMenu> childList = MetaMenu.all().filter("self.parent = ?1 AND self.left
        // = true AND ?2 MEMBER OF self.groups", menu,group).order("-priority").order("id").fetch();
        List<? extends MetaMenu> childList = Beans.get(MetaMenuRepository.class).all().filter("self.parent = ?1 AND self.left = true", menu).order("-priority").order("id").fetch();
        generateMenuGraph(childList);
    }
}
Also used : MetaMenuRepository(com.axelor.meta.db.repo.MetaMenuRepository) MetaMenu(com.axelor.meta.db.MetaMenu)

Aggregations

MetaMenu (com.axelor.meta.db.MetaMenu)19 Transactional (com.google.inject.persist.Transactional)10 Role (com.axelor.auth.db.Role)6 Group (com.axelor.auth.db.Group)5 MetaAction (com.axelor.meta.db.MetaAction)4 MetaMenuRepository (com.axelor.meta.db.repo.MetaMenuRepository)3 RoleRepository (com.axelor.auth.db.repo.RoleRepository)2 ActionBuilder (com.axelor.studio.db.ActionBuilder)2 HashSet (java.util.HashSet)2 App (com.axelor.apps.base.db.App)1 AppRepository (com.axelor.apps.base.db.repo.AppRepository)1 User (com.axelor.auth.db.User)1 GroupRepository (com.axelor.auth.db.repo.GroupRepository)1 UserRepository (com.axelor.auth.db.repo.UserRepository)1 MetaActionRepository (com.axelor.meta.db.repo.MetaActionRepository)1 MenuBuilder (com.axelor.studio.db.MenuBuilder)1