Search in sources :

Example 1 with GetAssignedGroups

use of cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedGroups in project perun by CESNET.

the class ResourceAssignedGroupsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": manage assigned groups");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    final GetAssignedGroups resourceGroups = new GetAssignedGroups(resourceId);
    final JsonCallbackEvents localEvents = JsonCallbackEvents.refreshTableEvents(resourceGroups);
    CustomButton assignGroupButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.assignGroupToResource(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new AssignGroupTabItem(resource), true);
        }
    });
    final CustomButton removeGroupButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeGroupFromResource());
    removeGroupButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<Group> groupsForRemoving = resourceGroups.getTableSelectedList();
            String text = "Following groups will be removed from resource.";
            UiElements.showDeleteConfirm(groupsForRemoving, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    RemoveGroupsFromResource request = new RemoveGroupsFromResource(JsonCallbackEvents.disableButtonEvents(removeGroupButton, localEvents));
                    request.removeGroupsFromResource(groupsForRemoving, resource);
                }
            });
        }
    });
    if (!session.isVoAdmin(resource.getVoId())) {
        resourceGroups.setCheckable(false);
        assignGroupButton.setEnabled(false);
    }
    menu.addWidget(assignGroupButton);
    menu.addWidget(removeGroupButton);
    menu.addFilterWidget(new ExtendedSuggestBox(resourceGroups.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            resourceGroups.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterGroup());
    // display menu to vo admin only
    if (session.isVoAdmin(resource.getVoId())) {
        resourceGroups.setCheckable(true);
        vp.add(menu);
        vp.setCellHeight(menu, "30px");
    } else {
        resourceGroups.setCheckable(false);
    }
    // table with field updater which leads to group detail
    CellTable<Group> table = resourceGroups.getTable(new FieldUpdater<Group, String>() {

        public void update(int index, Group object, String value) {
            session.getTabManager().addTab(new GroupDetailTabItem(object));
        }
    });
    removeGroupButton.setEnabled(false);
    if (session.isVoAdmin(resource.getVoId()))
        JsonUtils.addTableManagedButton(resourceGroups, table, removeGroupButton);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : GetAssignedGroups(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedGroups) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Group(cz.metacentrum.perun.webgui.model.Group) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) RemoveGroupsFromResource(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveGroupsFromResource) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) GroupDetailTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupDetailTabItem) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)

Example 2 with GetAssignedGroups

use of cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedGroups in project perun by CESNET.

the class ResourceGroupSettingsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": group settings");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    final ListBoxWithObjects<Group> groupListBox = new ListBoxWithObjects<>();
    final ListBoxWithObjects<Service> serviceListBox = new ListBoxWithObjects<>();
    // load
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    // to get attributes for all services
    final GetResourceRequiredAttributesV2 resReqAttrs = new GetResourceRequiredAttributesV2();
    final GetRequiredAttributesV2 reqAttrs = new GetRequiredAttributesV2(ids, JsonCallbackEvents.passDataToAnotherCallback(resReqAttrs));
    // puts first table
    final CellTable<Attribute> table = resReqAttrs.getEmptyTable();
    // get assigned groups
    final GetAssignedGroups groups = new GetAssignedGroups(resourceId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            groupListBox.removeAllOption();
            groupListBox.clear();
            ArrayList<Group> grp = JsonUtils.jsoAsList(jso);
            grp = new TableSorter<Group>().sortByName(grp);
            if (grp == null || grp.isEmpty()) {
                groupListBox.addItem("No groups assigned");
                lastSelectedGroup = 0;
                ((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("No group or service assigned. Please assign them first to see their resource setting.");
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
                return;
            }
            groupListBox.addAllItems(grp);
            for (Group g : groupListBox.getAllObjects()) {
                if (lastSelectedGroup != 0 && g.getId() == lastSelectedGroup)
                    groupListBox.setSelected(g, true);
            }
            groupCallDone = true;
            if (lastSelectedService == 0) {
                // load resource-required
                if (servCallDone) {
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("resourceToGetServicesFrom", resourceId);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                }
            } else {
                if (servCallDone) {
                    // load resource-service-group
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    reqAttrs.setIds(ids);
                    reqAttrs.retrieveData();
                }
            }
        }

        @Override
        public void onError(PerunError error) {
            groupListBox.removeAllOption();
            groupListBox.clear();
            groupListBox.addItem("Error while loading");
            groupCallDone = true;
        }

        @Override
        public void onLoadingStart() {
            groupListBox.removeAllOption();
            groupListBox.clear();
            groupListBox.addItem("Loading...");
            groupCallDone = false;
        }
    });
    groups.retrieveData();
    GetAssignedServices services = new GetAssignedServices(resourceId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            serviceListBox.removeAllOption();
            serviceListBox.clear();
            ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
            srv = new TableSorter<Service>().sortByName(srv);
            if (srv == null || srv.isEmpty()) {
                serviceListBox.addItem("No services assigned");
                lastSelectedService = 0;
                ((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("No group or service assigned. Please assign them first to see their resource setting.");
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
                return;
            }
            serviceListBox.addAllItems(srv);
            serviceListBox.addAllOption();
            if (lastSelectedService == 0)
                serviceListBox.setSelectedIndex(0);
            for (Service s : serviceListBox.getAllObjects()) {
                if (lastSelectedService != 0 && s.getId() == lastSelectedService)
                    serviceListBox.setSelected(s, true);
            }
            servCallDone = true;
            if (lastSelectedService == 0) {
                // load resource-required
                if (groupCallDone) {
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("resourceToGetServicesFrom", resourceId);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                }
            } else {
                if (groupCallDone) {
                    // load resource-service-group
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    reqAttrs.setIds(ids);
                    reqAttrs.retrieveData();
                }
            }
        }

        @Override
        public void onError(PerunError error) {
            serviceListBox.removeAllOption();
            serviceListBox.clear();
            serviceListBox.addItem("Error while loading");
            servCallDone = true;
        }

        @Override
        public void onLoadingStart() {
            serviceListBox.removeAllOption();
            serviceListBox.clear();
            serviceListBox.addItem("Loading...");
            servCallDone = false;
        }
    });
    services.retrieveData();
    ChangeHandler changeHandler = new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            if (groupCallDone && servCallDone) {
                if (groupListBox.getSelectedObject() != null) {
                    lastSelectedGroup = groupListBox.getSelectedObject().getId();
                } else {
                    lastSelectedGroup = 0;
                }
                if (serviceListBox.getSelectedIndex() > 0) {
                    lastSelectedService = serviceListBox.getSelectedObject().getId();
                } else {
                    lastSelectedService = 0;
                }
                if (lastSelectedService == 0) {
                    // load resource-required
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("resourceToGetServicesFrom", resourceId);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    resReqAttrs.setIds(ids);
                    resReqAttrs.retrieveData();
                } else {
                    // load resource-service-group
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("resource", resourceId);
                    ids.put("service", lastSelectedService);
                    ids.put("group", groupListBox.getSelectedObject().getId());
                    ids.put("workWithGroupAttributes", 1);
                    reqAttrs.setIds(ids);
                    reqAttrs.retrieveData();
                }
            }
        }
    };
    groupListBox.addChangeHandler(changeHandler);
    serviceListBox.addChangeHandler(changeHandler);
    final JsonCallbackEvents refreshTable = JsonCallbackEvents.refreshTableEvents(resReqAttrs);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        resReqAttrs.setCheckable(false);
    // add save changes to menu
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    menu.addWidget(saveChangesButton);
    // set button disable event
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        saveChangesButton.setEnabled(false);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = resReqAttrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                ids.put("group", groupListBox.getSelectedObject().getId());
                ids.put("workWithGroupAttributes", 1);
                SetAttributes request = new SetAttributes(saveChangesButtonEvent);
                request.setAttributes(ids, list);
            }
        }
    });
    // add set new to menu
    CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("resource", resourceId);
            ids.put("group", groupListBox.getSelectedObject().getId());
            ids.put("workWithGroupAttributes", 1);
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, resReqAttrs.getList()), true);
        }
    });
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        setNewAttributeButton.setEnabled(false);
    menu.addWidget(setNewAttributeButton);
    // remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    // remove button event
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        removeButton.setEnabled(false);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = resReqAttrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                ids.put("group", groupListBox.getSelectedObject().getId());
                ids.put("workWithGroupAttributes", 1);
                RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(removeButton);
    // add group selection to menu
    menu.addWidget(new HTML("<strong>Selected&nbsp;group: </strong>"));
    menu.addWidget(groupListBox);
    // add group selection to menu
    menu.addWidget(new HTML("<strong>Selected&nbsp;service: </strong>"));
    menu.addWidget(serviceListBox);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    vp.add(sp);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetAssignedGroups(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedGroups) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with GetAssignedGroups

use of cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedGroups in project perun by CESNET.

the class AssignGroupTabItem method draw.

public Widget draw() {
    titleWidget.setText("Assign group");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    final GetAllGroups voGroups = new GetAllGroups(resource.getVoId());
    voGroups.setCoreGroupsCheckable(true);
    final CellTable<Group> table = voGroups.getEmptyTable(new FieldUpdater<Group, String>() {

        public void update(int index, Group object, String value) {
            session.getTabManager().addTab(new GroupDetailTabItem(object));
        }
    });
    // remove already assigned groups from offering
    voGroups.setEvents(new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            final GetAssignedGroups alreadyAssigned = new GetAssignedGroups(resourceId, new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    JsArray<Group> groupsToRemove = JsonUtils.jsoAsArray(jso);
                    for (int i = 0; i < groupsToRemove.length(); i++) {
                        voGroups.removeFromTable(groupsToRemove.get(i));
                    }
                    // if single group, select
                    if (voGroups.getList().size() == 1) {
                        table.getSelectionModel().setSelected(voGroups.getList().get(0), true);
                    }
                }
            });
            alreadyAssigned.retrieveData();
        }
    });
    // checbox is selected by default
    final CheckBox chb = new CheckBox();
    chb.setText(WidgetTranslation.INSTANCE.configureGroupBeforeAssign());
    chb.setTitle(WidgetTranslation.INSTANCE.configureGroupBeforeAssignTitle());
    chb.setValue(false);
    final TabItem tab = this;
    // button
    final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.assignSelectedGroupsToResource());
    assignButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Group> groupsToAssign = voGroups.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(groupsToAssign)) {
                if (chb.getValue() == false) {
                    AssignGroupsToResource request = new AssignGroupsToResource(JsonCallbackEvents.closeTabDisableButtonEvents(assignButton, tab));
                    request.assignGroupsToResource(groupsToAssign, resource);
                }
                if (chb.getValue() == true) {
                    session.getTabManager().addTabToCurrentTab(new ManageGroupsBeforeAssigning(resource, groupsToAssign), true);
                }
            }
        }
    });
    menu.addWidget(assignButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    menu.addFilterWidget(new ExtendedSuggestBox(voGroups.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            voGroups.filterTable(text);
            // if single group, select
            if (voGroups.getList().size() == 1) {
                table.getSelectionModel().setSelected(voGroups.getList().get(0), true);
            }
        }
    }, ButtonTranslation.INSTANCE.filterGroup());
    if (session.isPerunAdmin()) {
        // TODO - now is for testing so perun admin only
        menu.addWidget(chb);
    }
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    assignButton.setEnabled(false);
    JsonUtils.addTableManagedButton(voGroups, table, assignButton);
    voGroups.retrieveData();
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Group(cz.metacentrum.perun.webgui.model.Group) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) GetAssignedGroups(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedGroups) AssignGroupsToResource(cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupsToResource) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GroupDetailTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupDetailTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) GroupDetailTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupDetailTabItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)3 GetAssignedGroups (cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedGroups)3 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)3 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)3 ArrayList (java.util.ArrayList)3 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 Group (cz.metacentrum.perun.webgui.model.Group)2 GroupDetailTabItem (cz.metacentrum.perun.webgui.tabs.groupstabs.GroupDetailTabItem)2 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 GetAllGroups (cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups)1 AssignGroupsToResource (cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupsToResource)1 GetAssignedServices (cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices)1 RemoveGroupsFromResource (cz.metacentrum.perun.webgui.json.resourcesManager.RemoveGroupsFromResource)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1 SetNewAttributeTabItem (cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem)1 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)1