-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataTransformer.js
More file actions
169 lines (169 loc) · 7.79 KB
/
Copy pathDataTransformer.js
File metadata and controls
169 lines (169 loc) · 7.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* This file is part of the web-vision/kanban_workspaces TYPO3 extension.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2 of the
* License, or any later version.
*
* Generated from Build/Sources/TypeScript/ - do not edit directly, change the
* TypeScript source and re-run "npm run build:js" instead.
*/
import { convertWorkspaceDate, extractPageNameFromPath } from '@web-vision/kanban-workspaces/core/utils.js';
/**
* Converts raw TYPO3 workspace API payloads into the card / comment / history /
* diff shapes consumed by the board UI. Stateless: every method is a pure
* transform of its input.
*/
export class DataTransformer {
convertWorkspaceDataToCards(apiResponse) {
if (!apiResponse || !Array.isArray(apiResponse) || apiResponse.length === 0) {
return [];
}
const result = apiResponse[0];
if (!result || !result.result || !result.result.data) {
return [];
}
const workspaceData = result.result.data;
return workspaceData.map((item, index) => {
// Map table type to content type
const typeMapping = {
'pages': 'page',
'tt_content': 'content',
};
// Extract editor name from various possible sources
let editor = '';
if (item.cruser_id || item.tstamp_user) {
// In real implementation, you'd fetch user data
editor = `User ${item.cruser_id || item.tstamp_user}`;
}
// Determine priority based on state or other factors
let priority = 'medium';
if (item.state_Workspace === 'new') {
priority = 'high';
}
else if (item.state_Workspace === 'modified') {
priority = 'medium';
}
else {
priority = 'low';
}
// Process integrity data from TYPO3 Workspaces IntegrityService
const integrity = item.integrity || { status: 'success', messages: '' };
// Adjust priority based on integrity status
let adjustedPriority = priority;
if (integrity.status === 'error') {
adjustedPriority = 'critical'; // New priority level for blocking issues
}
else if (integrity.status === 'warning' && priority !== 'high') {
adjustedPriority = 'high'; // Elevate to high if not already
}
// Create the card object
return {
id: item.id || `${item.table}_${item.uid}`,
title: item.label_Workspace || `${item.table} record ${item.uid}`,
type: typeMapping[item.table] || 'content',
uid: item.uid,
pageName: extractPageNameFromPath(item.path_Workspace) || 'Home',
editor: editor,
editorId: `user_${item.cruser_id || item.uid}`,
modifiedDate: convertWorkspaceDate(item.lastChangedFormatted),
stage: item.stage || 0,
language: item.language || { icon: '', title: 'Default', title_crop: 'Default' },
languageCode: item.language ? item.language.title_crop.toLowerCase().substring(0, 2) : 'en',
priority: adjustedPriority,
originalPriority: priority, // Preserve original priority for reference
integrityStatus: integrity.status,
integrityMessages: integrity.messages,
hasSchedule: false, // TYPO3 workspace doesn't have built-in scheduling
scheduleText: item.stage === -10 ? 'Published' : null,
comments: 0, // Would need separate API call to get comments
assignedUsers: item.assignee_uid ? [{ uid: item.assignee_uid, username: item.assignee_username || '', avatar_url: item.assignee_avatar_url || null }] : [],
assignee: item.assignee_uid ? { uid: item.assignee_uid, username: item.assignee_username || '', avatar_url: item.assignee_avatar_url || null } : null,
t3ver_oid: item.t3ver_oid || null,
t3ver_wsid: item.t3ver_wsid || null,
table: item.table,
pid: item.livepid || null,
nextStage: item.value_nextStage,
prevStage: item.value_prevStage
};
});
}
// Convert TYPO3 API response to the format used by the modal tabs.
convertCardDetailsToFormat(apiResponse, cardId) {
if (!apiResponse || !Array.isArray(apiResponse) || apiResponse.length === 0) {
return { comments: [], history: [], diff: [] };
}
const result = apiResponse[0];
if (!result || !result.result || !result.result.data || !result.result.data[0]) {
return { comments: [], history: [], diff: [] };
}
const data = result.result.data[0];
// Transform comments
const comments = this.transformCommentsFromAPI(data.comments || []);
// Transform history
const history = this.transformHistoryFromAPI(data.history || {});
// Extract diff data (already in HTML format from TYPO3)
const diff = data.diff || [];
return { comments, history, diff };
}
// Transform comments from TYPO3 API format to the UI format.
transformCommentsFromAPI(apiComments) {
if (!Array.isArray(apiComments) || apiComments.length === 0) {
return [];
}
return apiComments.map((comment, index) => {
// Extract avatar from HTML or use username
const avatarMatch = comment.user_avatar?.match(/src="([^"]+)"/);
const avatarUrl = avatarMatch ? avatarMatch[1] : null;
// Build content: show user comment if exists, otherwise show stage movement
let content = '';
if (comment.user_comment && comment.user_comment.trim() !== '') {
content = comment.user_comment;
}
else {
// Show stage movement without comment
content = `Moved from "${comment.previous_stage_title}" to "${comment.stage_title}"`;
}
return {
id: `c${index + 1}`,
author: comment.user_username || 'Unknown User',
timestamp: convertWorkspaceDate(comment.tstamp),
content: content,
avatar: avatarUrl,
stageTitle: comment.stage_title,
previousStageTitle: comment.previous_stage_title
};
});
}
// Transform history from TYPO3 API format to the UI format.
transformHistoryFromAPI(apiHistory) {
if (!apiHistory || !apiHistory.data || !Array.isArray(apiHistory.data)) {
return [];
}
return apiHistory.data.map((item, index) => {
let action = '';
// Extract avatar from HTML or use null
const avatarMatch = item.user_avatar?.match(/src="([^"]+)"/);
const avatarUrl = avatarMatch ? avatarMatch[1] : null;
// Determine action based on differences
if (item.differences === 'insert') {
action = 'Created card';
}
else if (Array.isArray(item.differences) && item.differences.length > 0) {
const fields = item.differences.map(d => d.label).join(', ');
action = `Modified: ${fields}`;
}
else {
action = 'Updated card';
}
return {
id: `h${index + 1}`,
action: action,
author: item.user || 'Unknown User',
timestamp: convertWorkspaceDate(item.datetime),
avatar: avatarUrl,
differences: item.differences
};
});
}
}