mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-04-16 22:24:49 +00:00
ACS-10914 Remove unused allowable operation directive (#11476)
This commit is contained in:
@@ -321,7 +321,6 @@ for more information about installing and using the source code.
|
||||
| Name | Description | Source link |
|
||||
| ---- | ----------- | ----------- |
|
||||
| [Auto Focus directive](content-services/directives/auto-focus.directive.md) | Automatically focuses HTML element after content is initialized. | [Source](../lib/content-services/src/lib/directives/auto-focus.directive.ts) |
|
||||
| [Check Allowable Operation directive](content-services/directives/check-allowable-operation.directive.md) | Selectively disables an HTML element or Angular component. | [Source](../lib/content-services/src/lib/directives/check-allowable-operation.directive.ts) |
|
||||
| [Node Public File Share Directive](content-services/directives/content-node-share.directive.md) | Creates and manages public shared links for files. | [Source](../lib/content-services/src/lib/content-node-share/content-node-share.directive.ts) |
|
||||
| [File Draggable directive](content-services/directives/file-draggable.directive.md) | Provides drag-and-drop features for an element such as a div. | [Source](../lib/content-services/src/lib/upload/directives/file-draggable.directive.ts) |
|
||||
| [Inherit Permission directive](content-services/directives/inherited-button.directive.md) | Update the current node by adding/removing the inherited permissions. | [Source](../lib/content-services/src/lib/permission-manager/components/inherited-button.directive.ts) |
|
||||
@@ -344,7 +343,6 @@ for more information about installing and using the source code.
|
||||
|
||||
| Name | Description | Source link |
|
||||
| ---- | ----------- | ----------- |
|
||||
| [Base Card View Content Update interface](content-services/interfaces/base-card-view-content-update.interface.md) | Specifies required properties and methods for Card View Content Update service. Extends from BaseCardViewUpdate. | [Source](../lib/content-services/src/lib/interfaces/base-card-view-content-update.interface.ts) | |
|
||||
| [Search widget interface](content-services/interfaces/search-widget.interface.md) | Specifies required properties for Search filter component widgets. | [Source](../lib/content-services/src/lib/search/models/search-widget.interface.ts) |
|
||||
| [Content Metadata Custom Panel interface](content-services/interfaces/content-metadata-custom-panel.interface.md) | Specifies required properties for metadata custom panel. | [Source](../lib/content-services/src/lib/content-metadata/interfaces/content-metadata-custom-panel.interface.ts) |
|
||||
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
---
|
||||
Title: Check Allowable Operation directive
|
||||
Added: v2.0.0
|
||||
Status: Active
|
||||
Last reviewed: 2019-02-13
|
||||
---
|
||||
|
||||
# [Check Allowable Operation directive](../../../lib/content-services/src/lib/directives/check-allowable-operation.directive.ts "Defined in check-allowable-operation.directive.ts")
|
||||
|
||||
Selectively disables an HTML element or Angular component.
|
||||
|
||||
## Contents
|
||||
|
||||
- [Basic Usage](#basic-usage)
|
||||
- [Class members](#class-members)
|
||||
- [Properties](#properties)
|
||||
- [Details](#details)
|
||||
- [HTML element example](#html-element-example)
|
||||
- [Angular component example](#angular-component-example)
|
||||
- [Implementing the NodeAllowableOperationSubject interface](#implementing-the-nodeallowableoperationsubject-interface)
|
||||
- [Defining your component as an EXTENDIBLE_COMPONENT parent component](#defining-your-component-as-an-extendible_component-parent-component)
|
||||
|
||||
## Basic Usage
|
||||
|
||||
```html
|
||||
<adf-toolbar title="toolbar example">
|
||||
<button mat-icon-button
|
||||
adf-check-allowable-operation="delete"
|
||||
[adf-nodes]="documentList.selection">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</adf-toolbar>
|
||||
|
||||
<adf-document-list #documentList ...>
|
||||
...
|
||||
</adf-document-list>
|
||||
```
|
||||
|
||||
## Class members
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Default value | Description |
|
||||
| ---- | ---- | ------------- | ----------- |
|
||||
| nodes | [`NodeEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md)`[]` | \[] | Nodes to check permission for. |
|
||||
| permission | `string` | null | Node permission to check (create, delete, update, updatePermissions, !create, !delete, !update, !updatePermissions). |
|
||||
|
||||
## Details
|
||||
|
||||
The [Check Allowable Operation Directive](../../../lib/content-services/src/lib/directives/check-allowable-operation.directive.ts) lets you disable an HTML element or Angular component
|
||||
by taking a collection of [`NodeEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md) instances and checking their permissions.
|
||||
|
||||
The decorated element will be disabled if:
|
||||
|
||||
- there are no nodes in the collection
|
||||
- at least one of the nodes does not have the required permission
|
||||
|
||||
### HTML element example
|
||||
|
||||
A typical use case is to bind a [Document List](../components/document-list.component.md)
|
||||
selection property to a toolbar button. In the following example, the "Delete" button should
|
||||
be disabled if no selection is present or if user does not have permission to delete at least one node in the selection:
|
||||
|
||||
```html
|
||||
<adf-toolbar title="toolbar example">
|
||||
<button mat-icon-button
|
||||
adf-check-allowable-operation="delete"
|
||||
[adf-nodes]="documentList.selection">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</adf-toolbar>
|
||||
|
||||
<adf-document-list #documentList ...>
|
||||
...
|
||||
</adf-document-list>
|
||||
```
|
||||
|
||||
The button will be disabled by default and will change state when the user selects or deselects
|
||||
one or more documents that they have permission to delete.
|
||||
|
||||
### Angular component example
|
||||
|
||||
You can add the directive to any Angular component that implements the [`NodeAllowableOperationSubject`](../../../lib/content-services/src/lib/interfaces/node-allowable-operation-subject.interface.ts)
|
||||
interface (the [Upload Drag Area component](../components/upload-drag-area.component.md),
|
||||
for example). You can also use it in much the same way as you would with an HTML element:
|
||||
|
||||
```html
|
||||
<alfresco-upload-drag-area
|
||||
[rootFolderId]="..."
|
||||
[versioning]="..."
|
||||
[adf-check-allowable-operation]="'create'"
|
||||
[adf-nodes]="getCurrentDocumentListNode()">
|
||||
...
|
||||
</alfresco-upload-drag-area>
|
||||
```
|
||||
|
||||
To enable your own component to work with this directive, you need to implement the
|
||||
[`NodeAllowableOperationSubject`](../../../lib/content-services/src/lib/interfaces/node-allowable-operation-subject.interface.ts) interface and also define it as an
|
||||
[`EXTENDIBLE_COMPONENT`](../../../lib/core/src/lib/interface/injection.tokens.ts)
|
||||
parent component,
|
||||
as described in the following sections.
|
||||
|
||||
### Implementing the NodeAllowableOperationSubject interface
|
||||
|
||||
The component must implement the [`NodeAllowableOperationSubject`](../../../lib/content-services/src/lib/interfaces/node-allowable-operation-subject.interface.ts) interface which means it must have a
|
||||
boolean `disabled` property. This is the property that will be set by the directive:
|
||||
|
||||
```js
|
||||
import { NodePermissionSubject } from '@alfresco/adf-core';
|
||||
|
||||
@Component({...})
|
||||
export class UploadDragAreaComponent implements NodeAllowableOperationSubject {
|
||||
public disabled: boolean = false;
|
||||
}
|
||||
```
|
||||
|
||||
### Defining your component as an EXTENDIBLE_COMPONENT parent component
|
||||
|
||||
The directive will look up the component in the dependency injection tree,
|
||||
up to the `@Host()` component. The host component is typically the component that requests
|
||||
the dependency. However, when this component is projected into a parent component, the
|
||||
parent becomes the host. This means you must provide your component with forward referencing
|
||||
as the
|
||||
[`EXTENDIBLE_COMPONENT`](../../../lib/core/src/lib/interface/injection.tokens.ts)
|
||||
and also provide your component as a `viewProvider`:
|
||||
|
||||
```js
|
||||
import { EXTENDIBLE_COMPONENT } from '@alfresco/adf-core';
|
||||
|
||||
@Component({
|
||||
...
|
||||
viewProviders: [
|
||||
{ provide: EXTENDIBLE_COMPONENT, useExisting: forwardRef(() => UploadDragAreaComponent)}
|
||||
]
|
||||
})
|
||||
export class UploadDragAreaComponent implements NodeAllowableOperationSubject { ... }
|
||||
```
|
||||
|
||||
**Note:** the usage of **viewProviders** (instead of **providers**) is very important, especially if you want to use this directive on a transcluded component.
|
||||
@@ -1,52 +0,0 @@
|
||||
---
|
||||
Title: Base Card View Content Update interface
|
||||
Added: v6.0.0
|
||||
Status: Active
|
||||
Last reviewed: 2022-11-25
|
||||
---
|
||||
|
||||
# [Base Card View Content Update interface](../../../lib/content-services/src/lib/interfaces/base-card-view-content-update.interface.ts "Defined in base-card-view-content-update.interface.ts")
|
||||
|
||||
Specifies required properties and methods for [Card View Content Update service](lib/content-services/src/lib/common/services/card-view-content-update.service.ts).
|
||||
Extends from [`BaseCardViewUpdate`](../../../lib/core/src/lib/card-view/interfaces/base-card-view-update.interface.ts).
|
||||
|
||||
## Basic usage
|
||||
|
||||
```ts
|
||||
export interface BaseCardViewContentUpdate {
|
||||
itemUpdated$: Subject<UpdateNotification>;
|
||||
updatedAspect$: Subject<Node>;
|
||||
|
||||
update(property: CardViewBaseItemModel, newValue: any);
|
||||
updateElement(notification: CardViewBaseItemModel);
|
||||
updateNodeAspect(node: Node);
|
||||
}
|
||||
```
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Default value | Description |
|
||||
| ---- | ---- | ------------- | ----------- |
|
||||
| itemUpdated$ | [`Subject`](http://reactivex.io/documentation/subject.html)`<`[`UpdateNotification`](../../../lib/core/src/lib/card-view/interfaces/update-notification.interface.ts)`>` | | The current updated item. |
|
||||
| updatedAspect$ | [`Subject`](http://reactivex.io/documentation/subject.html)`<`[`MinimalNode`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeMinimalEntry.md)`>`(@alfresco/js-api) | | [`Subject`](http://reactivex.io/documentation/subject.html) holding the current node |
|
||||
|
||||
### Methods
|
||||
|
||||
- **update**(property: [`CardViewBaseItemModel`](../../../lib/core/src/lib/card-view/models/card-view-baseitem.model.ts), newValue: `any`)<br/>
|
||||
Update itemUpdated$ property.
|
||||
|
||||
- property:\_ [`CardViewBaseItemModel`](../../../lib/core/src/lib/card-view/models/card-view-baseitem.model.ts) - The property.
|
||||
- newValue:\_ `any` - new value.
|
||||
|
||||
- **updateElement**(notification: [`CardViewBaseItemModel`](../../../lib/core/src/lib/card-view/models/card-view-baseitem.model.ts))<br/>
|
||||
Update updateItem$ observable.
|
||||
|
||||
- notification:\_ [`CardViewBaseItemModel`](../../../lib/core/src/lib/card-view/models/card-view-baseitem.model.ts) - The notification.
|
||||
|
||||
- **updateNodeAspect**(node: [`MinimalNode`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeMinimalEntry.md))<br/>
|
||||
Update node aspect observable.
|
||||
- node:\_ [`MinimalNode`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeMinimalEntry.md) - The node.
|
||||
|
||||
## See also
|
||||
|
||||
- [CardViewContentUpdate service](../services/card-view-content-update.service.md)
|
||||
@@ -8,7 +8,6 @@ Last reviewed: 2022-11-25
|
||||
# [Card View Content Update Service](../../../lib/content-services/src/lib/common/services/card-view-content-update.service.ts "Defined in card-view-content-update.service.ts")
|
||||
|
||||
Manages Card View properties in the content services environment.
|
||||
Implements [`BaseCardViewContentUpdate`](../../../lib/content-services/src/lib/interfaces/base-card-view-content-update.interface.ts).
|
||||
|
||||
## Class members
|
||||
|
||||
|
||||
@@ -19,12 +19,11 @@ import { UpdateNotification, CardViewBaseItemModel, CardViewUpdateService } from
|
||||
import { Node } from '@alfresco/js-api';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { BaseCardViewContentUpdate } from '../../interfaces/base-card-view-content-update.interface';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CardViewContentUpdateService implements BaseCardViewContentUpdate {
|
||||
export class CardViewContentUpdateService {
|
||||
itemUpdated$ = new Subject<UpdateNotification>();
|
||||
updatedAspect$ = new Subject<Node>();
|
||||
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const mockGroupProperties = [
|
||||
{
|
||||
title: 'EXIF',
|
||||
properties: [
|
||||
{
|
||||
label: 'Image Width',
|
||||
value: 363,
|
||||
key: 'properties.exif:pixelXDimension',
|
||||
default: null,
|
||||
editable: true,
|
||||
clickable: false,
|
||||
icon: '',
|
||||
data: null,
|
||||
type: 'int',
|
||||
multiline: false,
|
||||
pipes: [],
|
||||
clickCallBack: null,
|
||||
displayValue: 400
|
||||
},
|
||||
{
|
||||
label: 'Image Height',
|
||||
value: 400,
|
||||
key: 'properties.exif:pixelYDimension',
|
||||
default: null,
|
||||
editable: true,
|
||||
clickable: false,
|
||||
icon: '',
|
||||
data: null,
|
||||
type: 'int',
|
||||
multiline: false,
|
||||
pipes: [],
|
||||
clickCallBack: null,
|
||||
displayValue: 400
|
||||
}
|
||||
],
|
||||
editable: true,
|
||||
expanded: true
|
||||
},
|
||||
{
|
||||
title: 'CUSTOM',
|
||||
properties: [
|
||||
{
|
||||
label: 'Height',
|
||||
value: 400,
|
||||
key: 'properties.custom:abc',
|
||||
default: null,
|
||||
editable: true,
|
||||
clickable: false,
|
||||
icon: '',
|
||||
data: null,
|
||||
type: 'int',
|
||||
multiline: false,
|
||||
pipes: [],
|
||||
clickCallBack: null,
|
||||
displayValue: 400
|
||||
}
|
||||
],
|
||||
editable: true,
|
||||
expanded: true
|
||||
}
|
||||
];
|
||||
@@ -1,160 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ChangeDetectorRef, Component, ElementRef, SimpleChange } from '@angular/core';
|
||||
import { ContentService } from '../common/services/content.service';
|
||||
import { CheckAllowableOperationDirective } from './check-allowable-operation.directive';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { NodeAllowableOperationSubject } from '../interfaces/node-allowable-operation-subject.interface';
|
||||
import { RedirectAuthService } from '@alfresco/adf-core';
|
||||
import { EMPTY, of } from 'rxjs';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-text-subject',
|
||||
template: ''
|
||||
})
|
||||
class TestComponent implements NodeAllowableOperationSubject {
|
||||
disabled: boolean = false;
|
||||
}
|
||||
|
||||
describe('CheckAllowableOperationDirective', () => {
|
||||
let changeDetectorMock: ChangeDetectorRef;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule],
|
||||
providers: [{ provide: RedirectAuthService, useValue: { onLogin: EMPTY, onTokenReceived: of() } }]
|
||||
});
|
||||
changeDetectorMock = { detectChanges: () => {} } as ChangeDetectorRef;
|
||||
});
|
||||
|
||||
describe('HTML nativeElement as subject', () => {
|
||||
it('updates element on nodes change', () => {
|
||||
const directive = new CheckAllowableOperationDirective(null, null, null, changeDetectorMock);
|
||||
spyOn(directive, 'updateElement').and.stub();
|
||||
|
||||
const nodes = [{}, {}];
|
||||
const change = new SimpleChange([], nodes, false);
|
||||
directive.ngOnChanges({ nodes: change });
|
||||
|
||||
expect(directive.updateElement).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('updates element only on subsequent change', () => {
|
||||
const directive = new CheckAllowableOperationDirective(null, null, null, changeDetectorMock);
|
||||
spyOn(directive, 'updateElement').and.stub();
|
||||
|
||||
const nodes = [{}, {}];
|
||||
const change = new SimpleChange([], nodes, true);
|
||||
directive.ngOnChanges({ nodes: change });
|
||||
|
||||
expect(directive.updateElement).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('enables decorated element', () => {
|
||||
const renderer = jasmine.createSpyObj('renderer', ['removeAttribute']);
|
||||
const elementRef = new ElementRef({});
|
||||
const directive = new CheckAllowableOperationDirective(elementRef, renderer, null, changeDetectorMock);
|
||||
|
||||
directive.enableElement();
|
||||
|
||||
expect(renderer.removeAttribute).toHaveBeenCalledWith(elementRef.nativeElement, 'disabled');
|
||||
});
|
||||
|
||||
it('disables decorated element', () => {
|
||||
const renderer = jasmine.createSpyObj('renderer', ['setAttribute']);
|
||||
const elementRef = new ElementRef({});
|
||||
const directive = new CheckAllowableOperationDirective(elementRef, renderer, null, changeDetectorMock);
|
||||
|
||||
directive.disableElement();
|
||||
|
||||
expect(renderer.setAttribute).toHaveBeenCalledWith(elementRef.nativeElement, 'disabled', 'true');
|
||||
});
|
||||
|
||||
it('disables element when nodes not available', () => {
|
||||
const directive = new CheckAllowableOperationDirective(null, null, null, changeDetectorMock);
|
||||
spyOn(directive, 'disableElement').and.stub();
|
||||
|
||||
directive.nodes = null;
|
||||
expect(directive.updateElement()).toBeFalsy();
|
||||
|
||||
directive.nodes = [];
|
||||
expect(directive.updateElement()).toBeFalsy();
|
||||
});
|
||||
|
||||
it('enables element when all nodes have expected permission', () => {
|
||||
const contentService = TestBed.inject(ContentService);
|
||||
spyOn(contentService, 'hasAllowableOperations').and.returnValue(true);
|
||||
|
||||
const directive = new CheckAllowableOperationDirective(null, null, contentService, changeDetectorMock);
|
||||
spyOn(directive, 'enableElement').and.stub();
|
||||
|
||||
directive.nodes = [{}, {}] as any[];
|
||||
|
||||
expect(directive.updateElement()).toBeTruthy();
|
||||
expect(directive.enableElement).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('disables element when one of the nodes have no permission', () => {
|
||||
const contentService = TestBed.inject(ContentService);
|
||||
spyOn(contentService, 'hasAllowableOperations').and.returnValue(false);
|
||||
|
||||
const directive = new CheckAllowableOperationDirective(null, null, contentService, changeDetectorMock);
|
||||
spyOn(directive, 'disableElement').and.stub();
|
||||
|
||||
directive.nodes = [{}, {}] as any[];
|
||||
|
||||
expect(directive.updateElement()).toBeFalsy();
|
||||
expect(directive.disableElement).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Angular component as subject', () => {
|
||||
it('disables decorated component', () => {
|
||||
const contentService = TestBed.inject(ContentService);
|
||||
spyOn(contentService, 'hasAllowableOperations').and.returnValue(false);
|
||||
spyOn(changeDetectorMock, 'detectChanges');
|
||||
|
||||
const testComponent = new TestComponent();
|
||||
testComponent.disabled = false;
|
||||
const directive = new CheckAllowableOperationDirective(null, null, contentService, changeDetectorMock, testComponent);
|
||||
directive.nodes = [{}, {}] as any[];
|
||||
|
||||
directive.updateElement();
|
||||
|
||||
expect(testComponent.disabled).toBeTruthy();
|
||||
expect(changeDetectorMock.detectChanges).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('enables decorated component', () => {
|
||||
const contentService = TestBed.inject(ContentService);
|
||||
spyOn(contentService, 'hasAllowableOperations').and.returnValue(true);
|
||||
spyOn(changeDetectorMock, 'detectChanges');
|
||||
|
||||
const testComponent = new TestComponent();
|
||||
testComponent.disabled = true;
|
||||
const directive = new CheckAllowableOperationDirective(null, null, contentService, changeDetectorMock, testComponent);
|
||||
directive.nodes = [{}, {}] as any[];
|
||||
|
||||
directive.updateElement();
|
||||
|
||||
expect(testComponent.disabled).toBeFalsy();
|
||||
expect(changeDetectorMock.detectChanges).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,125 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* eslint-disable @angular-eslint/no-input-rename */
|
||||
|
||||
import { ChangeDetectorRef, Directive, ElementRef, Host, Inject, Input, OnChanges, Optional, Renderer2, SimpleChanges } from '@angular/core';
|
||||
import { NodeEntry } from '@alfresco/js-api';
|
||||
import { EXTENDIBLE_COMPONENT } from '@alfresco/adf-core';
|
||||
import { ContentService } from '../common/services/content.service';
|
||||
import { NodeAllowableOperationSubject } from '../interfaces/node-allowable-operation-subject.interface';
|
||||
|
||||
@Directive({
|
||||
standalone: true,
|
||||
selector: '[adf-check-allowable-operation]'
|
||||
})
|
||||
export class CheckAllowableOperationDirective implements OnChanges {
|
||||
/**
|
||||
* Node permission to check (create, delete, update, updatePermissions,
|
||||
* !create, !delete, !update, !updatePermissions).
|
||||
*/
|
||||
@Input('adf-check-allowable-operation')
|
||||
permission: string = null;
|
||||
|
||||
/** Nodes to check permission for. */
|
||||
@Input('adf-nodes')
|
||||
nodes: NodeEntry[] = [];
|
||||
|
||||
constructor(
|
||||
private elementRef: ElementRef,
|
||||
private renderer: Renderer2,
|
||||
private contentService: ContentService,
|
||||
private changeDetector: ChangeDetectorRef,
|
||||
|
||||
@Host()
|
||||
@Optional()
|
||||
@Inject(EXTENDIBLE_COMPONENT)
|
||||
private parentComponent?: NodeAllowableOperationSubject
|
||||
) {}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (changes.nodes && !changes.nodes.firstChange) {
|
||||
this.updateElement();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates disabled state for the decorated element
|
||||
*
|
||||
* @returns the new state
|
||||
*/
|
||||
updateElement(): boolean {
|
||||
const enable = this.hasAllowableOperations(this.nodes, this.permission);
|
||||
|
||||
if (enable) {
|
||||
this.enable();
|
||||
} else {
|
||||
this.disable();
|
||||
}
|
||||
|
||||
return enable;
|
||||
}
|
||||
|
||||
private enable(): void {
|
||||
if (this.parentComponent) {
|
||||
this.parentComponent.disabled = false;
|
||||
this.changeDetector.detectChanges();
|
||||
} else {
|
||||
this.enableElement();
|
||||
}
|
||||
}
|
||||
|
||||
private disable(): void {
|
||||
if (this.parentComponent) {
|
||||
this.parentComponent.disabled = true;
|
||||
this.changeDetector.detectChanges();
|
||||
} else {
|
||||
this.disableElement();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables decorated element
|
||||
*
|
||||
*/
|
||||
enableElement(): void {
|
||||
this.renderer.removeAttribute(this.elementRef.nativeElement, 'disabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables decorated element
|
||||
*
|
||||
*/
|
||||
disableElement(): void {
|
||||
this.renderer.setAttribute(this.elementRef.nativeElement, 'disabled', 'true');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether all nodes have a particular permission
|
||||
*
|
||||
* @param nodes Node collection to check
|
||||
* @param permission Permission to check for each node
|
||||
* @returns `true` if there are allowable operations, otherwise `false`
|
||||
*/
|
||||
hasAllowableOperations(nodes: NodeEntry[], permission: string): boolean {
|
||||
if (nodes && nodes.length > 0) {
|
||||
return nodes.every((node) => this.contentService.hasAllowableOperations(node.entry, permission));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ import { NgModule } from '@angular/core';
|
||||
import { NodeLockDirective } from './node-lock.directive';
|
||||
import { NodeCounterComponent, NodeCounterDirective } from './node-counter.directive';
|
||||
import { AutoFocusDirective } from './auto-focus.directive';
|
||||
import { CheckAllowableOperationDirective } from './check-allowable-operation.directive';
|
||||
import { LibraryFavoriteDirective } from './library-favorite.directive';
|
||||
import { LibraryMembershipDirective } from './library-membership.directive';
|
||||
import { NodeDeleteDirective } from './node-delete.directive';
|
||||
@@ -27,12 +26,12 @@ import { NodeFavoriteDirective } from './node-favorite.directive';
|
||||
import { NodeRestoreDirective } from './node-restore.directive';
|
||||
import { NodeDownloadDirective } from './node-download.directive';
|
||||
|
||||
/* @deprecated import standalone directives instead */
|
||||
export const CONTENT_DIRECTIVES = [
|
||||
NodeLockDirective,
|
||||
NodeCounterDirective,
|
||||
NodeCounterComponent,
|
||||
AutoFocusDirective,
|
||||
CheckAllowableOperationDirective,
|
||||
LibraryFavoriteDirective,
|
||||
LibraryMembershipDirective,
|
||||
NodeDeleteDirective,
|
||||
@@ -41,7 +40,7 @@ export const CONTENT_DIRECTIVES = [
|
||||
NodeDownloadDirective
|
||||
];
|
||||
|
||||
/** @deprecated import CONTENT_DIRECTIVES or standalone directives instead */
|
||||
/** @deprecated import standalone directives instead */
|
||||
@NgModule({
|
||||
imports: [...CONTENT_DIRECTIVES],
|
||||
exports: [...CONTENT_DIRECTIVES]
|
||||
|
||||
@@ -21,7 +21,6 @@ import { By } from '@angular/platform-browser';
|
||||
import { NodeDeleteDirective } from './node-delete.directive';
|
||||
import { RedirectAuthService } from '@alfresco/adf-core';
|
||||
import { EMPTY, of, Subscription } from 'rxjs';
|
||||
import { CheckAllowableOperationDirective } from './check-allowable-operation.directive';
|
||||
|
||||
@Component({
|
||||
imports: [NodeDeleteDirective],
|
||||
@@ -37,8 +36,8 @@ class TestComponent {
|
||||
}
|
||||
|
||||
@Component({
|
||||
imports: [NodeDeleteDirective, CheckAllowableOperationDirective],
|
||||
template: `<div id="delete-component" [adf-check-allowable-operation]="'delete'" [adf-delete]="selection" (delete)="onDelete($event)"></div>`
|
||||
imports: [NodeDeleteDirective],
|
||||
template: `<div id="delete-component" [adf-delete]="selection" (delete)="onDelete($event)"></div>`
|
||||
})
|
||||
class TestWithPermissionsComponent {
|
||||
selection: any[] = [];
|
||||
|
||||
@@ -19,7 +19,6 @@ export * from './content-directive.module';
|
||||
export * from './node-lock.directive';
|
||||
export * from './node-counter.directive';
|
||||
export * from './auto-focus.directive';
|
||||
export * from './check-allowable-operation.directive';
|
||||
export * from './library-favorite.directive';
|
||||
export * from './library-membership.directive';
|
||||
export * from './node-delete.directive';
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { CardViewBaseItemModel, UpdateNotification } from '@alfresco/adf-core';
|
||||
import { Node } from '@alfresco/js-api';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
export interface BaseCardViewContentUpdate {
|
||||
itemUpdated$: Subject<UpdateNotification>;
|
||||
updatedAspect$: Subject<Node>;
|
||||
|
||||
update(property: CardViewBaseItemModel, newValue: any);
|
||||
updateElement(notification: CardViewBaseItemModel);
|
||||
updateNodeAspect(node: Node);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export interface NodeAllowableOperationSubject {
|
||||
disabled: boolean;
|
||||
}
|
||||
@@ -15,10 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './node-allowable-operation-subject.interface';
|
||||
export * from './library-entity.interface';
|
||||
export * from './restore-message-model.interface';
|
||||
export * from './library-membership-error-event.interface';
|
||||
export * from './library-membership-toggle-event.interface';
|
||||
export * from './base-card-view-content-update.interface';
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { EXTENDIBLE_COMPONENT, FileUtils } from '@alfresco/adf-core';
|
||||
import { Component, EventEmitter, forwardRef, Input, OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation, inject } from '@angular/core';
|
||||
import { FileUtils } from '@alfresco/adf-core';
|
||||
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation, inject } from '@angular/core';
|
||||
import { NodesApiService } from '../../common/services/nodes-api.service';
|
||||
import { ContentService } from '../../common/services/content.service';
|
||||
import { AllowableOperationsEnum } from '../../common/models/allowable-operations.enum';
|
||||
@@ -24,7 +24,6 @@ import { Node } from '@alfresco/js-api';
|
||||
import { Subject } from 'rxjs';
|
||||
import { PermissionModel } from '../../document-list/models/permissions.model';
|
||||
import { UploadBase } from './base-upload/upload-base';
|
||||
import { NodeAllowableOperationSubject } from '../../interfaces/node-allowable-operation-subject.interface';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { TranslatePipe } from '@ngx-translate/core';
|
||||
@@ -35,10 +34,9 @@ import { MatIconModule } from '@angular/material/icon';
|
||||
imports: [CommonModule, MatButtonModule, TranslatePipe, MatIconModule],
|
||||
templateUrl: './upload-button.component.html',
|
||||
styleUrls: ['./upload-button.component.scss'],
|
||||
viewProviders: [{ provide: EXTENDIBLE_COMPONENT, useExisting: forwardRef(() => UploadButtonComponent) }],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class UploadButtonComponent extends UploadBase implements OnInit, OnChanges, NodeAllowableOperationSubject {
|
||||
export class UploadButtonComponent extends UploadBase implements OnInit, OnChanges {
|
||||
private contentService = inject(ContentService);
|
||||
private nodesApiService = inject(NodesApiService);
|
||||
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { EXTENDIBLE_COMPONENT, FileInfo, FileUtils, NotificationService } from '@alfresco/adf-core';
|
||||
import { Component, forwardRef, ViewEncapsulation, inject } from '@angular/core';
|
||||
import { NodeAllowableOperationSubject } from '../../interfaces/node-allowable-operation-subject.interface';
|
||||
import { FileInfo, FileUtils, NotificationService } from '@alfresco/adf-core';
|
||||
import { Component, ViewEncapsulation, inject } from '@angular/core';
|
||||
import { UploadBase } from './base-upload/upload-base';
|
||||
import { AllowableOperationsEnum } from '../../common/models/allowable-operations.enum';
|
||||
import { ContentService } from '../../common/services/content.service';
|
||||
@@ -31,10 +30,9 @@ import { FileDraggableDirective } from '../directives/file-draggable.directive';
|
||||
templateUrl: './upload-drag-area.component.html',
|
||||
styleUrls: ['./upload-drag-area.component.scss'],
|
||||
host: { class: 'adf-upload-drag-area' },
|
||||
viewProviders: [{ provide: EXTENDIBLE_COMPONENT, useExisting: forwardRef(() => UploadDragAreaComponent) }],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class UploadDragAreaComponent extends UploadBase implements NodeAllowableOperationSubject {
|
||||
export class UploadDragAreaComponent extends UploadBase {
|
||||
private notificationService = inject(NotificationService);
|
||||
private contentService = inject(ContentService);
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { EXTENDIBLE_COMPONENT } from '@alfresco/adf-core';
|
||||
import { Component, forwardRef, Input, OnChanges, ViewEncapsulation, OnInit } from '@angular/core';
|
||||
import { Component, Input, OnChanges, ViewEncapsulation, OnInit } from '@angular/core';
|
||||
import { Node } from '@alfresco/js-api';
|
||||
import { UploadButtonComponent } from './upload-button.component';
|
||||
import { AllowableOperationsEnum } from '../../common/models/allowable-operations.enum';
|
||||
@@ -31,7 +30,6 @@ import { MatIconModule } from '@angular/material/icon';
|
||||
imports: [CommonModule, MatButtonModule, TranslatePipe, MatIconModule],
|
||||
templateUrl: './upload-button.component.html',
|
||||
styleUrls: ['./upload-button.component.scss'],
|
||||
viewProviders: [{ provide: EXTENDIBLE_COMPONENT, useExisting: forwardRef(() => UploadVersionButtonComponent) }],
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
host: { class: 'adf-upload-version-button' }
|
||||
})
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './public-api';
|
||||
@@ -1,20 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, InjectionToken } from '@angular/core';
|
||||
|
||||
export const EXTENDIBLE_COMPONENT = new InjectionToken<Component>('extendible.component');
|
||||
@@ -1,18 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './injection.tokens';
|
||||
@@ -50,7 +50,6 @@ export * from './lib/search-text/index';
|
||||
export * from './lib/snackbar-content/index';
|
||||
export * from './lib/translation/index';
|
||||
export * from './lib/common/utils/index';
|
||||
export * from './lib/interface/index';
|
||||
export * from './lib/models/index';
|
||||
export * from './lib/events/index';
|
||||
export * from './lib/mock/index';
|
||||
|
||||
Reference in New Issue
Block a user