Skip to content

Commit

Permalink
(#137) Only show sharing icon when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
squaregoldfish committed Dec 13, 2024
1 parent 9500696 commit 0a42813
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 11 deletions.
14 changes: 10 additions & 4 deletions WebApp/WebContent/instrument/instrument_list.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,16 @@
<h:graphicImage value="/resources/image/spacer.svg" alt="" title=""
styleClass="actionIconLarge"/>
</ui:fragment>
<p:commandLink onclick="showOwnershipDialog(#{instrument.id})">
<h:graphicImage value="/resources/image/share.svg" alt="Ownership and Sharing"
title="Ownership and Sharing" styleClass="actionIconLarge"/>
</p:commandLink>
<ui:fragment rendered="#{instrument.canShare}">
<p:commandLink onclick="showOwnershipDialog(#{instrument.id})">
<h:graphicImage value="/resources/image/share.svg" alt="Ownership and Sharing"
title="Ownership and Sharing" styleClass="actionIconLarge"/>
</p:commandLink>
</ui:fragment>
<ui:fragment rendered="#{not instrument.canShare}">
<h:graphicImage value="/resources/image/spacer.svg" alt="" title=""
styleClass="actionIconLarge"/>
</ui:fragment>
<ui:fragment rendered="#{not instrumentListBean.hasDatasets(instrument.id)}">
<p:commandLink onclick="confirmInstrumentDelete(#{instrument.id}, '#{instrument.displayName}')">
<h:graphicImage value="/resources/image/trash.svg" alt="Delete instrument"
Expand Down
22 changes: 22 additions & 0 deletions WebApp/src/uk/ac/exeter/QuinCe/data/Instrument/Instrument.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,28 @@ public Instrument(User owner, long databaseId, String name,
parsePropertiesJson(propertiesJson);
}

/**
* Copy constructor. Performs a shallow copy on members.
*
* @param source
* The source object.
*/
public Instrument(Instrument source) {
this.owner = source.owner;
this.id = source.id;
this.name = source.name;
this.sharedWith = source.sharedWith;
this.fileDefinitions = source.fileDefinitions;
this.variables = source.variables;
this.variableProperties = source.variableProperties;
this.sensorAssignments = source.sensorAssignments;
this.platformName = source.platformName;
this.platformCode = source.platformCode;
this.nrt = source.nrt;
this.lastNrtExport = source.lastNrtExport;
this.properties = source.properties;
}

/**
* Create a new instrument with defined properties.
*
Expand Down
23 changes: 23 additions & 0 deletions WebApp/src/uk/ac/exeter/QuinCe/web/Instrument/BeanInstrument.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package uk.ac.exeter.QuinCe.web.Instrument;

import uk.ac.exeter.QuinCe.User.User;
import uk.ac.exeter.QuinCe.data.Instrument.Instrument;

/**
* Wrapper around the {@link Instrument} class that adds some extra features for
* use in a web context.
*/
public class BeanInstrument extends Instrument {

private boolean canShare;

protected BeanInstrument(Instrument instrument, User currentUser) {
super(instrument);
canShare = currentUser.isAdminUser()
|| currentUser.equals(instrument.getOwner());
}

public boolean getCanShare() {
return canShare;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class InstrumentListBean extends BaseManagedBean {

private Map<Long, Integer> datasetCounts;

private List<Instrument> filteredInstruments;
private List<BeanInstrument> filteredInstruments;

private LinkedHashMap<Long, String> userNames;

Expand All @@ -69,7 +69,7 @@ public class InstrumentListBean extends BaseManagedBean {
/**
* The ID of the instrument chosen from the instrument list
*/
private Instrument chosenInstrument = null;
private BeanInstrument chosenInstrument = null;

private int shareAction = Integer.MIN_VALUE;

Expand All @@ -94,15 +94,16 @@ public String start() {
*
* @return The instruments owned by the current user
*/
public List<Instrument> getInstrumentList() {
return getInstruments();
public List<BeanInstrument> getInstrumentList() {
return getInstruments().stream().map(i -> new BeanInstrument(i, getUser()))
.toList();
}

public List<Instrument> getFilteredInstruments() {
public List<BeanInstrument> getFilteredInstruments() {
return filteredInstruments;
}

public void setFilteredInstruments(List<Instrument> filteredInstruments) {
public void setFilteredInstruments(List<BeanInstrument> filteredInstruments) {
this.filteredInstruments = filteredInstruments;
}

Expand Down Expand Up @@ -157,7 +158,7 @@ public long getChosenInstrument() {
* The instrument ID
*/
public void setChosenInstrument(long chosenInstrument) {
for (Instrument instrument : getInstruments()) {
for (BeanInstrument instrument : getInstrumentList()) {
if (instrument.getId() == chosenInstrument) {
this.chosenInstrument = instrument;
setCurrentInstrumentId(instrument.getId());
Expand Down

0 comments on commit 0a42813

Please sign in to comment.