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

* ACS-5281 Allow to change editable of content metadata from parent

* ACS-5281 Added empty spaces to import
This commit is contained in:
AleksanderSklorz
2023-08-25 10:49:28 +02:00
committed by GitHub
parent b77691bb08
commit efa691b249
3 changed files with 33 additions and 11 deletions

View File

@@ -16,6 +16,7 @@ Displays and edits metadata related to a node.
- [Basic Usage](#basic-usage) - [Basic Usage](#basic-usage)
- [Class members](#class-members) - [Class members](#class-members)
- [Properties](#properties) - [Properties](#properties)
- [Events](#events)
- [Details](#details) - [Details](#details)
- [Application config presets](#application-config-presets) - [Application config presets](#application-config-presets)
- [Layout oriented config](#layout-oriented-config) - [Layout oriented config](#layout-oriented-config)
@@ -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. | | 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. | | 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. | | 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 ## Details

View File

@@ -37,6 +37,8 @@ describe('ContentMetadataCardComponent', () => {
const preset = 'custom-preset'; const preset = 'custom-preset';
let nodeAspectService: NodeAspectService = null; let nodeAspectService: NodeAspectService = null;
const getToggleEditButton = () => fixture.debugElement.query(By.css('[data-automation-id="meta-data-card-toggle-edit"]'));
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
@@ -150,13 +152,21 @@ describe('ContentMetadataCardComponent', () => {
component.node.allowableOperations = [AllowableOperationsEnum.UPDATE]; component.node.allowableOperations = [AllowableOperationsEnum.UPDATE];
fixture.detectChanges(); fixture.detectChanges();
const button = fixture.debugElement.query(By.css('[data-automation-id="meta-data-card-toggle-edit"]')); getToggleEditButton().triggerEventHandler('click', {});
button.triggerEventHandler('click', {});
fixture.detectChanges(); fixture.detectChanges();
expect(component.editable).toBe(false); 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', () => { it('should toggle expanded by clicking on the button', () => {
component.expanded = true; component.expanded = true;
fixture.detectChanges(); fixture.detectChanges();
@@ -190,8 +200,7 @@ describe('ContentMetadataCardComponent', () => {
component.readOnly = true; component.readOnly = true;
fixture.detectChanges(); fixture.detectChanges();
const button = fixture.debugElement.query(By.css('[data-automation-id="meta-data-card-toggle-edit"]')); expect(getToggleEditButton()).toBeNull();
expect(button).toBeNull();
}); });
it('should hide the edit button if node does not have `update` permissions', () => { it('should hide the edit button if node does not have `update` permissions', () => {
@@ -199,8 +208,7 @@ describe('ContentMetadataCardComponent', () => {
component.node.allowableOperations = null; component.node.allowableOperations = null;
fixture.detectChanges(); fixture.detectChanges();
const button = fixture.debugElement.query(By.css('[data-automation-id="meta-data-card-toggle-edit"]')); expect(getToggleEditButton()).toBeNull();
expect(button).toBeNull();
}); });
it('should show the edit button if node does has `update` permissions', () => { it('should show the edit button if node does has `update` permissions', () => {
@@ -208,8 +216,7 @@ describe('ContentMetadataCardComponent', () => {
component.node.allowableOperations = [AllowableOperationsEnum.UPDATE]; component.node.allowableOperations = [AllowableOperationsEnum.UPDATE];
fixture.detectChanges(); fixture.detectChanges();
const button = fixture.debugElement.query(By.css('[data-automation-id="meta-data-card-toggle-edit"]')); expect(getToggleEditButton()).not.toBeNull();
expect(button).not.toBeNull();
}); });
it('should expand the card when custom display aspect is valid', () => { it('should expand the card when custom display aspect is valid', () => {

View File

@@ -15,7 +15,7 @@
* limitations under the License. * 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 { Node } from '@alfresco/js-api';
import { NodeAspectService } from '../../../aspect-list/services/node-aspect.service'; import { NodeAspectService } from '../../../aspect-list/services/node-aspect.service';
import { PresetConfig } from '../../interfaces/content-metadata.interfaces'; import { PresetConfig } from '../../interfaces/content-metadata.interfaces';
@@ -74,6 +74,14 @@ export class ContentMetadataCardComponent implements OnChanges {
@Input() @Input()
multi = false; 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; private _displayDefaultProperties: boolean = true;
/** (optional) This flag displays/hides the metadata /** (optional) This flag displays/hides the metadata
@@ -89,8 +97,6 @@ export class ContentMetadataCardComponent implements OnChanges {
return this._displayDefaultProperties; return this._displayDefaultProperties;
} }
editable: boolean = false;
expanded: boolean; expanded: boolean;
editAspectSupported = false; editAspectSupported = false;
@@ -111,6 +117,7 @@ export class ContentMetadataCardComponent implements OnChanges {
toggleEdit(): void { toggleEdit(): void {
this.editable = !this.editable; this.editable = !this.editable;
this.editableChange.emit(this.editable);
} }
toggleExpanded(): void { toggleExpanded(): void {