Skip to content

Commit

Permalink
chore: add time, upload
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Oct 21, 2023
1 parent 561064c commit 0bf5d35
Show file tree
Hide file tree
Showing 29 changed files with 203 additions and 129 deletions.
10 changes: 8 additions & 2 deletions packages/form/spec/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@ export function builder(options?: {
};
}

export function configureSFTestSuite(): void {
export function configureSFTestSuite(options?: { imports?: NzSafeAny[] }): void {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [NoopAnimationsModule, AlainThemeModule.forRoot(), DelonFormModule.forRoot(), HttpClientTestingModule],
imports: [
NoopAnimationsModule,
AlainThemeModule.forRoot(),
DelonFormModule.forRoot(),
HttpClientTestingModule,
...(options?.imports ?? [])
],
declarations: [TestFormComponent]
});
});
Expand Down
10 changes: 1 addition & 9 deletions packages/form/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import { NzModalModule } from 'ng-zorro-antd/modal';
import { NzRadioModule } from 'ng-zorro-antd/radio';
import { NzSelectModule } from 'ng-zorro-antd/select';
import { NzSwitchModule } from 'ng-zorro-antd/switch';
import { NzTimePickerModule } from 'ng-zorro-antd/time-picker';
import { NzToolTipModule } from 'ng-zorro-antd/tooltip';
import { NzUploadModule } from 'ng-zorro-antd/upload';

import { DelonLocaleModule } from '@delon/theme';
import { AlainConfigService } from '@delon/util/config';
Expand All @@ -39,9 +37,7 @@ const ZORROS = [
NzRadioModule,
NzSelectModule,
NzSwitchModule,
NzTimePickerModule,
NzToolTipModule,
NzUploadModule
NzToolTipModule
];

import { SFFixedDirective } from './sf-fixed.directive';
Expand Down Expand Up @@ -70,22 +66,18 @@ import { SelectWidget } from './widgets/select/select.widget';
import { StringWidget } from './widgets/string/string.widget';
import { TextWidget } from './widgets/text/text.widget';
import { TextareaWidget } from './widgets/textarea/textarea.widget';
import { TimeWidget } from './widgets/time/time.widget';
import { UploadWidget } from './widgets/upload/upload.widget';

const WIDGETS = [
ObjectWidget,
ArrayWidget,
StringWidget,
NumberWidget,
DateWidget,
TimeWidget,
RadioWidget,
CheckboxWidget,
BooleanWidget,
TextareaWidget,
SelectWidget,
UploadWidget,
AutoCompleteWidget,
CustomWidget,
TextWidget
Expand Down
4 changes: 0 additions & 4 deletions packages/form/src/widgets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export * from './number/number.widget';
export * from './number/schema';
export * from './date/date.widget';
export * from './date/schema';
export * from './time/time.widget';
export * from './time/schema';
export * from './radio/radio.widget';
export * from './radio/schema';
export * from './checkbox/checkbox.widget';
Expand All @@ -19,8 +17,6 @@ export * from './textarea/textarea.widget';
export * from './textarea/schema';
export * from './select/select.widget';
export * from './select/schema';
export * from './upload/upload.widget';
export * from './upload/schema';
export * from './autocomplete/autocomplete.widget';
export * from './autocomplete/schema';
export * from './text/text.widget';
Expand Down
4 changes: 0 additions & 4 deletions packages/form/src/widgets/nz-widget.registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { SelectWidget } from './select/select.widget';
import { StringWidget } from './string/string.widget';
import { TextWidget } from './text/text.widget';
import { TextareaWidget } from './textarea/textarea.widget';
import { TimeWidget } from './time/time.widget';
import { UploadWidget } from './upload/upload.widget';
import { WidgetRegistry } from '../widget.factory';

export class NzWidgetRegistry extends WidgetRegistry {
Expand All @@ -27,13 +25,11 @@ export class NzWidgetRegistry extends WidgetRegistry {
this.register('number', NumberWidget);
this.register('integer', NumberWidget);
this.register('date', DateWidget);
this.register('time', TimeWidget);
this.register('radio', RadioWidget);
this.register('checkbox', CheckboxWidget);
this.register('boolean', BooleanWidget);
this.register('textarea', TextareaWidget);
this.register('select', SelectWidget);
this.register('upload', UploadWidget);
this.register('autocomplete', AutoCompleteWidget);
this.register('custom', CustomWidget);

Expand Down
26 changes: 0 additions & 26 deletions packages/form/src/widgets/time/time.widget.html

This file was deleted.

46 changes: 0 additions & 46 deletions packages/form/src/widgets/upload/upload.widget.html

This file was deleted.

3 changes: 2 additions & 1 deletion packages/form/widgets/cascader/widget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ComponentFixture, fakeAsync } from '@angular/core/testing';

import { createTestContext } from '@delon/testing';

import { CascaderWidgetModule } from './index';
import { CascaderWidget } from './widget';
import { configureSFTestSuite, SFPage, TestFormComponent } from '../../spec/base.spec';

Expand All @@ -13,7 +14,7 @@ describe('form: widget: cascader', () => {
let page: SFPage;
const widget = 'cascader';

configureSFTestSuite();
configureSFTestSuite({ imports: [CascaderWidgetModule] });

beforeEach(() => {
({ fixture, dl, context } = createTestContext(TestFormComponent));
Expand Down
3 changes: 2 additions & 1 deletion packages/form/widgets/mention/widget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { SFSchema } from '@delon/form';
import { createTestContext } from '@delon/testing';
import { NzSafeAny } from 'ng-zorro-antd/core/types';

import { MentionWidgetModule } from './index';
import { MentionWidget } from './widget';
import { configureSFTestSuite, SFPage, TestFormComponent } from '../../spec/base.spec';

Expand All @@ -18,7 +19,7 @@ describe('form: widget: mention', () => {
let page: SFPage;
const widget = 'mention';

configureSFTestSuite();
configureSFTestSuite({ imports: [MentionWidgetModule] });

beforeEach(() => {
({ fixture, dl, context } = createTestContext(TestFormComponent));
Expand Down
3 changes: 2 additions & 1 deletion packages/form/widgets/rate/widget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ComponentFixture, fakeAsync } from '@angular/core/testing';

import { createTestContext } from '@delon/testing';

import { RateWidgetModule } from './index';
import { configureSFTestSuite, SFPage, TestFormComponent } from '../../spec/base.spec';

describe('form: widget: rate', () => {
Expand All @@ -12,7 +13,7 @@ describe('form: widget: rate', () => {
let page: SFPage;
const widget = 'rate';

configureSFTestSuite();
configureSFTestSuite({ imports: [RateWidgetModule] });

beforeEach(() => {
({ fixture, dl, context } = createTestContext(TestFormComponent));
Expand Down
3 changes: 2 additions & 1 deletion packages/form/widgets/slider/widget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createTestContext } from '@delon/testing';
import { NzSafeAny } from 'ng-zorro-antd/core/types';
import { NzSliderComponent } from 'ng-zorro-antd/slider';

import { SliderWidgetModule } from './index';
import { SliderWidget } from './widget';
import { configureSFTestSuite, SFPage, TestFormComponent } from '../../spec/base.spec';

Expand All @@ -16,7 +17,7 @@ describe('form: widget: slider', () => {
let page: SFPage;
const widget = 'slider';

configureSFTestSuite();
configureSFTestSuite({ imports: [SliderWidgetModule] });

beforeEach(() => {
({ fixture, dl, context } = createTestContext(TestFormComponent));
Expand Down
3 changes: 2 additions & 1 deletion packages/form/widgets/tag/widget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createTestContext } from '@delon/testing';
import { NzSafeAny } from 'ng-zorro-antd/core/types';
import { NzTagComponent } from 'ng-zorro-antd/tag';

import { TagWidgetModule } from './index';
import { configureSFTestSuite, SFPage, TestFormComponent } from '../../spec/base.spec';

describe('form: widget: tag', () => {
Expand All @@ -14,7 +15,7 @@ describe('form: widget: tag', () => {
let context: TestFormComponent;
let page: SFPage;

configureSFTestSuite();
configureSFTestSuite({ imports: [TagWidgetModule] });

beforeEach(() => {
({ fixture, dl, context } = createTestContext(TestFormComponent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ Simplest of usage.

```ts
import { Component } from '@angular/core';
import { SFSchema, SFTimeWidgetSchema } from '@delon/form';
import { SFSchema } from '@delon/form';
import type { SFTimeWidgetSchema } from '@delon/form/widgets/time';
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
selector: 'app-demo',
template: ` <sf [schema]="schema" (formSubmit)="submit($event)"></sf> `,
template: ` <sf [schema]="schema" (formSubmit)="submit($event)"/>`,
})
export class DemoComponent {
schema: SFSchema = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
---
title: time
subtitle: Time
type: Widgets
type: Non-built-in widgets
---

To select/input a time.

## Import module

Non-built-in modules, Should be import `TimeWidgetModule` in [json-schema.module.ts](https://github.com/ng-alain/ng-alain/blob/master/src/app/shared/json-schema/json-schema.module.ts#L11).

## Notice

- Format is divided into two types: **Data format** means form data, **Display format** means display data ([nzFormat](https://ng.ant.design/components/time-picker/en#api))
Expand Down
20 changes: 20 additions & 0 deletions packages/form/widgets/time/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { DelonFormModule, WidgetRegistry } from '@delon/form';
import { NzTimePickerModule } from 'ng-zorro-antd/time-picker';

import { TimeWidget } from './widget';

export * from './widget';
export * from './schema';

@NgModule({
imports: [FormsModule, DelonFormModule, NzTimePickerModule],
declarations: [TimeWidget]
})
export class TimeWidgetModule {
constructor(widgetRegistry: WidgetRegistry) {
widgetRegistry.register(TimeWidget.KEY, TimeWidget);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
---
title: time
subtitle: 时间
type: Widgets
type: Non-built-in widgets
---

输入或选择时间的控件。

## 导入模块

非内置模块,需要额外在 [json-schema.module.ts](https://github.com/ng-alain/ng-alain/blob/master/src/app/shared/json-schema/json-schema.module.ts#L11) 导入 `TimeWidgetModule`

## 注意事项

- 格式化分为:**数据格式化**表示表单数据和**显示格式化**显示数据(等同 [nzFormat](https://ng.ant.design/components/time-picker/zh#api) 值)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SFDLSSize, SFUISchemaItem } from '../../schema/ui';
import type { SFDLSSize, SFUISchemaItem } from '@delon/form';

export interface SFTimeWidgetSchema extends SFUISchemaItem {
size?: SFDLSSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { ComponentFixture } from '@angular/core/testing';

import { format } from 'date-fns';

import type { SFSchema } from '@delon/form';
import { createTestContext } from '@delon/testing';

import { TimeWidget } from './time.widget';
import { configureSFTestSuite, SFPage, TestFormComponent } from '../../../spec/base.spec';
import { SFSchema } from '../../../src/schema/index';
import { TimeWidgetModule } from './index';
import { TimeWidget } from './widget';
import { configureSFTestSuite, SFPage, TestFormComponent } from '../../spec/base.spec';

const FORMAT = 'yyyy-MM-dd HH:mm:ss';

Expand All @@ -18,7 +19,7 @@ describe('form: widget: time', () => {
let dl: DebugElement;
const widget = 'time';

configureSFTestSuite();
configureSFTestSuite({ imports: [TimeWidgetModule] });

beforeEach(() => {
({ fixture, dl, context } = createTestContext(TestFormComponent));
Expand Down
Loading

0 comments on commit 0bf5d35

Please sign in to comment.