AddOn/Datenexport_Zeiterfassung/test.html aktualisiert
This commit is contained in:
parent
408bb3ae26
commit
c4291374b9
|
|
@ -2,7 +2,7 @@
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>TimeTracking API WebUI - Test</title>
|
<title>TimeTracking API WebUI - Test mit Polling</title>
|
||||||
<style>
|
<style>
|
||||||
body { font-family: Arial, sans-serif; margin: 20px; max-width: 600px; }
|
body { font-family: Arial, sans-serif; margin: 20px; max-width: 600px; }
|
||||||
label, select, input, button { display: block; width: 100%; margin-top: 10px; padding: 8px; }
|
label, select, input, button { display: block; width: 100%; margin-top: 10px; padding: 8px; }
|
||||||
|
|
@ -48,43 +48,26 @@
|
||||||
<script>
|
<script>
|
||||||
let baseUrl = '';
|
let baseUrl = '';
|
||||||
let token = '';
|
let token = '';
|
||||||
let apiSite = ''; // Optional, falls die API-URL schon api beinhaltet, kann leer bleiben.
|
let apiSite = '';
|
||||||
|
|
||||||
async function apiRequest(baseUrl, token, apiSite, method, endpoint, body = null) {
|
async function apiRequest(baseUrl, token, apiSite, method, endpoint, body = null) {
|
||||||
let url = baseUrl.replace(/\/+$/, '') + (apiSite ? '/' + apiSite.replace(/^\/+|\/+$/g, '') : '') + '/' + endpoint.replace(/^\/+/, '');
|
const url = baseUrl.replace(/\/+$/g, '') + (apiSite ? '/' + apiSite.replace(/^\/+|\/+$/g, '') : '') + '/' + endpoint.replace(/^\/+/, '');
|
||||||
|
const headers = { 'Authorization': token };
|
||||||
const headers = {
|
if (body) headers['Content-Type'] = 'application/json';
|
||||||
'Authorization': token,
|
const options = { method: method.toUpperCase(), headers };
|
||||||
};
|
if (body) options.body = JSON.stringify(body);
|
||||||
if (body) {
|
|
||||||
headers['Content-Type'] = 'application/json';
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
method: method.toUpperCase(),
|
|
||||||
headers,
|
|
||||||
};
|
|
||||||
if (body) {
|
|
||||||
options.body = JSON.stringify(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(url, options);
|
const response = await fetch(url, options);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorText = await response.text();
|
const errorText = await response.text();
|
||||||
throw new Error(`API Fehler ${response.status}: ${errorText}`);
|
throw new Error(`API Fehler ${response.status}: ${errorText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const contentType = response.headers.get('content-type') || '';
|
const contentType = response.headers.get('content-type') || '';
|
||||||
if (contentType.includes('application/json')) {
|
return contentType.includes('application/json') ? response.json() : response.text();
|
||||||
return response.json();
|
|
||||||
}
|
|
||||||
return response.text();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('connectBtn').addEventListener('click', async () => {
|
document.getElementById('connectBtn').addEventListener('click', async () => {
|
||||||
baseUrl = document.getElementById('apiUrl').value.trim();
|
baseUrl = document.getElementById('apiUrl').value.trim();
|
||||||
token = document.getElementById('token').value.trim();
|
token = document.getElementById('token').value.trim();
|
||||||
apiSite = ''; // Kann erweitert werden, falls nötig
|
|
||||||
|
|
||||||
if (!baseUrl || !token) {
|
if (!baseUrl || !token) {
|
||||||
alert('Bitte WebAPI URL und Token eingeben.');
|
alert('Bitte WebAPI URL und Token eingeben.');
|
||||||
|
|
@ -92,9 +75,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// OE laden
|
|
||||||
const orgUnits = await apiRequest(baseUrl, token, apiSite, 'GET', 'api/organization/');
|
const orgUnits = await apiRequest(baseUrl, token, apiSite, 'GET', 'api/organization/');
|
||||||
// Export-Definitionen laden
|
|
||||||
const exportDefs = await apiRequest(baseUrl, token, apiSite, 'GET', 'api/export/');
|
const exportDefs = await apiRequest(baseUrl, token, apiSite, 'GET', 'api/export/');
|
||||||
|
|
||||||
const orgSelect = document.getElementById('organizationUnit');
|
const orgSelect = document.getElementById('organizationUnit');
|
||||||
|
|
@ -110,24 +91,19 @@
|
||||||
exportSelect.innerHTML = '';
|
exportSelect.innerHTML = '';
|
||||||
exportDefs.forEach(def => {
|
exportDefs.forEach(def => {
|
||||||
const opt = document.createElement('option');
|
const opt = document.createElement('option');
|
||||||
//opt.value = def.Id || def.id || def.ExportDefinitionId || def.ExportDefinition || '';
|
|
||||||
opt.value = def.ObjectId || '';
|
opt.value = def.ObjectId || '';
|
||||||
opt.textContent = def.ObjectNaming || def.ObjectPatternNumber || opt.ObjectShortTerm;
|
opt.textContent = def.ObjectNaming || def.ObjectPatternNumber || def.ObjectShortTerm;
|
||||||
exportSelect.appendChild(opt);
|
exportSelect.appendChild(opt);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Schritt 2 einblenden
|
|
||||||
document.getElementById('step1').style.display = 'none';
|
document.getElementById('step1').style.display = 'none';
|
||||||
document.getElementById('step2').style.display = 'block';
|
document.getElementById('step2').style.display = 'block';
|
||||||
|
|
||||||
// Datum Default setzen (letzte Woche)
|
|
||||||
const dateFromInput = document.getElementById('dateFrom');
|
|
||||||
const dateUntilInput = document.getElementById('dateUntil');
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const lastWeek = new Date(today);
|
const lastWeek = new Date(today);
|
||||||
lastWeek.setDate(today.getDate() - 7);
|
lastWeek.setDate(today.getDate() - 7);
|
||||||
dateFromInput.value = lastWeek.toISOString().split('T')[0];
|
document.getElementById('dateFrom').value = lastWeek.toISOString().split('T')[0];
|
||||||
dateUntilInput.value = today.toISOString().split('T')[0];
|
document.getElementById('dateUntil').value = today.toISOString().split('T')[0];
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert('Fehler beim Laden der Daten: ' + e.message);
|
alert('Fehler beim Laden der Daten: ' + e.message);
|
||||||
|
|
@ -146,27 +122,32 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Export anfragen
|
const guid = await apiRequest(baseUrl, token, apiSite, 'POST', 'api/export', {
|
||||||
const result = await apiRequest(baseUrl, token, apiSite, 'POST', 'api/export', {
|
|
||||||
ExportDefinition: exportDefinitionId,
|
ExportDefinition: exportDefinitionId,
|
||||||
organizationUnit: organizationUnitId,
|
organizationUnit: organizationUnitId,
|
||||||
DateFrom: dateFrom,
|
DateFrom: dateFrom,
|
||||||
DateUntil: dateUntil
|
DateUntil: dateUntil
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
throw new Error('Kein Result im Antwortobjekt ('+result+')');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exportdaten abrufen (Result ist GUID)
|
|
||||||
const exportData = await apiRequest(baseUrl, token, apiSite, 'GET', `api/export/${result}`);
|
|
||||||
|
|
||||||
const pre = document.getElementById('exportResult');
|
const pre = document.getElementById('exportResult');
|
||||||
if (typeof exportData === 'object') {
|
pre.textContent = 'Job gestartet (GUID: ' + guid + '), warte auf Ergebnis...';
|
||||||
pre.textContent = JSON.stringify(exportData, null, 2);
|
|
||||||
} else {
|
const poll = async () => {
|
||||||
pre.textContent = exportData;
|
try {
|
||||||
}
|
const data = await apiRequest(baseUrl, token, apiSite, 'GET', `api/export/${guid}`);
|
||||||
|
if (typeof data === 'object') {
|
||||||
|
pre.textContent = JSON.stringify(data, null, 2);
|
||||||
|
if (data.Result === 'JobPending') {
|
||||||
|
setTimeout(poll, 60000);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pre.textContent = data;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Polling-Fehler:', err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
setTimeout(poll, 10000);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert('Fehler beim Export: ' + e.message);
|
alert('Fehler beim Export: ' + e.message);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue