Merge remote-tracking branch 'template/develop' into develop
This commit is contained in:
commit
35207aa6d4
|
@ -0,0 +1,114 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"parserOptions": {
|
||||
"project": [
|
||||
"./tsconfig.json",
|
||||
"./tsconfig.test.json",
|
||||
"./tsconfig.frontend.json"
|
||||
]
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"rules": {
|
||||
"indent": [
|
||||
"error",
|
||||
4,
|
||||
{
|
||||
"SwitchCase": 1
|
||||
}
|
||||
],
|
||||
"no-trailing-spaces": "error",
|
||||
"max-len": [
|
||||
"error",
|
||||
{
|
||||
"code": 120,
|
||||
"ignoreStrings": true,
|
||||
"ignoreTemplateLiterals": true,
|
||||
"ignoreRegExpLiterals": true
|
||||
}
|
||||
],
|
||||
"semi": "off",
|
||||
"@typescript-eslint/semi": [
|
||||
"error"
|
||||
],
|
||||
"no-extra-semi": "error",
|
||||
"eol-last": "error",
|
||||
"comma-dangle": "off",
|
||||
"@typescript-eslint/comma-dangle": [
|
||||
"error",
|
||||
{
|
||||
"arrays": "always-multiline",
|
||||
"objects": "always-multiline",
|
||||
"imports": "always-multiline",
|
||||
"exports": "always-multiline",
|
||||
"functions": "always-multiline",
|
||||
"enums": "always-multiline",
|
||||
"generics": "always-multiline",
|
||||
"tuples": "always-multiline"
|
||||
}
|
||||
],
|
||||
"no-extra-parens": "off",
|
||||
"@typescript-eslint/no-extra-parens": [
|
||||
"error"
|
||||
],
|
||||
"no-nested-ternary": "error",
|
||||
"@typescript-eslint/no-inferrable-types": "off",
|
||||
"@typescript-eslint/explicit-module-boundary-types": "error",
|
||||
"@typescript-eslint/no-unnecessary-condition": "error",
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
"argsIgnorePattern": "^_"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-non-null-assertion": "error",
|
||||
"no-useless-return": "error",
|
||||
"no-useless-constructor": "off",
|
||||
"@typescript-eslint/no-useless-constructor": [
|
||||
"error"
|
||||
],
|
||||
"no-return-await": "off",
|
||||
"@typescript-eslint/return-await": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"@typescript-eslint/explicit-member-accessibility": [
|
||||
"error",
|
||||
{
|
||||
"accessibility": "explicit"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-floating-promises": "error"
|
||||
},
|
||||
"ignorePatterns": [
|
||||
"jest.config.js",
|
||||
"webpack.config.js",
|
||||
"dist/**/*",
|
||||
"public/**/*",
|
||||
"config/**/*"
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"test/**/*"
|
||||
],
|
||||
"rules": {
|
||||
"max-len": [
|
||||
"error",
|
||||
{
|
||||
"code": 120,
|
||||
"ignoreTemplateLiterals": true,
|
||||
"ignoreRegExpLiterals": true,
|
||||
"ignoreStrings": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"bundles": {
|
||||
"app": "js/app.js",
|
||||
"app": "ts/app.ts",
|
||||
"register": "js/register.js",
|
||||
"layout": "sass/layout.scss",
|
||||
"error": "sass/error.scss",
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.querySelectorAll('.copyable-text').forEach(el => {
|
||||
const contentEl = el.querySelector('.content');
|
||||
contentEl.addEventListener('click', () => {
|
||||
window.getSelection().selectAllChildren(contentEl);
|
||||
});
|
||||
el.querySelector('.copy-button').addEventListener('click', () => {
|
||||
window.getSelection().selectAllChildren(contentEl);
|
||||
document.execCommand('copy');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,29 +0,0 @@
|
|||
// For labels to update their state (css selectors based on the value attribute)
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.querySelectorAll('input').forEach(el => {
|
||||
if (el.type !== 'checkbox') {
|
||||
el.setAttribute('value', el.value);
|
||||
el.addEventListener('change', () => {
|
||||
el.setAttribute('value', el.value);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
window.applyFormMessages = function (formElement, messages) {
|
||||
for (const fieldName of Object.keys(messages)) {
|
||||
const field = formElement.querySelector('#field-' + fieldName);
|
||||
let parent = field.parentElement;
|
||||
while (parent && !parent.classList.contains('form-field')) parent = parent.parentElement;
|
||||
|
||||
if (field) {
|
||||
let err = field.querySelector('.error');
|
||||
if (!err) {
|
||||
err = document.createElement('div');
|
||||
err.classList.add('error');
|
||||
parent.insertBefore(err, parent.querySelector('.hint') || parent);
|
||||
}
|
||||
err.innerHTML = `<i data-feather="x-circle"></i> ${messages[fieldName].message}`;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const menuButton = document.getElementById('menu-button');
|
||||
const mainMenu = document.getElementById('main-menu');
|
||||
|
||||
menuButton.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
mainMenu.classList.toggle('open');
|
||||
});
|
||||
|
||||
mainMenu.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
document.addEventListener('click', () => {
|
||||
mainMenu.classList.remove('open');
|
||||
});
|
||||
});
|
|
@ -9,6 +9,7 @@ $defaultTextColor: #ffffff;
|
|||
$headerBackground: darken($primary, 7.5%);
|
||||
$footerBackground: lighten($headerBackground, 1%);
|
||||
$panelBackground: lighten($headerBackground, 1%);
|
||||
$inputBackground: darken($panelBackground, 4%);
|
||||
|
||||
$info: #4499ff;
|
||||
$infoText: darken($info, 42%);
|
||||
|
|
|
@ -49,6 +49,11 @@ body {
|
|||
|
||||
text-transform: initial;
|
||||
font-weight: initial;
|
||||
|
||||
&.top {
|
||||
top: auto;
|
||||
bottom: calc(100% + 8px);
|
||||
}
|
||||
}
|
||||
|
||||
&:hover, &:active {
|
||||
|
@ -61,7 +66,8 @@ body {
|
|||
}
|
||||
}
|
||||
|
||||
header {
|
||||
body > header {
|
||||
z-index: 50;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
|
@ -101,6 +107,7 @@ header {
|
|||
font-size: 20px;
|
||||
|
||||
li {
|
||||
position: relative;
|
||||
list-style: none;
|
||||
|
||||
a, button {
|
||||
|
@ -140,6 +147,34 @@ header {
|
|||
align-items: center;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
&.auth-user {
|
||||
img {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 3px;
|
||||
margin-right: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.dropdown {
|
||||
position: absolute;
|
||||
z-index: -1;
|
||||
top: 100%;
|
||||
right: 0;
|
||||
|
||||
white-space: nowrap;
|
||||
background: $headerBackground;
|
||||
border-radius: 0 0 3px 3px;
|
||||
|
||||
a {
|
||||
padding: 0 8px;
|
||||
}
|
||||
}
|
||||
|
||||
&:hover .dropdown {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +212,7 @@ header {
|
|||
}
|
||||
}
|
||||
|
||||
ul {
|
||||
> ul {
|
||||
flex-direction: column;
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
|
@ -200,6 +235,12 @@ header {
|
|||
font-weight: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
.dropdown {
|
||||
position: initial;
|
||||
display: block;
|
||||
padding-left: 32px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -297,7 +338,7 @@ a {
|
|||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: lighten($secondary, 5%);
|
||||
color: lighten($secondary, 10%);
|
||||
}
|
||||
|
||||
.feather.feather-external-link {
|
||||
|
@ -312,11 +353,27 @@ form {
|
|||
text-align: center;
|
||||
|
||||
.form-field {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin: 16px auto;
|
||||
|
||||
.control {
|
||||
position: relative;
|
||||
background: $inputBackground;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.feather.icon {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 8px;
|
||||
transform: translateY(-50%);
|
||||
z-index: 0;
|
||||
|
||||
--icon-size: 24px;
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
label {
|
||||
position: absolute;
|
||||
left: 8px;
|
||||
|
@ -341,11 +398,11 @@ form {
|
|||
}
|
||||
}
|
||||
|
||||
input, select, .input-group {
|
||||
input, select, textarea, .input-group {
|
||||
z-index: 1;
|
||||
border: 0;
|
||||
color: $defaultTextColor;
|
||||
background: lighten($panelBackground, 4%);
|
||||
border-radius: 5px;
|
||||
background: transparent;
|
||||
font-size: 16px;
|
||||
|
||||
&:focus, &:not([value=""]), &[type="file"] {
|
||||
|
@ -356,7 +413,7 @@ form {
|
|||
}
|
||||
}
|
||||
|
||||
input, select, .form-display {
|
||||
input, select, textarea, .form-display {
|
||||
display: block;
|
||||
padding: 32px 8px 8px 8px;
|
||||
width: 100%;
|
||||
|
@ -387,30 +444,48 @@ form {
|
|||
}
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
min-height: 100px;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
input[type=color] {
|
||||
height: calc(32px + 8px + 32px);
|
||||
}
|
||||
|
||||
&.inline {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
input[type=checkbox] {
|
||||
text-align: left;
|
||||
width: min-content;
|
||||
height: min-content;
|
||||
.control {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
flex-grow: 1;
|
||||
|
||||
& ~ label {
|
||||
position: static;
|
||||
display: inline;
|
||||
padding-left: 8px;
|
||||
font-size: 16px;
|
||||
input[type=checkbox] {
|
||||
width: min-content;
|
||||
height: min-content;
|
||||
margin: 8px;
|
||||
text-align: left;
|
||||
|
||||
& ~ label {
|
||||
position: static;
|
||||
flex-grow: 1;
|
||||
display: inline;
|
||||
padding: 8px;
|
||||
|
||||
font-size: 16px;
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
flex-shrink: 1;
|
||||
flex-grow: 1;
|
||||
flex-direction: row;
|
||||
|
||||
div {
|
||||
|
@ -419,19 +494,9 @@ form {
|
|||
|
||||
input {
|
||||
width: 100%;
|
||||
margin-top: 24px;
|
||||
padding-top: 8px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
> input + * {
|
||||
position: absolute;
|
||||
top: 32px;
|
||||
right: 28px;
|
||||
user-select: none;
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -630,10 +695,16 @@ button, .button {
|
|||
// --- Feather
|
||||
// ---
|
||||
.feather {
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
flex-shrink: 0;
|
||||
--icon-size: 24px;
|
||||
width: var(--icon-size);
|
||||
height: var(--icon-size);
|
||||
|
||||
--icon-size: 16px;
|
||||
font-size: var(--icon-size);
|
||||
stroke: currentColor;
|
||||
stroke-width: 2;
|
||||
stroke-linecap: square;
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
export default class PersistentWebsocket {
|
||||
private webSocket?: WebSocket;
|
||||
|
||||
public constructor(
|
||||
protected readonly url: string,
|
||||
private readonly handler: MessageHandler,
|
||||
protected readonly reconnectOnClose: boolean = true,
|
||||
) {
|
||||
}
|
||||
|
||||
public run(): void {
|
||||
const _webSocket = this.webSocket = new WebSocket(this.url);
|
||||
this.webSocket.addEventListener('open', () => {
|
||||
console.debug('Websocket connected');
|
||||
});
|
||||
this.webSocket.addEventListener('message', (e) => {
|
||||
this.handler(_webSocket, e);
|
||||
});
|
||||
this.webSocket.addEventListener('error', (e) => {
|
||||
console.error('Websocket error', e);
|
||||
});
|
||||
this.webSocket.addEventListener('close', (e) => {
|
||||
this.webSocket = undefined;
|
||||
console.debug('Websocket closed', e.code, e.reason);
|
||||
|
||||
if (this.reconnectOnClose) {
|
||||
setTimeout(() => this.run(), 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public send(data: string): void {
|
||||
if (!this.webSocket) throw new Error('WebSocket not connected');
|
||||
|
||||
this.webSocket.send(data);
|
||||
}
|
||||
}
|
||||
|
||||
export type MessageHandler = (webSocket: WebSocket, e: MessageEvent) => void;
|
|
@ -2,8 +2,9 @@ import './external_links';
|
|||
import './message_icons';
|
||||
import './forms';
|
||||
import './copyable_text';
|
||||
import './tooltips-and-dropdowns';
|
||||
import './main_menu';
|
||||
import './font-awesome';
|
||||
|
||||
// css
|
||||
import '../sass/app.scss';
|
||||
|
||||
console.log('Hello world!');
|
|
@ -0,0 +1,15 @@
|
|||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.querySelectorAll('.copyable-text').forEach(el => {
|
||||
const contentEl = el.querySelector('.content');
|
||||
const selection = window.getSelection();
|
||||
if (contentEl && selection) {
|
||||
contentEl.addEventListener('click', () => {
|
||||
selection.selectAllChildren(contentEl);
|
||||
});
|
||||
el.querySelector('.copy-button')?.addEventListener('click', () => {
|
||||
selection.selectAllChildren(contentEl);
|
||||
document.execCommand('copy');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
|
@ -2,8 +2,10 @@ import feather from "feather-icons";
|
|||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.querySelectorAll('a[target="_blank"]').forEach(el => {
|
||||
el.innerHTML += `<i data-feather="external-link"></i>`;
|
||||
if (!el.classList.contains('no-icon')) {
|
||||
el.innerHTML += `<i data-feather="external-link"></i>`;
|
||||
}
|
||||
});
|
||||
|
||||
feather.replace();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,4 @@
|
|||
import '../../node_modules/@fortawesome/fontawesome-free/scss/fontawesome.scss';
|
||||
import '../../node_modules/@fortawesome/fontawesome-free/scss/regular.scss';
|
||||
import '../../node_modules/@fortawesome/fontawesome-free/scss/solid.scss';
|
||||
import '../../node_modules/@fortawesome/fontawesome-free/scss/brands.scss';
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* For labels to update their state (css selectors based on the value attribute)
|
||||
*/
|
||||
import {ValidationError} from "wms-core/db/Validator";
|
||||
|
||||
export function updateInputs(): void {
|
||||
document.querySelectorAll<HTMLInputElement | HTMLTextAreaElement>('input, textarea').forEach(el => {
|
||||
if (!el.dataset.inputSetup) {
|
||||
el.dataset.inputSetup = 'true';
|
||||
if (el.type !== 'checkbox') {
|
||||
el.setAttribute('value', el.value);
|
||||
el.addEventListener('change', () => {
|
||||
el.setAttribute('value', el.value);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
updateInputs();
|
||||
});
|
||||
|
||||
export function applyFormMessages(
|
||||
formElement: HTMLFormElement,
|
||||
messages: { [p: string]: ValidationError<unknown> },
|
||||
): void {
|
||||
for (const fieldName of Object.keys(messages)) {
|
||||
const field = formElement.querySelector('#field-' + fieldName);
|
||||
if (!field) continue;
|
||||
|
||||
let parent = field.parentElement;
|
||||
while (parent && !parent.classList.contains('form-field')) parent = parent.parentElement;
|
||||
|
||||
let err = field.querySelector('.error');
|
||||
if (!err) {
|
||||
err = document.createElement('div');
|
||||
err.classList.add('error');
|
||||
parent?.insertBefore(err, parent.querySelector('.hint') || parent);
|
||||
}
|
||||
err.innerHTML = `<i data-feather="x-circle"></i> ${messages[fieldName].message}`;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const menuButton = document.getElementById('menu-button');
|
||||
const mainMenu = document.getElementById('main-menu');
|
||||
|
||||
if (menuButton) {
|
||||
menuButton.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
mainMenu?.classList.toggle('open');
|
||||
});
|
||||
}
|
||||
|
||||
if (mainMenu) {
|
||||
mainMenu.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
document.addEventListener('click', () => {
|
||||
mainMenu.classList.remove('open');
|
||||
});
|
||||
}
|
||||
});
|
|
@ -1,21 +1,26 @@
|
|||
import feather from "feather-icons";
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const messageTypeToIcon = {
|
||||
const messageTypeToIcon: { [p: string]: string } = {
|
||||
info: 'info',
|
||||
success: 'check',
|
||||
warning: 'alert-triangle',
|
||||
error: 'x-circle',
|
||||
question: 'help-circle',
|
||||
};
|
||||
document.querySelectorAll('.message').forEach(el => {
|
||||
const type = el.dataset['type'];
|
||||
|
||||
document.querySelectorAll<HTMLElement>('.message').forEach(el => {
|
||||
const icon = el.querySelector('.icon');
|
||||
const type = el.dataset['type'];
|
||||
if (!icon || !type) return;
|
||||
if (!messageTypeToIcon[type]) throw new Error(`No icon for type ${type}`);
|
||||
|
||||
const svgContainer = document.createElement('div');
|
||||
svgContainer.innerHTML = feather.icons[messageTypeToIcon[type]].toSvg();
|
||||
el.insertBefore(svgContainer.firstChild, icon);
|
||||
|
||||
if (svgContainer.firstChild) el.insertBefore(svgContainer.firstChild, icon);
|
||||
icon.remove();
|
||||
});
|
||||
|
||||
feather.replace();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,31 @@
|
|||
export function updateTooltips(): void {
|
||||
console.debug('Updating tooltips');
|
||||
const elements = document.querySelectorAll<HTMLElement>('.tip, .dropdown');
|
||||
|
||||
// Calculate max potential displacement
|
||||
let max = 0;
|
||||
elements.forEach(el => {
|
||||
const box = el.getBoundingClientRect();
|
||||
if (max < box.height) max = box.height;
|
||||
});
|
||||
|
||||
// Prevent displacement
|
||||
elements.forEach(el => {
|
||||
if (!el.dataset.tooltipSetup) {
|
||||
el.dataset.tooltipSetup = 'true';
|
||||
const box = el.getBoundingClientRect();
|
||||
if (box.bottom >= document.body.clientHeight - (max + 32)) {
|
||||
el.classList.add('top');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
window.addEventListener('popstate', () => {
|
||||
updateTooltips();
|
||||
});
|
||||
window.requestAnimationFrame(() => {
|
||||
updateTooltips();
|
||||
});
|
||||
});
|
|
@ -1,14 +1,14 @@
|
|||
export default Object.assign(require("wms-core/config/default").default, {
|
||||
{
|
||||
app: {
|
||||
name: 'ALDAP',
|
||||
contact_email: 'contact@toot.party',
|
||||
},
|
||||
log_level: "DEV",
|
||||
db_log_level: "ERROR",
|
||||
base_url: "http://localhost:4899",
|
||||
public_url: "http://localhost:4899",
|
||||
public_websocket_url: "ws://localhost:4899",
|
||||
domain: 'localhost:4899',
|
||||
port: 4899,
|
||||
gitlab_webhook_token: 'secret',
|
||||
mysql: {
|
||||
connectionLimit: 10,
|
||||
host: "localhost",
|
||||
|
@ -26,7 +26,6 @@ export default Object.assign(require("wms-core/config/default").default, {
|
|||
secret: "very_secret_not_known",
|
||||
cookie: {
|
||||
secure: false,
|
||||
maxAge: 30 * 24 * 3600 * 1000,
|
||||
},
|
||||
},
|
||||
mail: {
|
||||
|
@ -42,8 +41,5 @@ export default Object.assign(require("wms-core/config/default").default, {
|
|||
view: {
|
||||
cache: false,
|
||||
},
|
||||
magic_link: {
|
||||
validity_period: 20,
|
||||
},
|
||||
approval_mode: false,
|
||||
});
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
export default Object.assign(require("wms-core/config/production").default, {
|
||||
{
|
||||
log_level: "DEBUG",
|
||||
db_log_level: "ERROR",
|
||||
base_url: "https://aldap.toot.party",
|
||||
public_url: "https://aldap.toot.party",
|
||||
public_websocket_url: "wss://aldap.toot.party",
|
||||
domain: 'aldap.toot.party',
|
||||
session: {
|
||||
cookie: {
|
||||
secure: true
|
||||
|
@ -13,8 +12,5 @@ export default Object.assign(require("wms-core/config/production").default, {
|
|||
secure: true,
|
||||
allow_invalid_tls: false
|
||||
},
|
||||
magic_link: {
|
||||
validity_period: 900,
|
||||
},
|
||||
approval_mode: true,
|
||||
});
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
export default Object.assign(require("wms-core/config/test").default, {
|
||||
{
|
||||
mysql: {
|
||||
host: "localhost",
|
||||
user: "root",
|
||||
password: "",
|
||||
database: "aldap_test",
|
||||
create_database_automatically: true
|
||||
},
|
||||
});
|
||||
}
|
33
package.json
33
package.json
|
@ -9,28 +9,36 @@
|
|||
"scripts": {
|
||||
"test": "jest --verbose --runInBand",
|
||||
"dist-webpack": "webpack --mode production",
|
||||
"dist": "tsc && npm run dist-webpack",
|
||||
"dist": "yarn compile && yarn dist-webpack",
|
||||
"clean": "(test ! -d dist || rm -r dist)",
|
||||
"compile": "yarn clean && tsc && mv dist/src/* dist/",
|
||||
"dev": "concurrently -k -n \"Typescript,Node,Webpack,Maildev\" -p \"[{name}]\" -c \"blue,green,red,yellow\" \"tsc --watch\" \"nodemon\" \"webpack --watch --mode development\" \"maildev\"",
|
||||
"start": "yarn dist && node dist/main.js"
|
||||
"start": "yarn dist && node dist/main.js",
|
||||
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.9.0",
|
||||
"@babel/preset-env": "^7.9.5",
|
||||
"@types/argon2": "^0.15.0",
|
||||
"@fortawesome/fontawesome-free": "^5.14.0",
|
||||
"@types/config": "^0.0.36",
|
||||
"@types/express": "^4.17.6",
|
||||
"@types/express-session": "^1.17.0",
|
||||
"@types/feather-icons": "^4.7.0",
|
||||
"@types/formidable": "^1.0.31",
|
||||
"@types/jest": "^26.0.4",
|
||||
"@types/ldapjs": "^1.0.7",
|
||||
"@types/mysql": "^2.15.15",
|
||||
"@types/node": "^14.0.23",
|
||||
"@types/node": "^14.6.3",
|
||||
"@types/nodemailer": "^6.4.0",
|
||||
"@types/nunjucks": "^3.1.3",
|
||||
"@types/ws": "^7.2.6",
|
||||
"@typescript-eslint/eslint-plugin": "^4.3.0",
|
||||
"@typescript-eslint/parser": "^4.3.0",
|
||||
"babel-loader": "^8.1.0",
|
||||
"concurrently": "^5.1.0",
|
||||
"css-loader": "^4.0.0",
|
||||
"css-loader": "^5.0.0",
|
||||
"eslint": "^7.10.0",
|
||||
"feather-icons": "^4.28.0",
|
||||
"file-loader": "^6.0.0",
|
||||
"imagemin": "^7.0.1",
|
||||
|
@ -40,21 +48,22 @@
|
|||
"imagemin-svgo": "^8.0.0",
|
||||
"img-loader": "^3.0.1",
|
||||
"jest": "^26.1.0",
|
||||
"mini-css-extract-plugin": "^0.9.0",
|
||||
"node-sass": "^4.14.0",
|
||||
"mini-css-extract-plugin": "^1.2.1",
|
||||
"node-sass": "^5.0.0",
|
||||
"nodemon": "^2.0.3",
|
||||
"sass-loader": "^9.0.2",
|
||||
"sass-loader": "^10.0.1",
|
||||
"terser-webpack-plugin": "^5.0.3",
|
||||
"ts-jest": "^26.1.1",
|
||||
"typescript": "^3.8.3",
|
||||
"uglifyjs-webpack-plugin": "^2.2.0",
|
||||
"webpack": "^4.43.0",
|
||||
"webpack-cli": "^3.3.11",
|
||||
"wms-core": "^0"
|
||||
"ts-loader": "^8.0.4",
|
||||
"typescript": "^4.0.2",
|
||||
"webpack": "^5.3.2",
|
||||
"webpack-cli": "^4.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"argon2": "^0.26.2",
|
||||
"config": "^3.3.1",
|
||||
"express": "^4.17.1",
|
||||
"wms-core": "^0.22.0",
|
||||
"ldapjs": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
|
20
src/App.ts
20
src/App.ts
|
@ -1,6 +1,5 @@
|
|||
import Application from "wms-core/Application";
|
||||
import {Type} from "wms-core/Utils";
|
||||
import Migration from "wms-core/db/Migration";
|
||||
import Migration, {MigrationType} from "wms-core/db/Migration";
|
||||
import ExpressAppComponent from "wms-core/components/ExpressAppComponent";
|
||||
import NunjucksComponent from "wms-core/components/NunjucksComponent";
|
||||
import MysqlComponent from "wms-core/components/MysqlComponent";
|
||||
|
@ -20,6 +19,9 @@ import AuthGuard from "wms-core/auth/AuthGuard";
|
|||
import {PasswordAuthProof} from "./models/UserPasswordComponent";
|
||||
import LDAPServerComponent from "./LDAPServerComponent";
|
||||
import AutoUpdateComponent from "wms-core/components/AutoUpdateComponent";
|
||||
import packageJson = require('../package.json');
|
||||
import DummyMigration from "wms-core/migrations/DummyMigration";
|
||||
import DropLegacyLogsTable from "wms-core/migrations/DropLegacyLogsTable";
|
||||
import AccountController from "./controllers/AccountController";
|
||||
import CreateMigrationsTable from "wms-core/migrations/CreateMigrationsTable";
|
||||
import CreateLogsTable from "wms-core/migrations/CreateLogsTable";
|
||||
|
@ -41,17 +43,19 @@ import RedirectBackComponent from "wms-core/components/RedirectBackComponent";
|
|||
import MailAutoConfigController from "./controllers/MailAutoConfigController";
|
||||
|
||||
export default class App extends Application {
|
||||
private readonly port: number;
|
||||
private magicLinkWebSocketListener?: MagicLinkWebSocketListener;
|
||||
|
||||
constructor(port: number) {
|
||||
super(require('../package.json').version);
|
||||
this.port = port;
|
||||
public constructor(
|
||||
private readonly addr: string,
|
||||
private readonly port: number,
|
||||
) {
|
||||
super(packageJson.version);
|
||||
}
|
||||
|
||||
protected getMigrations(): Type<Migration>[] {
|
||||
protected getMigrations(): MigrationType<Migration>[] {
|
||||
return [
|
||||
CreateMigrationsTable,
|
||||
DummyMigration,
|
||||
CreateLogsTable,
|
||||
CreateUsersAndUserEmailsTable,
|
||||
AddPasswordToUsers,
|
||||
|
@ -61,6 +65,7 @@ export default class App extends Application {
|
|||
DropNameFromUsers,
|
||||
AddNameToUsers,
|
||||
CreateMailTables,
|
||||
DropLegacyLogsTable,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -76,6 +81,7 @@ export default class App extends Application {
|
|||
const mysqlComponent = new MysqlComponent();
|
||||
|
||||
// Base
|
||||
const expressAppComponent = new ExpressAppComponent(this.addr, this.port);
|
||||
this.use(expressAppComponent);
|
||||
this.use(new LogRequestsComponent());
|
||||
|
||||
|
|
|
@ -2,16 +2,24 @@ import Controller from "wms-core/Controller";
|
|||
import {Request, Response} from "express";
|
||||
|
||||
export default class HomeController extends Controller {
|
||||
routes(): void {
|
||||
public routes(): void {
|
||||
this.get('/', this.getHome, 'home');
|
||||
this.get('/about', this.getAbout, 'about');
|
||||
this.get('/back', this.goBack, 'about');
|
||||
}
|
||||
|
||||
private async getHome(req: Request, res: Response) {
|
||||
protected async getHome(req: Request, res: Response): Promise<void> {
|
||||
res.render('home');
|
||||
}
|
||||
|
||||
private async getAbout(req: Request, res: Response) {
|
||||
protected async getAbout(req: Request, res: Response): Promise<void> {
|
||||
res.render('about');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is to test and assert that wms-core extended types are available
|
||||
*/
|
||||
protected async goBack(req: Request, res: Response): Promise<void> {
|
||||
res.redirectBack();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,10 @@ export default class MailAutoConfigController extends Controller {
|
|||
*/
|
||||
protected async getAutoConfig(req: Request, res: Response): Promise<void> {
|
||||
res.contentType('text/xml');
|
||||
const domains = await MailDomain.select().get();
|
||||
res.render('mail-auto-config.xml.njk', {
|
||||
domain: config.get<string>('domain'),
|
||||
domains: await MailDomain.select().get(),
|
||||
domain: domains[0],
|
||||
domains: domains,
|
||||
display_name: 'Rainbox Email',
|
||||
display_name_short: 'Rainbox',
|
||||
username: '%EMAILADDRESS%',
|
||||
|
|
18
src/main.ts
18
src/main.ts
|
@ -1,10 +1,20 @@
|
|||
import Logger from "wms-core/Logger";
|
||||
import {delimiter} from "path";
|
||||
|
||||
// Load config from specified path or default + wms-core/config (default defaults)
|
||||
process.env['NODE_CONFIG_DIR'] =
|
||||
__dirname + '/../node_modules/wms-core/config/'
|
||||
+ delimiter
|
||||
+ (process.env['NODE_CONFIG_DIR'] || __dirname + '/../config/');
|
||||
|
||||
import {log} from "wms-core/Logger";
|
||||
import App from "./App";
|
||||
import config from "config";
|
||||
|
||||
(async () => {
|
||||
const app = new App(config.get<number>('port'));
|
||||
log.debug('Config path:', process.env['NODE_CONFIG_DIR']);
|
||||
|
||||
const app = new App(config.get<string>('listen_addr'), config.get<number>('port'));
|
||||
await app.start();
|
||||
})().catch(err => {
|
||||
Logger.error(err);
|
||||
});
|
||||
log.error(err);
|
||||
});
|
||||
|
|
|
@ -2,4 +2,4 @@ describe('Write your tests', () => {
|
|||
test('Remove this when you have some tests', () => {
|
||||
expect(false).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "public/js",
|
||||
"target": "ES6",
|
||||
"strict": true,
|
||||
"lib": [
|
||||
"es2020",
|
||||
"DOM"
|
||||
],
|
||||
"typeRoots": [
|
||||
"./node_modules/@types"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"assets/ts/**/*"
|
||||
]
|
||||
}
|
|
@ -6,14 +6,16 @@
|
|||
"target": "ES6",
|
||||
"strict": true,
|
||||
"lib": [
|
||||
"es2020"
|
||||
"es2020",
|
||||
"DOM"
|
||||
],
|
||||
"typeRoots": [
|
||||
"./node_modules/@types"
|
||||
]
|
||||
],
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*",
|
||||
"node_modules/wms-core"
|
||||
"node_modules/wms-core/types"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"typeRoots": [
|
||||
"node_modules/@types",
|
||||
"src/types",
|
||||
"test/types"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/types/**/*",
|
||||
"test/**/*"
|
||||
]
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
const path = require('path');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
|
||||
const TerserPlugin = require('terser-webpack-plugin');
|
||||
|
||||
const dev = process.env.NODE_ENV === 'development';
|
||||
|
||||
|
@ -48,6 +48,16 @@ const config = {
|
|||
test: /\.(woff2?|eot|ttf|otf)$/i,
|
||||
use: 'file-loader?name=../fonts/[name].[ext]',
|
||||
},
|
||||
{
|
||||
test: /\.tsx?$/i,
|
||||
use: {
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
configFile: 'tsconfig.frontend.json',
|
||||
}
|
||||
},
|
||||
exclude: '/node_modules/'
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpe?g|gif|svg)$/i,
|
||||
use: [
|
||||
|
@ -68,6 +78,9 @@ const config = {
|
|||
}
|
||||
],
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.tsx', '.ts', '.js'],
|
||||
},
|
||||
plugins: [
|
||||
new MiniCssExtractPlugin({
|
||||
filename: '../css/[name].css',
|
||||
|
@ -77,8 +90,9 @@ const config = {
|
|||
|
||||
if (!dev) {
|
||||
config.optimization = {
|
||||
minimize: true,
|
||||
minimizer: [
|
||||
new UglifyJSPlugin(),
|
||||
new TerserPlugin(),
|
||||
]
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue