Skip to content

Commit

Permalink
chore: more maintainability fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumas committed Jul 17, 2024
1 parent 450be4e commit 14aa438
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 36 deletions.
20 changes: 4 additions & 16 deletions src/main/resources/default/wiki.css
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ html {
position: absolute !important;
left: 0px;
right: 0px;
background-color: #FFF;
}

.polarion-rpw-table-main {
Expand Down Expand Up @@ -1056,6 +1057,8 @@ a:hover .polarion-cross-reference-label,
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
top: -5px;
border-top-width: 8px;
}

.polarion-PlanProgressMacro-arrowTopLeft, .polarion-PlanProgressMacro-arrowTopRight, .polarion-PlansMacro-arrowTopLeft, .polarion-PlansMacro-arrowTopRight {
Expand All @@ -1065,10 +1068,7 @@ a:hover .polarion-cross-reference-label,

.polarion-PlanProgressMacro-arrowTopLeft, .polarion-PlanProgressMacro-arrowTopRight {
top: -6px;
}

.polarion-PlansMacro-arrowTopLeft, .polarion-PlansMacro-arrowTopRight {
top: -5px;
border-top-width: 11px;
}

.polarion-PlanProgressMacro-arrowBottomRight {
Expand All @@ -1079,14 +1079,6 @@ a:hover .polarion-cross-reference-label,
border-bottom-color: #3A7523;
}

.polarion-PlanProgressMacro-arrowTopLeft, .polarion-PlanProgressMacro-arrowTopRight {
border-top-width: 11px;
}

.polarion-PlansMacro-arrowTopLeft, .polarion-PlansMacro-arrowTopRight {
border-top-width: 8px;
}

.polarion-PlanProgressMacro-arrowBottomLeft, .polarion-PlanProgressMacro-arrowBottomLeftAligned, .polarion-PlanProgressMacro-arrowBottomRight {
border-bottom-width: 11px;
border-bottom-style: solid;
Expand Down Expand Up @@ -1944,10 +1936,6 @@ a:hover .polarion-cross-reference-label,
display: none;
}

.polarion-HistoryTable-mainPanel {
background-color: #FFF;
}

.polarion-HistoryTable-table {
width: 100%;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@
display: none;
}
td.action, div.action {
td.action, button.action {
border: none !important;
cursor: pointer;
vertical-align: middle !important;
text-align: center !important;
background: none;
min-width: 60px;
padding: 0 !important;
margin: 0 !important;
}
input.red-border {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/webapp/pdf-exporter/js/export-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function stylePackageSelected(stylePackage) {
displayIf("chapters", stylePackage.specificChapters);

setCheckbox("localization", stylePackage.language);
setValue("language", (stylePackage.exposeSettings && !!stylePackage.language && documentLanguage) ? documentLanguage : stylePackage.language);
setValue("language", (stylePackage.exposeSettings && stylePackage.language && documentLanguage) ? documentLanguage : stylePackage.language);
displayIf("language", stylePackage.language);

setCheckbox("selected-roles", stylePackage.linkedWorkitemRoles);
Expand Down
24 changes: 12 additions & 12 deletions src/main/resources/webapp/pdf-exporter/js/pdf-exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function ExportContext() {
? window.location.hash.substring(2, window.location.hash.indexOf("?"))
: window.location.hash.substring(2)
);
const locationParts = locationHash.match("(project/[^/]+/).*wiki/(.*)")
const locationParts = new RegExp("(project/[^/]+/).*wiki/(.*)").exec(locationHash);
if (locationParts) {
this.scope = locationParts[1]

Expand All @@ -49,7 +49,7 @@ function ExportContext() {
}

ExportContext.prototype.getProjectId = function() {
const foundValues = this.scope.match("project/(.*)/");
const foundValues = new RegExp("project/(.*)/").exec(this.scope);
return foundValues !== null ? foundValues[1] : null;
}

Expand Down Expand Up @@ -310,7 +310,7 @@ const PdfExporter = {

this.setCheckbox("popup-localization", stylePackage.language);
let languageValue;
if (stylePackage.exposeSettings && !!stylePackage.language && this.documentLanguage) {
if (stylePackage.exposeSettings && stylePackage.language && this.documentLanguage) {
languageValue = this.documentLanguage;
} else if (stylePackage.language) {
languageValue = stylePackage.language;
Expand Down Expand Up @@ -355,15 +355,16 @@ const PdfExporter = {
}).then(({response}) => {
this.actionInProgress({inProgress: false});

const pages = response.invalidPages && response.invalidPages.length;
const pages = response.invalidPages?.length;
if (pages && pages > 0) {
const pagesWord = 'page' + (pages === 1 ? '' : 's');
this.showValidationResult({
alertType: "error",
message: pages > MAX_PAGE_PREVIEWS
? `Invalid pages found. First ${MAX_PAGE_PREVIEWS} of them:`
: `${MAX_PAGE_PREVIEWS} invalid page${pages === 1 ? '' : 's'} found:`
: `${MAX_PAGE_PREVIEWS} invalid ${pagesWord} found:`
});
this.createPreviews(result);
this.createPreviews(response);
} else {
this.showValidationResult({alertType: "success", message: "All pages are valid"});
}
Expand Down Expand Up @@ -496,7 +497,7 @@ const PdfExporter = {
body: requestBody,
responseType: "json"
}).then(({response}) => {
if (response && response.containsNestedLists) {
if (response?.containsNestedLists) {
this.showNotification({alertType: "warning", message: "Document contains nested numbered lists which structures were not valid. We tried to fix this, but be aware of it."});
}
}).catch((error) => {
Expand Down Expand Up @@ -609,7 +610,7 @@ const PdfExporter = {

setSelector: function (elementId, value) {
const selector = document.getElementById(elementId);
selector.value = containsOption(selector, value) ? value : POPUP_DEFAULT_SETTING_NAME;
selector.value = this.containsOption(selector, value) ? value : POPUP_DEFAULT_SETTING_NAME;
},

setCheckbox: function (elementId, value) {
Expand Down Expand Up @@ -701,12 +702,11 @@ const PdfExporter = {
getCookie: function (name) {
const nameEQ = name + '=';
const cookiesArray = document.cookie.split(';');
for (let i = 0; i < cookiesArray.length; i++) {
let cookie = cookiesArray[i];
while (cookie.charAt(0) === ' ') {
for (let cookie of cookiesArray) {
while (cookie.startsWith(' ')) {
cookie = cookie.substring(1, cookie.length);
}
if (cookie.indexOf(nameEQ) === 0) {
if (cookie.startsWith(nameEQ)) {
return decodeURIComponent(cookie.substring(nameEQ.length, cookie.length));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/webapp/pdf-exporter/js/starter.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const PdfExporterStarter = {
inject: function () {
this.loadExtensionVersion()
.then((response) => {
this.bundleTimestamp = response && response.bundleBuildTimestampDigitsOnly;
this.bundleTimestamp = response?.bundleBuildTimestampDigitsOnly;
this.injectAll(this.bundleTimestamp ? `?bundle=${this.bundleTimestamp}` : "");
}).catch(() => {
// Fallback to load resources without timestamp in case of error
Expand Down Expand Up @@ -71,7 +71,7 @@ const PdfExporterStarter = {
injectToolbar: function (params) {
const bundleTimestampParam = this.bundleTimestamp ? `?bundle=${this.bundleTimestamp}` : "";

if (params && params.alternate) {
if (params?.alternate) {
const toolbarParent = top.document.querySelector('div.polarion-content-container div.polarion-Container div.polarion-dle-Container > div.polarion-dle-Wrapper > div.polarion-dle-RpcPanel > div.polarion-dle-MainDockPanel div.polarion-rte-ToolbarPanelWrapper table.polarion-dle-ToolbarPanel tr');
const toolbarContainer = document.createElement('td');
toolbarContainer.innerHTML = ALTERNATE_TOOLBAR_HTML.replaceAll("{BUNDLE_TIMESTAMP}", bundleTimestampParam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ void shouldGetAndReplaceCss() {

CssModel cssModel = CssModel.builder().css("my test css: {{ DOCUMENT_TITLE }} {{DOCUMENT_REVISION}} {{ REVISION }} {{ PRODUCT_NAME }} {{ PRODUCT_VERSION }} {{customField}}").build();
when(cssSettings.load("testProjectId", SettingId.fromName("testCssSetting"))).thenReturn(cssModel);
PlaceholderProcessor placeholderProcessor = new PlaceholderProcessor(pdfExporterPolarionService, liveDocHelper);
PlaceholderProcessor processor = new PlaceholderProcessor(pdfExporterPolarionService, liveDocHelper);
when(velocityEvaluator.evaluateVelocityExpressions(eq(documentData), anyString())).thenAnswer(a -> a.getArguments()[1]);
PdfConverter pdfConverter = new PdfConverter(null, null, cssSettings, null, placeholderProcessor, velocityEvaluator, null, null, null, pdfTemplateProcessor);
PdfConverter pdfConverter = new PdfConverter(null, null, cssSettings, null, processor, velocityEvaluator, null, null, null, pdfTemplateProcessor);

when(liveDocHelper.getDocumentStatus("testRevision", documentData)).thenReturn("testStatus");
when(pdfExporterPolarionService.getPolarionProductName()).thenReturn("testProductName");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected List<BufferedImage> exportAndGetAsImages(String fileName, String html)
if (pdfBytes != null) {
return getAllPagesAsImagesAndLogAsReports(fileName, pdfBytes);
} else {
logger.warn("No pdf file generated for name " + fileName);
logger.warn("No pdf file generated for name {}", fileName);
return new ArrayList<>();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void waitUntilReady(WaitStrategyTarget waitStrategyTarget) {
.untilAsserted(() -> {
logger.info("Check file existence...");
pdfFileData = waitStrategyTarget.copyFileFromContainer(filePath, InputStream::readAllBytes);
logger.info("Pdf file is ready, size = " + pdfFileData.length);
logger.info("Pdf file is ready, size = {}", pdfFileData.length);
});
}

Expand Down

0 comments on commit 14aa438

Please sign in to comment.