Search in sources :

Example 1 with ForceServicePropagation

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

the class DestinationResultsTabItem method draw.

public Widget draw() {
    this.titleWidget.setText("Tasks results: " + destination);
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    final ListBoxWithObjects<RichService> listbox = new ListBoxWithObjects<RichService>();
    final CustomButton cb = new CustomButton(ButtonTranslation.INSTANCE.forcePropagationButton(), ButtonTranslation.INSTANCE.forcePropagation(), SmallIcons.INSTANCE.arrowRightIcon());
    GetFacilityAssignedServicesForGUI servCall = new GetFacilityAssignedServicesForGUI(facilityId);
    servCall.setEvents(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            listbox.clear();
            ArrayList<RichService> list = JsonUtils.jsoAsList(jso);
            list = new TableSorter<RichService>().sortByName(list);
            for (RichService s : list) {
                if (s.getAllowedOnFacility().equalsIgnoreCase("allowed") && (s.getService() != null && s.getService().isEnabled())) {
                    listbox.addItem(s);
                }
            }
            if (listbox.isEmpty()) {
                listbox.addItem("No service available");
                cb.setEnabled(false);
            }
        }

        @Override
        public void onError(PerunError error) {
            listbox.clear();
            listbox.addItem("Error while loading");
            cb.setEnabled(false);
        }

        @Override
        public void onLoadingStart() {
            listbox.clear();
            listbox.addItem("Loading...");
        }
    });
    if (facilityId != 0) {
        servCall.retrieveData();
    }
    cb.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            ForceServicePropagation force = new ForceServicePropagation(JsonCallbackEvents.disableButtonEvents(cb));
            force.forcePropagation(facilityId, listbox.getSelectedObject().getId());
        }
    });
    menu.addWidget(cb);
    menu.addWidget(new HTML("<strong>Service: </strong>"));
    menu.addWidget(listbox);
    Anchor a = new Anchor("View facility details >>");
    a.setStyleName("pointer");
    a.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().addTab(new FacilityDetailTabItem(facility));
        }
    });
    menu.addWidget(a);
    ArrayList<String> dest = new ArrayList<String>();
    dest.add(destination);
    final GetTaskResultsByDestinations callback = new GetTaskResultsByDestinations(dest);
    CellTable<TaskResult> table = callback.getTable();
    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 : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ForceServicePropagation(cz.metacentrum.perun.webgui.json.servicesManager.ForceServicePropagation) GetTaskResultsByDestinations(cz.metacentrum.perun.webgui.json.tasksManager.GetTaskResultsByDestinations) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) GetFacilityAssignedServicesForGUI(cz.metacentrum.perun.webgui.json.servicesManager.GetFacilityAssignedServicesForGUI) ArrayList(java.util.ArrayList) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Example 2 with ForceServicePropagation

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

the class FacilityStatusTabItem method draw.

public Widget draw() {
    // title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Services status");
    // main content
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // get empty table
    final GetFacilityServicesState callback = new GetFacilityServicesState(facility.getId());
    CustomButton refreshButton = UiElements.getRefreshButton(this);
    // callback.setEvents(JsonCallbackEvents.disableButtonEvents(refreshButton));
    final CellTable<ServiceState> table = callback.getTable(new FieldUpdater<ServiceState, String>() {

        // on row click
        public void update(int index, final ServiceState object, String value) {
            // show results if any present
            if (object.getTask() != null) {
                session.getTabManager().addTab(new TaskResultsTabItem(object.getTask()));
            }
        }
    });
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    final CustomButton forceButton = new CustomButton(ButtonTranslation.INSTANCE.forcePropagationButton(), ButtonTranslation.INSTANCE.forcePropagation(), SmallIcons.INSTANCE.arrowRightIcon());
    forceButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<ServiceState> forceList = callback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(forceList)) {
                // TODO - translated Widget
                boolean denied = false;
                VerticalPanel vp = new VerticalPanel();
                vp.add(new HTML("<p>Some services can't be forcefully propagated, because they are <strong>blocked on facility</strong>. Please change their state to 'Allowed' before starting force propagation.</p>"));
                for (int i = 0; i < forceList.size(); i++) {
                    if (forceList.get(i).isBlockedOnFacility() || forceList.get(i).isBlockedGlobally()) {
                        vp.add(new Label(" - " + forceList.get(i).getService().getName()));
                        denied = true;
                    }
                }
                if (denied) {
                    // show conf
                    Confirm c = new Confirm("Can't propagated blocked services", vp, true);
                    c.show();
                    return;
                }
            }
            // show propagation status page on last call start
            JsonCallbackEvents events = new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // unselect all services
                    for (ServiceState service : forceList) {
                        callback.getSelectionModel().setSelected(service, false);
                    }
                }
            };
            // starts propagation for all selected services
            for (int i = 0; i < forceList.size(); i++) {
                if (i != forceList.size() - 1) {
                    // force propagation
                    ForceServicePropagation request = new ForceServicePropagation(JsonCallbackEvents.disableButtonEvents(forceButton));
                    request.forcePropagation(facility.getId(), forceList.get(i).getService().getId());
                } else {
                    // force propagation with show status page
                    ForceServicePropagation request = new ForceServicePropagation(JsonCallbackEvents.disableButtonEvents(forceButton, events));
                    request.forcePropagation(facility.getId(), forceList.get(i).getService().getId());
                }
            }
        }
    });
    final CustomButton blockButton = new CustomButton(ButtonTranslation.INSTANCE.blockPropagationButton(), ButtonTranslation.INSTANCE.blockServicesOnFacility(), SmallIcons.INSTANCE.stopIcon());
    final CustomButton allowButton = new CustomButton(ButtonTranslation.INSTANCE.allowPropagationButton(), ButtonTranslation.INSTANCE.allowServicesOnFacility(), SmallIcons.INSTANCE.acceptIcon());
    final CustomButton deleteButton = new CustomButton(ButtonTranslation.INSTANCE.deleteButton(), ButtonTranslation.INSTANCE.deleteTasks(), SmallIcons.INSTANCE.deleteIcon());
    blockButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<ServiceState> list = callback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                for (int i = 0; i < list.size(); i++) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    BlockServiceOnFacility sendRequest = new BlockServiceOnFacility(facilityId, JsonCallbackEvents.disableButtonEvents(blockButton));
                    JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(blockButton, JsonCallbackEvents.refreshTableEvents(callback));
                    if (i == list.size() - 1)
                        sendRequest.setEvents(events);
                    if (list.get(i).getTask() != null)
                        sendRequest.blockService(list.get(i).getTask().getService().getId());
                }
            }
        }
    });
    allowButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<ServiceState> list = callback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                for (int i = 0; i < list.size(); i++) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    UnblockServiceOnFacility sendRequest = new UnblockServiceOnFacility(facilityId, JsonCallbackEvents.disableButtonEvents(allowButton));
                    JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(allowButton, JsonCallbackEvents.refreshTableEvents(callback));
                    if (i == list.size() - 1)
                        sendRequest.setEvents(events);
                    if (list.get(i).getTask() != null)
                        sendRequest.unblockService(list.get(i).getTask().getService().getId());
                }
            }
        }
    });
    TabMenu menu = new TabMenu();
    menu.addWidget(refreshButton);
    menu.addWidget(forceButton);
    menu.addWidget(allowButton);
    menu.addWidget(blockButton);
    if (session.isPerunAdmin()) {
        menu.addWidget(deleteButton);
        deleteButton.setEnabled(false);
        JsonUtils.addTableManagedButton(callback, table, deleteButton);
        deleteButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                final ArrayList<ServiceState> list = callback.getTableSelectedList();
                if (UiElements.cantSaveEmptyListDialogBox(list)) {
                    UiElements.generateAlert("", "This action will also delete all propagation results. <p>If service is still assigned to any resource, it will be listed in a table.", new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            for (ServiceState ss : list) {
                                DeleteTask deleteTask = new DeleteTask(JsonCallbackEvents.disableButtonEvents(deleteButton));
                                deleteTask.setEvents(JsonCallbackEvents.disableButtonEvents(deleteButton, JsonCallbackEvents.refreshTableEvents(callback)));
                                if (ss.getTask() != null)
                                    deleteTask.deleteTask(ss.getTask().getId());
                            }
                        }
                    });
                }
            }
        });
    }
    forceButton.setEnabled(false);
    allowButton.setEnabled(false);
    blockButton.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, forceButton);
    JsonUtils.addTableManagedButton(callback, table, allowButton);
    JsonUtils.addTableManagedButton(callback, table, blockButton);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ForceServicePropagation(cz.metacentrum.perun.webgui.json.servicesManager.ForceServicePropagation) GetFacilityServicesState(cz.metacentrum.perun.webgui.json.tasksManager.GetFacilityServicesState) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) DeleteTask(cz.metacentrum.perun.webgui.json.tasksManager.DeleteTask) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) UnblockServiceOnFacility(cz.metacentrum.perun.webgui.json.servicesManager.UnblockServiceOnFacility) BlockServiceOnFacility(cz.metacentrum.perun.webgui.json.servicesManager.BlockServiceOnFacility)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)2 ForceServicePropagation (cz.metacentrum.perun.webgui.json.servicesManager.ForceServicePropagation)2 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2 ArrayList (java.util.ArrayList)2 BlockServiceOnFacility (cz.metacentrum.perun.webgui.json.servicesManager.BlockServiceOnFacility)1 GetFacilityAssignedServicesForGUI (cz.metacentrum.perun.webgui.json.servicesManager.GetFacilityAssignedServicesForGUI)1 UnblockServiceOnFacility (cz.metacentrum.perun.webgui.json.servicesManager.UnblockServiceOnFacility)1 DeleteTask (cz.metacentrum.perun.webgui.json.tasksManager.DeleteTask)1 GetFacilityServicesState (cz.metacentrum.perun.webgui.json.tasksManager.GetFacilityServicesState)1 GetTaskResultsByDestinations (cz.metacentrum.perun.webgui.json.tasksManager.GetTaskResultsByDestinations)1 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)1 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)1