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

Added draggable input to tree component #4793

Merged
merged 7 commits into from
Jul 17, 2020
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
3 changes: 0 additions & 3 deletions npm/ng-packs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,5 @@
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"resolutions": {
"@ngx-validate/core": "^0.0.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('AccountService', () => {
beforeEach(() => (spectator = createHttp()));

it('should send a GET to find tenant', () => {
spectator.get(Store).selectSnapshot.andReturn('https://abp.io');
spectator.inject(Store).selectSnapshot.andReturn('https://abp.io');
spectator.service.findTenant('test').subscribe();
spectator.expectOne(
'https://abp.io/api/abp/multi-tenancy/tenants/by-name/test',
Expand All @@ -30,7 +30,7 @@ describe('AccountService', () => {
password: 'test1234',
appName: 'Angular',
} as RegisterRequest;
spectator.get(Store).selectSnapshot.andReturn('https://abp.io');
spectator.inject(Store).selectSnapshot.andReturn('https://abp.io');
spectator.service.register(mock).subscribe();
const req = spectator.expectOne('https://abp.io/api/account/register', HttpMethod.POST);
expect(req.request.body).toEqual(mock);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<nz-tree
[nzBeforeDrop]="beforeDrop"
[nzDraggable]="draggable"
[nzCheckStrictly]="checkStrictly"
[nzCheckable]="checkable"
[nzCheckedKeys]="checkedKeys"
Expand All @@ -7,6 +9,7 @@
[nzExpandedKeys]="expandedKeys"
(nzExpandChange)="onExpandedKeysChange($event)"
(nzCheckBoxChange)="onCheckboxChange($event)"
(nzOnDrop)="onDrop($event)"
></nz-tree>
<ng-template #treeTemplate let-node>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import {
TemplateRef,
ViewEncapsulation,
} from '@angular/core';
import { NzFormatEmitEvent, NzFormatBeforeDropEvent } from 'ng-zorro-antd/tree';
import { of } from 'rxjs';

export type DropEvent = NzFormatEmitEvent & { pos: number };

@Component({
selector: 'abp-tree',
Expand All @@ -18,17 +22,25 @@ import {
encapsulation: ViewEncapsulation.None,
})
export class TreeComponent {
dropPosition: number;

@ContentChild('menu') menu: TemplateRef<any>;
@Output() readonly checkedKeysChange = new EventEmitter();
@Output() readonly expandedKeysChange = new EventEmitter<string[]>();
@Output() readonly selectedNodeChange = new EventEmitter();
@Output() readonly dropOver = new EventEmitter<DropEvent>();
@Input() draggable: boolean;
@Input() checkable: boolean;
@Input() checkStrictly: boolean;
@Input() checkedKeys = [];
@Input() nodes = [];
@Input() expandedKeys: string[] = [];
@Input() selectedNode: any;
@Input() isNodeSelected = node => this.selectedNode?.id === node.key;
@Input() beforeDrop = (event: NzFormatBeforeDropEvent) => {
this.dropPosition = event.pos;
return of(false);
};

onSelectedNodeChange(node) {
this.selectedNode = node.origin.entity;
Expand All @@ -44,4 +56,12 @@ export class TreeComponent {
this.expandedKeys = [...event.keys];
this.expandedKeysChange.emit(event.keys);
}

onDrop(event: DropEvent) {
event.event.stopPropagation();
event.event.preventDefault();
event.pos = this.dropPosition;

this.dropOver.emit(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe('ApiInterceptor', () => {
beforeEach(() => {
spectator = createService();
interceptor = spectator.service;
store = spectator.get(Store);
oauthService = spectator.get(OAuthService);
store = spectator.inject(Store);
oauthService = spectator.inject(OAuthService);
});

it('should add headers to http request', done => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('ApplicationConfigurationService', () => {
beforeEach(() => (spectator = createHttp()));

it('should send a GET to application-configuration API', () => {
spectator.get(Store).selectSnapshot.andReturn('https://abp.io');
spectator.inject(Store).selectSnapshot.andReturn('https://abp.io');
spectator.service.getConfiguration().subscribe();
spectator.expectOne('https://abp.io/api/abp/application-configuration', HttpMethod.GET);
});
Expand Down
6 changes: 3 additions & 3 deletions npm/ng-packs/packages/core/src/lib/tests/auth.guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ describe('AuthGuard', () => {
});

it('should return true when user logged in', () => {
spectator.get(OAuthService).hasValidAccessToken.andReturn(true);
spectator.inject(OAuthService).hasValidAccessToken.andReturn(true);
expect(guard.canActivate(null, null)).toBe(true);
});

it('should return navigate to login page with redirectUrl state', () => {
const router = spectator.get(Router);
spectator.get(OAuthService).hasValidAccessToken.andReturn(false);
const router = spectator.inject(Router);
spectator.inject(OAuthService).hasValidAccessToken.andReturn(false);

expect(guard.canActivate(null, { url: '/' } as any)).toBe(true);
expect(router.navigate).toHaveBeenCalledWith(['/account/login'], {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('ConfigStateService', () => {
beforeEach(() => {
spectator = createService();
service = spectator.service;
store = spectator.get(Store);
store = spectator.inject(Store);
});
test('should have the all ConfigState static methods', () => {
const reg = /(?<=static )(.*)(?=\()/gm;
Expand Down
6 changes: 3 additions & 3 deletions npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ describe('ConfigState', () => {

beforeEach(() => {
spectator = createService();
store = spectator.get(Store);
store = spectator.inject(Store);
service = spectator.service;
state = new ConfigState(spectator.get(HttpClient), store);
state = new ConfigState(spectator.inject(HttpClient), store);
});

describe('#getAll', () => {
Expand Down Expand Up @@ -250,7 +250,7 @@ describe('ConfigState', () => {
dispatchArg = a;
return of(a);
});
const httpClient = spectator.get(HttpClient);
const httpClient = spectator.inject(HttpClient);
httpClient.get.andReturn(res$);

state.addData({ patchState, dispatch } as any).subscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ describe('DynamicLayoutComponent', () => {

beforeEach(async () => {
spectator = createComponent();
store = spectator.get(Store);
const routesService = spectator.get(RoutesService);
store = spectator.inject(Store);
const routesService = spectator.inject(RoutesService);
routesService.add(routes);

store.reset(storeData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ describe('LocaleProvider', () => {
describe('#LOCALE_ID', () => {
test('should equal to currentLang', async () => {
spectator = createComponent();
const localizationService = spectator.get(LocalizationService);
const localizationService = spectator.inject(LocalizationService);

expect(spectator.get(LOCALE_ID).valueOf()).toBe(localesMapping['en-US'] || 'en-US');
expect(spectator.inject(LOCALE_ID).valueOf()).toBe(localesMapping['en-US'] || 'en-US');

(localizationService as any).currentLang = 'tr';
expect(spectator.get(LOCALE_ID).valueOf()).toBe(localesMapping['tr'] || 'tr');
expect(spectator.inject(LOCALE_ID).valueOf()).toBe(localesMapping['tr'] || 'tr');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ describe('LocalizationPipe', () => {

beforeEach(() => {
spectator = createService();
pipe = spectator.get(LocalizationPipe);
store = spectator.get(Store);
pipe = spectator.inject(LocalizationPipe);
store = spectator.inject(Store);
});

it('should call getLocalization selector', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('LocalizationService', () => {

beforeEach(() => {
spectator = createService();
store = spectator.get(Store);
store = spectator.inject(Store);
service = spectator.service;
});

Expand Down Expand Up @@ -52,7 +52,7 @@ describe('LocalizationService', () => {

describe('#registerLocale', () => {
it('should return registerLocale and then call setRouteReuse', () => {
const router = spectator.get(Router);
const router = spectator.inject(Router);

const shouldReuseRoute = () => true;
router.routeReuseStrategy = { shouldReuseRoute } as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('PermissionDirective', () => {
});

it('should do nothing when condition is undefined', () => {
const spy = jest.spyOn(spectator.get(Store), 'select');
const spy = jest.spyOn(spectator.inject(Store), 'select');
grantedPolicy$.next(false);
expect(spy.mock.calls).toHaveLength(0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('PermissionGuard', () => {
spectator = createService();
guard = spectator.service;
routes = spectator.inject(RoutesService);
store = spectator.get(Store);
store = spectator.inject(Store);
});

it('should return true when the grantedPolicy is true', done => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('ProfileStateService', () => {
beforeEach(() => {
spectator = createService();
service = spectator.service;
store = spectator.get(Store);
store = spectator.inject(Store);
});
test('should have the all ProfileState static methods', () => {
const reg = /(?<=static )(.*)(?=\()/gm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ describe('ProfileService', () => {
beforeEach(() => (spectator = createHttp()));

it('should send a GET to my-profile API', () => {
spectator.get(Store).selectSnapshot.andReturn('https://abp.io');
spectator.inject(Store).selectSnapshot.andReturn('https://abp.io');
spectator.service.get().subscribe();
spectator.expectOne('https://abp.io/api/identity/my-profile', HttpMethod.GET);
});

it('should send a POST to change-password API', () => {
const mock = { currentPassword: 'test', newPassword: 'test' };
spectator.get(Store).selectSnapshot.andReturn('https://abp.io');
spectator.inject(Store).selectSnapshot.andReturn('https://abp.io');
spectator.service.changePassword(mock).subscribe();
const req = spectator.expectOne(
'https://abp.io/api/identity/my-profile/change-password',
Expand All @@ -38,7 +38,7 @@ describe('ProfileService', () => {
surname: 'Doe',
phoneNumber: '+123456',
};
spectator.get(Store).selectSnapshot.andReturn('https://abp.io');
spectator.inject(Store).selectSnapshot.andReturn('https://abp.io');
spectator.service.update(mock).subscribe();
const req = spectator.expectOne('https://abp.io/api/identity/my-profile', HttpMethod.PUT);
expect(req.request.body).toEqual(mock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('ProfileState', () => {

beforeEach(() => {
spectator = createService();
profileService = spectator.get(ProfileService);
profileService = spectator.inject(ProfileService);
state = new ProfileState(profileService);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('ReplaceableComponentsState', () => {
});

it('should add a component to the state', () => {
const store = spectator.get(Store);
const store = spectator.inject(Store);
expect(store.selectSnapshot(ReplaceableComponentsState.getAll)).toEqual([]);
store.dispatch(new AddReplaceableComponent({ component: DummyComponent, key: 'Dummy' }));
expect(store.selectSnapshot(ReplaceableComponentsState.getComponent('Dummy'))).toEqual({
Expand All @@ -35,7 +35,7 @@ describe('ReplaceableComponentsState', () => {
});

it('should replace a exist component', () => {
const store = spectator.get(Store);
const store = spectator.inject(Store);
store.dispatch(new AddReplaceableComponent({ component: DummyComponent, key: 'Dummy' }));
store.dispatch(new AddReplaceableComponent({ component: null, key: 'Dummy' }));
expect(store.selectSnapshot(ReplaceableComponentsState.getComponent('Dummy'))).toEqual({
Expand All @@ -47,7 +47,7 @@ describe('ReplaceableComponentsState', () => {

it('should call reloadRoute when reload parameter is given as true to AddReplaceableComponent', async () => {
const spy = jest.spyOn(router, 'navigateByUrl');
const store = spectator.get(Store);
const store = spectator.inject(Store);
store.dispatch(new AddReplaceableComponent({ component: DummyComponent, key: 'Dummy' }));
store.dispatch(new AddReplaceableComponent({ component: null, key: 'Dummy' }, true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('HttpClient testing', () => {

beforeEach(() => {
spectator = createHttp();
store = spectator.get(Store);
store = spectator.inject(Store);
store.reset({
ConfigState: {
environment: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('SessionStateService', () => {
beforeEach(() => {
spectator = createService();
service = spectator.service;
store = spectator.get(Store);
store = spectator.inject(Store);
});
test('should have the all SessionState static methods', () => {
const reg = /(?<=static )(.*)(?=\()/gm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('FeatureManagementStateService', () => {
beforeEach(() => {
spectator = createService();
service = spectator.service;
store = spectator.get(Store);
store = spectator.inject(Store);
});

test('should have the all FeatureManagementState static methods', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('IdentityStateService', () => {
beforeEach(() => {
spectator = createService();
service = spectator.service;
store = spectator.get(Store);
store = spectator.inject(Store);
});

test('should have the all IdentityState static methods', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('PermissionManagementStateService', () => {
beforeEach(() => {
spectator = createService();
service = spectator.service;
store = spectator.get(Store);
store = spectator.inject(Store);
});
test('should have the all PermissionManagementState static methods', () => {
const reg = /(?<=static )(.*)(?=\()/gm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('TenantManagementStateService', () => {
beforeEach(() => {
spectator = createService();
service = spectator.service;
store = spectator.get(Store);
store = spectator.inject(Store);
});

test('should have the all TenantManagementState static methods', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ describe('Form Prop Utils', () => {

function* getInjected(spectator: SpectatorService<ExtensionsService>) {
yield spectator.service;
yield spectator.get(EXTENSIONS_IDENTIFIER);
yield spectator.get(LocalizationService);
yield spectator.inject(EXTENSIONS_IDENTIFIER);
yield spectator.inject(LocalizationService);
}

interface Foo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ describe('AppendContentToken', () => {
beforeEach(() => (spectator = createComponent()));

it('should insert a style element to the DOM', () => {
spectator.get(THEME_SHARED_APPEND_CONTENT);
expect(spectator.get(DomInsertionService).has(styles)).toBe(true);
spectator.inject(THEME_SHARED_APPEND_CONTENT);
expect(spectator.inject(DomInsertionService).has(styles)).toBe(true);
});

it('should be loaded the chart.js', done => {
Expand All @@ -25,6 +25,6 @@ describe('AppendContentToken', () => {
done();
});

spectator.get(THEME_SHARED_APPEND_CONTENT);
spectator.inject(THEME_SHARED_APPEND_CONTENT);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ describe('BreadcrumbComponent', () => {

beforeEach(() => {
spectator = createRouting();
routes = spectator.get(RoutesService);
store = spectator.get(Store);
routes = spectator.inject(RoutesService);
store = spectator.inject(Store);
});

it('should display the breadcrumb', async () => {
Expand Down
Loading