Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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,6 +1,8 @@
/* eslint-disable */
import "../../../testing/globals.definitions";
import {validateRequiredFields} from 'validation';
import CreateReportButtonComponent from "./create-report-button";
import { describe, it, expect, jest } from '@jest/globals';

describe('create-report-button', () => {
it('does not submit form if no checkboxes are checked', () => {
Expand Down
13 changes: 7 additions & 6 deletions src/frontend/components/button/lib/rename-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ declare global {
*/
class RenameButton {
private readonly dataClass = 'rename-button';
private value: string;
private value!: string;

/**
* Attach event to button
* @param {HTMLButtonElement} button Button to attach the event to
*/
constructor(button: HTMLButtonElement) {
if(!button) return;
const $button = $(button);
if ($button.data(this.dataClass) === 'true') return;
const data = $button.data('fieldId');
Expand Down Expand Up @@ -126,8 +127,8 @@ class RenameButton {
$(`#rename-confirm-${id}`)
.removeClass('hidden')
.attr('aria-hidden', null)
.on('click', (e) => {
this.triggerRename(id, ev.target, e)
.on('click', () => {
this.triggerRename(id, ev.target)
});
$(`#rename-cancel-${id}`)
.removeClass('hidden')
Expand Down Expand Up @@ -158,7 +159,7 @@ class RenameButton {
* @param {JQuery<HTMLButtonElement>} button The button that was clicked
* @param {JQuery.BlurEvent} e The blur event
*/
private triggerRename(id: number, button: JQuery<HTMLButtonElement>, e: JQuery.Event) {
private triggerRename(id: number, button: JQuery<HTMLButtonElement>) {
const previousValue = $(`#current-${id}`).text();
const extension = '.' + previousValue.split('.').pop();
const newName = this.value.endsWith(extension) ? this.value : this.value + extension;
Expand Down Expand Up @@ -190,8 +191,8 @@ class RenameButton {
if(typeof jQuery !== 'undefined') {
(function ($) {
$.fn.renameButton = function () {
return this.each(function (_: unknown, el: HTMLButtonElement) {
new RenameButton(el);
return this.each((_, el) => {
new RenameButton(el as HTMLButtonElement);
});
};
})(jQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AutosaveComponent extends AutosaveBase {
*/
async initAutosave() {
const $field = $(this.element);
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
const self = this;
if ($field.data('is-readonly')) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class DocumentComponent {
if(JSON.parse(e as string)?.message)
e = JSON.parse(e as string).message;
this.handler.addError(e);
logging.error("Failed to upload file:", e);
});
});
}
Expand Down Expand Up @@ -126,6 +127,7 @@ class DocumentComponent {
.hide();
});
} catch (e) {
logging.error("Failed to upload file:", e);
this.showException(e instanceof Error || "message" in e ? e.message : e as string ?? e.toString());
}
}
Expand Down Expand Up @@ -191,6 +193,7 @@ class DocumentComponent {
this.showException(e);
const current = $(`#current-${fileId}`);
current.text(oldName);
logging.error("Failed to rename file:", e);
}
}

Expand Down
32 changes: 18 additions & 14 deletions src/frontend/js/lib/logging.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
import { uploadMessage } from "util/scriptErrorHandler";

class Logging {
/**
* Create a new Logging instance.
*/
constructor() {
this.allowLogging =
window.test ||
location.hostname === 'localhost' ||
location.hostname === '127.0.0.1' ||
location.hostname.endsWith('.peek.digitpaint.nl')
location.hostname.endsWith('.peek.digitpaint.nl');
}

log(...message) {
if (this.allowLogging) {
console.log(message)
console.log(...message)
} else {
const message = this.formatMessage('log', ...message)
uploadMessage(message)
const msg = this.formatMessage('log', ...message)
uploadMessage(msg)
}
}

info(...message) {
if (this.allowLogging) {
console.info(message)
console.info(...message)
} else {
const message = this.formatMessage('info', ...message)
uploadMessage(message)
const msg = this.formatMessage('info', ...message)
uploadMessage(msg)
}
}

warn(...message) {
if (this.allowLogging) {
console.warn(message)
console.warn(...message)
} else {
const message = this.formatMessage('warn', ...message)
uploadMessage(message)
const msg = this.formatMessage('warn', ...message)
uploadMessage(msg)
}
}

error(...message) {
if (this.allowLogging) {
console.error(message)
console.error(...message)
} else {
const message = this.formatMessage('error', ...message)
uploadMessage(message)
const msg = this.formatMessage('error', ...message)
uploadMessage(msg)
}
}

formatMessage(type, ...message) {
let output = type + ': ';
for (let i = 0; i < message.length; i++) {
if(!message[i]) continue;
if (typeof message[i] === 'object') {
output += JSON.stringify(message[i]);
} else {
Expand All @@ -60,5 +64,5 @@ class Logging {
}
}

const logging = new Logging
const logging = new Logging();
export { logging }

This file was deleted.

14 changes: 11 additions & 3 deletions src/frontend/js/lib/util/scriptErrorHandler/lib/MessageUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ export const uploadMessage = async (message: string) => {
description: message,
url: window.location.href
};
const uploader = new Uploader('/api/script_error', 'POST');
const messageUploader = new MessageUploader(uploader);
const messageUploader = MessageUploader.instance;
return await messageUploader.uploadMessage(body.description);
};

export class MessageUploader {
class MessageUploader {
private static _instance: MessageUploader;

constructor(private uploader: Uploader) {
}

static get instance(): MessageUploader {
if (!this._instance) {
this._instance = new MessageUploader(new Uploader('/api/script_error', 'POST'));
}
return this._instance;
}

async uploadMessage(description: string): Promise<void> {
const csrf_token = document.body.dataset.csrf;
const body = {
Expand Down
Loading