Commit d9ebbd0c authored by Romain DELEAU's avatar Romain DELEAU

copy/paste tasks

parent 25734a4f
......@@ -473,7 +473,7 @@ export class AppComponent {
if (task.supplementaryRole) {
task.supplementaryRole = Object.assign(new SupplementaryRole, task.supplementaryRole);
let supplementaryRoleIndex: number | undefined = role.supplementaryRoles.findIndex(element =>
element.name == task.supplementaryRole.name && element.color == task.supplementaryRole.color
element.name == (task.supplementaryRole as SupplementaryRole).name && element.color == (task.supplementaryRole as SupplementaryRole).color
);
task.supplementaryRole = role.supplementaryRoles[supplementaryRoleIndex];
}
......
......@@ -60,6 +60,7 @@ import { CreateOptionnalTaskDialogComponent } from './components/dialogs/create-
import { DeleteOptionnalTasksComponent } from './components/snackbars/delete-optionnal-tasks/delete-optionnal-tasks.component';
import { DiscussionsComponent } from './sider-pieces/discussions/discussions.component';
import { DiscussionDialogComponent } from './components/dialogs/discussion-dialog/discussion-dialog.component';
import { CopyTaskSuccessComponent } from './components/snackbars/copy-task-success/copy-task-success.component';
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http);
......@@ -110,7 +111,8 @@ export function HttpLoaderFactory(http: HttpClient) {
CreateOptionnalTaskDialogComponent,
DeleteOptionnalTasksComponent,
DiscussionsComponent,
DiscussionDialogComponent
DiscussionDialogComponent,
CopyTaskSuccessComponent
],
imports: [
BrowserModule,
......
......@@ -34,7 +34,7 @@ export class Task {
other: string = '';
role: string = ''; //role.intitule
supplementaryRole!: SupplementaryRole;
supplementaryRole: SupplementaryRole|null = null;
interrupt: string = '';
rewards: Reward[] = [];
......
<span matSnackBarLabel>{{'task_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;
white-space: pre-wrap;
}
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CopyTaskSuccessComponent } from './copy-task-success.component';
describe('CopyTaskSuccessComponent', () => {
let component: CopyTaskSuccessComponent;
let fixture: ComponentFixture<CopyTaskSuccessComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ CopyTaskSuccessComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(CopyTaskSuccessComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-copy-task-success',
templateUrl: './copy-task-success.component.html',
styleUrls: ['./copy-task-success.component.scss']
})
export class CopyTaskSuccessComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
......@@ -9,6 +9,12 @@
<div class="piece-attach piece-attach-right" [style.background]="task.supplementaryRole ? task.supplementaryRole.color : 'var(--piece-background-color)'"></div>
<div class="piece-menu" [class]="displayMenu">
<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="copyTaskService.task && role != copyTaskService.role && (copyTaskService.task?.type == 'final' || copyTaskService.task?.type == 'repeat' ? canChangeInFinalTask() : true)"
[matTooltip]="translate.instant('role_paste_tooltip')"
matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>
<div>
<mat-icon fontIcon="change_circle" [matMenuTriggerFor]="menuChange"
[matTooltip]="translate.instant('task_transform_tooltip')"
......
......@@ -7,7 +7,7 @@
&-menu {
position: absolute;
width: 220px;
width: 260px;
height: 50px;
background-color: #f7f7f7;
z-index: -1;
......
......@@ -19,6 +19,8 @@ import { TranslateService } from '@ngx-translate/core';
import { TutorialService } from 'src/app/services/tutorial/tutorial.service';
import { FinishTutorialComponent } from 'src/app/components/snackbars/finish-tutorial/finish-tutorial.component';
import { UnityService } from 'src/app/services/unity/unity.service';
import { CopyTaskService } from 'src/app/services/copyTask/copy-task.service';
import { CopyTaskSuccessComponent } from 'src/app/components/snackbars/copy-task-success/copy-task-success.component';
@Component({
selector: 'app-annexe-task',
......@@ -46,7 +48,8 @@ export class AnnexeTaskComponent implements OnInit {
antecedent: boolean = false;
constructor(protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService, public dialog: MatDialog,
private _snackBar: MatSnackBar, private minimapService: MinimapService, protected translate: TranslateService, private tutorialService: TutorialService, protected unityService: UnityService) { }
private _snackBar: MatSnackBar, private minimapService: MinimapService, protected translate: TranslateService, private tutorialService: TutorialService, protected unityService: UnityService,
protected copyTaskService: CopyTaskService) { }
ngOnInit(): void {
this.setPieceWidth();
......@@ -156,6 +159,19 @@ export class AnnexeTaskComponent implements OnInit {
});
}
onClickCopy() {
this.copyTaskService.onClickCopy(this.scenario, this.role, this.task);
this._snackBar.openFromComponent(CopyTaskSuccessComponent, { duration: 5000 });
}
onClickPaste() {
this.role.tasks[this.i][this.j] = this.copyTaskService.onClickPaste(this.scenario);;
if (this.role.isAlreadyUsedIdentifier((this.role.tasks[this.i][this.j] as Task).identifier)) {
this._snackBar.openFromComponent(IdentifierSnackbarComponent, { duration: 5000 });
(this.role.tasks[this.i][this.j] as Task).identifier = '';
}
}
onClickChange(type: string): void {
this.task.changeType(type);
this.scenario.traces.push(new Trace(this.scenario.traces.length,'transform_into_['+type+']',this.missionIndex,this.roleIndex,'all','Side_task_['+this.i+';'+this.j+']', '#BCCECC'));
......
......@@ -8,6 +8,12 @@
<div class="piece-attach piece-attach-left"></div>
<div class="piece-menu" [class]="displayMenu">
<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="copyTaskService.task && role != copyTaskService.role && (copyTaskService.task?.type == 'final' || copyTaskService.task?.type == 'repeat' ? canChangeInFinalTask() : true)"
[matTooltip]="translate.instant('role_paste_tooltip')"
matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>
<div>
<mat-icon fontIcon="change_circle" [matMenuTriggerFor]="menuChange"
[matTooltip]="translate.instant('task_transform_tooltip')"
......
......@@ -7,7 +7,7 @@
&-menu {
position: absolute;
width: 220px;
width: 260px;
height: 50px;
background-color: #f7f7f7;
z-index: -1;
......
......@@ -17,6 +17,8 @@ import { Trace } from 'src/app/class/trace/trace';
import { MinimapService } from 'src/app/services/minimap/minimap.service';
import { TranslateService } from '@ngx-translate/core';
import { UnityService } from 'src/app/services/unity/unity.service';
import { CopyTaskSuccessComponent } from 'src/app/components/snackbars/copy-task-success/copy-task-success.component';
import { CopyTaskService } from 'src/app/services/copyTask/copy-task.service';
@Component({
selector: 'app-final-task',
......@@ -44,7 +46,7 @@ export class FinalTaskComponent implements OnInit {
antecedent: boolean = false;
constructor(protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService, public dialog: MatDialog,
private _snackBar: MatSnackBar, private minimapService: MinimapService, protected translate: TranslateService, protected unityService: UnityService) { }
private _snackBar: MatSnackBar, private minimapService: MinimapService, protected translate: TranslateService, protected unityService: UnityService, protected copyTaskService: CopyTaskService) { }
ngOnInit(): void {
this.setPieceWidth();
......@@ -159,6 +161,19 @@ export class FinalTaskComponent implements OnInit {
});
}
onClickCopy() {
this.copyTaskService.onClickCopy(this.scenario, this.role, this.task);
this._snackBar.openFromComponent(CopyTaskSuccessComponent, { duration: 5000 });
}
onClickPaste() {
this.role.tasks[this.i][this.j] = this.copyTaskService.onClickPaste(this.scenario);;
if (this.role.isAlreadyUsedIdentifier((this.role.tasks[this.i][this.j] as Task).identifier)) {
this._snackBar.openFromComponent(IdentifierSnackbarComponent, { duration: 5000 });
(this.role.tasks[this.i][this.j] as Task).identifier = '';
}
}
changeDisplaySymbolChoice(): void {
if(this.displaySymbolChoice == 'show') {
this.displaySymbolChoice = 'hide';
......@@ -198,6 +213,21 @@ export class FinalTaskComponent implements OnInit {
}
}
canChangeInFinalTask(): boolean {
let res: boolean = true;
let lastTaskIndex: number = -1;
for (let i = this.role.tasks[this.i].length - 1; i >= 0; i--) {
if (this.role.tasks[this.i][i] instanceof Task) {
lastTaskIndex = i;
break;
}
}
if (this.j < lastTaskIndex || this.role.tasks[this.i].some(task => task?.type == 'final') || this.role.tasks[this.i].some(task => task?.type == 'repeat')) {
res = false;
}
return res;
}
moveTask(direction: string): void {
if (direction == 'left' && this.canMoveTo('left')) {
this.role.moveTask(this.i, this.j, direction);
......
......@@ -9,6 +9,12 @@
<div class="piece-attach piece-attach-right" [style.background]="task.supplementaryRole ? task.supplementaryRole.color : 'var(--piece-background-color)'"></div>
<div class="piece-menu" [class]="displayMenu">
<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="copyTaskService.task && role != copyTaskService.role && (copyTaskService.task?.type == 'final' || copyTaskService.task?.type == 'repeat' ? canChangeInFinalTask() : true)"
[matTooltip]="translate.instant('role_paste_tooltip')"
matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>
<div>
<mat-icon fontIcon="change_circle" [matMenuTriggerFor]="menuChange"
[matTooltip]="translate.instant('task_transform_tooltip')"
......
......@@ -7,7 +7,7 @@
&-menu {
position: absolute;
width: 220px;
width: 260px;
height: 50px;
background-color: #f7f7f7;
z-index: -1;
......
......@@ -19,6 +19,8 @@ import { TranslateService } from '@ngx-translate/core';
import { MoveOptionnalTasksComponent } from 'src/app/components/snackbars/move-optionnal-tasks/move-optionnal-tasks.component';
import { DeleteOptionnalTasksComponent } from 'src/app/components/snackbars/delete-optionnal-tasks/delete-optionnal-tasks.component';
import { UnityService } from 'src/app/services/unity/unity.service';
import { CopyTaskService } from 'src/app/services/copyTask/copy-task.service';
import { CopyTaskSuccessComponent } from 'src/app/components/snackbars/copy-task-success/copy-task-success.component';
@Component({
selector: 'app-optionnal-task',
......@@ -46,7 +48,7 @@ export class OptionnalTaskComponent implements OnInit {
antecedent: boolean = false;
constructor(protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService, public dialog: MatDialog,
private _snackBar: MatSnackBar, private minimapService: MinimapService, protected translate: TranslateService, protected unityService: UnityService) { }
private _snackBar: MatSnackBar, private minimapService: MinimapService, protected translate: TranslateService, protected unityService: UnityService, protected copyTaskService: CopyTaskService) { }
ngOnInit(): void {
this.setPieceWidth();
......@@ -166,6 +168,19 @@ export class OptionnalTaskComponent implements OnInit {
});
}
onClickCopy() {
this.copyTaskService.onClickCopy(this.scenario, this.role, this.task);
this._snackBar.openFromComponent(CopyTaskSuccessComponent, { duration: 5000 });
}
onClickPaste() {
this.role.tasks[this.i][this.j] = this.copyTaskService.onClickPaste(this.scenario);;
if (this.role.isAlreadyUsedIdentifier((this.role.tasks[this.i][this.j] as Task).identifier)) {
this._snackBar.openFromComponent(IdentifierSnackbarComponent, { duration: 5000 });
(this.role.tasks[this.i][this.j] as Task).identifier = '';
}
}
changeDisplaySymbolChoice(): void {
if(this.displaySymbolChoice == 'show') {
this.displaySymbolChoice = 'hide';
......
......@@ -7,6 +7,12 @@
<div class="piece-attach piece-attach-right" [style.background]="task.supplementaryRole ? task.supplementaryRole.color : 'var(--piece-background-color)'"></div>
<div class="piece-menu" [class]="displayMenu">
<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="copyTaskService.task && role != copyTaskService.role && (copyTaskService.task?.type == 'final' || copyTaskService.task?.type == 'repeat' ? canChangeInFinalTask() : true)"
[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>
......
......@@ -7,7 +7,7 @@
&-menu {
position: absolute;
width: 220px;
width: 260px;
height: 50px;
background-color: #f7f7f7;
z-index: -1;
......
......@@ -17,6 +17,8 @@ import { Trace } from 'src/app/class/trace/trace';
import { MinimapService } from 'src/app/services/minimap/minimap.service';
import { TranslateService } from '@ngx-translate/core';
import { UnityService } from 'src/app/services/unity/unity.service';
import { CopyTaskSuccessComponent } from 'src/app/components/snackbars/copy-task-success/copy-task-success.component';
import { CopyTaskService } from 'src/app/services/copyTask/copy-task.service';
@Component({
selector: 'app-random-event',
......@@ -44,7 +46,7 @@ export class RandomEventComponent implements OnInit {
antecedent: boolean = false;
constructor(protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService, public dialog: MatDialog,
private _snackBar: MatSnackBar, private minimapService: MinimapService, protected translate: TranslateService, protected unityService: UnityService) { }
private _snackBar: MatSnackBar, private minimapService: MinimapService, protected translate: TranslateService, protected unityService: UnityService, protected copyTaskService: CopyTaskService) { }
ngOnInit(): void {
this.setPieceWidth();
......@@ -149,6 +151,19 @@ export class RandomEventComponent implements OnInit {
});
}
onClickCopy() {
this.copyTaskService.onClickCopy(this.scenario, this.role, this.task);
this._snackBar.openFromComponent(CopyTaskSuccessComponent, { duration: 5000 });
}
onClickPaste() {
this.role.tasks[this.i][this.j] = this.copyTaskService.onClickPaste(this.scenario);;
if (this.role.isAlreadyUsedIdentifier((this.role.tasks[this.i][this.j] as Task).identifier)) {
this._snackBar.openFromComponent(IdentifierSnackbarComponent, { duration: 5000 });
(this.role.tasks[this.i][this.j] as Task).identifier = '';
}
}
changeDisplaySymbolChoice(): void {
if(this.displaySymbolChoice == 'show') {
this.displaySymbolChoice = 'hide';
......@@ -188,6 +203,21 @@ export class RandomEventComponent implements OnInit {
}
}
canChangeInFinalTask(): boolean {
let res: boolean = true;
let lastTaskIndex: number = -1;
for (let i = this.role.tasks[this.i].length - 1; i >= 0; i--) {
if (this.role.tasks[this.i][i] instanceof Task) {
lastTaskIndex = i;
break;
}
}
if (this.j < lastTaskIndex || this.role.tasks[this.i].some(task => task?.type == 'final') || this.role.tasks[this.i].some(task => task?.type == 'repeat')) {
res = false;
}
return res;
}
moveTask(direction: string): void {
if (direction == 'left' && this.canMoveTo('left')) {
this.role.moveTask(this.i, this.j, direction);
......
......@@ -3,6 +3,12 @@
<div class="piece-attach piece-attach-left"></div>
<div class="piece-menu" [class]="displayMenu">
<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="copyTaskService.task && role != copyTaskService.role && (copyTaskService.task?.type == 'final' || copyTaskService.task?.type == 'repeat' ? canChangeInFinalTask() : true)"
[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>
......
......@@ -10,12 +10,12 @@
&-menu {
position: absolute;
width: 220px;
width: 260px;
height: 50px;
background-color: #f7f7f7;
z-index: -1;
top: -50px;
left: 35%;
left: 38%;
transform: translateX(-50%);
transition: transform 0.5s ease;
border-top-left-radius: 10px;
......
......@@ -16,6 +16,10 @@ import { PrerequireTask } from 'src/app/class/prerequires/prerequire-task/prereq
import { TutorialService } from 'src/app/services/tutorial/tutorial.service';
import { Ressource } from 'src/app/class/ressource/ressource';
import { PrerequireRessource } from 'src/app/class/prerequires/prerequire-ressource/prerequire-ressource';
import { CopyTaskService } from 'src/app/services/copyTask/copy-task.service';
import { CopyTaskSuccessComponent } from 'src/app/components/snackbars/copy-task-success/copy-task-success.component';
import { MatSnackBar } from '@angular/material/snack-bar';
import { IdentifierSnackbarComponent } from 'src/app/components/snackbars/identifier-snackbar/identifier-snackbar.component';
@Component({
selector: 'app-repeat-task',
......@@ -40,7 +44,7 @@ export class RepeatTaskComponent implements OnInit {
constructor(protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService, public dialog: MatDialog, private minimapService: MinimapService, protected translate: TranslateService,
protected unityService: UnityService, private tutorialService: TutorialService) { }
protected unityService: UnityService, private tutorialService: TutorialService, protected copyTaskService: CopyTaskService, private _snackBar: MatSnackBar) { }
ngOnInit(): void {
this.mission.equalizeLengths();
......@@ -89,6 +93,15 @@ export class RepeatTaskComponent implements OnInit {
});
}
onClickCopy() {
this.copyTaskService.onClickCopy(this.scenario, this.role, this.task);
this._snackBar.openFromComponent(CopyTaskSuccessComponent, { duration: 5000 });
}
onClickPaste() {
this.role.tasks[this.i][this.j] = this.copyTaskService.onClickPaste(this.scenario);;
}
moveTask(direction: string): void {
if (direction == 'left' && this.canMoveTo('left')) {
this.role.moveTask(this.i, this.j, direction);
......@@ -168,6 +181,21 @@ export class RepeatTaskComponent implements OnInit {
}
}
canChangeInFinalTask(): boolean {
let res: boolean = true;
let lastTaskIndex: number = -1;
for (let i = this.role.tasks[this.i].length - 1; i >= 0; i--) {
if (this.role.tasks[this.i][i] instanceof Task) {
lastTaskIndex = i;
break;
}
}
if (this.j < lastTaskIndex || this.role.tasks[this.i].some(task => task?.type == 'final') || this.role.tasks[this.i].some(task => task?.type == 'repeat')) {
res = false;
}
return res;
}
checkboxChangedTask(event: any, task:(Task|null)): void {
if (task instanceof Task) {
if (event.target.checked) {
......
......@@ -7,6 +7,12 @@
<div class="piece-attach piece-attach-right" [style.background]="task.supplementaryRole ? task.supplementaryRole.color : 'var(--piece-background-color)'"></div>
<div class="piece-menu" [class]="displayMenu">
<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="copyTaskService.task && role != copyTaskService.role && (copyTaskService.task?.type == 'final' || copyTaskService.task?.type == 'repeat' ? canChangeInFinalTask() : true)"
[matTooltip]="translate.instant('role_paste_tooltip')"
matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>
<div>
<mat-icon fontIcon="change_circle" [matMenuTriggerFor]="menuChange"
[matTooltip]="translate.instant('task_transform_tooltip')"
......
......@@ -7,7 +7,7 @@
&-menu {
position: absolute;
width: 220px;
width: 260px;
height: 50px;
background-color: #f7f7f7;
z-index: -1;
......
......@@ -18,6 +18,8 @@ import { MinimapService } from 'src/app/services/minimap/minimap.service';
import { TranslateService } from '@ngx-translate/core';
import { TutorialService } from 'src/app/services/tutorial/tutorial.service';
import { UnityService } from 'src/app/services/unity/unity.service';
import { CopyTaskService } from 'src/app/services/copyTask/copy-task.service';
import { CopyTaskSuccessComponent } from 'src/app/components/snackbars/copy-task-success/copy-task-success.component';
@Component({
selector: 'app-task',
......@@ -46,7 +48,7 @@ export class TaskComponent implements OnInit {
constructor(protected pieceDetailsService: PieceDetailsService, protected tooltipService: TooltipService, public dialog: MatDialog,
private _snackBar: MatSnackBar, private minimapService: MinimapService, protected translate: TranslateService, private tutorialService: TutorialService,
protected unityService: UnityService) { }
protected unityService: UnityService, protected copyTaskService: CopyTaskService) { }
ngOnInit(): void {
this.setPieceWidth();
......@@ -160,6 +162,19 @@ export class TaskComponent implements OnInit {
});
}
onClickCopy() {
this.copyTaskService.onClickCopy(this.scenario, this.role, this.task);
this._snackBar.openFromComponent(CopyTaskSuccessComponent, { duration: 5000 });
}
onClickPaste() {
this.role.tasks[this.i][this.j] = this.copyTaskService.onClickPaste(this.scenario);;
if (this.role.isAlreadyUsedIdentifier((this.role.tasks[this.i][this.j] as Task).identifier)) {
this._snackBar.openFromComponent(IdentifierSnackbarComponent, { duration: 5000 });
(this.role.tasks[this.i][this.j] as Task).identifier = '';
}
}
changeDisplaySymbolChoice(): void {
if(this.displaySymbolChoice == 'show') {
this.displaySymbolChoice = 'hide';
......
import { TestBed } from '@angular/core/testing';
import { CopyTaskService } from './copy-task.service';
describe('CopyTaskService', () => {
let service: CopyTaskService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(CopyTaskService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Character } from 'src/app/class/character/character';
import { Repeat } from 'src/app/class/repeat/repeat';
import { CharacterReward } from 'src/app/class/rewards/character-reward/character-reward';
import { Role } from 'src/app/class/role/role';
import { Scenario } from 'src/app/class/scenario/scenario';
import { Symbol } from 'src/app/class/symbol/symbol';
import { Task } from 'src/app/class/task/task';
@Injectable({
providedIn: 'root'
})
export class CopyTaskService {
task: Task|null = null;
role: Role|null = null;
constructor() { }
onClickCopy(scenario: Scenario, role: Role, task: Task) {
let newTask: Task = Object.assign(new Task('normal'), task);
newTask.prerequireRessources = [];
newTask.prerequireTasks = [];
newTask.symbol = Object.assign(new Symbol(), task.symbol);
newTask.comments = [];
newTask.repeat = Object.assign(new Repeat(), task.repeat);
newTask.characters.forEach(character => {
character = scenario.characters.find(element => element.color == character.color
&& element.description == character.description
&& element.name == character.name
&& element.tel == character.tel
) as Character;
});
newTask.objectQuantity = 1;
newTask.object = null;
if (task.character) {
newTask.character = scenario.characters.find(element => element.color == (task.character as Character).color
&& element.description == (task.character as Character).description
&& element.name == (task.character as Character).name
&& element.tel == (task.character as Character).tel
) as Character;
}
newTask.combineObjects = [[null,1],[null,1]];
newTask.giveObjects = [[null,1]];
newTask.receiveObjects = [[null,1]];
newTask.role = '';
newTask.supplementaryRole = null;
newTask.rewards = [];
task.rewards.forEach(reward => {
if (reward.type == 'character') {
let newReward: CharacterReward = new CharacterReward();
newReward.character = scenario.characters.find(element => element.color == (reward as CharacterReward).character.color
&& element.description == (task.character as Character).description
&& element.name == (task.character as Character).name
&& element.tel == (task.character as Character).tel
) as Character;
newTask.rewards.push(newReward);
}
});
this.role = role;
this.task = newTask;
}
onClickPaste(scenario: Scenario): Task {
let newTask: Task = Object.assign(new Task('normal'), this.task);
newTask.prerequireRessources = [];
newTask.prerequireTasks = [];
newTask.symbol = Object.assign(new Symbol(), (this.task as Task).symbol);
newTask.comments = [];
newTask.repeat = Object.assign(new Repeat(), (this.task as Task).repeat);
newTask.characters.forEach(character => {
character = scenario.characters.find(element => element.color == character.color
&& element.description == character.description
&& element.name == character.name
&& element.tel == character.tel
) as Character;
});
newTask.objectQuantity = 1;
newTask.object = null;
if (this.task?.character) {
newTask.character = scenario.characters.find(element => element.color == ((this.task as Task).character as Character).color
&& element.description == ((this.task as Task).character as Character).description
&& element.name == ((this.task as Task).character as Character).name
&& element.tel == ((this.task as Task).character as Character).tel
) as Character;
}
newTask.combineObjects = [[null,1],[null,1]];
newTask.giveObjects = [[null,1]];
newTask.receiveObjects = [[null,1]];
newTask.role = '';
newTask.supplementaryRole = null;
newTask.rewards = [];
(this.task as Task).rewards.forEach(reward => {
if (reward.type == 'character') {
let newReward: CharacterReward = new CharacterReward();
newReward.character = scenario.characters.find(element => element.color == (reward as CharacterReward).character.color
&& element.description == ((this.task as Task).character as Character).description
&& element.name == ((this.task as Task).character as Character).name
&& element.tel == ((this.task as Task).character as Character).tel
) as Character;
newTask.rewards.push(newReward);
}
});
return newTask;
}
}
......@@ -14,7 +14,7 @@
<div class="piece-form-select">
<label>{{'supplementaryRole_label' | translate}}</label>
<select [(ngModel)]="task.supplementaryRole" (change)="editTrace($event,'supplementaryRole')">
<option selected [ngValue]="undefined">{{'supplementaryRole_none' | translate}}</option>
<option selected [ngValue]="null">{{'supplementaryRole_none' | translate}}</option>
<ng-container *ngFor="let supplementaryRole of role.supplementaryRoles">
<option [ngValue]="supplementaryRole">{{supplementaryRole.name}}</option>
</ng-container>
......
......@@ -231,6 +231,7 @@
"task_unity_exchangeObjects_receive_label": "To receive:",
"task_unity_name_label": "Name:",
"task_unity_desc_label": "Descr:",
"task_copy_snackbar": "Task copied, go to another role to paste it\nSome fields are not copied, make sure to manually verify the information when pasting",
"normalTask_title": "Task",
"normalTask_action_placeholder": "Ordering the main HTML tags",
"normalTask_add": "Add a Task",
......
......@@ -231,6 +231,7 @@
"task_unity_exchangeObjects_receive_label": "A recevoir :",
"task_unity_name_label": "Nom :",
"task_unity_desc_label": "Descr :",
"task_copy_snackbar": "Tâche copiée, rendez-vous dans un autre rôle pour le coller\nCertains champs ne sont pas copiés, veillez à vérifier manuellement les informations lors du collage",
"normalTask_title": "Tâche",
"normalTask_action_placeholder": "Positionner dans l'ordre les balises HTML principales",
"normalTask_add": "Ajouter une Tâche",
......
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