|
@@ -3,6 +3,7 @@ import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
|
|
import { DataService } from 'src/services/data/data.service';
|
|
import { DataService } from 'src/services/data/data.service';
|
|
|
import { ModalService } from 'src/services/modal/modal.service';
|
|
import { ModalService } from 'src/services/modal/modal.service';
|
|
|
import { ToolsModalComponent } from './tools-modal/tools-modal.component';
|
|
import { ToolsModalComponent } from './tools-modal/tools-modal.component';
|
|
|
|
|
+import { FormBuilder } from '@angular/forms';
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'proficiencies-table',
|
|
selector: 'proficiencies-table',
|
|
@@ -10,21 +11,33 @@ import { ToolsModalComponent } from './tools-modal/tools-modal.component';
|
|
|
styleUrls: ['./proficiencies-table.component.scss'],
|
|
styleUrls: ['./proficiencies-table.component.scss'],
|
|
|
})
|
|
})
|
|
|
export class ProficienciesTableComponent {
|
|
export class ProficienciesTableComponent {
|
|
|
- public proficiencies!: any;
|
|
|
|
|
|
|
+ // public proficiencies!: any;
|
|
|
|
|
+ public proficiencies = this.formBuilder.group({
|
|
|
|
|
+ simple: false,
|
|
|
|
|
+ martial: false,
|
|
|
|
|
+ other: '',
|
|
|
|
|
+ light: false,
|
|
|
|
|
+ medium: false,
|
|
|
|
|
+ heavy: false,
|
|
|
|
|
+ shields: false,
|
|
|
|
|
+ tools: this.formBuilder.array([]),
|
|
|
|
|
+ languages: this.formBuilder.array([]),
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
public constructor(
|
|
public constructor(
|
|
|
public dataAccessor: DataService,
|
|
public dataAccessor: DataService,
|
|
|
- public modalAccessor: ModalService
|
|
|
|
|
- ) {
|
|
|
|
|
- // this.proficiencies = this.dataAccessor.proficiencies;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public modalAccessor: ModalService,
|
|
|
|
|
+ private formBuilder: FormBuilder
|
|
|
|
|
+ ) {}
|
|
|
|
|
+
|
|
|
public ngOnInit(): void {
|
|
public ngOnInit(): void {
|
|
|
- this.proficiencies = this.dataAccessor.proficiencies;
|
|
|
|
|
|
|
+ // this.proficiencies.setValue(this.dataAccessor.proficiencies);
|
|
|
|
|
+ this.setProficiencies(this.dataAccessor.proficiencies);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public dropTools(event: CdkDragDrop<string[]>): void {
|
|
public dropTools(event: CdkDragDrop<string[]>): void {
|
|
|
moveItemInArray(
|
|
moveItemInArray(
|
|
|
- this.proficiencies.tools,
|
|
|
|
|
|
|
+ this.proficiencies.get('tools')!.value,
|
|
|
event.previousIndex,
|
|
event.previousIndex,
|
|
|
event.currentIndex
|
|
event.currentIndex
|
|
|
);
|
|
);
|
|
@@ -33,35 +46,26 @@ export class ProficienciesTableComponent {
|
|
|
|
|
|
|
|
public dropLanguages(event: CdkDragDrop<string[]>): void {
|
|
public dropLanguages(event: CdkDragDrop<string[]>): void {
|
|
|
moveItemInArray(
|
|
moveItemInArray(
|
|
|
- this.proficiencies.languages,
|
|
|
|
|
|
|
+ this.proficiencies.get('languages')!.value,
|
|
|
event.previousIndex,
|
|
event.previousIndex,
|
|
|
event.currentIndex
|
|
event.currentIndex
|
|
|
);
|
|
);
|
|
|
this.updateDatabase();
|
|
this.updateDatabase();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public toggleAcordion(event: any): void {
|
|
|
|
|
- if (event.target.classList.contains('accordion')) {
|
|
|
|
|
- event.target.classList.toggle('active');
|
|
|
|
|
- var panel = event.target.nextElementSibling;
|
|
|
|
|
- if (panel.style.maxHeight) {
|
|
|
|
|
- panel.style.maxHeight = null;
|
|
|
|
|
- } else {
|
|
|
|
|
- panel.style.maxHeight = '100svh'; //Hier ansetzen um es später scrollable zu machen
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public openModal(): void {
|
|
public openModal(): void {
|
|
|
this.modalAccessor.openModal(ToolsModalComponent, {
|
|
this.modalAccessor.openModal(ToolsModalComponent, {
|
|
|
- proficiencies: JSON.parse(JSON.stringify(this.proficiencies)),
|
|
|
|
|
|
|
+ proficiencies: JSON.parse(JSON.stringify(this.proficiencies.value)),
|
|
|
});
|
|
});
|
|
|
const resultSubscription = this.modalAccessor.result$.subscribe(
|
|
const resultSubscription = this.modalAccessor.result$.subscribe(
|
|
|
(result) => {
|
|
(result) => {
|
|
|
if (result.state === 'update') {
|
|
if (result.state === 'update') {
|
|
|
- this.updateProficiencies(result.data);
|
|
|
|
|
|
|
+ this.setProficiencies(result.data);
|
|
|
|
|
+ this.updateDatabase();
|
|
|
|
|
+ } else if (result.state === 'cancel') {
|
|
|
|
|
+ // Do nothing
|
|
|
} else {
|
|
} else {
|
|
|
- throw new Error('DND-Error: Invalid result state');
|
|
|
|
|
|
|
+ throw new Error('DND-Error: Invalid result state: ' + result.state);
|
|
|
}
|
|
}
|
|
|
resultSubscription.unsubscribe();
|
|
resultSubscription.unsubscribe();
|
|
|
}
|
|
}
|
|
@@ -69,11 +73,19 @@ export class ProficienciesTableComponent {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public updateDatabase(): void {
|
|
public updateDatabase(): void {
|
|
|
- this.dataAccessor.proficiencies = this.proficiencies;
|
|
|
|
|
|
|
+ console.warn(this.proficiencies.value);
|
|
|
|
|
+ this.dataAccessor.proficiencies = this.proficiencies.value;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public updateProficiencies(data: any): void {
|
|
|
|
|
- this.proficiencies = data;
|
|
|
|
|
- this.updateDatabase();
|
|
|
|
|
|
|
+ public setProficiencies(data: any): void {
|
|
|
|
|
+ const { tools, languages, ...dataWithoutToolsAndLanguages } = data;
|
|
|
|
|
+ Object.keys(dataWithoutToolsAndLanguages).forEach((key) => {
|
|
|
|
|
+ this.proficiencies.get(key)?.setValue(dataWithoutToolsAndLanguages[key]);
|
|
|
|
|
+ });
|
|
|
|
|
+ this.proficiencies.setControl('tools', this.formBuilder.array(tools));
|
|
|
|
|
+ this.proficiencies.setControl(
|
|
|
|
|
+ 'languages',
|
|
|
|
|
+ this.formBuilder.array(languages)
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|