241 lines
8.5 KiB
HTML
241 lines
8.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Test Delete Custom Task Type</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
max-width: 800px;
|
|
margin: 50px auto;
|
|
padding: 20px;
|
|
}
|
|
.test-section {
|
|
margin: 20px 0;
|
|
padding: 15px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 5px;
|
|
}
|
|
button {
|
|
padding: 10px 20px;
|
|
margin: 5px;
|
|
cursor: pointer;
|
|
background: #007bff;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 4px;
|
|
}
|
|
button:hover {
|
|
background: #0056b3;
|
|
}
|
|
.success {
|
|
color: green;
|
|
font-weight: bold;
|
|
}
|
|
.error {
|
|
color: red;
|
|
font-weight: bold;
|
|
}
|
|
pre {
|
|
background: #f5f5f5;
|
|
padding: 10px;
|
|
border-radius: 4px;
|
|
overflow-x: auto;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Test Delete Custom Task Type</h1>
|
|
|
|
<div class="test-section">
|
|
<h3>Step 1: Login</h3>
|
|
<button onclick="login()">Login as Admin</button>
|
|
<div id="login-result"></div>
|
|
</div>
|
|
|
|
<div class="test-section">
|
|
<h3>Step 2: Add Test Task Type</h3>
|
|
<button onclick="addTaskType()">Add 'test_delete' Task Type</button>
|
|
<div id="add-result"></div>
|
|
</div>
|
|
|
|
<div class="test-section">
|
|
<h3>Step 3: Delete Task Type</h3>
|
|
<button onclick="deleteTaskType()">Delete 'test_delete' Task Type</button>
|
|
<div id="delete-result"></div>
|
|
</div>
|
|
|
|
<div class="test-section">
|
|
<h3>Step 4: Verify</h3>
|
|
<button onclick="getAllTaskTypes()">Get All Task Types</button>
|
|
<div id="verify-result"></div>
|
|
</div>
|
|
|
|
<script>
|
|
const API_BASE = 'http://localhost:8000';
|
|
let token = null;
|
|
const projectId = 1;
|
|
|
|
async function login() {
|
|
const resultDiv = document.getElementById('login-result');
|
|
resultDiv.innerHTML = 'Logging in...';
|
|
|
|
try {
|
|
const formData = new FormData();
|
|
formData.append('email', 'admin@vfx.com');
|
|
formData.append('password', 'admin123');
|
|
|
|
const response = await fetch(`${API_BASE}/auth/login`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
email: 'admin@vfx.com',
|
|
password: 'admin123'
|
|
})
|
|
});
|
|
|
|
if (response.ok) {
|
|
const data = await response.json();
|
|
token = data.access_token;
|
|
resultDiv.innerHTML = '<span class="success">✓ Logged in successfully!</span>';
|
|
} else {
|
|
const error = await response.text();
|
|
resultDiv.innerHTML = `<span class="error">✗ Login failed: ${error}</span>`;
|
|
}
|
|
} catch (error) {
|
|
resultDiv.innerHTML = `<span class="error">✗ Error: ${error.message}</span>`;
|
|
}
|
|
}
|
|
|
|
async function addTaskType() {
|
|
const resultDiv = document.getElementById('add-result');
|
|
|
|
if (!token) {
|
|
resultDiv.innerHTML = '<span class="error">Please login first!</span>';
|
|
return;
|
|
}
|
|
|
|
resultDiv.innerHTML = 'Adding task type...';
|
|
|
|
try {
|
|
const response = await fetch(`${API_BASE}/projects/${projectId}/custom-task-types`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`,
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
task_type: 'test_delete',
|
|
category: 'asset'
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
resultDiv.innerHTML = `
|
|
<span class="success">✓ Task type added!</span>
|
|
<pre>${JSON.stringify(data, null, 2)}</pre>
|
|
`;
|
|
} else {
|
|
resultDiv.innerHTML = `
|
|
<span class="error">✗ Failed (${response.status})</span>
|
|
<pre>${JSON.stringify(data, null, 2)}</pre>
|
|
`;
|
|
}
|
|
} catch (error) {
|
|
resultDiv.innerHTML = `<span class="error">✗ Error: ${error.message}</span>`;
|
|
}
|
|
}
|
|
|
|
async function deleteTaskType() {
|
|
const resultDiv = document.getElementById('delete-result');
|
|
|
|
if (!token) {
|
|
resultDiv.innerHTML = '<span class="error">Please login first!</span>';
|
|
return;
|
|
}
|
|
|
|
resultDiv.innerHTML = 'Deleting task type...';
|
|
|
|
try {
|
|
const url = new URL(`${API_BASE}/projects/${projectId}/custom-task-types/test_delete`);
|
|
url.searchParams.append('category', 'asset');
|
|
|
|
console.log('DELETE URL:', url.toString());
|
|
|
|
const response = await fetch(url, {
|
|
method: 'DELETE',
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`
|
|
}
|
|
});
|
|
|
|
console.log('Response status:', response.status);
|
|
|
|
if (response.ok) {
|
|
const data = await response.json();
|
|
resultDiv.innerHTML = `
|
|
<span class="success">✓ Task type deleted!</span>
|
|
<pre>${JSON.stringify(data, null, 2)}</pre>
|
|
`;
|
|
} else {
|
|
const text = await response.text();
|
|
resultDiv.innerHTML = `
|
|
<span class="error">✗ Failed (${response.status} ${response.statusText})</span>
|
|
<pre>${text}</pre>
|
|
`;
|
|
|
|
if (response.status === 405) {
|
|
resultDiv.innerHTML += '<p><strong>Method Not Allowed - Backend server needs restart!</strong></p>';
|
|
}
|
|
}
|
|
} catch (error) {
|
|
resultDiv.innerHTML = `<span class="error">✗ Error: ${error.message}</span>`;
|
|
}
|
|
}
|
|
|
|
async function getAllTaskTypes() {
|
|
const resultDiv = document.getElementById('verify-result');
|
|
|
|
if (!token) {
|
|
resultDiv.innerHTML = '<span class="error">Please login first!</span>';
|
|
return;
|
|
}
|
|
|
|
resultDiv.innerHTML = 'Loading task types...';
|
|
|
|
try {
|
|
const response = await fetch(`${API_BASE}/projects/${projectId}/custom-task-types`, {
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`
|
|
}
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
const hasTestDelete = data.custom_asset_types.includes('test_delete');
|
|
resultDiv.innerHTML = `
|
|
<span class="${hasTestDelete ? 'error' : 'success'}">
|
|
${hasTestDelete ? '✗ test_delete still exists!' : '✓ test_delete successfully removed!'}
|
|
</span>
|
|
<pre>${JSON.stringify(data, null, 2)}</pre>
|
|
`;
|
|
} else {
|
|
resultDiv.innerHTML = `
|
|
<span class="error">✗ Failed (${response.status})</span>
|
|
<pre>${JSON.stringify(data, null, 2)}</pre>
|
|
`;
|
|
}
|
|
} catch (error) {
|
|
resultDiv.innerHTML = `<span class="error">✗ Error: ${error.message}</span>`;
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|