Search in sources :

Example 1 with Alert

use of org.jboss.hal.ballroom.Alert in project console by hal.

the class StoresPresenter method verifyRenewCertificate.

void verifyRenewCertificate(Metadata metadata, String name, String alias) {
    metadata = metadata.forOperation(SHOULD_RENEW_CERTIFICATE);
    String id = Ids.build(KEY_STORE, SHOULD_RENEW_CERTIFICATE, FORM);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).build();
    form.setSaveCallback((form1, changedValues) -> {
        ResourceAddress address = KEY_STORE_TEMPLATE.resolve(statementContext, name);
        Operation operation = new Operation.Builder(address, SHOULD_RENEW_CERTIFICATE).payload(form.getModel()).build();
        dispatcher.execute(operation, result -> {
            int days = result.get("days-to-expiry").asInt();
            Date dueDate = new Date();
            CalendarUtil.addDaysToDate(dueDate, days);
            HTMLElement content;
            if (days < 1) {
                Alert warning = new Alert(Icons.WARNING, resources.messages().certificateExpired(alias));
                content = div().add(warning).element();
            } else {
                SafeHtml description = resources.messages().certificateShouldRenew(days, alias, Format.mediumDateTime(dueDate));
                content = p().innerHtml(description).element();
            }
            new Dialog.Builder(resources.constants().verifyRenewCertificate()).primary(resources.constants().ok(), null).size(Dialog.Size.MEDIUM).add(content).build().show();
        }, (operation1, failure) -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().verifyRenewError(alias, name, failure))), (operation1, ex) -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().verifyRenewError(alias, name, ex.getMessage()))));
    });
    Dialog dialog = new Dialog.Builder(resources.constants().verifyRenewCertificate()).add(p().textContent(metadata.getDescription().getDescription()).element()).add(form.element()).primary(resources.constants().verifyRenew(), form::save).size(Dialog.Size.MEDIUM).closeOnEsc(true).cancel().build();
    dialog.registerAttachable(form);
    dialog.show();
    ModelNode model = new ModelNode();
    model.get(ALIAS).set(alias);
    form.getFormItem(ALIAS).setEnabled(false);
    form.edit(model);
}
Also used : HTMLElement(elemental2.dom.HTMLElement) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Operation(org.jboss.hal.dmr.Operation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Date(java.util.Date) Dialog(org.jboss.hal.ballroom.dialog.Dialog) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) Alert(org.jboss.hal.ballroom.Alert) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 2 with Alert

use of org.jboss.hal.ballroom.Alert in project console by hal.

the class ModelNodeForm method attach.

@Override
@JsMethod
public void attach() {
    super.attach();
    if (Iterables.isEmpty(getFormItems())) {
        Alert alert = new Alert(Icons.INFO, MESSAGES.emptyModelNodeForm());
        Elements.removeChildrenFrom(element());
        element().appendChild(alert.element());
    }
    if (singleton && ping != null && ping.get() != null) {
        Core.INSTANCE.dispatcher().execute(ping.get(), result -> {
            if (!result.isDefined()) {
                flip(EMPTY);
            } else {
                flip(READONLY);
            }
        }, (op, failure) -> flip(READONLY));
    }
}
Also used : Alert(org.jboss.hal.ballroom.Alert) JsMethod(jsinterop.annotations.JsMethod)

Example 3 with Alert

use of org.jboss.hal.ballroom.Alert in project console by hal.

the class ServerActions method editUrl.

public void editUrl(Server server, Callback callback) {
    Alert alert = new Alert(Icons.ERROR, resources.messages().serverUrlError());
    HTMLElement info = p().element();
    TextBoxItem urlItem = new TextBoxItem(URL, Names.URL);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.SERVER_URL_FORM, Metadata.empty()).unboundFormItem(urlItem).addOnly().onSave((f, changedValues) -> {
        String url = urlItem.getValue();
        if (Strings.isNullOrEmpty(url)) {
            serverUrlStorage.remove(server.getHost(), server.getName());
        } else {
            serverUrlStorage.save(server.getHost(), server.getName(), url);
        }
        callback.execute();
    }).build();
    Dialog dialog = new Dialog.Builder(resources.constants().editURL()).add(alert.element()).add(info).add(form.element()).primary(form::save).cancel().closeIcon(true).closeOnEsc(true).build();
    dialog.registerAttachable(form);
    Elements.setVisible(alert.element(), false);
    Elements.setVisible(info, false);
    readUrl(server, new AsyncCallback<ServerUrl>() {

        @Override
        public void onFailure(Throwable caught) {
            Elements.setVisible(alert.element(), true);
            show(null);
        }

        @Override
        public void onSuccess(ServerUrl serverUrl) {
            if (serverUrl.isCustom()) {
                info.innerHTML = resources.messages().serverUrlCustom().asString();
            } else {
                info.innerHTML = resources.messages().serverUrlManagementModel().asString();
            }
            Elements.setVisible(info, true);
            show(serverUrl);
        }

        private void show(ServerUrl serverUrl) {
            dialog.show();
            form.edit(new ModelNode());
            if (serverUrl != null) {
                urlItem.setValue(serverUrl.getUrl());
            }
        }
    });
}
Also used : Dialog(org.jboss.hal.ballroom.dialog.Dialog) DISABLED(org.jboss.hal.core.runtime.server.ServerConfigStatus.DISABLED) Provider(javax.inject.Provider) Elements.a(org.jboss.gwt.elemento.core.Elements.a) TimeoutHandler.repeatUntilTimeout(org.jboss.hal.dmr.dispatch.TimeoutHandler.repeatUntilTimeout) STOPPED(org.jboss.hal.core.runtime.server.ServerConfigStatus.STOPPED) StatementContext(org.jboss.hal.meta.StatementContext) LoggerFactory(org.slf4j.LoggerFactory) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) ManagementModel(org.jboss.hal.meta.ManagementModel) Icons(org.jboss.hal.resources.Icons) ModelNodeHelper.asEnumValue(org.jboss.hal.dmr.ModelNodeHelper.asEnumValue) TextBoxItem(org.jboss.hal.ballroom.form.TextBoxItem) OnError(org.jboss.hal.dmr.dispatch.Dispatcher.OnError) Elements.p(org.jboss.gwt.elemento.core.Elements.p) STARTED(org.jboss.hal.core.runtime.server.ServerConfigStatus.STARTED) HTMLElement(elemental2.dom.HTMLElement) Map(java.util.Map) SuspendState(org.jboss.hal.core.runtime.SuspendState) Message(org.jboss.hal.spi.Message) Timeouts(org.jboss.hal.core.runtime.Timeouts) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) EnumSet(java.util.EnumSet) CSS.marginLeft5(org.jboss.hal.resources.CSS.marginLeft5) Predicate(java.util.function.Predicate) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) FORM(org.jboss.hal.resources.Ids.FORM) ReadSocketBinding(org.jboss.hal.core.runtime.server.ServerUrlTasks.ReadSocketBinding) List(java.util.List) MetadataProcessor(org.jboss.hal.meta.processing.MetadataProcessor) Callback(org.jboss.hal.spi.Callback) Action(org.jboss.hal.core.runtime.Action) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Core(org.jboss.hal.core.Core) Flow.series(org.jboss.hal.flow.Flow.series) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Subscription(rx.Subscription) CSS.fontAwesome(org.jboss.hal.resources.CSS.fontAwesome) DomGlobal.setTimeout(elemental2.dom.DomGlobal.setTimeout) ModelNode(org.jboss.hal.dmr.ModelNode) Alert(org.jboss.hal.ballroom.Alert) MessageEvent(org.jboss.hal.spi.MessageEvent) SHORT_TIMEOUT(org.jboss.hal.resources.UIConstants.SHORT_TIMEOUT) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback) ModelNodeHelper.getOrDefault(org.jboss.hal.dmr.ModelNodeHelper.getOrDefault) HashMap(java.util.HashMap) RUNNING(org.jboss.hal.core.runtime.RunningState.RUNNING) Result(org.jboss.hal.core.runtime.Result) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) ArrayList(java.util.ArrayList) OnFail(org.jboss.hal.dmr.dispatch.Dispatcher.OnFail) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Property(org.jboss.hal.dmr.Property) Strings(com.google.common.base.Strings) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) TimeoutHandler.repeatOperationUntil(org.jboss.hal.dmr.dispatch.TimeoutHandler.repeatOperationUntil) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) ReadSocketBindingGroup(org.jboss.hal.core.runtime.server.ServerUrlTasks.ReadSocketBindingGroup) BlockingDialog(org.jboss.hal.ballroom.dialog.BlockingDialog) Logger(org.slf4j.Logger) CompositeResult(org.jboss.hal.dmr.CompositeResult) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) EventBus(com.google.web.bindery.event.shared.EventBus) CSS.pfIcon(org.jboss.hal.resources.CSS.pfIcon) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) CompletableSubscriber(rx.CompletableSubscriber) Consumer(java.util.function.Consumer) Composite(org.jboss.hal.dmr.Composite) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Resources(org.jboss.hal.resources.Resources) SUSPENDED(org.jboss.hal.core.runtime.SuspendState.SUSPENDED) RunningState(org.jboss.hal.core.runtime.RunningState) Elements.span(org.jboss.gwt.elemento.core.Elements.span) Elements(org.jboss.gwt.elemento.core.Elements) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Form(org.jboss.hal.ballroom.form.Form) URL_KEY(org.jboss.hal.core.runtime.server.ServerUrlTasks.URL_KEY) HTMLElement(elemental2.dom.HTMLElement) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) TextBoxItem(org.jboss.hal.ballroom.form.TextBoxItem) Dialog(org.jboss.hal.ballroom.dialog.Dialog) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) BlockingDialog(org.jboss.hal.ballroom.dialog.BlockingDialog) Alert(org.jboss.hal.ballroom.Alert) ModelNode(org.jboss.hal.dmr.ModelNode)

Aggregations

Alert (org.jboss.hal.ballroom.Alert)3 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)2 HTMLElement (elemental2.dom.HTMLElement)2 Dialog (org.jboss.hal.ballroom.dialog.Dialog)2 AddResourceDialog (org.jboss.hal.core.mbui.dialog.AddResourceDialog)2 ModelNodeForm (org.jboss.hal.core.mbui.form.ModelNodeForm)2 Strings (com.google.common.base.Strings)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 EventBus (com.google.web.bindery.event.shared.EventBus)1 DomGlobal.setTimeout (elemental2.dom.DomGlobal.setTimeout)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 Predicate (java.util.function.Predicate)1 Inject (javax.inject.Inject)1 Provider (javax.inject.Provider)1