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

[ACS-5281] Allow to change editable of content metadata from parent #8841

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
Expand Up @@ -16,6 +16,7 @@ Displays and edits metadata related to a node.
- [Basic Usage](#basic-usage)
- [Class members](#class-members)
- [Properties](#properties)
- [Events](#events)
- [Details](#details)
- [Application config presets](#application-config-presets)
- [Layout oriented config](#layout-oriented-config)
Expand Down Expand Up @@ -51,6 +52,13 @@ Displays and edits metadata related to a node.
| preset | `string \| `[`PresetConfig`](../../../lib/content-services/src/lib/content-metadata/interfaces/preset-config.interface.ts) | | (required) Name or configuration of the metadata preset, which defines aspects and their properties. |
| readOnly | `boolean` | false | (optional) This flag sets the metadata in read only mode preventing changes. |
| displayDefaultProperties | `boolean` | | (optional) This flag displays/hides the metadata properties. |
| editable | `boolean` | | (optional) This flag toggles editable of content. |

### Events

| Name | Type | Description |
|----------------|-----------------------------------------------------------------------|---------------------------------------------------|
| editableChange | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<boolean>` | Emitted when content's editable state is changed. |

## Details

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ describe('ContentMetadataCardComponent', () => {
const preset = 'custom-preset';
let nodeAspectService: NodeAspectService = null;

const getToggleEditButton = () => fixture.debugElement.query(By.css('[data-automation-id="meta-data-card-toggle-edit"]'));

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
Expand Down Expand Up @@ -150,13 +152,21 @@ describe('ContentMetadataCardComponent', () => {
component.node.allowableOperations = [AllowableOperationsEnum.UPDATE];
fixture.detectChanges();

const button = fixture.debugElement.query(By.css('[data-automation-id="meta-data-card-toggle-edit"]'));
button.triggerEventHandler('click', {});
getToggleEditButton().triggerEventHandler('click', {});
fixture.detectChanges();

expect(component.editable).toBe(false);
});

it('should emit editableChange by clicking on toggle edit button', () => {
component.node.allowableOperations = [AllowableOperationsEnum.UPDATE];
fixture.detectChanges();
spyOn(component.editableChange, 'emit');

getToggleEditButton().nativeElement.click();
expect(component.editableChange.emit).toHaveBeenCalledWith(true);
});

it('should toggle expanded by clicking on the button', () => {
component.expanded = true;
fixture.detectChanges();
Expand Down Expand Up @@ -190,26 +200,23 @@ describe('ContentMetadataCardComponent', () => {
component.readOnly = true;
fixture.detectChanges();

const button = fixture.debugElement.query(By.css('[data-automation-id="meta-data-card-toggle-edit"]'));
expect(button).toBeNull();
expect(getToggleEditButton()).toBeNull();
});

it('should hide the edit button if node does not have `update` permissions', () => {
component.readOnly = false;
component.node.allowableOperations = null;
fixture.detectChanges();

const button = fixture.debugElement.query(By.css('[data-automation-id="meta-data-card-toggle-edit"]'));
expect(button).toBeNull();
expect(getToggleEditButton()).toBeNull();
});

it('should show the edit button if node does has `update` permissions', () => {
component.readOnly = false;
component.node.allowableOperations = [AllowableOperationsEnum.UPDATE];
fixture.detectChanges();

const button = fixture.debugElement.query(By.css('[data-automation-id="meta-data-card-toggle-edit"]'));
expect(button).not.toBeNull();
expect(getToggleEditButton()).not.toBeNull();
});

it('should expand the card when custom display aspect is valid', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Component, Input, OnChanges, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { Node } from '@alfresco/js-api';
import { NodeAspectService } from '../../../aspect-list/services/node-aspect.service';
import { PresetConfig } from '../../interfaces/content-metadata.interfaces';
Expand Down Expand Up @@ -74,6 +74,14 @@ export class ContentMetadataCardComponent implements OnChanges {
@Input()
multi = false;

/** (optional) This flag toggles editable of content. **/
@Input()
editable = false;

/** Emitted when content's editable state is changed. **/
@Output()
editableChange = new EventEmitter<boolean>();

private _displayDefaultProperties: boolean = true;

/** (optional) This flag displays/hides the metadata
Expand All @@ -89,8 +97,6 @@ export class ContentMetadataCardComponent implements OnChanges {
return this._displayDefaultProperties;
}

editable: boolean = false;

expanded: boolean;

editAspectSupported = false;
Expand All @@ -111,6 +117,7 @@ export class ContentMetadataCardComponent implements OnChanges {

toggleEdit(): void {
this.editable = !this.editable;
this.editableChange.emit(this.editable);
}

toggleExpanded(): void {
Expand Down
Loading