Fields are only available if they are available

- The user can change information about motions
- The user can send an invitation email
This commit is contained in:
GabrielMeyer 2019-04-30 16:53:50 +02:00
parent c560f511b5
commit 3d5f79a76c
3 changed files with 55 additions and 7 deletions

View File

@ -339,7 +339,7 @@
</h1>
<div class="os-form-card-mobile" mat-dialog-content>
<!-- Category -->
<mat-form-field>
<mat-form-field *ngIf="isCategoryAvailable()">
<mat-select placeholder="{{ 'Category' | translate }}" [(ngModel)]="infoDialog.category">
<mat-option [value]="null">-</mat-option>
<mat-option *ngFor="let category of categories" [value]="category.id">
@ -348,7 +348,7 @@
</mat-select>
</mat-form-field>
<!-- Motion block -->
<mat-form-field>
<mat-form-field *ngIf="isMotionBlockAvailable()">
<mat-select placeholder="{{ 'Motion block' | translate }}" [(ngModel)]="infoDialog.motionBlock">
<mat-option [value]="null">-</mat-option>
<mat-option *ngFor="let block of motionBlocks" [value]="block.id">
@ -357,7 +357,7 @@
</mat-select>
</mat-form-field>
<!-- Tag -->
<mat-form-field>
<mat-form-field *ngIf="isTagAvailable()">
<mat-select multiple placeholder="{{ 'Tags' | translate }}" [(ngModel)]="infoDialog.tags">
<mat-option *ngFor="let tag of tags" [value]="tag.id">
{{ tag.getTitle() | translate }}

View File

@ -169,9 +169,18 @@ export class MotionListComponent extends ListViewBaseComponent<ViewMotion, Motio
this.configService.get<string>('motions_recommendations_by').subscribe(recommender => {
this.recommendationEnabled = !!recommender;
});
this.motionBlockRepo.getViewModelListObservable().subscribe(mBs => (this.motionBlocks = mBs));
this.categoryRepo.getViewModelListObservable().subscribe(cats => (this.categories = cats));
this.tagRepo.getViewModelListObservable().subscribe(tags => (this.tags = tags));
this.motionBlockRepo.getViewModelListObservable().subscribe(mBs => {
this.motionBlocks = mBs;
this.updateStateColumnVisibility();
});
this.categoryRepo.getViewModelListObservable().subscribe(cats => {
this.categories = cats;
this.updateStateColumnVisibility();
});
this.tagRepo.getViewModelListObservable().subscribe(tags => {
this.tags = tags;
this.updateStateColumnVisibility();
});
this.workflowRepo.getViewModelListObservable().subscribe(wfs => (this.workflows = wfs));
this.setFulltextFilter();
}
@ -436,4 +445,43 @@ export class MotionListComponent extends ListViewBaseComponent<ViewMotion, Motio
}
});
}
/**
* Checks if there are at least categories, motion-blocks or tags the user can select.
*/
public updateStateColumnVisibility(): void {
const metaInfoAvailable = this.isCategoryAvailable() || this.isMotionBlockAvailable() || this.isTagAvailable();
if (!metaInfoAvailable && this.displayedColumnsDesktop.includes('state')) {
this.displayedColumnsDesktop.splice(this.displayedColumnsDesktop.indexOf('state'), 1);
} else if (metaInfoAvailable && !this.displayedColumnsDesktop.includes('state')) {
this.displayedColumnsDesktop = this.displayedColumnsDesktop.concat('state');
}
}
/**
* Checks motion-blocks are available.
*
* @returns A boolean if they are available.
*/
public isMotionBlockAvailable(): boolean {
return !!this.motionBlocks && this.motionBlocks.length > 0;
}
/**
* Checks if tags are available.
*
* @returns A boolean if they are available.
*/
public isTagAvailable(): boolean {
return !!this.tags && this.tags.length > 0;
}
/**
* Checks if categories are available.
*
* @returns A boolean if they are available.
*/
public isCategoryAvailable(): boolean {
return !!this.categories && this.categories.length > 0;
}
}

View File

@ -32,7 +32,7 @@
<span translate>Change password</span>
</button>
<!-- invitation email -->
<button mat-menu-item *ngIf="isAllowed('manage')" (click)="sendInvitationEmail()">
<button mat-menu-item *ngIf="isAllowed('manage') && user.email" (click)="sendInvitationEmail()">
<mat-icon>mail</mat-icon>
<span translate>Send invitation email</span>
</button>