mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Move 'pagination' to the core, barrel files for core
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 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 { describe, it, beforeEach } from '@angular/core/testing';
|
||||
import { ContextMenuService } from './context-menu.service';
|
||||
import { ContextMenuHolderComponent } from './context-menu-holder.component';
|
||||
|
||||
describe('ContextMenuHolderComponent', () => {
|
||||
|
||||
let contextMenuService;
|
||||
let menuHolder;
|
||||
|
||||
beforeEach(() => {
|
||||
contextMenuService = new ContextMenuService();
|
||||
menuHolder = new ContextMenuHolderComponent(contextMenuService);
|
||||
});
|
||||
|
||||
it('should show menu on service event', () => {
|
||||
spyOn(menuHolder, 'showMenu').and.callThrough();
|
||||
contextMenuService.show.next({});
|
||||
|
||||
expect(menuHolder.showMenu).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should have fixed position', () => {
|
||||
expect(menuHolder.locationCss).toEqual(
|
||||
jasmine.objectContaining({
|
||||
position: 'fixed'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should setup empty location by default', () => {
|
||||
expect(menuHolder.locationCss).toEqual(
|
||||
jasmine.objectContaining({
|
||||
left: '0px',
|
||||
top: '0px'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should be hidden by default', () => {
|
||||
expect(menuHolder.isShown).toBeFalsy();
|
||||
expect(menuHolder.locationCss).toEqual(
|
||||
jasmine.objectContaining({
|
||||
display: 'none'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should show on service event', () => {
|
||||
expect(menuHolder.isShown).toBeFalsy();
|
||||
contextMenuService.show.next({});
|
||||
expect(menuHolder.isShown).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should update position from service event', () => {
|
||||
|
||||
expect(menuHolder.locationCss).toEqual(
|
||||
jasmine.objectContaining({
|
||||
left: '0px',
|
||||
top: '0px'
|
||||
})
|
||||
);
|
||||
|
||||
let event = new MouseEvent('click', {
|
||||
clientX: 10,
|
||||
clientY: 20
|
||||
});
|
||||
|
||||
contextMenuService.show.next({ event: event });
|
||||
|
||||
expect(menuHolder.locationCss).toEqual(
|
||||
jasmine.objectContaining({
|
||||
left: '10px',
|
||||
top: '20px'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should take links from service event', () => {
|
||||
let links = [{}, {}];
|
||||
contextMenuService.show.next({ obj: links });
|
||||
expect(menuHolder.links).toBe(links);
|
||||
});
|
||||
|
||||
it('should hide on outside click', () => {
|
||||
contextMenuService.show.next({});
|
||||
expect(menuHolder.isShown).toBeTruthy();
|
||||
|
||||
menuHolder.clickedOutside();
|
||||
expect(menuHolder.isShown).toBeFalsy();
|
||||
expect(menuHolder.locationCss).toEqual(
|
||||
jasmine.objectContaining({
|
||||
display: 'none'
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,107 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 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 { Component, HostListener } from '@angular/core';
|
||||
import { ContextMenuService } from './context-menu.service';
|
||||
|
||||
@Component({
|
||||
selector:'context-menu-holder',
|
||||
styles:[
|
||||
`
|
||||
.menu-container {
|
||||
background: #fff;
|
||||
display: block;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: none;
|
||||
overflow: visible;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
.context-menu {
|
||||
list-style-type: none;
|
||||
position: static;
|
||||
|
||||
|
||||
height: auto;
|
||||
width: auto;
|
||||
min-width: 124px;
|
||||
padding: 8px 0;
|
||||
margin: 0;
|
||||
|
||||
box-shadow: 0 2px 2px 0 rgba(0,0,0,.14),0 3px 1px -2px rgba(0,0,0,.2),0 1px 5px 0 rgba(0,0,0,.12);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.context-menu .link {
|
||||
opacity: 1;
|
||||
}
|
||||
`
|
||||
],
|
||||
template: `
|
||||
<div [ngStyle]="locationCss" class="menu-container">
|
||||
<ul class="context-menu">
|
||||
<li (click)="link.subject.next(link)" class="mdl-menu__item link" *ngFor="let link of links">
|
||||
{{link.title || link.model?.title}}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
export class ContextMenuHolderComponent {
|
||||
links = [];
|
||||
isShown = false;
|
||||
private mouseLocation: { left: number, top: number } = { left: 0, top: 0 };
|
||||
|
||||
constructor(
|
||||
private _contextMenuService: ContextMenuService) {
|
||||
_contextMenuService.show.subscribe(e => this.showMenu(e.event, e.obj));
|
||||
}
|
||||
|
||||
get locationCss() {
|
||||
return {
|
||||
position: 'fixed',
|
||||
display: this.isShown ? 'block' : 'none',
|
||||
left: this.mouseLocation.left + 'px',
|
||||
top: this.mouseLocation.top + 'px'
|
||||
};
|
||||
}
|
||||
|
||||
@HostListener('document:click')
|
||||
clickedOutside() {
|
||||
this.isShown = false;
|
||||
}
|
||||
|
||||
showMenu(e, links) {
|
||||
this.isShown = true;
|
||||
this.links = links;
|
||||
|
||||
if (e) {
|
||||
this.mouseLocation = {
|
||||
left: e.clientX,
|
||||
top: e.clientY
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@HostListener('contextmenu', ['$event'])
|
||||
onShowContextMenu(event?: MouseEvent) {
|
||||
if (event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 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 { describe, it, beforeEach } from '@angular/core/testing';
|
||||
import { ContextMenuDirective } from './context-menu.directive';
|
||||
import { ContextMenuService } from './context-menu.service';
|
||||
|
||||
describe('ContextMenuDirective', () => {
|
||||
|
||||
let contextMenuService;
|
||||
let directive;
|
||||
|
||||
beforeEach(() => {
|
||||
contextMenuService = new ContextMenuService();
|
||||
directive = new ContextMenuDirective(contextMenuService);
|
||||
});
|
||||
|
||||
it('should show menu via service', (done) => {
|
||||
contextMenuService.show.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
directive.links = [{}];
|
||||
directive.onShowContextMenu(null);
|
||||
});
|
||||
|
||||
it('should prevent default behavior', () => {
|
||||
let event = new MouseEvent('click');
|
||||
spyOn(event, 'preventDefault').and.callThrough();
|
||||
|
||||
directive.onShowContextMenu(event);
|
||||
expect(event.preventDefault).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should forward event to service', () => {
|
||||
let event = new MouseEvent('click');
|
||||
|
||||
contextMenuService.show.subscribe(e => {
|
||||
expect(e.event).toBeDefined();
|
||||
expect(e.event).toBe(event);
|
||||
});
|
||||
|
||||
directive.onShowContextMenu(event);
|
||||
});
|
||||
|
||||
it('should forward menu items to service', () => {
|
||||
let links = [{}, {}];
|
||||
directive.links = links;
|
||||
|
||||
contextMenuService.show.subscribe(e => {
|
||||
expect(e.obj).toBeDefined();
|
||||
expect(e.obj).toBe(links);
|
||||
});
|
||||
|
||||
directive.onShowContextMenu(null);
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,43 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 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, Input, HostListener } from '@angular/core';
|
||||
import { ContextMenuService } from './context-menu.service';
|
||||
|
||||
@Directive({
|
||||
selector:'[context-menu]'
|
||||
})
|
||||
export class ContextMenuDirective {
|
||||
@Input('context-menu')
|
||||
links: any[];
|
||||
|
||||
constructor(
|
||||
private _contextMenuService: ContextMenuService) {}
|
||||
|
||||
@HostListener('contextmenu', ['$event'])
|
||||
onShowContextMenu(event?: MouseEvent) {
|
||||
if (event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (this.links && this.links.length > 0) {
|
||||
if (this._contextMenuService) {
|
||||
this._contextMenuService.show.next({event: event, obj: this.links});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 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 { describe, it, beforeEach } from '@angular/core/testing';
|
||||
import { ContextMenuService } from './context-menu.service';
|
||||
|
||||
describe('ContextMenuService', () => {
|
||||
|
||||
let service;
|
||||
|
||||
beforeEach(() => {
|
||||
service = new ContextMenuService();
|
||||
});
|
||||
|
||||
it('should setup default show subject', () => {
|
||||
expect(service.show).toBeDefined();
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,24 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 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 {Injectable} from '@angular/core';
|
||||
import {Subject} from 'rxjs/Rx';
|
||||
|
||||
@Injectable()
|
||||
export class ContextMenuService {
|
||||
public show: Subject<{event: MouseEvent, obj: any[]}> = new Subject<{event: MouseEvent, obj: any[]}>();
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 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 { ContextMenuService } from './context-menu.service';
|
||||
import { ContextMenuHolderComponent } from './context-menu-holder.component';
|
||||
import { ContextMenuDirective } from './context-menu.directive';
|
||||
|
||||
export * from './context-menu.service';
|
||||
export * from './context-menu-holder.component';
|
||||
export * from './context-menu.directive';
|
||||
|
||||
export const CONTEXT_MENU_PROVIDERS: [any] = [
|
||||
ContextMenuService
|
||||
];
|
||||
|
||||
export const CONTEXT_MENU_DIRECTIVES: [any] = [
|
||||
ContextMenuHolderComponent,
|
||||
ContextMenuDirective
|
||||
];
|
Reference in New Issue
Block a user