use of org.jboss.hal.resources.Ids.FORM in project console by hal.
the class ServerColumn method addServer.
private void addServer(boolean browseByHost) {
if (browseByHost) {
AddressTemplate template = serverConfigTemplate(statementContext.selectedHost());
String id = Ids.build(HOST, statementContext.selectedHost(), SERVER, Ids.ADD);
List<String> attributes = asList(AUTO_START, GROUP, SOCKET_BINDING_DEFAULT_INTERFACE, SOCKET_BINDING_GROUP, SOCKET_BINDING_PORT_OFFSET, UPDATE_AUTO_START_WITH_SERVER_STATUS);
crud.add(id, Names.SERVER, template, attributes, createUniqueValidation(), (name, address) -> refresh(RESTORE_SELECTION));
} else {
// load all available hosts to show in the copy dialog
Operation operation = new Operation.Builder(ResourceAddress.root(), READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, HOST).build();
dispatcher.execute(operation, result -> {
List<String> hosts = new ArrayList<>();
result.asList().forEach(m -> hosts.add(m.asString()));
// get the first host, only to retrieve the r-r-d for server-config
// as /host=*/server-config=*:read-operation-description(name=add) does not work
AddressTemplate template = serverConfigTemplate(hosts.get(0));
metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {
@Override
public void onMetadata(Metadata metadata) {
String id = Ids.build(SERVER_GROUP, statementContext.selectedServerGroup(), SERVER, FORM);
SingleSelectBoxItem hostFormItem = new SingleSelectBoxItem(HOST, Names.HOST, hosts, false);
hostFormItem.setRequired(true);
NameItem nameItem = new NameItem();
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).unboundFormItem(nameItem, 0).unboundFormItem(hostFormItem, 1, resources.messages().addServerHostHelp()).customFormItem(GROUP, attributeDescription -> {
TextBoxItem groupItem = new TextBoxItem(GROUP, resources.constants().group());
groupItem.setEnabled(false);
return groupItem;
}).fromRequestProperties().build();
AddResourceDialog dialog = new AddResourceDialog(resources.messages().addServerTitle(), form, (resource, payload) -> {
payload.get(GROUP).set(statementContext.selectedServerGroup());
String serverName = nameItem.getValue();
ResourceAddress address = serverConfigTemplate(hostFormItem.getValue()).resolve(statementContext, serverName);
crud.add(serverName, address, payload, resources.messages().addResourceSuccess(Names.SERVER, serverName), (name, address1) -> refresh(RESTORE_SELECTION));
});
dialog.getForm().<String>getFormItem(NAME).addValidationHandler(createUniqueValidation());
dialog.show();
form.<String>getFormItem(GROUP).setValue(statementContext.selectedServerGroup());
}
});
});
}
}
use of org.jboss.hal.resources.Ids.FORM in project console by hal.
the class HostPresenter method disableSslForManagementInterface.
@Override
@SuppressWarnings("DuplicatedCode")
public void disableSslForManagementInterface() {
Constants constants = resources.constants();
String serverName = environment.isStandalone() ? Names.STANDALONE_SERVER : Names.DOMAIN_CONTROLLER;
String label = constants.reload() + " " + serverName;
SwitchItem reload = new SwitchItem(RELOAD, label);
reload.setExpressionAllowed(false);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(RELOAD, FORM), Metadata.empty()).unboundFormItem(reload).build();
form.attach();
HTMLElement formElement = form.element();
ModelNode model = new ModelNode();
model.setEmptyObject();
form.edit(model);
ResourceAddress httpAddress = HTTP_INTERFACE_TEMPLATE.resolve(statementContext);
DialogFactory.buildConfirmation(constants.disableSSL(), resources.messages().disableSSLManagementQuestion(serverName), formElement, Dialog.Size.MEDIUM, () -> {
List<Task<FlowContext>> tasks = new ArrayList<>();
// load the http-interface resource to get the port
Task<FlowContext> loadHttpInterface = flowContext -> {
Operation readHttpInterface = new Operation.Builder(httpAddress, READ_RESOURCE_OPERATION).build();
return dispatcher.execute(readHttpInterface).doOnSuccess(value -> {
if (value.hasDefined(PORT)) {
// only domain mode contains "port" attribute
String port = value.get(PORT).asString();
if (port.contains("$")) {
// if it contains an expression value, resolve it at host level
ResourceAddress address = AddressTemplate.of("/host=" + environment.getDomainController()).resolve(statementContext);
Operation readPort = new Operation.Builder(address, RESOLVE_EXPRESSION).param(EXPRESSION, port).build();
dispatcher.execute(readPort, portResult -> flowContext.set(PORT, portResult.asString()));
} else {
flowContext.set(PORT, port);
}
}
}).toCompletable();
};
tasks.add(loadHttpInterface);
// in domain-mode read the /host=<dc> domain controller
// it is important for later use if user wants to reload dc if in admin-mode
Task<FlowContext> loadDc = flowContext -> {
ResourceAddress dcAddress = AddressTemplate.of("/host=" + environment.getDomainController()).resolve(statementContext);
Operation readDcOp = new Operation.Builder(dcAddress, READ_RESOURCE_OPERATION).param(ATTRIBUTES_ONLY, true).build();
return dispatcher.execute(readDcOp).doOnSuccess(value -> flowContext.set(HOST, new Host(value))).toCompletable();
};
tasks.add(loadDc);
// as part of the disable ssl task, undefine the secure-port, it only exists in domain mode
Task<FlowContext> undefineSecurePortTask = flowContext -> {
Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SECURE_PORT).build();
return dispatcher.execute(op).toCompletable();
};
tasks.add(undefineSecurePortTask);
// as part of the disable ssl task, undefine the ssl-context
Task<FlowContext> undefineSslContextTask = flowContext -> {
Operation op = new Operation.Builder(httpAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SSL_CONTEXT).build();
return dispatcher.execute(op).toCompletable();
};
tasks.add(undefineSslContextTask);
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext flowContext) {
if (reload.getValue() != null && reload.getValue()) {
String port = flowContext.get(PORT).toString();
// extracts the url search path, so the reload shows the same view the use is on
String urlSuffix = window.location.getHref();
urlSuffix = urlSuffix.substring(urlSuffix.indexOf("//") + 2);
urlSuffix = urlSuffix.substring(urlSuffix.indexOf("/"));
// the location to redirect the browser to the unsecure URL
// TODO Replace hardcoded scheme
String location = "http://" + window.location.getHostname() + ":" + port + urlSuffix;
Host host = flowContext.get(HOST);
reloadServer(host, location);
} else {
reloadView();
MessageEvent.fire(getEventBus(), Message.success(resources.messages().disableSSLManagementSuccess()));
}
}
@Override
public void onError(FlowContext context, Throwable throwable) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().disableSSLManagementError(throwable.getMessage())));
}
});
}).show();
}
use of org.jboss.hal.resources.Ids.FORM 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());
}
}
});
}
use of org.jboss.hal.resources.Ids.FORM in project console by hal.
the class LoggingView method init.
@PostConstruct
void init() {
noRootLogger = new EmptyState.Builder("logging-root-logger-empty", mbuiContext.resources().constants().noRootLogger()).description(mbuiContext.resources().constants().noRootLoggerDescription()).icon("fa fa-sitemap").primaryAction(mbuiContext.resources().constants().add(), this::addRootLogger).build();
noRootLogger.element().classList.add(marginTopLarge);
// hack which relies on the element hierarchy given in the template. will break if you change that hierarchy.
rootLoggerForm.element().parentNode.appendChild(noRootLogger.element());
rootLoggerVisibility(true);
// --------------------------- json formatter
LabelBuilder labelBuilder = new LabelBuilder();
Metadata jsonMetadata = mbuiContext.metadataRegistry().lookup(JSON_FORMATTER_TEMPLATE);
Metadata jsonKeyOverridesMetadata = jsonMetadata.forComplexAttribute(KEY_OVERRIDES);
String jsonLabel = labelBuilder.label(JSON_FORMATTER_TEMPLATE.lastName());
jsonFormatterTable = new ModelNodeTable.Builder<NamedNode>(Ids.build(LOGGING, JSON, FORMATTER, TABLE), jsonMetadata).button(mbuiContext.tableButtonFactory().add(Ids.build(LOGGING, JSON, FORMATTER, Ids.ADD), jsonLabel, JSON_FORMATTER_TEMPLATE, (name, address) -> presenter.reload())).button(mbuiContext.tableButtonFactory().remove(jsonLabel, JSON_FORMATTER_TEMPLATE, table -> table.selectedRow().getName(), () -> presenter.reload())).column(NAME, (cell, type, row, meta) -> row.getName()).build();
jsonFormatterForm = new ModelNodeForm.Builder<NamedNode>(Ids.build(LOGGING, JSON, FORMATTER, FORM), jsonMetadata).onSave((form, changedValues) -> mbuiContext.crud().save(jsonLabel, form.getModel().getName(), JSON_FORMATTER_TEMPLATE, changedValues, () -> presenter.reload())).prepareReset(form -> mbuiContext.crud().reset(jsonLabel, jsonFormatterTable.selectedRow().getName(), JSON_FORMATTER_TEMPLATE, form, jsonMetadata, () -> presenter.reload())).build();
jsonKeyOverridesForm = new ModelNodeForm.Builder<>(Ids.build(LOGGING, FORMATTER, JSON, KEY_OVERRIDES, FORM), jsonKeyOverridesMetadata).singleton(() -> {
StatementContext jsonStatementContext = new SelectionAwareStatementContext(presenter.getStatementContext(), () -> jsonFormatterTable.selectedRow().getName());
return new Operation.Builder(JSON_FORMATTER_TEMPLATE.resolve(jsonStatementContext), READ_ATTRIBUTE_OPERATION).param(NAME, KEY_OVERRIDES).build();
}, () -> presenter.addComplexObject(jsonLabel, jsonFormatterTable.selectedRow().getName(), KEY_OVERRIDES, JSON_FORMATTER_TEMPLATE)).onSave((form, changedValues) -> presenter.saveComplexObject(jsonLabel, jsonFormatterTable.selectedRow().getName(), KEY_OVERRIDES, JSON_FORMATTER_TEMPLATE, changedValues)).prepareReset(form -> presenter.resetComplexObject(jsonLabel, jsonFormatterTable.selectedRow().getName(), KEY_OVERRIDES, JSON_FORMATTER_TEMPLATE, jsonKeyOverridesMetadata, form)).prepareRemove(form -> presenter.removeComplexObject(jsonLabel, jsonFormatterTable.selectedRow().getName(), KEY_OVERRIDES, JSON_FORMATTER_TEMPLATE)).build();
Tabs jsonTabs = new Tabs(Ids.build(LOGGING, FORMATTER, JSON, TAB_CONTAINER));
jsonTabs.add(Ids.build(LOGGING, FORMATTER, JSON, ATTRIBUTES, TAB), mbuiContext.resources().constants().attributes(), jsonFormatterForm.element());
jsonTabs.add(Ids.build(LOGGING, FORMATTER, JSON, KEY_OVERRIDES, TAB), Names.KEY_OVERRIDES, jsonKeyOverridesForm.element());
HTMLElement jsonSection = section().add(h(1).textContent(Names.JSON_FORMATTER)).add(p().textContent(jsonMetadata.getDescription().getDescription())).add(jsonFormatterTable).add(jsonTabs).element();
registerAttachable(jsonFormatterTable, jsonFormatterForm, jsonKeyOverridesForm);
navigation.insertSecondary(LOGGING_FORMATTER_ITEM, Ids.build(LOGGING, FORMATTER, JSON, Ids.ITEM), null, Names.JSON_FORMATTER, jsonSection);
// --------------------------- xml formatter
Metadata xmlMetadata = mbuiContext.metadataRegistry().lookup(XML_FORMATTER_TEMPLATE);
Metadata xmlKeyOverridesMetadata = xmlMetadata.forComplexAttribute(KEY_OVERRIDES);
String xmlLabel = labelBuilder.label(XML_FORMATTER_TEMPLATE.lastName());
xmlFormatterTable = new ModelNodeTable.Builder<NamedNode>(Ids.build(LOGGING, XML, FORMATTER, TABLE), xmlMetadata).button(mbuiContext.tableButtonFactory().add(Ids.build(LOGGING, XML, FORMATTER, Ids.ADD), xmlLabel, XML_FORMATTER_TEMPLATE, (name, address) -> presenter.reload())).button(mbuiContext.tableButtonFactory().remove(xmlLabel, XML_FORMATTER_TEMPLATE, table -> table.selectedRow().getName(), () -> presenter.reload())).column(NAME, (cell, type, row, meta) -> row.getName()).build();
xmlFormatterForm = new ModelNodeForm.Builder<NamedNode>(Ids.build(LOGGING, XML, FORMATTER, FORM), xmlMetadata).onSave((form, changedValues) -> mbuiContext.crud().save(xmlLabel, form.getModel().getName(), XML_FORMATTER_TEMPLATE, changedValues, () -> presenter.reload())).prepareReset(form -> mbuiContext.crud().reset(xmlLabel, xmlFormatterTable.selectedRow().getName(), XML_FORMATTER_TEMPLATE, form, xmlMetadata, () -> presenter.reload())).build();
xmlKeyOverridesForm = new ModelNodeForm.Builder<>(Ids.build(LOGGING, FORMATTER, XML, KEY_OVERRIDES, FORM), xmlKeyOverridesMetadata).singleton(() -> {
StatementContext xmlStatementContext = new SelectionAwareStatementContext(presenter.getStatementContext(), () -> xmlFormatterTable.selectedRow().getName());
return new Operation.Builder(XML_FORMATTER_TEMPLATE.resolve(xmlStatementContext), READ_ATTRIBUTE_OPERATION).param(NAME, KEY_OVERRIDES).build();
}, () -> presenter.addComplexObject(xmlLabel, xmlFormatterTable.selectedRow().getName(), KEY_OVERRIDES, XML_FORMATTER_TEMPLATE)).onSave((form, changedValues) -> presenter.saveComplexObject(xmlLabel, xmlFormatterTable.selectedRow().getName(), KEY_OVERRIDES, XML_FORMATTER_TEMPLATE, changedValues)).prepareReset(form -> presenter.resetComplexObject(xmlLabel, xmlFormatterTable.selectedRow().getName(), KEY_OVERRIDES, XML_FORMATTER_TEMPLATE, xmlKeyOverridesMetadata, form)).prepareRemove(form -> presenter.removeComplexObject(xmlLabel, xmlFormatterTable.selectedRow().getName(), KEY_OVERRIDES, XML_FORMATTER_TEMPLATE)).build();
Tabs xmlTabs = new Tabs(Ids.build(LOGGING, FORMATTER, XML, TAB_CONTAINER));
xmlTabs.add(Ids.build(LOGGING, FORMATTER, XML, ATTRIBUTES, TAB), mbuiContext.resources().constants().attributes(), xmlFormatterForm.element());
xmlTabs.add(Ids.build(LOGGING, FORMATTER, XML, KEY_OVERRIDES, TAB), Names.KEY_OVERRIDES, xmlKeyOverridesForm.element());
HTMLElement xmlSection = section().add(h(1).textContent(Names.XML_FORMATTER)).add(p().textContent(xmlMetadata.getDescription().getDescription())).add(xmlFormatterTable).add(xmlTabs).element();
registerAttachable(xmlFormatterTable, xmlFormatterForm, xmlKeyOverridesForm);
navigation.insertSecondary(LOGGING_FORMATTER_ITEM, Ids.build(LOGGING, FORMATTER, XML, Ids.ITEM), null, Names.XML_FORMATTER, xmlSection);
}
Aggregations