mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 22:15:26 +00:00
bug3484 pl print view style added + checkboxes fix in dialog
This commit is contained in:
1 parent
3bc2526639
commit
5b4acf8f44
4 files changed
+94
-85
No files matched your search
+16
-29
@@ -8,10 +8,10 @@ import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.CaptionPanel;
|
||||
import com.google.gwt.user.client.ui.Grid;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.ScrollPanel;
|
||||
@@ -31,9 +31,9 @@ public class PairingListCreationDialog extends DataEntryDialog<PairingListTempla
|
||||
private final StringMessages stringMessages;
|
||||
|
||||
private final Button applyToRacelogButton;
|
||||
private final Button cSVExportButton;
|
||||
private final Button printViewButton;
|
||||
|
||||
private final Anchor cSVExportAnchor;
|
||||
|
||||
public PairingListCreationDialog(StrippedLeaderboardDTO leaderboardDTO, final StringMessages stringMessages,
|
||||
PairingListTemplateDTO template, SailingServiceAsync sailingService) {
|
||||
super(stringMessages.pairingList(), null, stringMessages.close(), null, null, null);
|
||||
@@ -44,8 +44,12 @@ public class PairingListCreationDialog extends DataEntryDialog<PairingListTempla
|
||||
this.ensureDebugId("PairingListCreationDialog");
|
||||
|
||||
applyToRacelogButton = new Button(stringMessages.applyToRacelog());
|
||||
cSVExportButton = new Button(stringMessages.csvExport());
|
||||
printViewButton = new Button(stringMessages.printView());
|
||||
cSVExportAnchor = new Anchor(stringMessages.csvExport());
|
||||
cSVExportAnchor.ensureDebugId("CSVExportAnchor");
|
||||
cSVExportAnchor.getElement().setAttribute("href",
|
||||
"data:text/plain;charset=utf-8," + getCSVFromPairingListTemplate(getResult().getPairingListTemplate()));
|
||||
cSVExportAnchor.getElement().setAttribute("download", "pairingListTemplate.csv");
|
||||
|
||||
if (template.getCompetitorCount() != leaderboardDTO.competitorsCount) {
|
||||
this.disableApplyToRacelogs();
|
||||
@@ -126,14 +130,13 @@ public class PairingListCreationDialog extends DataEntryDialog<PairingListTempla
|
||||
getRightButtonPannel().remove(getCancelButton());
|
||||
applyToRacelogButton.getElement().getStyle().setMargin(3, Unit.PX);
|
||||
applyToRacelogButton.ensureDebugId("ApplyToRacelogButton");
|
||||
cSVExportButton.getElement().getStyle().setMargin(3, Unit.PX);
|
||||
cSVExportButton.ensureDebugId("CSVExportButton");
|
||||
printViewButton.getElement().getStyle().setMargin(3, Unit.PX);
|
||||
printViewButton.ensureDebugId("printViewButton");
|
||||
getRightButtonPannel().add(applyToRacelogButton);
|
||||
getRightButtonPannel().add(cSVExportButton);
|
||||
getRightButtonPannel().add(printViewButton);
|
||||
getRightButtonPannel().add(new HTML(stringMessages.printHint()));
|
||||
getRightButtonPannel().add(cSVExportAnchor);
|
||||
//TODO add info to UI
|
||||
// getRightButtonPannel().add(new HTML(stringMessages.printHint()));
|
||||
if (!applyToRacelogButton.isEnabled()) {
|
||||
Label label = new Label(stringMessages.blockedApplyButton());
|
||||
label.getElement().getStyle().setColor("red");
|
||||
@@ -143,9 +146,12 @@ public class PairingListCreationDialog extends DataEntryDialog<PairingListTempla
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
sailingService.fillRaceLogsFromPairingListTemplate(leaderboardDTO.getName(),
|
||||
template.getFlightMultiplier(), template.getSelectedFlightNames(),template, new AsyncCallback<Void>() {
|
||||
template.getFlightMultiplier(), template.getSelectedFlightNames(), template,
|
||||
new AsyncCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void result) { /*TODO: log successfull*/}
|
||||
public void onSuccess(Void result) {
|
||||
/* TODO: log successfull */}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
caught.printStackTrace();
|
||||
@@ -153,34 +159,15 @@ public class PairingListCreationDialog extends DataEntryDialog<PairingListTempla
|
||||
});
|
||||
}
|
||||
});
|
||||
cSVExportButton.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
downloadPairingListTemplate(getCSVFromPairingListTemplate(getResult().getPairingListTemplate()));
|
||||
}
|
||||
});
|
||||
printViewButton.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
String link = EntryPointLinkFactory.createPairingListLink(createLinkParameters());
|
||||
Window.open(link, "", "");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//TODO set Anchor link to Button (see link with settings under configure url)
|
||||
private native void downloadPairingListTemplate(String pairingListCSV)/*-{
|
||||
var dummy = document.createElement('a');
|
||||
dummy.setAttribute('href', 'data:text/plain;charset=utf-8,'
|
||||
+ encodeURIComponent(pairingListCSV));
|
||||
dummy.setAttribute('download', "pairingListTemplate.csv");
|
||||
document.body.appendChild(dummy);
|
||||
dummy.click();
|
||||
document.body.removeChild(dummy);
|
||||
}-*/;
|
||||
|
||||
private String getCSVFromPairingListTemplate(int[][] pairingListTemplate) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int[] row : pairingListTemplate) {
|
||||
|
||||
+33
-23
@@ -61,6 +61,7 @@ public class PairingListCreationSetupDialog extends AbstractPairingListCreationS
|
||||
enableOrDisableAllSelectedSeriesCheckBoxes(false, true);
|
||||
}
|
||||
} else {
|
||||
flightMultiplierTextBox.setText("1");
|
||||
enableOrDisableAllSelectedSeriesCheckBoxes(true, false);
|
||||
}
|
||||
}
|
||||
@@ -72,35 +73,15 @@ public class PairingListCreationSetupDialog extends AbstractPairingListCreationS
|
||||
current.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
|
||||
@Override
|
||||
public void onValueChange(ValueChangeEvent<Boolean> event) {
|
||||
if(event.getValue()) {
|
||||
disableSelectedSeriesCheckBoxes(leaderboardDTO);
|
||||
if (flightMultiplierCheckBox.getValue()) {
|
||||
if (Util.size(getCheckedSelectedCheckBoxes()) > 0) {
|
||||
enableOrDisableAllSelectedSeriesCheckBoxes(false, true);
|
||||
}
|
||||
} else {
|
||||
if (Util.size(getCheckedSelectedCheckBoxes()) > 1) {
|
||||
flightMultiplierCheckBox.setEnabled(false);
|
||||
} else {
|
||||
flightMultiplierCheckBox.setEnabled(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(Util.size(getCheckedSelectedCheckBoxes()) > 0) {
|
||||
|
||||
} else {
|
||||
enableOrDisableAllSelectedSeriesCheckBoxes(true, false);
|
||||
}
|
||||
if(Util.size(getCheckedSelectedCheckBoxes()) < 2) {
|
||||
flightMultiplierCheckBox.setEnabled(true);
|
||||
}
|
||||
}
|
||||
validateCheckboxes(event.getValue());
|
||||
}
|
||||
});
|
||||
current.ensureDebugId("SelectedFlightsCheckbox: " + seriesName);
|
||||
checkboxes.add(current);
|
||||
}
|
||||
selectedSeriesCheckboxes = checkboxes;
|
||||
Util.get(selectedSeriesCheckboxes, 0).setValue(true);
|
||||
validateCheckboxes(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,6 +153,32 @@ public class PairingListCreationSetupDialog extends AbstractPairingListCreationS
|
||||
this.validateAndUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private void validateCheckboxes(boolean enabled) {
|
||||
if(enabled) {
|
||||
disableSelectedSeriesCheckBoxes(leaderboardDTO);
|
||||
if (flightMultiplierCheckBox.getValue()) {
|
||||
if (Util.size(getCheckedSelectedCheckBoxes()) > 0) {
|
||||
enableOrDisableAllSelectedSeriesCheckBoxes(false, true);
|
||||
}
|
||||
} else {
|
||||
if (Util.size(getCheckedSelectedCheckBoxes()) > 1) {
|
||||
flightMultiplierCheckBox.setEnabled(false);
|
||||
} else {
|
||||
flightMultiplierCheckBox.setEnabled(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(Util.size(getCheckedSelectedCheckBoxes()) > 0) {
|
||||
|
||||
} else {
|
||||
enableOrDisableAllSelectedSeriesCheckBoxes(true, false);
|
||||
}
|
||||
if(Util.size(getCheckedSelectedCheckBoxes()) < 2) {
|
||||
flightMultiplierCheckBox.setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Iterable<String> getSeriesNamesFromAllRaces(final Iterable<RaceColumnDTO> raceColumns) {
|
||||
List<String> result = new ArrayList<>();
|
||||
@@ -245,6 +252,9 @@ public class PairingListCreationSetupDialog extends AbstractPairingListCreationS
|
||||
box.setEnabled(enabled);
|
||||
}
|
||||
} else {
|
||||
if(Util.size(getCheckedSelectedCheckBoxes())>0) {
|
||||
return;
|
||||
}
|
||||
for (CheckBox box : selectedSeriesCheckboxes) {
|
||||
box.setEnabled(enabled);
|
||||
}
|
||||
|
||||
+38
-25
@@ -8,6 +8,7 @@ import com.google.gwt.dom.client.Style.TextAlign;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.DockLayoutPanel;
|
||||
@@ -34,7 +35,7 @@ public class PairingListEntryPoint extends AbstractSailingEntryPoint {
|
||||
private PairingListContextDefinition pairingListContextDefinition;
|
||||
|
||||
private StringMessages stringmessages = StringMessages.INSTANCE;
|
||||
|
||||
|
||||
@Override
|
||||
protected void doOnModuleLoad() {
|
||||
super.doOnModuleLoad();
|
||||
@@ -59,7 +60,7 @@ public class PairingListEntryPoint extends AbstractSailingEntryPoint {
|
||||
mainPanel.addNorth(header, 75);
|
||||
|
||||
Button btn = new Button("Print");
|
||||
|
||||
|
||||
VerticalPanel contentPanel = new VerticalPanel();
|
||||
contentPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
|
||||
contentPanel.add(btn);
|
||||
@@ -67,20 +68,24 @@ public class PairingListEntryPoint extends AbstractSailingEntryPoint {
|
||||
contentPanel.getElement().getStyle().setProperty("marginTop", "15px");
|
||||
contentPanel.getElement().getStyle().setProperty("marginBottom", "15px");
|
||||
scrollPanel.add(contentPanel);
|
||||
|
||||
|
||||
sailingService.getPairingListFromRaceLogs(pairingListContextDefinition.getLeaderboardName(),
|
||||
new AsyncCallback<PairingListDTO>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(PairingListDTO result) {
|
||||
VerticalPanel pairingListPanel = createPairingListPanel(result);
|
||||
contentPanel.add(pairingListPanel);
|
||||
contentPanel.add(pairingListPanel);
|
||||
|
||||
btn.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
//TODO use safe html encoding
|
||||
printPairingListGrid("<h2>" + pairingListContextDefinition.getLeaderboardName()
|
||||
+ "</h2>" + pairingListPanel.asWidget().getElement().getInnerHTML());
|
||||
printPairingListGrid("<div class='printHeader'><img src='images/home/logo-small@2x.png' </img>"
|
||||
+ "<b class='title'>"
|
||||
+ SafeHtmlUtils.fromString(pairingListContextDefinition.getLeaderboardName())
|
||||
.asString()
|
||||
+ "</b></div>" + pairingListPanel.asWidget().getElement().getInnerHTML());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -180,6 +185,7 @@ public class PairingListEntryPoint extends AbstractSailingEntryPoint {
|
||||
flightIndexInGrid++;
|
||||
}
|
||||
|
||||
|
||||
VerticalPanel pairingListPanel = new VerticalPanel();
|
||||
pairingListPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
|
||||
pairingListPanel.add(pairingListGrid);
|
||||
@@ -187,40 +193,47 @@ public class PairingListEntryPoint extends AbstractSailingEntryPoint {
|
||||
pairingListPanel.ensureDebugId("PairingListPanel");
|
||||
pairingListPanel.getElement().getStyle().setProperty("marginTop", "15px");
|
||||
|
||||
ScrollPanel result = new ScrollPanel();
|
||||
result.add(pairingListPanel);
|
||||
|
||||
return pairingListPanel;
|
||||
}
|
||||
|
||||
//TODO search for gwt API (Window, Document)
|
||||
private native void printPairingListGrid(String pageHTMLContent) /*-{
|
||||
|
||||
var frame = $doc.getElementById('__gwt_historyFrame');
|
||||
var frameID = '__gwt_historyFrame';
|
||||
var frame = $doc.getElementById(frameID);
|
||||
if (!frame) {
|
||||
$wnd.alert("Error: Can not find frame '" + frameID + "'");
|
||||
return;
|
||||
}
|
||||
frame = frame.contentWindow;
|
||||
var doc = frame.document;
|
||||
doc.open();
|
||||
doc.write(pageHTMLContent);
|
||||
var document = frame.document;
|
||||
document.open();
|
||||
document.write(pageHTMLContent);
|
||||
|
||||
//adding style to doc
|
||||
var css = "body { background: #fff; font-family: 'Open Sans', Arial, Verdana, sans-serif;"
|
||||
+ "line-height: 1; font-weight: 400; border: 0}"
|
||||
+ "h2 { text-align: center }"
|
||||
+ "table { border-collapse: collapse; border: 1px solid black; margin: auto}"
|
||||
+ "td { font-size: 15px; }"
|
||||
head = doc.head || doc.getElementsByTagName('head')[0], style = doc
|
||||
.createElement('style');
|
||||
+ "line-height: 1; font-weight: 400; border: 0 }"
|
||||
+ ".title { font-size: 18px; text-align: center; float: right; color: #f6f9fc; margin-bottom: 0.466666666666667em; margin-right: 0.466666666666667em }"
|
||||
+ "img { max-height: 2em; float:left; margin-top: 0.466666666666667em; margin-left: 0.466666666666667em }"
|
||||
+ ".printHeader { font-size: 1rem; background: #333; border-bottom: 0.333333333333333em solid #f0ab00;"
|
||||
+ "height: 3.333333333333333em; line-height: 3em; width: 100%; overflow: hidden;}"
|
||||
+ "table { border-collapse: collapse; border: 1px solid black; margin: auto; width: 100%}"
|
||||
+ "td { font-size: 1em; }"
|
||||
head = document.head || document.getElementsByTagName('head')[0];
|
||||
style = document.createElement('style');
|
||||
style.type = 'text/css';
|
||||
if (style.styleSheet) {
|
||||
style.styleSheet.cssText = css;
|
||||
} else {
|
||||
style.appendChild(doc.createTextNode(css));
|
||||
style.appendChild(document.createTextNode(css));
|
||||
}
|
||||
head.appendChild(style);
|
||||
|
||||
doc.close();
|
||||
frame.focus();
|
||||
frame.print();
|
||||
document.close();
|
||||
|
||||
setTimeout(function() {
|
||||
frame.focus();
|
||||
frame.print();
|
||||
}, 500);
|
||||
}-*/;
|
||||
|
||||
}
|
||||
@@ -33,17 +33,16 @@ public class PairingListImpl<Flight, Group, Competitor,Boat> implements PairingL
|
||||
final int groupIndex = Util.indexOf(competitionFormat.getGroups(flight), group);
|
||||
final int groupCount =Util.size(competitionFormat.getGroups(flight));
|
||||
final ArrayList<Integer> competitorIndicesInRace = new ArrayList<>();
|
||||
|
||||
for (Integer integer : competitorIndices[flightIndex*groupCount+groupIndex]) {
|
||||
competitorIndicesInRace.add(integer);
|
||||
}
|
||||
|
||||
final List<Pair<Competitor,Boat>> result = new ArrayList<>();
|
||||
for(int slot=0;slot<competitorIndicesInRace.size();slot++){
|
||||
if(competitorIndicesInRace.get(slot)>=0){
|
||||
result.add(new Pair<Competitor, Boat>(competitors.get(competitorIndicesInRace.get(slot)), boats.get(slot)));
|
||||
}else{
|
||||
result.add(new Pair<Competitor, Boat>(null, boats.get(slot)));
|
||||
final List<Pair<Competitor, Boat>> result = new ArrayList<>();
|
||||
for (int boatSlotInRace = 0; boatSlotInRace < competitorIndicesInRace.size(); boatSlotInRace++) {
|
||||
if (competitorIndicesInRace.get(boatSlotInRace) >= 0) {
|
||||
result.add(new Pair<Competitor, Boat>(competitors.get(competitorIndicesInRace.get(boatSlotInRace)),
|
||||
boats.get(boatSlotInRace)));
|
||||
} else {
|
||||
result.add(new Pair<Competitor, Boat>(null, boats.get(boatSlotInRace)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in new issue
Block a user