Commit 2d53dd1f authored by Romain DELEAU's avatar Romain DELEAU

copy role

parent 163aa336
......@@ -51,6 +51,7 @@ import { FinishTutorialComponent } from './components/snackbars/finish-tutorial/
import { VerifyGameFailSnackbarComponent } from './components/snackbars/verify-game-fail-snackbar/verify-game-fail-snackbar.component';
import { VerifyDialogComponent } from './components/dialogs/verify-dialog/verify-dialog.component';
import { RoleNameDuplicateComponent } from './components/snackbars/role-name-duplicate/role-name-duplicate.component';
import { CopyRoleSuccessComponent } from './components/snackbars/copy-role-success/copy-role-success.component';
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http);
......@@ -93,7 +94,8 @@ export function HttpLoaderFactory(http: HttpClient) {
FinishTutorialComponent,
VerifyGameFailSnackbarComponent,
VerifyDialogComponent,
RoleNameDuplicateComponent
RoleNameDuplicateComponent,
CopyRoleSuccessComponent
],
imports: [
BrowserModule,
......
<span matSnackBarLabel>{{'role_copy_snackbar' | translate}}</span>
\ No newline at end of file
::ng-deep .mat-snack-bar-container {
background-color: #1ba345;
color: white;
box-shadow: 0px 0px 15px 5px #1ba345;
text-align: center;
}
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CopyRoleSuccessComponent } from './copy-role-success.component';
describe('CopyRoleSuccessComponent', () => {
let component: CopyRoleSuccessComponent;
let fixture: ComponentFixture<CopyRoleSuccessComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ CopyRoleSuccessComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(CopyRoleSuccessComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-copy-role-success',
templateUrl: './copy-role-success.component.html',
styleUrls: ['./copy-role-success.component.scss']
})
export class CopyRoleSuccessComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
......@@ -10,6 +10,12 @@ matTooltipPosition="left" [matTooltipDisabled]="!tooltipService.activatedTooltip
<mat-icon fontIcon="add" (click)="onClickAdd()"
[matTooltip]="translate.instant('role_add_tooltip')"
matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>
<mat-icon fontIcon="content_copy" (click)="onClickCopy()"
[matTooltip]="translate.instant('role_copy_tooltip')"
matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>
<mat-icon fontIcon="content_paste" (click)="onClickPaste()" *ngIf="copyRoleService.role && mission != copyRoleService.mission"
[matTooltip]="translate.instant('role_paste_tooltip')"
matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>
<mat-icon fontIcon="backspace" (click)="onClickErase()"
[matTooltip]="translate.instant('clearPiece_tooltip')"
matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>
......@@ -25,7 +31,7 @@ matTooltipPosition="left" [matTooltipDisabled]="!tooltipService.activatedTooltip
<img src="./assets/background-images/role2_opacity0.png" draggable="false" *ngIf="i == 1"/>
<div class="piece-form-intitule">
<label for="intitule">{{'role_intitule_label' | translate}}</label>
<input name="intitule" type="text" [(ngModel)]="role.intitule" (change)="changeIntitule($event); validTutorialPhase4();" [placeholder]="translate.instant('role_intitule_placeholder')"
<input name="intitule" type="text" [(ngModel)]="role.intitule" (change)="intituleIsAlreadyUsed(); editTrace($event, 'name');; validTutorialPhase4();" [placeholder]="translate.instant('role_intitule_placeholder')"
[matTooltip]="translate.instant('role_intitule_tooltip')"
matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"/>
</div>
......
......@@ -23,6 +23,9 @@ import { TranslateService } from '@ngx-translate/core';
import { TutorialService } from 'src/app/services/tutorial/tutorial.service';
import { MatSnackBar } from '@angular/material/snack-bar';
import { RoleNameDuplicateComponent } from 'src/app/components/snackbars/role-name-duplicate/role-name-duplicate.component';
import { CopyRoleService } from 'src/app/services/copyRole/copy-role.service';
import { Task } from 'src/app/class/task/task';
import { CopyRoleSuccessComponent } from 'src/app/components/snackbars/copy-role-success/copy-role-success.component';
@Component({
selector: 'app-role',
......@@ -37,7 +40,7 @@ export class RoleComponent implements OnInit {
@Input() i: number = 0;
@Input() missionIndex: number = 0;
constructor(protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService, public dialog: MatDialog, private minimapService: MinimapService, protected translate: TranslateService, private tutorialService: TutorialService, private _snackBar: MatSnackBar,) { }
constructor(protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService, public dialog: MatDialog, private minimapService: MinimapService, protected translate: TranslateService, private tutorialService: TutorialService, private _snackBar: MatSnackBar, protected copyRoleService: CopyRoleService) { }
ngOnInit(): void {
this.mission.equalizeLengths();
......@@ -64,6 +67,28 @@ export class RoleComponent implements OnInit {
});
}
onClickCopy(): void {
this.copyRoleService.role = Object.assign({}, this.role);
this.copyRoleService.role.questName = '';
this.copyRoleService.role.description = '';
this.copyRoleService.role.educationnalObjectives = [];
this.copyRoleService.role.rewards = [];
this.copyRoleService.role.ressources = this.role.ressources.map((ressourceData: any) => Object.assign(new Ressource(), ressourceData));
this.copyRoleService.role.supplementaryRoles = this.role.supplementaryRoles.map((supplementaryRoleData: any) => Object.assign(new SupplementaryRole(), supplementaryRoleData));
this.copyRoleService.role.tasks = [[new Task('normal')], []];
this.copyRoleService.role.chronologie = [];
this.copyRoleService.mission = this.mission;
this._snackBar.openFromComponent(CopyRoleSuccessComponent, { duration: 5000 });
}
onClickPaste(): void {
this.role = Object.assign({}, this.copyRoleService.role);
this.role.ressources = (this.copyRoleService.role as Role).ressources.map((ressourceData: any) => Object.assign(new Ressource(), ressourceData));
this.role.supplementaryRoles = (this.copyRoleService.role as Role).supplementaryRoles.map((supplementaryRoleData: any) => Object.assign(new SupplementaryRole(), supplementaryRoleData));
this.role.tasks = [[new Task('normal')], []];
this.intituleIsAlreadyUsed();
}
onClickErase(): void {
const dialogRef = this.dialog.open(CleanDialogComponent, { data: this.translate.instant('role_clean')+' '+(this.role.intitule ? '<'+this.role.intitule+'>' : (this.i+1)) });
dialogRef.afterClosed().subscribe(result => {
......@@ -296,13 +321,12 @@ export class RoleComponent implements OnInit {
}
}
changeIntitule(event: any): void {
intituleIsAlreadyUsed(): void {
this.mission.roles.forEach(role => {
if (role != this.role && role.intitule == this.role.intitule) {
this._snackBar.openFromComponent(RoleNameDuplicateComponent, { duration: 5000 });
this.role.intitule = '';
}
});
this.editTrace(event, 'name');
}
}
import { TestBed } from '@angular/core/testing';
import { CopyRoleService } from './copy-role.service';
describe('CopyRoleService', () => {
let service: CopyRoleService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(CopyRoleService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import { Mission } from 'src/app/class/mission/mission';
import { Role } from 'src/app/class/role/role';
@Injectable({
providedIn: 'root'
})
export class CopyRoleService {
role: Role|null = null;
mission: Mission|null = null;
constructor() { }
}
......@@ -153,6 +153,9 @@
"role_supplementaryRole_rule_label": "Rules",
"role_supplementaryRole_rule_tooltip": "Rules specific to this role (does it have any constraints or additional rights or access?)",
"role_supplementaryRole_delete": "this Additional role",
"role_copy_tooltip": "Copy the content",
"role_copy_snackbar": "Role copied, go to another mission to paste it.",
"role_paste_tooltip": "Paste the content",
"steps_mission": "Chronology of the mission",
"steps_role": "Chronology of the role",
......
......@@ -153,6 +153,9 @@
"role_supplementaryRole_rule_label": "Règles",
"role_supplementaryRole_rule_tooltip": "Règles spécifiques à ce rôle (a-t-il des contraintes ou des droits, accès supplémentaires ?)",
"role_supplementaryRole_delete": "ce Rôle supplémentaire",
"role_copy_tooltip": "Copier le contenu",
"role_copy_snackbar": "Role copié, rendez-vous dans une autre mission pour le coller",
"role_paste_tooltip": "Coller le contenu",
"steps_mission": "Chronologie de la mission",
"steps_role": "Chronologie du rôle",
......
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