Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove ExportParams.DocumentType.MIXED from javascript code #302

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ch.sbb.polarion.extension.pdf_exporter.widgets;

import ch.sbb.polarion.extension.pdf_exporter.rest.model.conversion.DocumentType;
import com.polarion.alm.server.api.model.rp.widget.AbstractWidgetRenderer;
import com.polarion.alm.server.api.model.rp.widget.BottomQueryLinksBuilder;
import com.polarion.alm.shared.api.model.ModelObject;
import com.polarion.alm.shared.api.model.PrototypeEnum;
import com.polarion.alm.shared.api.model.rp.parameter.CompositeParameter;
import com.polarion.alm.shared.api.model.rp.parameter.DataSet;
import com.polarion.alm.shared.api.model.rp.parameter.DataSetParameter;
Expand Down Expand Up @@ -30,7 +32,7 @@ public class BulkPdfExportWidgetRenderer extends AbstractWidgetRenderer {
private final int topItems;
@NotNull
private final IterableWithSize<Field> columns;
private final String dataType;
private final @NotNull PrototypeEnum itemsPrototype;

public BulkPdfExportWidgetRenderer(@NotNull RichPageWidgetCommonContext context) {
super(context);
Expand All @@ -40,12 +42,7 @@ public BulkPdfExportWidgetRenderer(@NotNull RichPageWidgetCommonContext context)
String sort = sortByParameter.asLuceneSortString();
this.dataSet = dataSetParameter.getFor().sort(sort).revision(null);
this.items = this.dataSet.items();
switch (dataSetParameter.prototype()) {
case Document: dataType = "Documents"; break;
case RichPage: dataType = "Pages"; break;
case TestRun: dataType = "Test Runs"; break;
default: dataType = "Unknown"; break;
}
itemsPrototype = dataSetParameter.prototype();
this.columns = columnsParameter.fields();

CompositeParameter advanced = context.parameter("advanced");
Expand All @@ -59,6 +56,24 @@ public BulkPdfExportWidgetRenderer(@NotNull RichPageWidgetCommonContext context)

}

private @NotNull DocumentType getItemsType(@NotNull PrototypeEnum prototype) {
return switch (prototype) {
case Document -> DocumentType.LIVE_DOC;
case RichPage -> DocumentType.LIVE_REPORT;
case TestRun -> DocumentType.TEST_RUN;
default -> throw new IllegalStateException("Unexpected value: " + prototype);
};
}

private @NotNull String getWidgetItemsType(@NotNull PrototypeEnum prototype) {
return switch (prototype) {
case Document -> "Documents";
case RichPage -> "Pages";
case TestRun -> "Test Runs";
default -> throw new IllegalStateException("Unexpected value: " + prototype);
};
}

protected void render(@NotNull HtmlFragmentBuilder builder) {
if (this.topItems < 0) {
builder.html(this.context.renderWarning(this.localization.getString("richpages.widget.table.invalidTopValue")));
Expand All @@ -68,14 +83,15 @@ protected void render(@NotNull HtmlFragmentBuilder builder) {

HtmlTagBuilder header = wrap.append().tag().div();
header.attributes().className("header");
header.attributes().byName("document-type", getItemsType(itemsPrototype).name());

HtmlTagBuilder title = header.append().tag().h3();
title.append().text(dataType);
title.append().text(getWidgetItemsType(itemsPrototype));

renderExportButton(header);

HtmlTagBuilder description = header.append().tag().div();
description.append().tag().p().append().text(String.format("Please select %s below which you want to export and click button above", dataType));
description.append().tag().p().append().text(String.format("Please select %s below which you want to export and click button above", getWidgetItemsType(itemsPrototype)));

HtmlTagBuilder exportItems = wrap.append().tag().div();
exportItems.attributes().className("export-items");
Expand Down
22 changes: 11 additions & 11 deletions src/main/resources/webapp/pdf-exporter/html/popupForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

<div class="flex-container">
<div class="flex-column">
<div class='property-wrapper hidden visible-for-live-doc visible-for-test-run'>
<div class='property-wrapper hidden visible-for-LIVE_DOC visible-for-TEST_RUN'>
<label for='popup-fit-to-page'>
<input id='popup-fit-to-page' type='checkbox'/>
Fit images and tables to page
Expand All @@ -104,7 +104,7 @@
Follow HTML presentational hints
</label>
</div>
<div class='property-wrapper hidden visible-for-live-doc'>
<div class='property-wrapper hidden visible-for-LIVE_DOC'>
<label for='popup-enable-comments-rendering'>
<input id='popup-enable-comments-rendering' type='checkbox'/>
Comments rendering
Expand All @@ -118,13 +118,13 @@
</div>
</div>
<div class="flex-column">
<div class='property-wrapper hidden visible-for-live-doc'>
<div class='property-wrapper hidden visible-for-LIVE_DOC'>
<label for='popup-cut-empty-chapters'>
<input id='popup-cut-empty-chapters' type='checkbox'/>
Cut empty chapters (any level)
</label>
</div>
<div class='property-wrapper hidden visible-for-live-doc'>
<div class='property-wrapper hidden visible-for-LIVE_DOC'>
<label for='popup-cut-empty-wi-attributes'>
<input id='popup-cut-empty-wi-attributes' type='checkbox'/>
Cut empty Workitem attributes
Expand All @@ -136,13 +136,13 @@
Cut local Polarion URLs
</label>
</div>
<div class='property-wrapper hidden visible-for-live-doc'>
<div class='property-wrapper hidden visible-for-LIVE_DOC'>
<label for='popup-mark-referenced-workitems'>
<input id='popup-mark-referenced-workitems' type='checkbox'/>
Mark referenced Workitems
</label>
</div>
<div class='property-wrapper hidden visible-for-test-run visible-for-mixed'>
<div class='property-wrapper hidden visible-for-TEST_RUN'>
<label for='popup-download-attachments'>
<input id='popup-download-attachments' onchange='document.getElementById("popup-attachments-filter").style.visibility = this.checked ? "visible" : "hidden"' type='checkbox'/>
Download attachments
Expand All @@ -154,14 +154,14 @@

<div class="flex-container">
<div class="flex-column">
<div class='property-wrapper hidden visible-for-live-doc'>
<div class='property-wrapper hidden visible-for-LIVE_DOC'>
<label for='popup-custom-list-styles'>
<input id='popup-custom-list-styles' onchange='document.getElementById("popup-numbered-list-styles").style.visibility = this.checked ? "visible" : "hidden"' type='checkbox'/>
Custom styles of numbered lists
</label>
<input id='popup-numbered-list-styles' placeholder='eg. 1ai' style='width: 84px' type='text'/>
</div>
<div class='property-wrapper hidden visible-for-live-doc'>
<div class='property-wrapper hidden visible-for-LIVE_DOC'>
<label for='popup-specific-chapters'>
<input id='popup-specific-chapters' onchange='document.getElementById("popup-chapters").style.visibility = this.checked ? "visible" : "hidden"' type='checkbox'/>
Specific higher level chapters
Expand All @@ -170,7 +170,7 @@
</div>
</div>
<div class="flex-column">
<div class='property-wrapper hidden visible-for-live-doc'>
<div class='property-wrapper hidden visible-for-LIVE_DOC'>
<label for='popup-localization'>
<input id='popup-localization' onchange='document.getElementById("popup-language").style.visibility = this.checked ? "visible" : "hidden"' type='checkbox'/>
Localize enums
Expand All @@ -181,7 +181,7 @@
<option value='it'>Italiano</option>
</select>
</div>
<div class='property-wrapper hidden visible-for-live-doc'>
<div class='property-wrapper hidden visible-for-LIVE_DOC'>
<label for='popup-selected-roles' style="align-self: flex-start;">
<input id='popup-selected-roles' onchange='document.getElementById("popup-roles-selector").style.display = this.checked ? "inline-block" : "none"' type='checkbox'/>
Specific Workitem roles
Expand All @@ -192,7 +192,7 @@
</div>
</div>

<div class='property-wrapper not-visible-for-mixed'>
<div class='property-wrapper not-visible-for-BULK'>
<label for='popup-filename'>File name:</label>
<input id='popup-filename' type='text' style="width: 594px" />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ export default class ExportContext {
locationPath = undefined;
revision = undefined;
documentType = undefined;
exportType = undefined;
urlQueryParameters = undefined;
bulkExportWidget = undefined;

constructor({documentType = ExportParams.DocumentType.LIVE_DOC, polarionLocationHash = window.location.hash, bulkExportWidget}) {
constructor({documentType = ExportParams.DocumentType.LIVE_DOC, exportType = ExportParams.ExportType.SINGLE, polarionLocationHash = window.location.hash, bulkExportWidget}) {
this.documentType = documentType;
this.exportType = exportType;

const urlPathAndSearchParams = getPathAndQueryParams(polarionLocationHash);
const normalizedPolarionLocationHash = urlPathAndSearchParams.path;
Expand All @@ -18,7 +20,7 @@ export default class ExportContext {
const scope = getScope(normalizedPolarionLocationHash);
this.projectId = getProjectId(scope);

if (this.documentType !== ExportParams.DocumentType.MIXED) {
if (this.exportType !== ExportParams.ExportType.BULK) {
this.locationPath = getPath(normalizedPolarionLocationHash, scope);

// if "testrun" or "testruns" is present return undefined
Expand Down Expand Up @@ -129,6 +131,10 @@ export default class ExportContext {
return this.documentType;
}

getExportType() {
return this.exportType;
}

getUrlQueryParameters() {
return this.urlQueryParameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export default class ExportParams {
LIVE_REPORT: 'LIVE_REPORT',
TEST_RUN: 'TEST_RUN',
WIKI_PAGE: 'WIKI_PAGE',
MIXED: 'MIXED',
};

static Orientation = {
Expand All @@ -25,6 +24,11 @@ export default class ExportParams {
LEDGER: 'LEDGER',
};

static ExportType = {
SINGLE: 'SINGLE',
BULK: 'BULK',
}

constructor(builder) {
this.projectId = builder.projectId;
this.locationPath = builder.locationPath;
Expand Down
68 changes: 43 additions & 25 deletions src/main/resources/webapp/pdf-exporter/js/pdf-exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,48 @@ const PdfExporter = {

this.hideAlerts();
this.loadFormData();
switch (this.exportContext.getDocumentType()) {
case ExportParams.DocumentType.LIVE_DOC:
document.querySelectorAll(".modal__container.pdf-exporter .property-wrapper.visible-for-live-doc")
.forEach(propertyBlock => propertyBlock.style.display = "flex");
break;
case ExportParams.DocumentType.TEST_RUN:
document.querySelectorAll(".modal__container.pdf-exporter .property-wrapper.visible-for-test-run")
.forEach(propertyBlock => propertyBlock.style.display = "flex");
break;
case ExportParams.DocumentType.MIXED:
document.querySelectorAll(".modal__container.pdf-exporter .property-wrapper.not-visible-for-mixed")
.forEach(propertyBlock => propertyBlock.style.display = "none");
document.querySelectorAll(".modal__container.pdf-exporter .property-wrapper.visible-for-mixed")
.forEach(propertyBlock => propertyBlock.style.display = "flex");
break;

const Action = {
SHOW: "flex",
HIDE: "none",
getOpposite(value) {
return value === this.HIDE ? this.SHOW : this.HIDE;
}
}
function toggleAllOptionalPropertyBlocks(action) {
const types = [
ExportParams.DocumentType.LIVE_DOC,
ExportParams.DocumentType.LIVE_REPORT,
ExportParams.DocumentType.TEST_RUN,
ExportParams.DocumentType.WIKI_PAGE,
ExportParams.ExportType.SINGLE,
ExportParams.ExportType.BULK,
];
types.forEach(documentType => {
toggleOptionalPropertyBlocks(documentType, action);
});
}
function toggleOptionalPropertyBlocks(documentType, action) {
document.querySelectorAll(`.modal__container.pdf-exporter .property-wrapper.visible-for-${documentType}`)
.forEach(propertyBlock => propertyBlock.style.display = action);
document.querySelectorAll(`.modal__container.pdf-exporter .property-wrapper.not-visible-for-${documentType}`)
.forEach(propertyBlock => propertyBlock.style.display = Action.getOpposite(action));
}

toggleAllOptionalPropertyBlocks(Action.HIDE);
toggleOptionalPropertyBlocks(this.exportContext.getDocumentType(), Action.SHOW);
toggleOptionalPropertyBlocks(this.exportContext.getExportType(), Action.SHOW);

MicroModal.show(POPUP_ID);
},

openPopupForBulkExport: function (bulkExportWidget) {
const documentType = bulkExportWidget?.querySelector(".polarion-PdfExporter-BulkExportWidget .header")?.getAttribute("document-type");

PdfExporter.openPopup({ exportContext: new ExportContext(
{
documentType: ExportParams.DocumentType.MIXED,
documentType: documentType,
exportType: ExportParams.ExportType.BULK,
bulkExportWidget: bulkExportWidget
})
});
Expand Down Expand Up @@ -150,7 +169,7 @@ const PdfExporter = {
loadLinkRoles: function (exportContext) {
if (exportContext.getDocumentType() === ExportParams.DocumentType.LIVE_REPORT
|| exportContext.getDocumentType() === ExportParams.DocumentType.TEST_RUN
|| exportContext.getDocumentType() === ExportParams.DocumentType.MIXED) {
|| exportContext.getExportType() === ExportParams.ExportType.BULK) {
return Promise.resolve(); // Skip loading link roles for reports, test runs and bulk export
}

Expand All @@ -174,7 +193,7 @@ const PdfExporter = {
},

loadFileName: function (exportContext) {
if (exportContext.getDocumentType() === ExportParams.DocumentType.MIXED) {
if (exportContext.getExportType() === ExportParams.ExportType.BULK) {
return Promise.resolve(); // Skip loading file name for bulk export
}

Expand Down Expand Up @@ -209,7 +228,7 @@ const PdfExporter = {
loadDocumentLanguage: function (exportContext) {
if (exportContext.documentType === ExportParams.DocumentType.LIVE_REPORT
|| exportContext.documentType === ExportParams.DocumentType.TEST_RUN
|| exportContext.getDocumentType() === ExportParams.DocumentType.MIXED) {
|| exportContext.getExportType() === ExportParams.ExportType.BULK) {
return Promise.resolve(); // Skip loading language for reports, test runs and bulk export
}

Expand All @@ -230,7 +249,7 @@ const PdfExporter = {

loadStylePackages: function (exportContext) {
let stylePackagesUrl;
if (exportContext.getDocumentType() === ExportParams.DocumentType.MIXED) {
if (exportContext.getExportType() === ExportParams.ExportType.BULK) {
stylePackagesUrl = `/polarion/pdf-exporter/rest/internal/settings/style-package/names?scope=${exportContext.getScope()}`;
} else {
stylePackagesUrl = `/polarion/pdf-exporter/rest/internal/settings/style-package/suitable-names`
Expand Down Expand Up @@ -339,10 +358,10 @@ const PdfExporter = {
});
}
}
ExportCommon.displayIf("popup-roles-selector", this.exportContext.getDocumentType() !== ExportParams.DocumentType.MIXED && stylePackage.linkedWorkitemRoles, "inline-block");
ExportCommon.displayIf("popup-roles-selector", this.exportContext.getExportType() !== ExportParams.ExportType.BULK && stylePackage.linkedWorkitemRoles, "inline-block");

ExportCommon.displayIf("popup-style-package-content", stylePackage.exposeSettings);
ExportCommon.displayIf("popup-page-width-validation", this.exportContext.getDocumentType() !== ExportParams.DocumentType.MIXED && stylePackage.exposePageWidthValidation);
ExportCommon.displayIf("popup-page-width-validation", this.exportContext.getExportType() !== ExportParams.ExportType.BULK && stylePackage.exposePageWidthValidation);

ExportCommon.setCheckbox("popup-download-attachments", stylePackage.attachmentsFilter);
ExportCommon.setValue("popup-attachments-filter", stylePackage.attachmentsFilter || "");
Expand Down Expand Up @@ -438,7 +457,7 @@ const PdfExporter = {
return;
}

if (this.exportContext.getBulkExportWidget() && this.exportContext.getDocumentType() === ExportParams.DocumentType.MIXED) {
if (this.exportContext.getBulkExportWidget() && this.exportContext.getExportType() === ExportParams.ExportType.BULK) {
this.closePopup();
BulkPdfExporter.openPopup(this.exportContext.getBulkExportWidget(), exportParams);
return;
Expand Down Expand Up @@ -526,7 +545,6 @@ const PdfExporter = {
buildExportParams: function (selectedChapters, numberedListStyles, selectedRoles, fileName, attachmentsFilter) {
const live_doc = this.exportContext.getDocumentType() === ExportParams.DocumentType.LIVE_DOC;
const test_run = this.exportContext.getDocumentType() === ExportParams.DocumentType.TEST_RUN;
const mixed = this.exportContext.getDocumentType() === ExportParams.DocumentType.MIXED;
return new ExportParams.Builder(this.exportContext.getDocumentType())
.setProjectId(this.exportContext.getProjectId())
.setLocationPath(this.exportContext.getLocationPath())
Expand All @@ -553,7 +571,7 @@ const PdfExporter = {
.setLinkedWorkitemRoles(selectedRoles)
.setFileName(fileName)
.setUrlQueryParameters(this.exportContext.getUrlQueryParameters())
.setAttachmentsFilter((test_run || mixed) && attachmentsFilter ? attachmentsFilter : null)
.setAttachmentsFilter(test_run && attachmentsFilter ? attachmentsFilter : null)
.build();
},

Expand Down
Loading