Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ <h3 class="text-xl pb-4">{{ 'myProjects.settings.projectAffiliation' | translate
icon="fas fa-trash"
severity="danger"
text
[disabled]="!removeAffiliationPermission().get(affiliation.id)"
[ariaLabel]="'common.buttons.delete' | translate"
(onClick)="removeAffiliation(affiliation)"
></p-button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { createDispatchMap, select } from '@ngxs/store';

import { TranslatePipe } from '@ngx-translate/core';

import { Button } from 'primeng/button';
import { Card } from 'primeng/card';

import { NgOptimizedImage } from '@angular/common';
import { ChangeDetectionStrategy, Component, input, output } from '@angular/core';
import { ChangeDetectionStrategy, Component, computed, input, OnInit, output } from '@angular/core';

import { Institution } from '@osf/shared/models';
import { FetchUserInstitutions, InstitutionsSelectors } from '@shared/stores';

@Component({
selector: 'osf-settings-project-affiliation',
Expand All @@ -15,11 +18,36 @@ import { Institution } from '@osf/shared/models';
styleUrl: './settings-project-affiliation.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SettingsProjectAffiliationComponent {
export class SettingsProjectAffiliationComponent implements OnInit {
affiliations = input<Institution[]>([]);
userInstitutions = select(InstitutionsSelectors.getUserInstitutions);
removed = output<Institution>();
canEdit = input<boolean>(false);

removeAffiliationPermission = computed(() => {
const affiliatedInstitutions = this.affiliations();
const userInstitutions = this.userInstitutions();

const result = new Map<string, boolean>();

for (const institution of affiliatedInstitutions) {
const isUserAffiliatedWithCurrentInstitution = userInstitutions.some(
(userInstitution) => userInstitution.id === institution.id
);
result.set(institution.id, isUserAffiliatedWithCurrentInstitution);
}

return result;
});

private readonly actions = createDispatchMap({
fetchUserInstitutions: FetchUserInstitutions,
});

ngOnInit() {
this.actions.fetchUserInstitutions();
}

removeAffiliation(affiliation: Institution) {
this.removed.emit(affiliation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,26 @@ export class AffiliatedInstitutionSelectComponent {
isSelectAllDisabled = computed(() => {
const institutions = this.institutions();
const selected = this.selectedInstitutions();
return institutions.length === 0 || institutions.length === selected.length;
const selectedInstitutionsAvailableToModify = selected.filter((selected) =>
institutions.some((inst) => inst.id === selected.id)
);
return institutions.length === 0 || institutions.length === selectedInstitutionsAvailableToModify.length;
});

isRemoveAllDisabled = computed(() => this.selectedInstitutions().length === 0);

removeAll() {
this.selectedInstitutions.set([]);
const institutionsUnableToModify = this.selectedInstitutions().filter(
(selected) => !this.institutions().some((inst) => inst.id === selected.id)
);
this.selectedInstitutions.set([...institutionsUnableToModify]);
}

selectAll() {
this.selectedInstitutions.set([...this.institutions()]);
const institutionsUnableToModify = this.selectedInstitutions().filter(
(selected) => !this.institutions().some((inst) => inst.id === selected.id)
);
this.selectedInstitutions.set([...this.institutions(), ...institutionsUnableToModify]);
}

selectDeselectInstitution(institution: Institution) {
Expand Down
Loading