mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-14 13:33:03 +00:00
Disabled add section button when no options are available
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
[ngClass]="{'w-100': windowService.isXs()}">
|
[ngClass]="{'w-100': windowService.isXs()}">
|
||||||
<button class="btn btn-outline-primary dropdown-toggle"
|
<button class="btn btn-outline-primary dropdown-toggle"
|
||||||
id="sectionControls"
|
id="sectionControls"
|
||||||
|
[disabled]="!(hasSections$ | async)"
|
||||||
[ngClass]="{'w-100': (windowService.isXs() | async)}"
|
[ngClass]="{'w-100': (windowService.isXs() | async)}"
|
||||||
ngbDropdownToggle>
|
ngbDropdownToggle>
|
||||||
{{ 'submission.sections.general.add-more' | translate }} <i class="fa fa-plus" aria-hidden="true"></i>
|
{{ 'submission.sections.general.add-more' | translate }} <i class="fa fa-plus" aria-hidden="true"></i>
|
||||||
@@ -13,10 +14,10 @@
|
|||||||
class="sections-dropdown-menu"
|
class="sections-dropdown-menu"
|
||||||
aria-labelledby="sectionControls"
|
aria-labelledby="sectionControls"
|
||||||
[ngClass]="{'w-100': (windowService.isXs() | async)}">
|
[ngClass]="{'w-100': (windowService.isXs() | async)}">
|
||||||
<button class="dropdown-item disabled" *ngIf="(sectionList | async)?.length == 0">
|
<button class="dropdown-item disabled" *ngIf="!(hasSections$ | async)">
|
||||||
{{ 'submission.sections.general.no-sections' | translate }}
|
{{ 'submission.sections.general.no-sections' | translate }}
|
||||||
</button>
|
</button>
|
||||||
<button class="dropdown-item" *ngFor="let listItem of (sectionList | async)" (click)="addSection(listItem.id)">
|
<button class="dropdown-item" *ngFor="let listItem of (sectionList$ | async)" (click)="addSection(listItem.id)">
|
||||||
{{'submission.sections.'+listItem.header | translate }}
|
{{'submission.sections.'+listItem.header | translate }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -130,13 +130,18 @@ describe('SubmissionFormSectionAddComponent Component', () => {
|
|||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
comp.sectionList.subscribe((list) => {
|
comp.sectionList$.subscribe((list) => {
|
||||||
expect(list).toEqual(mockAvailableSections);
|
expect(list).toEqual(mockAvailableSections);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
comp.hasSections$.subscribe((hasSections) => {
|
||||||
|
expect(hasSections).toEqual(true);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call addSection', () => {
|
it('should call addSection', () => {
|
||||||
|
submissionServiceStub.getDisabledSectionsList.and.returnValue(observableOf(mockAvailableSections));
|
||||||
|
|
||||||
comp.addSection(mockAvailableSections[1].id);
|
comp.addSection(mockAvailableSections[1].id);
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
@@ -6,6 +6,7 @@ import { SectionsService } from '../../sections/sections.service';
|
|||||||
import { HostWindowService } from '../../../shared/host-window.service';
|
import { HostWindowService } from '../../../shared/host-window.service';
|
||||||
import { SubmissionService } from '../../submission.service';
|
import { SubmissionService } from '../../submission.service';
|
||||||
import { SectionDataObject } from '../../sections/models/section-data.model';
|
import { SectionDataObject } from '../../sections/models/section-data.model';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-submission-form-section-add',
|
selector: 'ds-submission-form-section-add',
|
||||||
@@ -16,7 +17,8 @@ export class SubmissionFormSectionAddComponent implements OnInit {
|
|||||||
@Input() collectionId: string;
|
@Input() collectionId: string;
|
||||||
@Input() submissionId: string;
|
@Input() submissionId: string;
|
||||||
|
|
||||||
public sectionList: Observable<SectionDataObject[]>;
|
public sectionList$: Observable<SectionDataObject[]>;
|
||||||
|
public hasSections$: Observable<boolean>;
|
||||||
|
|
||||||
constructor(private sectionService: SectionsService,
|
constructor(private sectionService: SectionsService,
|
||||||
private submissionService: SubmissionService,
|
private submissionService: SubmissionService,
|
||||||
@@ -24,7 +26,10 @@ export class SubmissionFormSectionAddComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.sectionList = this.submissionService.getDisabledSectionsList(this.submissionId);
|
this.sectionList$ = this.submissionService.getDisabledSectionsList(this.submissionId);
|
||||||
|
this.hasSections$ = this.sectionList$.pipe(
|
||||||
|
map((list: SectionDataObject[]) => list.length > 0)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
addSection(sectionId) {
|
addSection(sectionId) {
|
||||||
|
Reference in New Issue
Block a user