Spaces:
Building
Building
Update flare-ui/src/app/components/projects/projects.component.ts
Browse files
flare-ui/src/app/components/projects/projects.component.ts
CHANGED
@@ -1,425 +1,558 @@
|
|
1 |
-
import { Component,
|
2 |
-
import { CommonModule } from '@angular/common';
|
3 |
-
import { FormsModule } from '@angular/forms';
|
4 |
-
import {
|
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 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
.
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
}
|
|
|
1 |
+
import { Component, OnInit } from '@angular/core';
|
2 |
+
import { CommonModule } from '@angular/common';
|
3 |
+
import { FormsModule } from '@angular/forms';
|
4 |
+
import { MatDialog } from '@angular/material/dialog';
|
5 |
+
import { MatSnackBar } from '@angular/material/snack-bar';
|
6 |
+
import { MatTableModule } from '@angular/material/table';
|
7 |
+
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
8 |
+
import { MatButtonModule } from '@angular/material/button';
|
9 |
+
import { MatCheckboxModule } from '@angular/material/checkbox';
|
10 |
+
import { MatFormFieldModule } from '@angular/material/form-field';
|
11 |
+
import { MatInputModule } from '@angular/material/input';
|
12 |
+
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
13 |
+
import { MatCardModule } from '@angular/material/card';
|
14 |
+
import { MatChipsModule } from '@angular/material/chips';
|
15 |
+
import { MatIconModule } from '@angular/material/icon';
|
16 |
+
import { ApiService, Project } from '../../services/api.service';
|
17 |
+
import { ProjectEditDialogComponent } from '../../dialogs/project-edit-dialog/project-edit-dialog.component';
|
18 |
+
import { VersionEditDialogComponent } from '../../dialogs/version-edit-dialog/version-edit-dialog.component';
|
19 |
+
import { ConfirmDialogComponent } from '../../dialogs/confirm-dialog/confirm-dialog.component';
|
20 |
+
|
21 |
+
@Component({
|
22 |
+
selector: 'app-projects',
|
23 |
+
standalone: true,
|
24 |
+
imports: [
|
25 |
+
CommonModule,
|
26 |
+
FormsModule,
|
27 |
+
MatTableModule,
|
28 |
+
MatProgressBarModule,
|
29 |
+
MatButtonModule,
|
30 |
+
MatCheckboxModule,
|
31 |
+
MatFormFieldModule,
|
32 |
+
MatInputModule,
|
33 |
+
MatButtonToggleModule,
|
34 |
+
MatCardModule,
|
35 |
+
MatChipsModule,
|
36 |
+
MatIconModule
|
37 |
+
],
|
38 |
+
templateUrl: './projects.component.html',
|
39 |
+
styleUrls: ['./projects.component.scss']
|
40 |
+
})
|
41 |
+
export class ProjectsComponent implements OnInit {
|
42 |
+
projects: Project[] = [];
|
43 |
+
filteredProjects: Project[] = [];
|
44 |
+
searchTerm = '';
|
45 |
+
showDeleted = false;
|
46 |
+
viewMode: 'list' | 'card' = 'card';
|
47 |
+
loading = false;
|
48 |
+
message = '';
|
49 |
+
isError = false;
|
50 |
+
|
51 |
+
constructor(
|
52 |
+
private apiService: ApiService,
|
53 |
+
private dialog: MatDialog,
|
54 |
+
private snackBar: MatSnackBar
|
55 |
+
) {}
|
56 |
+
|
57 |
+
ngOnInit() {
|
58 |
+
this.loadProjects();
|
59 |
+
}
|
60 |
+
|
61 |
+
async loadProjects() {
|
62 |
+
this.loading = true;
|
63 |
+
try {
|
64 |
+
this.projects = await this.apiService.getProjects(this.showDeleted).toPromise() || [];
|
65 |
+
this.applyFilter();
|
66 |
+
} catch (error) {
|
67 |
+
this.showMessage('Failed to load projects', true);
|
68 |
+
} finally {
|
69 |
+
this.loading = false;
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
applyFilter() {
|
74 |
+
this.filteredProjects = this.projects.filter(project => {
|
75 |
+
const matchesSearch = !this.searchTerm ||
|
76 |
+
project.name.toLowerCase().includes(this.searchTerm.toLowerCase()) ||
|
77 |
+
(project.caption || '').toLowerCase().includes(this.searchTerm.toLowerCase());
|
78 |
+
|
79 |
+
const matchesDeleted = this.showDeleted || !project.deleted;
|
80 |
+
|
81 |
+
return matchesSearch && matchesDeleted;
|
82 |
+
});
|
83 |
+
}
|
84 |
+
|
85 |
+
filterProjects() {
|
86 |
+
this.applyFilter();
|
87 |
+
}
|
88 |
+
|
89 |
+
onSearchChange() {
|
90 |
+
this.applyFilter();
|
91 |
+
}
|
92 |
+
|
93 |
+
onShowDeletedChange() {
|
94 |
+
this.loadProjects();
|
95 |
+
}
|
96 |
+
|
97 |
+
createProject() {
|
98 |
+
const dialogRef = this.dialog.open(ProjectEditDialogComponent, {
|
99 |
+
width: '500px',
|
100 |
+
data: { mode: 'create' }
|
101 |
+
});
|
102 |
+
|
103 |
+
dialogRef.afterClosed().subscribe(result => {
|
104 |
+
if (result) {
|
105 |
+
this.loadProjects();
|
106 |
+
}
|
107 |
+
});
|
108 |
+
}
|
109 |
+
|
110 |
+
editProject(project: Project) {
|
111 |
+
const dialogRef = this.dialog.open(ProjectEditDialogComponent, {
|
112 |
+
width: '500px',
|
113 |
+
data: { mode: 'edit', project: { ...project } }
|
114 |
+
});
|
115 |
+
|
116 |
+
dialogRef.afterClosed().subscribe(result => {
|
117 |
+
if (result) {
|
118 |
+
this.loadProjects();
|
119 |
+
}
|
120 |
+
});
|
121 |
+
}
|
122 |
+
|
123 |
+
async toggleProject(project: Project) {
|
124 |
+
try {
|
125 |
+
const result = await this.apiService.toggleProject(project.id).toPromise();
|
126 |
+
project.enabled = result.enabled;
|
127 |
+
this.showMessage(
|
128 |
+
`Project "${project.name}" ${project.enabled ? 'enabled' : 'disabled'} successfully`,
|
129 |
+
false
|
130 |
+
);
|
131 |
+
} catch (error) {
|
132 |
+
this.showMessage('Failed to toggle project', true);
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
manageVersions(project: Project) {
|
137 |
+
const dialogRef = this.dialog.open(VersionEditDialogComponent, {
|
138 |
+
width: '90vw',
|
139 |
+
maxWidth: '1200px',
|
140 |
+
height: '90vh',
|
141 |
+
data: { project }
|
142 |
+
});
|
143 |
+
|
144 |
+
dialogRef.afterClosed().subscribe(result => {
|
145 |
+
if (result) {
|
146 |
+
this.loadProjects();
|
147 |
+
}
|
148 |
+
});
|
149 |
+
}
|
150 |
+
|
151 |
+
async deleteProject(project: Project) {
|
152 |
+
const hasVersions = project.versions && project.versions.length > 0;
|
153 |
+
const message = hasVersions ?
|
154 |
+
`Project "${project.name}" has ${project.versions.length} version(s). Are you sure you want to delete it?` :
|
155 |
+
`Are you sure you want to delete project "${project.name}"?`;
|
156 |
+
|
157 |
+
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
158 |
+
width: '400px',
|
159 |
+
data: {
|
160 |
+
title: 'Delete Project',
|
161 |
+
message: message,
|
162 |
+
confirmText: 'Delete',
|
163 |
+
confirmColor: 'warn'
|
164 |
+
}
|
165 |
+
});
|
166 |
+
|
167 |
+
dialogRef.afterClosed().subscribe(async confirmed => {
|
168 |
+
if (confirmed) {
|
169 |
+
try {
|
170 |
+
await this.apiService.deleteProject(project.id).toPromise();
|
171 |
+
this.showMessage('Project deleted successfully', false);
|
172 |
+
this.loadProjects();
|
173 |
+
} catch (error: any) {
|
174 |
+
const message = error.error?.detail || 'Failed to delete project';
|
175 |
+
this.showMessage(message, true);
|
176 |
+
}
|
177 |
+
}
|
178 |
+
});
|
179 |
+
}
|
180 |
+
|
181 |
+
async exportProject(project: Project) {
|
182 |
+
try {
|
183 |
+
const data = await this.apiService.exportProject(project.id).toPromise();
|
184 |
+
|
185 |
+
// Create and download file
|
186 |
+
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
|
187 |
+
const url = window.URL.createObjectURL(blob);
|
188 |
+
const link = document.createElement('a');
|
189 |
+
link.href = url;
|
190 |
+
link.download = `${project.name}_export_${new Date().getTime()}.json`;
|
191 |
+
link.click();
|
192 |
+
window.URL.revokeObjectURL(url);
|
193 |
+
|
194 |
+
this.showMessage('Project exported successfully', false);
|
195 |
+
} catch (error) {
|
196 |
+
this.showMessage('Failed to export project', true);
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
importProject() {
|
201 |
+
const input = document.createElement('input');
|
202 |
+
input.type = 'file';
|
203 |
+
input.accept = '.json';
|
204 |
+
|
205 |
+
input.onchange = async (event: any) => {
|
206 |
+
const file = event.target.files[0];
|
207 |
+
if (!file) return;
|
208 |
+
|
209 |
+
try {
|
210 |
+
const text = await file.text();
|
211 |
+
const data = JSON.parse(text);
|
212 |
+
|
213 |
+
await this.apiService.importProject(data).toPromise();
|
214 |
+
this.showMessage('Project imported successfully', false);
|
215 |
+
this.loadProjects();
|
216 |
+
} catch (error: any) {
|
217 |
+
const message = error.error?.detail || 'Failed to import project';
|
218 |
+
this.showMessage(message, true);
|
219 |
+
}
|
220 |
+
};
|
221 |
+
|
222 |
+
input.click();
|
223 |
+
}
|
224 |
+
|
225 |
+
getPublishedCount(project: Project): number {
|
226 |
+
return project.versions?.filter(v => v.published).length || 0;
|
227 |
+
}
|
228 |
+
|
229 |
+
getRelativeTime(timestamp: string | undefined): string {
|
230 |
+
if (!timestamp) return 'Never';
|
231 |
+
|
232 |
+
const date = new Date(timestamp);
|
233 |
+
const now = new Date();
|
234 |
+
const diffMs = now.getTime() - date.getTime();
|
235 |
+
const diffMins = Math.floor(diffMs / 60000);
|
236 |
+
const diffHours = Math.floor(diffMs / 3600000);
|
237 |
+
const diffDays = Math.floor(diffMs / 86400000);
|
238 |
+
|
239 |
+
if (diffMins < 60) return `${diffMins} minutes ago`;
|
240 |
+
if (diffHours < 24) return `${diffHours} hours ago`;
|
241 |
+
if (diffDays < 7) return `${diffDays} days ago`;
|
242 |
+
|
243 |
+
return date.toLocaleDateString();
|
244 |
+
}
|
245 |
+
|
246 |
+
private showMessage(message: string, isError: boolean) {
|
247 |
+
this.message = message;
|
248 |
+
this.isError = isError;
|
249 |
+
|
250 |
+
setTimeout(() => {
|
251 |
+
this.message = '';
|
252 |
+
}, 5000);
|
253 |
+
}
|
254 |
+
}
|
255 |
+
|
256 |
+
|
257 |
+
|
258 |
+
|
259 |
+
import { Component, inject, OnInit } from '@angular/core';
|
260 |
+
import { CommonModule } from '@angular/common';
|
261 |
+
import { FormsModule } from '@angular/forms';
|
262 |
+
import { ApiService, Project } from '../../services/api.service';
|
263 |
+
|
264 |
+
@Component({
|
265 |
+
selector: 'app-projects',
|
266 |
+
standalone: true,
|
267 |
+
imports: [CommonModule, FormsModule],
|
268 |
+
template: `
|
269 |
+
|
270 |
+
`,
|
271 |
+
styles: [`
|
272 |
+
.projects-container {
|
273 |
+
.toolbar {
|
274 |
+
display: flex;
|
275 |
+
justify-content: space-between;
|
276 |
+
align-items: center;
|
277 |
+
margin-bottom: 1.5rem;
|
278 |
+
|
279 |
+
h2 {
|
280 |
+
margin: 0;
|
281 |
+
}
|
282 |
+
|
283 |
+
.toolbar-actions {
|
284 |
+
display: flex;
|
285 |
+
gap: 0.5rem;
|
286 |
+
align-items: center;
|
287 |
+
}
|
288 |
+
}
|
289 |
+
|
290 |
+
.search-input {
|
291 |
+
padding: 0.375rem 0.75rem;
|
292 |
+
border: 1px solid #ced4da;
|
293 |
+
border-radius: 0.25rem;
|
294 |
+
width: 200px;
|
295 |
+
}
|
296 |
+
|
297 |
+
.checkbox-label {
|
298 |
+
display: flex;
|
299 |
+
align-items: center;
|
300 |
+
gap: 0.25rem;
|
301 |
+
cursor: pointer;
|
302 |
+
}
|
303 |
+
|
304 |
+
.view-toggle {
|
305 |
+
display: flex;
|
306 |
+
border: 1px solid #ced4da;
|
307 |
+
border-radius: 0.25rem;
|
308 |
+
overflow: hidden;
|
309 |
+
|
310 |
+
button {
|
311 |
+
background: white;
|
312 |
+
border: none;
|
313 |
+
padding: 0.375rem 0.75rem;
|
314 |
+
cursor: pointer;
|
315 |
+
|
316 |
+
&.active {
|
317 |
+
background-color: #007bff;
|
318 |
+
color: white;
|
319 |
+
}
|
320 |
+
}
|
321 |
+
}
|
322 |
+
|
323 |
+
.loading, .empty-state {
|
324 |
+
text-align: center;
|
325 |
+
padding: 3rem;
|
326 |
+
background-color: white;
|
327 |
+
border-radius: 0.25rem;
|
328 |
+
|
329 |
+
p {
|
330 |
+
margin-bottom: 1rem;
|
331 |
+
color: #6c757d;
|
332 |
+
}
|
333 |
+
}
|
334 |
+
|
335 |
+
.project-cards {
|
336 |
+
display: grid;
|
337 |
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
338 |
+
gap: 1rem;
|
339 |
+
}
|
340 |
+
|
341 |
+
.project-card {
|
342 |
+
background: white;
|
343 |
+
border: 1px solid #dee2e6;
|
344 |
+
border-radius: 0.5rem;
|
345 |
+
padding: 1.5rem;
|
346 |
+
|
347 |
+
&:hover {
|
348 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
349 |
+
}
|
350 |
+
|
351 |
+
&.disabled {
|
352 |
+
opacity: 0.7;
|
353 |
+
}
|
354 |
+
|
355 |
+
&.deleted {
|
356 |
+
background-color: #f8f9fa;
|
357 |
+
}
|
358 |
+
|
359 |
+
.project-icon {
|
360 |
+
font-size: 2rem;
|
361 |
+
margin-bottom: 0.5rem;
|
362 |
+
}
|
363 |
+
|
364 |
+
h3 {
|
365 |
+
margin: 0 0 0.5rem 0;
|
366 |
+
font-size: 1.25rem;
|
367 |
+
}
|
368 |
+
|
369 |
+
p {
|
370 |
+
color: #6c757d;
|
371 |
+
margin-bottom: 1rem;
|
372 |
+
}
|
373 |
+
|
374 |
+
.project-meta {
|
375 |
+
font-size: 0.875rem;
|
376 |
+
color: #6c757d;
|
377 |
+
margin-bottom: 1rem;
|
378 |
+
|
379 |
+
span {
|
380 |
+
display: block;
|
381 |
+
margin-bottom: 0.25rem;
|
382 |
+
}
|
383 |
+
}
|
384 |
+
|
385 |
+
.project-actions {
|
386 |
+
display: flex;
|
387 |
+
gap: 0.5rem;
|
388 |
+
flex-wrap: wrap;
|
389 |
+
|
390 |
+
button {
|
391 |
+
flex: 1;
|
392 |
+
min-width: 80px;
|
393 |
+
font-size: 0.875rem;
|
394 |
+
padding: 0.375rem 0.5rem;
|
395 |
+
}
|
396 |
+
}
|
397 |
+
}
|
398 |
+
|
399 |
+
.status-badge {
|
400 |
+
&.enabled { color: #28a745; }
|
401 |
+
&.deleted { color: #dc3545; }
|
402 |
+
}
|
403 |
+
|
404 |
+
.actions {
|
405 |
+
display: flex;
|
406 |
+
gap: 0.25rem;
|
407 |
+
}
|
408 |
+
|
409 |
+
.action-btn {
|
410 |
+
background: none;
|
411 |
+
border: none;
|
412 |
+
cursor: pointer;
|
413 |
+
font-size: 1.1rem;
|
414 |
+
padding: 0.25rem;
|
415 |
+
border-radius: 0.25rem;
|
416 |
+
|
417 |
+
&:hover {
|
418 |
+
background-color: #f8f9fa;
|
419 |
+
}
|
420 |
+
|
421 |
+
&.danger:hover {
|
422 |
+
background-color: #f8d7da;
|
423 |
+
}
|
424 |
+
}
|
425 |
+
|
426 |
+
tr.deleted {
|
427 |
+
opacity: 0.6;
|
428 |
+
background-color: #f8f9fa;
|
429 |
+
}
|
430 |
+
}
|
431 |
+
`]
|
432 |
+
})
|
433 |
+
export class ProjectsComponent implements OnInit {
|
434 |
+
private apiService = inject(ApiService);
|
435 |
+
|
436 |
+
projects: Project[] = [];
|
437 |
+
filteredProjects: Project[] = [];
|
438 |
+
loading = true;
|
439 |
+
showDeleted = false;
|
440 |
+
searchTerm = '';
|
441 |
+
viewMode: 'card' | 'list' = 'card';
|
442 |
+
message = '';
|
443 |
+
isError = false;
|
444 |
+
|
445 |
+
ngOnInit() {
|
446 |
+
this.loadProjects();
|
447 |
+
}
|
448 |
+
|
449 |
+
loadProjects() {
|
450 |
+
this.loading = true;
|
451 |
+
this.apiService.getProjects(this.showDeleted).subscribe({
|
452 |
+
next: (projects) => {
|
453 |
+
this.projects = projects;
|
454 |
+
this.filterProjects();
|
455 |
+
this.loading = false;
|
456 |
+
},
|
457 |
+
error: (err) => {
|
458 |
+
this.showMessage('Failed to load projects', true);
|
459 |
+
this.loading = false;
|
460 |
+
}
|
461 |
+
});
|
462 |
+
}
|
463 |
+
|
464 |
+
filterProjects() {
|
465 |
+
const term = this.searchTerm.toLowerCase();
|
466 |
+
this.filteredProjects = this.projects.filter(project =>
|
467 |
+
project.name.toLowerCase().includes(term) ||
|
468 |
+
(project.caption || '').toLowerCase().includes(term)
|
469 |
+
);
|
470 |
+
}
|
471 |
+
|
472 |
+
getPublishedCount(project: Project): number {
|
473 |
+
return project.versions.filter(v => v.published).length || 0;
|
474 |
+
}
|
475 |
+
|
476 |
+
getRelativeTime(timestamp: string): string {
|
477 |
+
const date = new Date(timestamp);
|
478 |
+
const now = new Date();
|
479 |
+
const diff = now.getTime() - date.getTime();
|
480 |
+
|
481 |
+
const minutes = Math.floor(diff / 60000);
|
482 |
+
const hours = Math.floor(diff / 3600000);
|
483 |
+
const days = Math.floor(diff / 86400000);
|
484 |
+
|
485 |
+
if (minutes < 1) return 'just now';
|
486 |
+
if (minutes < 60) return `${minutes} min ago`;
|
487 |
+
if (hours < 24) return `${hours} hour${hours > 1 ? 's' : ''} ago`;
|
488 |
+
return `${days} day${days > 1 ? 's' : ''} ago`;
|
489 |
+
}
|
490 |
+
|
491 |
+
createProject() {
|
492 |
+
// TODO: Open create dialog
|
493 |
+
console.log('Create project - not implemented yet');
|
494 |
+
}
|
495 |
+
|
496 |
+
editProject(project: Project) {
|
497 |
+
// TODO: Open edit dialog
|
498 |
+
console.log('Edit project:', project.name);
|
499 |
+
}
|
500 |
+
|
501 |
+
manageVersions(project: Project) {
|
502 |
+
// TODO: Open versions dialog
|
503 |
+
console.log('Manage versions:', project.name);
|
504 |
+
}
|
505 |
+
|
506 |
+
exportProject(project: Project) {
|
507 |
+
this.apiService.exportProject(project.id).subscribe({
|
508 |
+
next: (data) => {
|
509 |
+
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
|
510 |
+
const url = window.URL.createObjectURL(blob);
|
511 |
+
const a = document.createElement('a');
|
512 |
+
a.href = url;
|
513 |
+
a.download = `${project.name}_export.json`;
|
514 |
+
a.click();
|
515 |
+
window.URL.revokeObjectURL(url);
|
516 |
+
this.showMessage(`Project "${project.name}" exported successfully`, false);
|
517 |
+
},
|
518 |
+
error: (err) => {
|
519 |
+
this.showMessage('Failed to export project', true);
|
520 |
+
}
|
521 |
+
});
|
522 |
+
}
|
523 |
+
|
524 |
+
toggleProject(project: Project) {
|
525 |
+
this.apiService.toggleProject(project.id).subscribe({
|
526 |
+
next: (result) => {
|
527 |
+
project.enabled = result.enabled;
|
528 |
+
this.showMessage(`Project "${project.name}" ${result.enabled ? 'enabled' : 'disabled'}`, false);
|
529 |
+
},
|
530 |
+
error: (err) => {
|
531 |
+
this.showMessage('Failed to toggle project', true);
|
532 |
+
}
|
533 |
+
});
|
534 |
+
}
|
535 |
+
|
536 |
+
deleteProject(project: Project) {
|
537 |
+
if (confirm(`Are you sure you want to delete "${project.name}"?`)) {
|
538 |
+
this.apiService.deleteProject(project.id).subscribe({
|
539 |
+
next: () => {
|
540 |
+
this.showMessage(`Project "${project.name}" deleted successfully`, false);
|
541 |
+
this.loadProjects();
|
542 |
+
},
|
543 |
+
error: (err) => {
|
544 |
+
this.showMessage(err.error?.detail || 'Failed to delete project', true);
|
545 |
+
}
|
546 |
+
});
|
547 |
+
}
|
548 |
+
}
|
549 |
+
|
550 |
+
private showMessage(message: string, isError: boolean) {
|
551 |
+
this.message = message;
|
552 |
+
this.isError = isError;
|
553 |
+
|
554 |
+
setTimeout(() => {
|
555 |
+
this.message = '';
|
556 |
+
}, 5000);
|
557 |
+
}
|
558 |
}
|