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

Update motion submission date label visiblity #4428

Merged
merged 5 commits into from
Dec 12, 2024
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
@@ -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
Loading