Skip to content

Commit

Permalink
Update motion submission date label visiblity (#4428)
Browse files Browse the repository at this point in the history
  • Loading branch information
reiterl authored Dec 12, 2024
1 parent adf4778 commit 94082e0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<h4>
<span class="title-font">{{ title }}</span>
@if (perms.isAllowed('change_metadata')) {
@if (!isEmpty || canChangeMetadata) {
<span class="title-font">{{ title }}</span>
}
@if (canChangeMetadata) {
@if (isEditMode) {
<button class="small-button" disableRipple mat-icon-button type="button" (click)="onCancel()">
<mat-icon>close</mat-icon>
Expand All @@ -13,7 +15,7 @@ <h4>
}
</h4>

@if (!isEditMode || !perms.isAllowed('change_metadata')) {
@if (!isEditMode || !canChangeMetadata) {
<div>
<div>{{ motion[field] | localizedDate }}</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit } from '@angular/core';
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { fromUnixTime, getHours, getMinutes, isDate } from 'date-fns';
import { Permission } from 'src/app/domain/definitions/permission';
import { KeyOfType } from 'src/app/infrastructure/utils/keyof-type';
import { OperatorService } from 'src/app/site/services/operator.service';
import { BaseUiComponent } from 'src/app/ui/base/base-ui-component';

import { MotionControllerService } from '../../../../../../services/common/motion-controller.service';
import { MotionPermissionService } from '../../../../../../services/common/motion-permission.service';
import { ViewMotion } from '../../../../../../view-models';

@Component({
Expand All @@ -14,7 +15,7 @@ import { ViewMotion } from '../../../../../../view-models';
styleUrls: [`./motion-manage-timestamp.component.scss`],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class MotionManageTimestampComponent extends BaseUiComponent {
export class MotionManageTimestampComponent extends BaseUiComponent implements OnInit {
public get motion(): ViewMotion {
return this._motion;
}
Expand Down Expand Up @@ -43,14 +44,24 @@ export class MotionManageTimestampComponent extends BaseUiComponent {
return this._editMode;
}

public get isEmpty(): boolean {
return !this.motion[this.field];
}

public get canChangeMetadata(): boolean {
return this._change_metadata;
}

private _editMode = false;
private _change_metadata = false;

private _motion!: ViewMotion;

public constructor(
public perms: MotionPermissionService,
private motionController: MotionControllerService,
private fb: UntypedFormBuilder
private fb: UntypedFormBuilder,
private operator: OperatorService,
private cd: ChangeDetectorRef
) {
super();

Expand All @@ -73,6 +84,15 @@ export class MotionManageTimestampComponent extends BaseUiComponent {
);
}

public ngOnInit(): void {
this.subscriptions.push(
this.operator.permissionsObservable.subscribe(() => {
this._change_metadata = this.operator.hasPerms(Permission.motionCanManageMetadata);
this.cd.markForCheck();
})
);
}

public async onSave(): Promise<void> {
const date: { date: Date | null; time: string } = this.form.value;
const [hours, minutes, ..._] = date.time.split(`:`);
Expand Down

0 comments on commit 94082e0

Please sign in to comment.