Commit 750541f9 authored by Romain DELEAU's avatar Romain DELEAU

add name input and idialog when download button is clicked + change font-family of dialogs

parent c19a76c3
...@@ -25,6 +25,8 @@ import { OtherReward } from './class/rewards/other-reward/other-reward'; ...@@ -25,6 +25,8 @@ import { OtherReward } from './class/rewards/other-reward/other-reward';
import { PrerequireRessource } from './class/prerequires/prerequire-ressource/prerequire-ressource'; import { PrerequireRessource } from './class/prerequires/prerequire-ressource/prerequire-ressource';
import { TooltipService } from './services/tooltip/tooltip.service'; import { TooltipService } from './services/tooltip/tooltip.service';
import { ZoomService } from './services/zoom/zoom.service'; import { ZoomService } from './services/zoom/zoom.service';
import { MatDialog } from '@angular/material/dialog';
import { SaveDialogComponent } from './components/dialogs/save-dialog/save-dialog.component';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
...@@ -38,7 +40,7 @@ export class AppComponent { ...@@ -38,7 +40,7 @@ export class AppComponent {
@ViewChild('fileInput') fileInput: any; @ViewChild('fileInput') fileInput: any;
constructor(private cdr: ChangeDetectorRef, protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService, constructor(private cdr: ChangeDetectorRef, protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService,
private elementRef: ElementRef, private zoomService: ZoomService) { private elementRef: ElementRef, private zoomService: ZoomService, private dialog: MatDialog) {
pieceDetailsService.piece = this.scenario; pieceDetailsService.piece = this.scenario;
this.scenario.missions.forEach(mission => { this.scenario.missions.forEach(mission => {
...@@ -54,14 +56,31 @@ export class AppComponent { ...@@ -54,14 +56,31 @@ export class AppComponent {
} }
downloadFile(): void { downloadFile(): void {
const jsonString = JSON.stringify(this.scenario); let fileName: string = this.scenario.projectName;
const blob = new Blob([jsonString], { type: 'application/json' }); const dialogRef = this.dialog.open(SaveDialogComponent, {
const url = URL.createObjectURL(blob); data: {
const link = document.createElement('a'); fileName: fileName,
link.download = 'scenario.json'; result: false
link.href = url; }
link.click(); });
URL.revokeObjectURL(url); dialogRef.afterClosed().subscribe(data => {
if (data.result) {
if (data.fileName == '') {
fileName = "Scénario - RLG Maker";
} else {
this.scenario.projectName = data.fileName;
fileName = data.fileName+' - RLG Maker';
}
const jsonString = JSON.stringify(this.scenario);
const blob = new Blob([jsonString], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.download = fileName;
link.href = url;
link.click();
URL.revokeObjectURL(url);
}
});
} }
selectFile(): void { selectFile(): void {
......
...@@ -37,6 +37,7 @@ import { MouseWheelZoomDirective } from './directives/mouse-wheel-zoom.directive ...@@ -37,6 +37,7 @@ import { MouseWheelZoomDirective } from './directives/mouse-wheel-zoom.directive
import { CleanDialogComponent } from './components/dialogs/clean-dialog/clean-dialog.component'; import { CleanDialogComponent } from './components/dialogs/clean-dialog/clean-dialog.component';
import { CreateDialogComponent } from './components/dialogs/create-dialog/create-dialog.component'; import { CreateDialogComponent } from './components/dialogs/create-dialog/create-dialog.component';
import { GameCharactersComponent } from './pieces/game-characters/game-characters.component'; import { GameCharactersComponent } from './pieces/game-characters/game-characters.component';
import { SaveDialogComponent } from './components/dialogs/save-dialog/save-dialog.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
...@@ -66,7 +67,8 @@ import { GameCharactersComponent } from './pieces/game-characters/game-character ...@@ -66,7 +67,8 @@ import { GameCharactersComponent } from './pieces/game-characters/game-character
SuppressDialogComponent, SuppressDialogComponent,
CleanDialogComponent, CleanDialogComponent,
CreateDialogComponent, CreateDialogComponent,
GameCharactersComponent GameCharactersComponent,
SaveDialogComponent
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
......
...@@ -14,4 +14,5 @@ export class Scenario { ...@@ -14,4 +14,5 @@ export class Scenario {
gameRules: string = ''; gameRules: string = '';
ressources: Ressource[] = []; ressources: Ressource[] = [];
comments: Comment[] = []; comments: Comment[] = [];
projectName: string = '';
} }
\ No newline at end of file
h2 {
font-family: 'Glacial Indifference Bold';
}
button { button {
margin-top: 20px; margin-top: 20px;
} }
\ No newline at end of file
h2 {
font-family: 'Glacial Indifference Bold', sans-serif;
}
button { button {
margin-top: 20px; margin-top: 20px;
} }
\ No newline at end of file
<h2 mat-dialog-title>Télécharger le scénario</h2>
<mat-dialog-content>
<label for="name">Nom du projet :</label>
<input name="name" type="text" placeholder="Mon Scénario" [(ngModel)]="data.fileName"/>
</mat-dialog-content>
<mat-dialog-actions align="center">
<button mat-button mat-dialog-close>Annuler</button>
<button mat-button (click)="data.result = true" [mat-dialog-close]="data" cdkFocusInitial>Télécharger</button>
</mat-dialog-actions>
\ No newline at end of file
h2 {
font-family: 'Glacial Indifference Bold', sans-serif;
}
mat-dialog-content {
display: flex;
flex-direction: column;
text-align: center;
label {
font-size: 17px;
margin-bottom: 5px;
}
input {
text-align: center;
border-radius: 5px;
height: 25px;
}
}
button {
margin-top: 20px;
}
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SaveDialogComponent } from './save-dialog.component';
describe('SaveDialogComponent', () => {
let component: SaveDialogComponent;
let fixture: ComponentFixture<SaveDialogComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ SaveDialogComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(SaveDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit, Inject } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
@Component({
selector: 'app-save-dialog',
templateUrl: './save-dialog.component.html',
styleUrls: ['./save-dialog.component.scss']
})
export class SaveDialogComponent implements OnInit {
constructor(@Inject(MAT_DIALOG_DATA) public data: {fileName: string, result: boolean}) { }
ngOnInit(): void {
}
}
h2 {
font-family: 'Glacial Indifference Bold', sans-serif;
}
button { button {
margin-top: 20px; margin-top: 20px;
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment