Skip to content

Commit

Permalink
PER-8562
Browse files Browse the repository at this point in the history
refactored the code, removed a variable that was not needed after all. Now the same behaviour is present in the sidebar too, making the app more consistent.
  • Loading branch information
crisnicandrei committed Jan 17, 2024
1 parent 959f362 commit db19d4d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@
<tr>
<td class="title">Tags</td>
<td (click)="onTagsClick('keyword')">
<pr-tags
[canEditOnFullscreen]="canEditFieldsOnFullscreen"
[tags]="keywords"
></pr-tags>
<pr-tags [tags]="keywords" [canEdit]="canEdit"></pr-tags>
</td>
</tr>
<tr>
Expand All @@ -146,10 +143,7 @@
Metadata
</td>
<td (click)="onTagsClick('custom')">
<pr-tags
[canEditOnFullscreen]="canEditFieldsOnFullscreen"
[tags]="customMetadata"
></pr-tags>
<pr-tags [tags]="customMetadata" [canEdit]="canEdit"></pr-tags>
</td>
</tr>
<tr>
Expand All @@ -162,19 +156,11 @@
<span *ngIf="currentRecord.LocnVO">{{
(currentRecord.LocnVO | prLocation)?.full
}}</span>
<span
class="add-location"
*ngIf="!currentRecord.LocnVO && canEditFieldsOnFullscreen"
>
<fa-icon
*ngIf="canEditFieldsOnFullscreen"
[icon]="['fas', 'pen-square']"
></fa-icon>
<span class="add-location" *ngIf="!currentRecord.LocnVO && canEdit">
<fa-icon [icon]="['fas', 'pen-square']"></fa-icon>
Click to add location</span
>
<span *ngIf="!currentRecord.LocnVO && !canEditFieldsOnFullscreen"
>No location</span
>
<span *ngIf="!currentRecord.LocnVO && !canEdit">No location</span>
</td>
</tr>
<tr></tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ describe('FileViewerComponent', () => {

it('should display "Click to add location" on fullscreen view', async () => {
const { fixture, instance, find } = await defaultRender();
instance.canEditFieldsOnFullscreen = true;
instance.canEdit = true;
await fixture.detectChanges();
const locationSpan = find('.add-location');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class FileViewerComponent implements OnInit, OnDestroy {
public documentUrl = null;

public canEdit: boolean;
public canEditFieldsOnFullscreen = false;

// Swiping
private touchElement: HTMLElement;
Expand Down Expand Up @@ -122,8 +121,6 @@ export class FileViewerComponent implements OnInit, OnDestroy {
AccessRole.Editor
) && !route.snapshot.data?.isPublicArchive;

this.canEditFieldsOnFullscreen = this.canEdit && this.canEditOnFullScreen();

this.tagSubscription = this.tagsService
.getItemTags$()
?.subscribe((tags) => {
Expand Down Expand Up @@ -407,12 +404,4 @@ export class FileViewerComponent implements OnInit, OnDestroy {
tag.type.includes('type.tag.metadata')
);
}

private canEditOnFullScreen(): boolean {
return (
this.router.routerState.snapshot.url.includes('private/record') ||
this.router.routerState.snapshot.url.includes('public/record') ||
this.router.routerState.snapshot.url.includes('shares/record')
);
}
}
16 changes: 13 additions & 3 deletions src/app/file-browser/components/sidebar/sidebar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,19 @@
<span *ngIf="selectedItem.LocnVO">{{
(selectedItem.LocnVO | prLocation)?.full
}}</span>
<span *ngIf="!selectedItem.LocnVO" class="sidebar-item-content-empty">{{
canEdit ? 'Click to set location' : 'No location'
}}</span>
<span
*ngIf="!selectedItem.LocnVO && !canEdit"
class="sidebar-item-content-empty"
>
No location
</span>
<span
*ngIf="!selectedItem.LocnVO && canEdit"
class="sidebar-item-content-empty"
>
<fa-icon [icon]="['fas', 'pen-square']"></fa-icon>
Click to set location
</span>
</div>
<div
class="sidebar-item-content"
Expand Down
12 changes: 6 additions & 6 deletions src/app/shared/components/tags/tags.component.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<!-- @format -->
<div class="not-empty" *ngIf="tags?.length && !isEditing && canEdit">
<fa-icon
*ngIf="isEditableFullscreen"
[icon]="['fas', 'pen-square']"
></fa-icon>
Click to add
</div>
<div class="tags">
<div class="empty" *ngIf="!tags?.length">
<fa-icon
*ngIf="isEditableFullscreen"
*ngIf="canEdit && !isEditing"
[icon]="['fas', 'pen-square']"
></fa-icon>
{{
(canEdit && !isEditing) || isEditableFullscreen
? 'Click to add'
: 'No tags'
}}
{{ canEdit && !isEditing ? 'Click to add' : 'No tags' }}
</div>
<ng-container *ngIf="tags?.length">
<div
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/components/tags/tags.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('TagsComponent', () => {
it('should display the "Click to add" text when in fullscreen view', () => {
const tags = [];
component.tags = tags;
component.isEditableFullscreen = true;
component.canEdit = true;
component.ngOnChanges();
fixture.detectChanges();
const div = fixture.debugElement.query(By.css('.empty'));
Expand All @@ -71,7 +71,7 @@ describe('TagsComponent', () => {
it('should display the "No tags" text when in fullscreen view, but on the public archive', () => {
const tags = [];
component.tags = tags;
component.isEditableFullscreen = false;
component.canEdit = false;
component.ngOnChanges();
fixture.detectChanges();
const div = fixture.debugElement.query(By.css('.empty'));
Expand Down
5 changes: 1 addition & 4 deletions src/app/shared/components/tags/tags.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@ import { ngIfScaleAnimationDynamic } from '@shared/animations';
export class TagsComponent implements OnInit, OnChanges {
@Input() tags: TagVOData[];
@HostBinding('class.read-only') @Input() readOnly = true;
@HostBinding('class.can-edit') @Input() canEdit: boolean;
@Input() canEdit = false;
@Input() isEditing = false;
@Input() animate = false;
@Input() isDialog = false;
@Input() canEditOnFullscreen: boolean = false;

orderedTags: TagVOData[] = [];
public isEditableFullscreen: boolean = false;

constructor() {}

ngOnInit(): void {
this.isEditableFullscreen = this.canEditOnFullscreen && !this.isDialog;
}

ngOnChanges() {
Expand Down

0 comments on commit db19d4d

Please sign in to comment.