1
0
mirror of https://github.com/pocket-id/pocket-id.git synced 2026-03-22 18:30:09 +00:00

feat: add various improvements to the table component (#961)

Co-authored-by: Kyle Mendell <kmendell@ofkm.us>
This commit is contained in:
Elias Schneider
2025-10-13 11:12:55 +02:00
committed by GitHub
parent 24ca6a106d
commit c20e93b55c
76 changed files with 1948 additions and 1434 deletions

View File

@@ -3,39 +3,33 @@ import { cachedApplicationLogo, cachedBackgroundImage } from '$lib/utils/cached-
import APIService from './api-service';
export default class AppConfigService extends APIService {
async list(showAll = false) {
list = async (showAll = false) => {
let url = '/application-configuration';
if (showAll) {
url += '/all';
}
if (showAll) url += '/all';
const { data } = await this.api.get<AppConfigRawResponse>(url);
return this.parseConfigList(data);
}
return parseConfigList(data);
};
async update(appConfig: AllAppConfig) {
update = async (appConfig: AllAppConfig) => {
// Convert all values to string, stringifying JSON where needed
const appConfigConvertedToString: Record<string, string> = {};
for (const key in appConfig) {
const value = (appConfig as any)[key];
if (typeof value === 'object' && value !== null) {
appConfigConvertedToString[key] = JSON.stringify(value);
} else {
appConfigConvertedToString[key] = String(value);
}
appConfigConvertedToString[key] =
typeof value === 'object' && value !== null ? JSON.stringify(value) : String(value);
}
const res = await this.api.put('/application-configuration', appConfigConvertedToString);
return this.parseConfigList(res.data);
}
return parseConfigList(res.data);
};
async updateFavicon(favicon: File) {
updateFavicon = async (favicon: File) => {
const formData = new FormData();
formData.append('file', favicon!);
await this.api.put(`/application-images/favicon`, formData);
}
async updateLogo(logo: File, light = true) {
updateLogo = async (logo: File, light = true) => {
const formData = new FormData();
formData.append('file', logo!);
@@ -43,52 +37,52 @@ export default class AppConfigService extends APIService {
params: { light }
});
cachedApplicationLogo.bustCache(light);
}
};
async updateBackgroundImage(backgroundImage: File) {
updateBackgroundImage = async (backgroundImage: File) => {
const formData = new FormData();
formData.append('file', backgroundImage!);
await this.api.put(`/application-images/background`, formData);
cachedBackgroundImage.bustCache();
}
};
async sendTestEmail() {
sendTestEmail = async () => {
await this.api.post('/application-configuration/test-email');
}
};
async syncLdap() {
syncLdap = async () => {
await this.api.post('/application-configuration/sync-ldap');
}
};
}
private parseConfigList(data: AppConfigRawResponse) {
const appConfig: Partial<AllAppConfig> = {};
data.forEach(({ key, value }) => {
(appConfig as any)[key] = this.parseValue(value);
});
function parseConfigList(data: AppConfigRawResponse) {
const appConfig: Partial<AllAppConfig> = {};
data.forEach(({ key, value }) => {
(appConfig as any)[key] = parseValue(value);
});
return appConfig as AllAppConfig;
}
return appConfig as AllAppConfig;
}
private parseValue(value: string) {
// Try to parse JSON first
try {
const parsed = JSON.parse(value);
if (typeof parsed === 'object' && parsed !== null) {
return parsed;
}
value = String(parsed);
} catch {}
// Handle rest of the types
if (value === 'true') {
return true;
} else if (value === 'false') {
return false;
} else if (/^-?\d+(\.\d+)?$/.test(value)) {
return parseFloat(value);
} else {
return value;
function parseValue(value: string) {
// Try to parse JSON first
try {
const parsed = JSON.parse(value);
if (typeof parsed === 'object' && parsed !== null) {
return parsed;
}
value = String(parsed);
} catch {}
// Handle rest of the types
if (value === 'true') {
return true;
} else if (value === 'false') {
return false;
} else if (/^-?\d+(\.\d+)?$/.test(value)) {
return parseFloat(value);
} else {
return value;
}
}