Add endpoints, services, and security controls for particle file management, including save and download APIs.
This commit is contained in:
@@ -22,6 +22,7 @@ import {ParticleComponent} from './components/particle/particle.component';
|
||||
import {FramesComponent} from './components/frames/frames.component';
|
||||
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||
import {RenderContainerComponent} from './components/render-container/render-container.component';
|
||||
import {ParticlesService} from '../../api';
|
||||
|
||||
@Component({
|
||||
selector: 'app-particles',
|
||||
@@ -55,6 +56,7 @@ export class ParticlesComponent {
|
||||
private intersectionPlaneService: IntersectionPlaneService,
|
||||
private particleManagerService: ParticleManagerService,
|
||||
private matSnackBar: MatSnackBar,
|
||||
private particlesService: ParticlesService,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -93,9 +95,38 @@ export class ParticlesComponent {
|
||||
return this.particleManagerService.generateJson();
|
||||
}
|
||||
|
||||
public getJsonFile(): Blob {
|
||||
const jsonContent = this.generateJson();
|
||||
return new Blob([jsonContent], {type: 'application/json'});
|
||||
}
|
||||
|
||||
public saveJsonToFile(): void {
|
||||
const jsonContent = this.generateJson();
|
||||
const blob = new Blob([jsonContent], {type: 'application/json'});
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
|
||||
// Create a temporary link element
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'particle-data.json';
|
||||
|
||||
// Append to the document, click it, and remove it
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// Clean up
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
|
||||
this.matSnackBar.open('JSON file downloaded', '', {duration: 2000});
|
||||
}
|
||||
|
||||
|
||||
public copyJson() {
|
||||
navigator.clipboard.writeText(this.generateJson()).then(() => {
|
||||
this.matSnackBar.open('Copied to clipboard', '', {duration: 2000})
|
||||
});
|
||||
//TODO validation
|
||||
this.particlesService.saveFile(this.particleManagerService.getParticleData().particle_name, this.getJsonFile());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user