mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2026-09-09 18:02:54 +00:00
switch to adf component (#38)
This commit is contained in:
committed by
Denys Vuika
parent
1a16ae588d
commit
71c5d96cf3
@@ -24,8 +24,6 @@ import { AdfModule } from '../adf.module';
|
||||
import { MaterialModule } from './material.module';
|
||||
|
||||
import { FolderDialogComponent } from './dialogs/folder-dialog.component';
|
||||
|
||||
import { FolderCreateDirective } from './directives/folder-create.directive';
|
||||
import { FolderEditDirective } from './directives/folder-edit.directive';
|
||||
import { NodeCopyDirective } from './directives/node-copy.directive';
|
||||
import { NodeDeleteDirective } from './directives/node-delete.directive';
|
||||
@@ -52,8 +50,6 @@ export function modules() {
|
||||
export function declarations() {
|
||||
return [
|
||||
FolderDialogComponent,
|
||||
|
||||
FolderCreateDirective,
|
||||
FolderEditDirective,
|
||||
NodeCopyDirective,
|
||||
NodeDeleteDirective,
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2017 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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 { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { Component } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { MatDialogModule, MatDialog } from '@angular/material';
|
||||
|
||||
import { FolderCreateDirective } from './folder-create.directive';
|
||||
import { ContentManagementService } from '../services/content-management.service';
|
||||
|
||||
@Component({
|
||||
template: '<div [app-create-folder]="parentNode"></div>'
|
||||
})
|
||||
class TestComponent {
|
||||
parentNode = '';
|
||||
}
|
||||
|
||||
describe('FolderCreateDirective', () => {
|
||||
let fixture: ComponentFixture<TestComponent>;
|
||||
let element;
|
||||
let node: any;
|
||||
let dialog: MatDialog;
|
||||
let contentService: ContentManagementService;
|
||||
let dialogRefMock;
|
||||
|
||||
const event: any = {
|
||||
type: 'click',
|
||||
preventDefault: () => null
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ MatDialogModule ],
|
||||
declarations: [
|
||||
TestComponent,
|
||||
FolderCreateDirective
|
||||
]
|
||||
,
|
||||
providers: [
|
||||
ContentManagementService
|
||||
]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
element = fixture.debugElement.query(By.directive(FolderCreateDirective));
|
||||
dialog = TestBed.get(MatDialog);
|
||||
contentService = TestBed.get(ContentManagementService);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
node = { entry: { id: 'nodeId' } };
|
||||
|
||||
dialogRefMock = {
|
||||
afterClosed: val => Observable.of(val)
|
||||
};
|
||||
|
||||
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
|
||||
});
|
||||
|
||||
it('emits createFolder event when input value is not undefined', () => {
|
||||
spyOn(dialogRefMock, 'afterClosed').and.returnValue(Observable.of(node));
|
||||
|
||||
contentService.createFolder.subscribe((val) => {
|
||||
expect(val).toBe(node);
|
||||
});
|
||||
|
||||
element.triggerEventHandler('click', event);
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('does not emits createFolder event when input value is undefined', () => {
|
||||
spyOn(dialogRefMock, 'afterClosed').and.returnValue(Observable.of(null));
|
||||
spyOn(contentService.createFolder, 'next');
|
||||
|
||||
element.triggerEventHandler('click', event);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(contentService.createFolder.next).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,66 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2017 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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 { Directive, HostListener, Input } from '@angular/core';
|
||||
import { MatDialog, MatDialogConfig } from '@angular/material';
|
||||
|
||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||
|
||||
import { FolderDialogComponent } from '../dialogs/folder-dialog.component';
|
||||
import { ContentManagementService } from '../services/content-management.service';
|
||||
|
||||
@Directive({
|
||||
selector: '[app-create-folder]'
|
||||
})
|
||||
export class FolderCreateDirective {
|
||||
static DIALOG_WIDTH: number = 400;
|
||||
|
||||
@Input('app-create-folder')
|
||||
parentNodeId: string;
|
||||
|
||||
@HostListener('click', [ '$event' ])
|
||||
onClick(event) {
|
||||
event.preventDefault();
|
||||
this.openDialog();
|
||||
}
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialog,
|
||||
public content: ContentManagementService
|
||||
) {}
|
||||
|
||||
private get dialogConfig(): MatDialogConfig {
|
||||
const { DIALOG_WIDTH: width } = FolderCreateDirective;
|
||||
const { parentNodeId } = this;
|
||||
|
||||
return {
|
||||
data: { parentNodeId },
|
||||
width: `${width}px`
|
||||
};
|
||||
}
|
||||
|
||||
private openDialog(): void {
|
||||
const { dialogRef, dialogConfig, content } = this;
|
||||
const dialogInstance = dialogRef.open(FolderDialogComponent, dialogConfig);
|
||||
|
||||
dialogInstance.afterClosed().subscribe((node: MinimalNodeEntryEntity) => {
|
||||
if (node) {
|
||||
content.createFolder.next(node);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,8 @@
|
||||
<mat-menu #menu="matMenu" [overlapTrigger]="false">
|
||||
<button
|
||||
mat-menu-item
|
||||
[app-create-folder]="node?.id"
|
||||
[disabled]="!canCreateContent(node)"
|
||||
[adf-create-folder]="node?.id"
|
||||
title="{{
|
||||
( canCreateContent(node)
|
||||
? 'APP.NEW_MENU.TOOLTIPS.CREATE_FOLDER'
|
||||
|
||||
Reference in New Issue
Block a user