Skip to content

Commit

Permalink
Merge branch 'fix/viewer-control' into 'main'
Browse files Browse the repository at this point in the history
Fix/viewer control

See merge request org/jdrupes/vm-operator!7
  • Loading branch information
mnlipp committed Nov 9, 2024
2 parents a9c31a3 + abe06b4 commit 2d51421
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/
public final class DataPath {

@SuppressWarnings("PMD.FieldNamingConventions")
private static final Logger logger
= Logger.getLogger(DataPath.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.ResourceBundle;
import java.util.Set;
import java.util.logging.Level;
import java.util.stream.Collectors;
import org.bouncycastle.util.Objects;
import org.jdrupes.vmoperator.common.K8sObserver;
import org.jdrupes.vmoperator.common.VmDefinition;
Expand All @@ -55,7 +56,6 @@
import org.jdrupes.vmoperator.manager.events.ResetVm;
import org.jdrupes.vmoperator.manager.events.VmChannel;
import org.jdrupes.vmoperator.manager.events.VmDefChanged;
import org.jdrupes.vmoperator.util.DataPath;
import org.jgrapes.core.Channel;
import org.jgrapes.core.Components;
import org.jgrapes.core.Event;
Expand Down Expand Up @@ -123,7 +123,7 @@ public class VmViewer extends FreeMarkerConlet<VmViewer.ViewerModel> {
private static ObjectMapper objectMapper
= new ObjectMapper().registerModule(new JavaTimeModule());
private Class<?> preferredIpVersion = Inet4Address.class;
private final Set<String> syncUsers = new HashSet<>();
private Set<String> syncUsers = new HashSet<>();
private final Set<String> syncRoles = new HashSet<>();
private boolean deleteConnectionFile = true;

Expand Down Expand Up @@ -173,15 +173,12 @@ public void onConfigurationUpdate(ConfigurationUpdate event) {
.filter(v -> v instanceof String).map(v -> (String) v)
.map(Boolean::parseBoolean).orElse(true);

// Sync
for (var entry : (List<Map<String, String>>) c.getOrDefault(
"syncPreviewsFor", Collections.emptyList())) {
if (entry.containsKey("user")) {
syncUsers.add(entry.get("user"));
} else if (entry.containsKey("role")) {
syncRoles.add(entry.get("role"));
}
}
// Sync preview for users or roles
syncUsers = ((List<Map<String, String>>) c.getOrDefault(
"syncPreviewsFor", Collections.emptyList())).stream()
.map(m -> Optional.ofNullable(m.get("user"))
.orElse(m.get("role")))
.filter(s -> s != null).collect(Collectors.toSet());
} catch (ClassCastException e) {
logger.config("Malformed configuration: " + e.getMessage());
}
Expand Down Expand Up @@ -367,8 +364,9 @@ protected Set<RenderMode> doRenderConlet(RenderConletRequestBase<?> event,
fmModel(event, channel, conletId, model)))
.setRenderAs(
RenderMode.Preview.addModifiers(event.renderAs()))
.setSupportedModes(
model.isGenerated() ? MODES_FOR_GENERATED : MODES));
.setSupportedModes(syncPreviews(channel.session())
? MODES_FOR_GENERATED
: MODES));
renderedAs.add(RenderMode.Preview);
if (!Strings.isNullOrEmpty(model.vmName())) {
Optional.ofNullable(channel.session().get(RENDERED))
Expand Down

0 comments on commit 2d51421

Please sign in to comment.