Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree scroll #2593

Merged
merged 7 commits into from
Jan 28, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tree no display with coils + equipments
  • Loading branch information
julien-louis committed Jan 24, 2025
commit 67088f87422a9e1c32cc03f7938e0cff5614ef29
28 changes: 19 additions & 9 deletions shanoir-ng-front/src/app/centers/tree/center-node.component.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ import { CoilService } from 'src/app/coils/shared/coil.service';
import { TreeNodeAbstractComponent } from 'src/app/shared/components/tree/tree-node.abstract.component';
import { TreeService } from 'src/app/studies/study/tree.service';
import { KeycloakService } from "../../shared/keycloak/keycloak.service";
import { AcquisitionEquipmentNode, CenterNode, CoilNode } from '../../tree/tree.model';
import { AcquisitionEquipmentNode, CenterNode, CoilNode, UNLOADED } from '../../tree/tree.model';
import { Center } from '../shared/center.model';
import { CenterService } from '../shared/center.service';

@@ -54,26 +54,27 @@ export class CenterNodeComponent extends TreeNodeAbstractComponent<CenterNode> i
} else {
throw new Error('not implemented yet');
}
this.node.registerOpenPromise(this.contentLoaded);
}
}

hasChildren(): boolean | 'unknown' {
if (!this.node.acquisitionEquipments) return false;
else if (this.node.acquisitionEquipments == 'UNLOADED') return 'unknown';
else return this.node.acquisitionEquipments.length > 0;
if (!this.node.acquisitionEquipments && !this.node.coils) return false;
else if (this.node.acquisitionEquipments == UNLOADED && this.node.coils == UNLOADED ) return 'unknown';
else return this.node.acquisitionEquipments?.length + this.node.coils?.length > 0;
}

loadEquipments() {
loadEquipments(): Promise<void> {
this.loading = true;
this.centerService.get(this.node.id).then(
return this.centerService.get(this.node.id).then(
center => {
if (center.acquisitionEquipments) {
this.node.acquisitionEquipments = center.acquisitionEquipments.map(
acqEq => new AcquisitionEquipmentNode(this.node, acqEq.id, this.acquisitionEquipmentPipe.transform(acqEq), 'UNLOADED', this.keycloakService.isUserAdminOrExpert()));
this.loading = false;
this.node.open();
} else {
this.acquisitionEquipmentService.getAllByCenter(this.node.id).then(eqs => {
return this.acquisitionEquipmentService.getAllByCenter(this.node.id).then(eqs => {
this.node.acquisitionEquipments = eqs.map(acqEq => new AcquisitionEquipmentNode(this.node, acqEq.id, this.acquisitionEquipmentPipe.transform(acqEq), 'UNLOADED', this.keycloakService.isUserAdminOrExpert()));
this.loading = false;
this.node.open();
@@ -84,9 +85,9 @@ export class CenterNodeComponent extends TreeNodeAbstractComponent<CenterNode> i
});
}

loadCoils() {
loadCoils(): Promise<void> {
this.loading = true;
this.coilService.findByCenter(this.node.id).then(
return this.coilService.findByCenter(this.node.id).then(
coils => {
if (coils) {
this.node.coils = coils.map(coil => new CoilNode(this.node, coil.id, coil.name));
@@ -98,6 +99,15 @@ export class CenterNodeComponent extends TreeNodeAbstractComponent<CenterNode> i
});
}

onFirstOpen() {
Promise.all([
this.loadEquipments(),
this.loadCoils()
]).then(() => {
this.contentLoaded.resolve();
});
}

onEquipmentDelete(index: number) {
(this.node.acquisitionEquipments as AcquisitionEquipmentNode[]).splice(index, 1) ;
}
4 changes: 3 additions & 1 deletion shanoir-ng-front/src/app/coils/coil/coil.component.ts
Original file line number Diff line number Diff line change
@@ -64,7 +64,9 @@ export class CoilComponent extends EntityComponent<Coil> {
}

initView(): Promise<void> {
return Promise.resolve();
return this.centerService.getAll().then(centers => {
this.coil.center = centers.find(center => center.id == this.coil.center.id);
});
}

initEdit(): Promise<void> {
Original file line number Diff line number Diff line change
@@ -171,10 +171,11 @@ export abstract class EntityComponent<T extends Entity> implements OnDestroy, On
throw Error('mode has to be set!');
}
}
Promise.all([this.entityPromise, choose]).then(() => {
let choosePromise: Promise<void> = choose();
Promise.all([this.entityPromise, choosePromise]).then(() => {
if (this.mode != 'create' && this.getTreeSelection) this.treeService.select(this.getTreeSelection());
});
choose().then(() => {
choosePromise.then(() => {
this.footerState = new FooterState(this.mode);
this.footerState.backButton = this.isMainComponent;
this.hasEditRight().then(right => this.footerState.canEdit = right);