Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Oct 11, 2024
1 parent 24b03fb commit 0141ab3
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 67 deletions.
5 changes: 4 additions & 1 deletion handlers/admin-post/doSaveApplicationSetting.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { Request, Response } from 'express';
export interface DoSaveApplicationSettingResponse {
success: boolean;
}
export default function handler(request: Request<unknown, unknown, {
settingKey: string;
settingValue: string;
}>, response: Response): void;
}>, response: Response<DoSaveApplicationSettingResponse>): void;
6 changes: 5 additions & 1 deletion handlers/admin-post/doSaveApplicationSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import type { Request, Response } from 'express'

import updateApplicationSetting from '../../helpers/licencesDB/updateApplicationSetting.js'

export interface DoSaveApplicationSettingResponse {
success: boolean
}

export default function handler(
request: Request<
unknown,
unknown,
{ settingKey: string; settingValue: string }
>,
response: Response
response: Response<DoSaveApplicationSettingResponse>
): void {
const settingKey = request.body.settingKey
const settingValue = request.body.settingValue
Expand Down
40 changes: 24 additions & 16 deletions public-typescript/admin-applicationSettings.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
(() => {
const urlPrefix = document.querySelector("main").dataset.urlPrefix;
const getMessageElement = (formElement) => {
return formElement.closest("tr").querySelectorAll(".formMessage")[0];
};
const submitFunction = (formEvent) => {
const urlPrefix = document.querySelector('main').dataset
.urlPrefix;
function getMessageElement(formElement) {
var _a;
return (_a = formElement
.closest('tr')) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.formMessage').item(0);
}
function submitFunction(formEvent) {
formEvent.preventDefault();
const formElement = formEvent.currentTarget;
const messageElement = getMessageElement(formElement);
messageElement.innerHTML = "Saving... <i class=\"fas fa-circle-notch fa-spin\" aria-hidden=\"true\"></i>";
cityssm.postJSON(urlPrefix + "/admin/doSaveApplicationSetting", formElement, (responseJSON) => {
messageElement.innerHTML =
'Saving... <i class="fas fa-circle-notch fa-spin" aria-hidden="true"></i>';
cityssm.postJSON(`${urlPrefix}/admin/doSaveApplicationSetting`, formElement, (rawResponseJSON) => {
const responseJSON = rawResponseJSON;
messageElement.innerHTML = responseJSON.success
? "<span class=\"has-text-success\">Updated Successfully</span>"
: "<span class=\"has-text-danger\">Update Error</span>";
? '<span class="has-text-success">Updated Successfully</span>'
: '<span class="has-text-danger">Update Error</span>';
});
};
const changeFunction = (inputEvent) => {
}
function changeFunction(inputEvent) {
getMessageElement(inputEvent.currentTarget).innerHTML =
"<span class=\"has-text-info\">Unsaved Changes</span>";
};
const formElements = document.querySelectorAll(".form--applicationSetting");
'<span class="has-text-info">Unsaved Changes</span>';
}
const formElements = document.querySelectorAll('.form--applicationSetting');
for (const formElement of formElements) {
formElement.addEventListener("submit", submitFunction);
formElement.querySelectorAll(".input")[0].addEventListener("change", changeFunction);
formElement.addEventListener('submit', submitFunction);
formElement
.querySelectorAll('.input')
.item(0)
.addEventListener('change', changeFunction);
}
})();
72 changes: 43 additions & 29 deletions public-typescript/admin-applicationSettings.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,65 @@
/* eslint-disable unicorn/filename-case */
/* eslint-disable unicorn/filename-case, @eslint-community/eslint-comments/disable-enable-pair */

import type { cityssmGlobal } from "@cityssm/bulma-webapp-js/src/types";
declare const cityssm: cityssmGlobal;
import type { cityssmGlobal } from '@cityssm/bulma-webapp-js/src/types'

import type { DoSaveApplicationSettingResponse } from '../handlers/admin-post/doSaveApplicationSetting.js'

(() => {
declare const cityssm: cityssmGlobal
;(() => {
const urlPrefix = (document.querySelector('main') as HTMLElement).dataset
.urlPrefix

const urlPrefix = document.querySelector("main").dataset.urlPrefix;

const getMessageElement = (formElement: HTMLFormElement | HTMLInputElement) => {
return formElement.closest("tr").querySelectorAll(".formMessage")[0] as HTMLElement;
};
function getMessageElement(
formElement: HTMLFormElement | HTMLInputElement
): HTMLElement {
return formElement
.closest('tr')
?.querySelectorAll('.formMessage')
.item(0) as HTMLElement
}

/*
* Form
*/

const submitFunction = (formEvent: Event) => {

formEvent.preventDefault();
function submitFunction(formEvent: Event): void {
formEvent.preventDefault()

const formElement = formEvent.currentTarget as HTMLFormElement;
const messageElement = getMessageElement(formElement);
const formElement = formEvent.currentTarget as HTMLFormElement
const messageElement = getMessageElement(formElement)

messageElement.innerHTML = "Saving... <i class=\"fas fa-circle-notch fa-spin\" aria-hidden=\"true\"></i>";
messageElement.innerHTML =
'Saving... <i class="fas fa-circle-notch fa-spin" aria-hidden="true"></i>'

cityssm.postJSON(urlPrefix + "/admin/doSaveApplicationSetting",
cityssm.postJSON(
`${urlPrefix}/admin/doSaveApplicationSetting`,
formElement,
(responseJSON: { success: boolean }) => {
(rawResponseJSON) => {
const responseJSON =
rawResponseJSON as unknown as DoSaveApplicationSettingResponse

// eslint-disable-next-line no-unsanitized/property
messageElement.innerHTML = responseJSON.success
? "<span class=\"has-text-success\">Updated Successfully</span>"
: "<span class=\"has-text-danger\">Update Error</span>";
? '<span class="has-text-success">Updated Successfully</span>'
: '<span class="has-text-danger">Update Error</span>'
}
);
};
)
}

const changeFunction = (inputEvent: Event) => {
function changeFunction(inputEvent: Event): void {
getMessageElement(inputEvent.currentTarget as HTMLInputElement).innerHTML =
"<span class=\"has-text-info\">Unsaved Changes</span>";
};

'<span class="has-text-info">Unsaved Changes</span>'
}

const formElements = document.querySelectorAll(".form--applicationSetting") as NodeListOf<HTMLFormElement>;
const formElements = document.querySelectorAll(
'.form--applicationSetting'
) as NodeListOf<HTMLFormElement>

for (const formElement of formElements) {
formElement.addEventListener("submit", submitFunction);
formElement.querySelectorAll(".input")[0].addEventListener("change", changeFunction);
formElement.addEventListener('submit', submitFunction)
formElement
.querySelectorAll('.input')
.item(0)
.addEventListener('change', changeFunction)
}
})();
})()
22 changes: 3 additions & 19 deletions public-typescript/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,13 @@
"compilerOptions": {
"target": "ES6",
"module": "CommonJS",
"moduleResolution": "Node",
"isolatedModules": false,
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"allowUnreachableCode": false
"allowUnreachableCode": false,
"strictNullChecks": true
},
"compileOnSave": true,
"buildOnSave": true,
"atom": {
"rewriteTsconfig": false,
"formatOnSave": true
},
"formatCodeOptions": {
"indentSize": 2,
"tabSize": 2,
"insertSpaceAfterCommaDelimiter": true,
"insertSpaceAfterSemicolonInForStatements": true,
"insertSpaceBeforeAndAfterBinaryOperators": true,
"insertSpaceAfterKeywordsInControlFlowStatements": true,
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"placeOpenBraceOnNewLineForFunctions": false,
"placeOpenBraceOnNewLineForControlBlocks": false
}
"buildOnSave": true
}
2 changes: 1 addition & 1 deletion public/javascripts/admin-applicationSettings.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0141ab3

Please sign in to comment.