Search in sources :

Example 1 with GetFacilityAssignedServices

use of cz.metacentrum.perun.webgui.json.servicesManager.GetFacilityAssignedServices in project perun by CESNET.

the class FacilityAllowedGroupsTabItem method draw.

public Widget draw() {
    // set title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Allowed Groups");
    final ListBoxWithObjects<VirtualOrganization> vosListbox = new ListBoxWithObjects<VirtualOrganization>();
    final ListBoxWithObjects<Service> servicesListbox = new ListBoxWithObjects<Service>();
    final GetAllowedGroups jsonCallback = new GetAllowedGroups(facilityId);
    jsonCallback.setCheckable(false);
    // content
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(new HTML("<strong>Filter by VO:</strong>"));
    menu.addWidget(vosListbox);
    menu.addWidget(new HTML("<strong>Filter by service:</strong>"));
    menu.addWidget(servicesListbox);
    // get the table
    final GetAllowedVos vosCall = new GetAllowedVos(facilityId, new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            vosListbox.clear();
            vosListbox.removeAllOption();
            vosListbox.addAllItems(new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso)));
            vosListbox.addAllOption();
            if (lastSelectedVoId == 0) {
                vosListbox.setSelectedIndex(0);
            } else {
                for (VirtualOrganization vo : vosListbox.getAllObjects()) {
                    if (vo.getId() == lastSelectedVoId) {
                        vosListbox.setSelected(vo, true);
                        break;
                    }
                }
            }
            jsonCallback.setVos(vosListbox.getAllObjects());
            vosCallDone = true;
        }

        public void onLoadingStart() {
            vosListbox.removeAllOption();
            vosListbox.clear();
            vosListbox.addItem("Loading...");
            vosCallDone = false;
        }

        public void onError(PerunError error) {
            vosListbox.clear();
            vosListbox.removeAllOption();
            vosListbox.addItem("Error while loading");
            vosCallDone = false;
        }
    });
    vosCall.retrieveData();
    GetFacilityAssignedServices servCall = new GetFacilityAssignedServices(facilityId, new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            servicesListbox.clear();
            servicesListbox.removeAllOption();
            servicesListbox.addAllItems(new TableSorter<Service>().sortByName(JsonUtils.<Service>jsoAsList(jso)));
            servicesListbox.addAllOption();
            if (servicesListbox.isEmpty()) {
                servicesListbox.addItem("No service available on facility");
            }
            if (lastSelectedServiceId == 0) {
                // choose all
                servicesListbox.setSelectedIndex(0);
            } else {
                for (Service s : servicesListbox.getAllObjects()) {
                    if (s.getId() == lastSelectedServiceId) {
                        servicesListbox.setSelected(s, true);
                        break;
                    }
                }
            }
            callDone = true;
        }

        public void onLoadingStart() {
            servicesListbox.removeAllOption();
            servicesListbox.clear();
            servicesListbox.addItem("Loading...");
            callDone = false;
        }

        public void onError(PerunError error) {
            servicesListbox.clear();
            servicesListbox.removeAllOption();
            servicesListbox.addItem("Error while loading");
            callDone = false;
        }
    });
    servCall.retrieveData();
    Scheduler.get().scheduleFixedPeriod(new Scheduler.RepeatingCommand() {

        @Override
        public boolean execute() {
            if (vosCallDone && callDone) {
                jsonCallback.setVoId(lastSelectedVoId);
                jsonCallback.setServiceId(lastSelectedServiceId);
                jsonCallback.retrieveData();
                return false;
            } else {
                return true;
            }
        }
    }, 200);
    vosListbox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (vosListbox.getSelectedIndex() > 0) {
                jsonCallback.setVoId(vosListbox.getSelectedObject().getId());
                lastSelectedVoId = vosListbox.getSelectedObject().getId();
            } else {
                jsonCallback.setVoId(0);
                lastSelectedVoId = 0;
            }
            jsonCallback.retrieveData();
        }
    });
    servicesListbox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (servicesListbox.getSelectedIndex() > 0) {
                jsonCallback.setServiceId(servicesListbox.getSelectedObject().getId());
                lastSelectedServiceId = servicesListbox.getSelectedObject().getId();
            } else {
                jsonCallback.setServiceId(0);
                lastSelectedServiceId = 0;
            }
            jsonCallback.retrieveData();
        }
    });
    CellTable<Group> table = jsonCallback.getEmptyTable(new FieldUpdater<Group, String>() {

        @Override
        public void update(int i, Group group, String s) {
            if (session.isVoAdmin(group.getVoId()) || session.isGroupAdmin(group.getId())) {
                session.getTabManager().addTab(new GroupDetailTabItem(group));
            } else {
                // show alert
                UiElements.generateInfo("You are not VO / Group manager of this group", "You MUST be VO manager or Group manager of group: <strong>" + SafeHtmlUtils.fromString(group.getName()).asString() + "</strong> to view it's details.");
            }
        }
    });
    table.addStyleName("perun-table");
    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 : GetAllowedGroups(cz.metacentrum.perun.webgui.json.facilitiesManager.GetAllowedGroups) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Scheduler(com.google.gwt.core.client.Scheduler) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) GetAllowedVos(cz.metacentrum.perun.webgui.json.facilitiesManager.GetAllowedVos) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetFacilityAssignedServices(cz.metacentrum.perun.webgui.json.servicesManager.GetFacilityAssignedServices) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) GroupDetailTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupDetailTabItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Example 2 with GetFacilityAssignedServices

use of cz.metacentrum.perun.webgui.json.servicesManager.GetFacilityAssignedServices in project perun by CESNET.

the class FacilitySettingsTabItem method draw.

public Widget draw() {
    // set title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Service settings");
    // content
    vp.setSize("100%", "100%");
    vp.clear();
    // HORIZONTAL MENU
    TabMenu menu = new TabMenu();
    // Get Attributes method
    final GetRequiredAttributesV2 reqAttrs = new GetRequiredAttributesV2();
    final GetAttributesV2 attrs = new GetAttributesV2();
    attrs.getFacilityAttributes(facilityId);
    // get empty table
    final CellTable<Attribute> table = reqAttrs.getEmptyTable();
    final CellTable<Attribute> table2 = attrs.getEmptyTable();
    sp.setWidget(table);
    sp2.setWidget(table2);
    // ids to retrieve data from rpc
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("facility", facility.getId());
    // service switcher checkbox
    final CheckBox switchServicesChb = new CheckBox(WidgetTranslation.INSTANCE.offerAvailableServicesOnly(), false);
    // selected by default - unselected if switch hidden
    switchServicesChb.setValue(lastCheckBoxValue);
    switchServicesChb.setTitle(WidgetTranslation.INSTANCE.offerAvailableServicesOnlyTitle());
    // services listbox
    final ListBoxWithObjects<Service> servList = new ListBoxWithObjects<Service>();
    // on change of service update table
    servList.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            if (servList.getSelectedIndex() == 0) {
                // show all facility attributes
                attrs.retrieveData();
                setTable(false);
                lastServiceId = 0;
                indexInList = 0;
                return;
            }
            if (switchServicesChb.getValue() == true && servList.getSelectedIndex() == 1) {
                // show required attrs for all assigned services
                ids.remove("service");
                lastServiceId = 0;
                indexInList = 1;
            } else if ((switchServicesChb.getValue() == true && servList.getSelectedIndex() > 1) || (switchServicesChb.getValue() == false && servList.getSelectedIndex() > 0)) {
                // show required attrs for selected service
                // >0 when listing all services
                // >1 when listing assigned services
                ids.put("service", servList.getSelectedObject().getId());
                lastServiceId = servList.getSelectedObject().getId();
            }
            // load req attrs
            reqAttrs.setIds(ids);
            reqAttrs.clearTable();
            reqAttrs.retrieveData();
            setTable(true);
        }
    });
    // event which fills the listbox and call getRequiredAttributes
    final JsonCallbackEvents event = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            servList.clear();
            ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
            srv = new TableSorter<Service>().sortByName(srv);
            for (int i = 0; i < srv.size(); i++) {
                servList.addItem(srv.get(i));
            }
            // no services available - load all facility attrs
            if (servList.isEmpty()) {
                servList.addNotSelectedOption();
                lastServiceId = 0;
                indexInList = 0;
                attrs.retrieveData();
                setTable(false);
                return;
            }
            // offer only available
            if (switchServicesChb.getValue() == true) {
                servList.addNotSelectedOption();
                servList.addAllOption();
                if (lastServiceId == 0) {
                    if (indexInList == 1) {
                        // all
                        servList.setSelectedIndex(1);
                    } else if (indexInList == 0) {
                        // not selected - load all fac attrs
                        servList.setSelectedIndex(0);
                        attrs.retrieveData();
                        setTable(false);
                        return;
                    }
                }
            } else {
                // offer all services
                servList.addNotSelectedOption();
                if (lastServiceId == 0) {
                    // if no service selected, load all fac attrs
                    servList.setSelectedIndex(0);
                    attrs.retrieveData();
                    setTable(false);
                    return;
                }
            }
            // if some service was selected
            if (lastServiceId != 0) {
                // remove service since we can't be sure, it was loaded again
                ids.remove("service");
                // either all or first service in a list
                servList.setSelectedIndex(1);
                for (Service s : servList.getAllObjects()) {
                    if (s.getId() == lastServiceId) {
                        // if found, select it
                        servList.setSelected(s, true);
                        ids.put("service", lastServiceId);
                        break;
                    }
                }
            }
            // get required attrs for service
            reqAttrs.clearTable();
            reqAttrs.setIds(ids);
            reqAttrs.retrieveData();
            setTable(true);
        }

        @Override
        public void onError(PerunError error) {
            servList.clear();
            if (required) {
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
            } else {
                ((AjaxLoaderImage) table2.getEmptyTableWidget()).loadingError(error);
            }
            servList.addItem("Error while loading");
        }

        @Override
        public void onLoadingStart() {
            servList.removeAllOption();
            servList.removeNotSelectedOption();
            servList.clear();
            servList.addItem("Loading...");
        }
    };
    final GetServices allServices = new GetServices(event);
    final GetFacilityAssignedServices assignedServices = new GetFacilityAssignedServices(facility.getId(), event);
    // if hide and unchecked or just unchecked
    if (!lastCheckBoxValue) {
        allServices.retrieveData();
    } else {
        assignedServices.retrieveData();
    }
    // Save changes button
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    final JsonCallbackEvents refreshEvents = JsonCallbackEvents.refreshTableEvents(reqAttrs);
    final JsonCallbackEvents refreshEvents2 = JsonCallbackEvents.refreshTableEvents(attrs);
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshEvents);
    final JsonCallbackEvents saveChangesButtonEvent2 = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshEvents2);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = (required) ? reqAttrs.getTableSelectedList() : attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                SetAttributes request = new SetAttributes((required) ? saveChangesButtonEvent : saveChangesButtonEvent2);
                request.setAttributes(ids, list);
            }
        }
    });
    // Remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvents);
    final JsonCallbackEvents removeButtonEvent2 = JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvents2);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = (required) ? reqAttrs.getTableSelectedList() : attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("facility", facilityId);
                RemoveAttributes request = new RemoveAttributes((required) ? removeButtonEvent : removeButtonEvent2);
                request.removeAttributes(ids, list);
            }
        }
    });
    // switch serv checkbox
    switchServicesChb.addClickHandler(new ClickHandler() {

        // load proper set of services on click
        public void onClick(ClickEvent event) {
            lastCheckBoxValue = switchServicesChb.getValue();
            if (switchServicesChb.getValue() == true) {
                assignedServices.retrieveData();
            } else {
                allServices.retrieveData();
            }
        }
    });
    // allow to set new (currently unused facility attribute)
    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("facility", facility.getId());
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, (required) ? reqAttrs.getList() : attrs.getList()), true);
        }
    });
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(saveChangesButton);
    menu.addWidget(setNewAttributeButton);
    menu.addWidget(removeButton);
    menu.addWidget(new HTML("<strong>Service: </strong>"));
    menu.addWidget(servList);
    if (!hide) {
        menu.addWidget(switchServicesChb);
    }
    /* TODO - not yet implemented

			 CustomButton fillDefaultButton = new CustomButton("Fill default values", SmallIcons.INSTANCE.scriptGoIcon(), new ClickHandler(){
			 public void onClick(ClickEvent event) {
			 Window.alert("not yet implemented");
			 }
			 });
			 fillDefaultButton.setTitle("Fill default values for this service/facility - nothing is saved unless you click on 'Save changes'");
			 CustomButton checkValuesButton = new CustomButton("Check values", SmallIcons.INSTANCE.scriptGearIcon(), new ClickHandler(){
			 public void onClick(ClickEvent event) {
			 Window.alert("not yet implemented");
			 }
			 });
			 checkValuesButton.setTitle("Checks inserted values against current Perun state - nothing is saved unless you click on 'Save changes'");

			 menu.addWidget(fillDefaultButton);
			 menu.addWidget(checkValuesButton);

*/
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    table.setWidth("100%");
    table2.addStyleName("perun-table");
    table2.setWidth("100%");
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    sp2.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp2, 350, this);
    // add menu and the table to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    // default is required attributes
    setTable(true);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) Attribute(cz.metacentrum.perun.webgui.model.Attribute) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) GetServices(cz.metacentrum.perun.webgui.json.servicesManager.GetServices) 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) GetRequiredAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetRequiredAttributesV2) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) Service(cz.metacentrum.perun.webgui.model.Service) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) GetFacilityAssignedServices(cz.metacentrum.perun.webgui.json.servicesManager.GetFacilityAssignedServices) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)2 GetFacilityAssignedServices (cz.metacentrum.perun.webgui.json.servicesManager.GetFacilityAssignedServices)2 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2 Scheduler (com.google.gwt.core.client.Scheduler)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 GetAttributesV2 (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2)1 GetRequiredAttributesV2 (cz.metacentrum.perun.webgui.json.attributesManager.GetRequiredAttributesV2)1 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)1 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)1 GetAllowedGroups (cz.metacentrum.perun.webgui.json.facilitiesManager.GetAllowedGroups)1 GetAllowedVos (cz.metacentrum.perun.webgui.json.facilitiesManager.GetAllowedVos)1 GetServices (cz.metacentrum.perun.webgui.json.servicesManager.GetServices)1 Attribute (cz.metacentrum.perun.webgui.model.Attribute)1 PerunError (cz.metacentrum.perun.webgui.model.PerunError)1 Service (cz.metacentrum.perun.webgui.model.Service)1