asset metadata form added
This commit is contained in:
@@ -97,6 +97,7 @@ public enum I18n {
|
||||
ASSETS_SECTION_SUMMARY("assets.section.summary"),
|
||||
ASSETS_SECTION_RUNTIME_CONTRACT("assets.section.runtimeContract"),
|
||||
ASSETS_SUBSECTION_CODEC_CONFIGURATION("assets.subsection.codecConfiguration"),
|
||||
ASSETS_SUBSECTION_METADATA("assets.subsection.metadata"),
|
||||
ASSETS_SECTION_INPUTS_PREVIEW("assets.section.inputsPreview"),
|
||||
ASSETS_SECTION_DIAGNOSTICS("assets.section.diagnostics"),
|
||||
ASSETS_SECTION_ACTIONS("assets.section.actions"),
|
||||
@@ -177,6 +178,7 @@ public enum I18n {
|
||||
ASSETS_DETAILS_READY("assets.details.ready"),
|
||||
ASSETS_DETAILS_NO_SELECTION("assets.details.noSelection"),
|
||||
ASSETS_DETAILS_CODEC_CONFIGURATION_EMPTY("assets.details.codecConfiguration.empty"),
|
||||
ASSETS_DETAILS_METADATA_EMPTY("assets.details.metadata.empty"),
|
||||
ASSETS_ADD_WIZARD_TITLE("assets.addWizard.title"),
|
||||
ASSETS_ADD_WIZARD_DESCRIPTION("assets.addWizard.description"),
|
||||
ASSETS_ADD_WIZARD_STEP_ROOT_TITLE("assets.addWizard.step.root.title"),
|
||||
|
||||
+1
@@ -416,6 +416,7 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
details.outputCodec(),
|
||||
details.availableOutputCodecs(),
|
||||
details.codecConfigurationFieldsByCodec(),
|
||||
details.metadataFields(),
|
||||
Map.copyOf(details.inputsByRole()));
|
||||
}
|
||||
}
|
||||
|
||||
+20
-5
@@ -14,45 +14,60 @@ public record AssetContractDraft(
|
||||
boolean preload,
|
||||
OutputFormatCatalog bank,
|
||||
OutputCodecCatalog selectedCodec,
|
||||
Map<String, String> codecFieldValues) {
|
||||
Map<String, String> codecFieldValues,
|
||||
Map<String, String> metadataFieldValues) {
|
||||
|
||||
public AssetContractDraft {
|
||||
Objects.requireNonNull(assetReference, "assetReference");
|
||||
bank = Objects.requireNonNullElse(bank, OutputFormatCatalog.UNKNOWN);
|
||||
selectedCodec = Objects.requireNonNullElse(selectedCodec, OutputCodecCatalog.UNKNOWN);
|
||||
codecFieldValues = Map.copyOf(Objects.requireNonNull(codecFieldValues, "codecFieldValues"));
|
||||
metadataFieldValues = Map.copyOf(Objects.requireNonNull(metadataFieldValues, "metadataFieldValues"));
|
||||
}
|
||||
|
||||
public static AssetContractDraft fromDetails(AssetWorkspaceAssetDetails details) {
|
||||
final Map<String, String> codecFieldValues = new LinkedHashMap<>();
|
||||
details.codecConfigurationFieldsByCodec().forEach((codec, fields) ->
|
||||
fields.forEach(field -> codecFieldValues.put(keyOf(codec, field.key()), field.value())));
|
||||
final Map<String, String> metadataFieldValues = new LinkedHashMap<>();
|
||||
details.metadataFields().forEach(field -> metadataFieldValues.put(field.key(), field.value()));
|
||||
return new AssetContractDraft(
|
||||
details.summary().assetReference(),
|
||||
details.summary().preload(),
|
||||
details.outputFormat(),
|
||||
details.outputCodec(),
|
||||
codecFieldValues);
|
||||
codecFieldValues,
|
||||
metadataFieldValues);
|
||||
}
|
||||
|
||||
public AssetContractDraft withPreload(boolean preload) {
|
||||
return new AssetContractDraft(assetReference, preload, bank, selectedCodec, codecFieldValues);
|
||||
return new AssetContractDraft(assetReference, preload, bank, selectedCodec, codecFieldValues, metadataFieldValues);
|
||||
}
|
||||
|
||||
public AssetContractDraft withSelectedCodec(OutputCodecCatalog selectedCodec) {
|
||||
return new AssetContractDraft(assetReference, preload, bank, selectedCodec, codecFieldValues);
|
||||
return new AssetContractDraft(assetReference, preload, bank, selectedCodec, codecFieldValues, metadataFieldValues);
|
||||
}
|
||||
|
||||
public AssetContractDraft withCodecFieldValue(OutputCodecCatalog codec, String fieldKey, String value) {
|
||||
final Map<String, String> nextValues = new LinkedHashMap<>(codecFieldValues);
|
||||
nextValues.put(keyOf(codec, fieldKey), Objects.requireNonNullElse(value, ""));
|
||||
return new AssetContractDraft(assetReference, preload, bank, selectedCodec, nextValues);
|
||||
return new AssetContractDraft(assetReference, preload, bank, selectedCodec, nextValues, metadataFieldValues);
|
||||
}
|
||||
|
||||
public AssetContractDraft withMetadataFieldValue(String fieldKey, String value) {
|
||||
final Map<String, String> nextValues = new LinkedHashMap<>(metadataFieldValues);
|
||||
nextValues.put(fieldKey, Objects.requireNonNullElse(value, ""));
|
||||
return new AssetContractDraft(assetReference, preload, bank, selectedCodec, codecFieldValues, nextValues);
|
||||
}
|
||||
|
||||
public String codecFieldValue(OutputCodecCatalog codec, String fieldKey, String fallback) {
|
||||
return codecFieldValues.getOrDefault(keyOf(codec, fieldKey), Objects.requireNonNullElse(fallback, ""));
|
||||
}
|
||||
|
||||
public String metadataFieldValue(String fieldKey, String fallback) {
|
||||
return metadataFieldValues.getOrDefault(fieldKey, Objects.requireNonNullElse(fallback, ""));
|
||||
}
|
||||
|
||||
private static String keyOf(OutputCodecCatalog codec, String fieldKey) {
|
||||
return codec.name() + ":" + fieldKey;
|
||||
}
|
||||
|
||||
+112
-2
@@ -105,7 +105,8 @@ public final class AssetDetailsContractControl extends VBox implements StudioCon
|
||||
createPreloadEditor(draft, editing)),
|
||||
AssetDetailsUiSupport.createKeyValueRow(
|
||||
Container.i18n().text(I18n.ASSETS_LABEL_BANK),
|
||||
draft.bank()));
|
||||
draft.bank()),
|
||||
createMetadataSection(details, draft, editing));
|
||||
|
||||
final VBox codecColumn = new VBox(10);
|
||||
codecColumn.getStyleClass().addAll("assets-details-contract-column", "assets-details-contract-codec-column");
|
||||
@@ -220,6 +221,110 @@ public final class AssetDetailsContractControl extends VBox implements StudioCon
|
||||
return createCodecMetadataPane(title, content);
|
||||
}
|
||||
|
||||
private Node createMetadataSection(
|
||||
AssetWorkspaceAssetDetails details,
|
||||
AssetContractDraft draft,
|
||||
boolean editing) {
|
||||
final VBox subsection = new VBox(8);
|
||||
subsection.getStyleClass().add("assets-details-contract-metadata");
|
||||
final Label title = new Label(Container.i18n().text(I18n.ASSETS_SUBSECTION_METADATA));
|
||||
title.getStyleClass().add("assets-details-subsection-title");
|
||||
final VBox content = new VBox(8);
|
||||
content.getStyleClass().add("assets-details-contract-metadata-content");
|
||||
|
||||
if (details.metadataFields().isEmpty()) {
|
||||
content.getChildren().add(AssetDetailsUiSupport.createSectionMessage(
|
||||
Container.i18n().text(I18n.ASSETS_DETAILS_METADATA_EMPTY)));
|
||||
return createCodecMetadataPane(title, content);
|
||||
}
|
||||
|
||||
for (PackerCodecConfigurationFieldDTO field : details.metadataFields()) {
|
||||
content.getChildren().add(createMetadataFieldRow(field, draft, editing));
|
||||
}
|
||||
return createCodecMetadataPane(title, content);
|
||||
}
|
||||
|
||||
private Node createMetadataFieldRow(
|
||||
PackerCodecConfigurationFieldDTO field,
|
||||
AssetContractDraft draft,
|
||||
boolean editing) {
|
||||
final Node valueNode = switch (field.fieldType()) {
|
||||
case BOOLEAN -> createMetadataBooleanField(field, draft, editing);
|
||||
case ENUM -> createMetadataEnumField(field, draft, editing);
|
||||
case INTEGER, TEXT -> createMetadataTextField(field, draft, editing);
|
||||
};
|
||||
return AssetDetailsUiSupport.createKeyValueRow(field.label(), valueNode);
|
||||
}
|
||||
|
||||
private Node createMetadataBooleanField(
|
||||
PackerCodecConfigurationFieldDTO field,
|
||||
AssetContractDraft draft,
|
||||
boolean editing) {
|
||||
final CheckBox checkBox = new CheckBox();
|
||||
checkBox.getStyleClass().add("assets-details-readonly-check");
|
||||
checkBox.setSelected(Boolean.parseBoolean(currentMetadataValue(field, draft)));
|
||||
if (editing) {
|
||||
checkBox.selectedProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (!Objects.equals(oldValue, newValue)) {
|
||||
formSession.updateDraft(current -> current.withMetadataFieldValue(
|
||||
field.key(),
|
||||
Boolean.toString(newValue)));
|
||||
actionBar.updateState(formSession.mode(), formSession.isDirty());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
configureReadOnlyControl(checkBox);
|
||||
}
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
private Node createMetadataEnumField(
|
||||
PackerCodecConfigurationFieldDTO field,
|
||||
AssetContractDraft draft,
|
||||
boolean editing) {
|
||||
final ComboBox<String> comboBox = new ComboBox<>(FXCollections.observableArrayList(field.options()));
|
||||
comboBox.getStyleClass().add("assets-details-combo");
|
||||
comboBox.setMaxWidth(Double.MAX_VALUE);
|
||||
comboBox.getSelectionModel().select(currentMetadataValue(field, draft));
|
||||
if (editing) {
|
||||
comboBox.valueProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (newValue != null && !Objects.equals(oldValue, newValue)) {
|
||||
formSession.updateDraft(current -> current.withMetadataFieldValue(
|
||||
field.key(),
|
||||
newValue));
|
||||
actionBar.updateState(formSession.mode(), formSession.isDirty());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
configureReadOnlyControl(comboBox);
|
||||
}
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
private Node createMetadataTextField(
|
||||
PackerCodecConfigurationFieldDTO field,
|
||||
AssetContractDraft draft,
|
||||
boolean editing) {
|
||||
final TextField textField = new TextField(currentMetadataValue(field, draft));
|
||||
textField.getStyleClass().add("assets-workspace-search");
|
||||
textField.setMaxWidth(Double.MAX_VALUE);
|
||||
HBox.setHgrow(textField, Priority.ALWAYS);
|
||||
if (editing) {
|
||||
textField.textProperty().addListener((ignored, oldValue, newValue) -> {
|
||||
if (!Objects.equals(oldValue, newValue)) {
|
||||
formSession.updateDraft(current -> current.withMetadataFieldValue(
|
||||
field.key(),
|
||||
Objects.requireNonNullElse(newValue, "")));
|
||||
actionBar.updateState(formSession.mode(), formSession.isDirty());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
textField.setEditable(false);
|
||||
configureReadOnlyControl(textField);
|
||||
}
|
||||
return textField;
|
||||
}
|
||||
|
||||
private Node createCodecMetadataPane(Label title, VBox content) {
|
||||
final ScrollPane scrollPane = new ScrollPane(content);
|
||||
scrollPane.setFitToWidth(true);
|
||||
@@ -320,6 +425,10 @@ public final class AssetDetailsContractControl extends VBox implements StudioCon
|
||||
return draft.codecFieldValue(draft.selectedCodec(), field.key(), field.value());
|
||||
}
|
||||
|
||||
private String currentMetadataValue(PackerCodecConfigurationFieldDTO field, AssetContractDraft draft) {
|
||||
return draft.metadataFieldValue(field.key(), field.value());
|
||||
}
|
||||
|
||||
private void configureReadOnlyControl(javafx.scene.control.Control control) {
|
||||
control.setMouseTransparent(true);
|
||||
control.setFocusTraversable(false);
|
||||
@@ -344,7 +453,8 @@ public final class AssetDetailsContractControl extends VBox implements StudioCon
|
||||
draft.assetReference(),
|
||||
draft.preload(),
|
||||
draft.selectedCodec(),
|
||||
draft.codecFieldValues());
|
||||
draft.codecFieldValues(),
|
||||
draft.metadataFieldValues());
|
||||
try {
|
||||
final var response = Container.packer().workspaceService().updateAssetContract(request);
|
||||
if (response.success()) {
|
||||
|
||||
+2
@@ -16,6 +16,7 @@ public record AssetWorkspaceAssetDetails(
|
||||
OutputCodecCatalog outputCodec,
|
||||
List<OutputCodecCatalog> availableOutputCodecs,
|
||||
Map<OutputCodecCatalog, List<PackerCodecConfigurationFieldDTO>> codecConfigurationFieldsByCodec,
|
||||
List<PackerCodecConfigurationFieldDTO> metadataFields,
|
||||
Map<String, List<Path>> inputsByRole) {
|
||||
|
||||
public AssetWorkspaceAssetDetails {
|
||||
@@ -25,6 +26,7 @@ public record AssetWorkspaceAssetDetails(
|
||||
outputCodec = Objects.requireNonNullElse(outputCodec, OutputCodecCatalog.UNKNOWN);
|
||||
availableOutputCodecs = List.copyOf(Objects.requireNonNull(availableOutputCodecs, "availableOutputCodecs"));
|
||||
codecConfigurationFieldsByCodec = Map.copyOf(Objects.requireNonNull(codecConfigurationFieldsByCodec, "codecConfigurationFieldsByCodec"));
|
||||
metadataFields = List.copyOf(Objects.requireNonNull(metadataFields, "metadataFields"));
|
||||
inputsByRole = Map.copyOf(Objects.requireNonNull(inputsByRole, "inputsByRole"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ assets.badge.diagnostics=Diagnostics
|
||||
assets.section.summary=Summary
|
||||
assets.section.runtimeContract=Runtime Contract
|
||||
assets.subsection.codecConfiguration=Codec Configuration
|
||||
assets.subsection.metadata=Metadata
|
||||
assets.section.inputsPreview=Inputs / Preview
|
||||
assets.section.diagnostics=Diagnostics
|
||||
assets.section.actions=Actions
|
||||
@@ -168,6 +169,7 @@ assets.details.empty=Create or add assets to this project to start using the Ass
|
||||
assets.details.ready=Selected asset: {0}\nState: {1}\nRoot: {2}
|
||||
assets.details.noSelection=Select an asset from the navigator once assets are available.
|
||||
assets.details.codecConfiguration.empty=This codec does not expose configuration fields yet.
|
||||
assets.details.metadata.empty=This asset does not expose metadata fields yet.
|
||||
assets.addWizard.title=Add Asset
|
||||
assets.addWizard.description=Create a registered asset root through a guided flow.
|
||||
assets.addWizard.step.root.title=Choose Asset Root
|
||||
|
||||
Reference in New Issue
Block a user