added text component (#1462)

* added text component
This commit is contained in:
Leila Lali
2018-05-22 16:12:02 -07:00
committed by GitHub
parent 4bfc549927
commit 1461929f86
6 changed files with 109 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ import DropDownComponent from './dropdown.component';
import ButtonComponent from './button.component';
import CheckBoxComponent from './checkbox.component';
import RadioButtonComponent from './radioButton.component';
import TextComponent from './text.component';
import { registerComponentType } from 'sql/platform/dashboard/common/modelComponentRegistry';
import { ModelComponentTypes } from 'sql/workbench/api/common/sqlExtHostTypes';
@@ -38,3 +39,6 @@ registerComponentType(CHECKBOX_COMPONENT, ModelComponentTypes.CheckBox, CheckBox
export const RADIOBUTTON_COMPONENT = 'radiobutton-component';
registerComponentType(RADIOBUTTON_COMPONENT, ModelComponentTypes.RadioButton, RadioButtonComponent);
export const TEXT_COMPONENT = 'text-component';
registerComponentType(TEXT_COMPONENT, ModelComponentTypes.Text, TextComponent);

View File

@@ -50,6 +50,7 @@ export default class RadioButtonComponent extends ComponentBase implements IComp
this._register(this._input);
this._register(this._input.onClicked(e => {
this.checked = this._input.checked;
this._onEventEmitter.fire({
eventType: ComponentEventType.onDidClick,
args: e
@@ -89,8 +90,12 @@ export default class RadioButtonComponent extends ComponentBase implements IComp
return this.getPropertyOrDefault<sqlops.RadioButtonProperties, boolean>((props) => props.checked, false);
}
public set checked(newValue: boolean) {
this.setPropertyFromUI<sqlops.RadioButtonProperties, boolean>((properties, value) => { properties.checked = value; }, newValue);
}
public set value(newValue: string) {
this.setPropertyFromUI<sqlops.RadioButtonProperties, string>((properties, value) => { properties.checked = value; }, newValue);
this.setPropertyFromUI<sqlops.RadioButtonProperties, string>((properties, value) => { properties.value = value; }, newValue);
}
public get value(): string {

View File

@@ -0,0 +1,67 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./radioButton';
import {
Component, Input, Inject, ChangeDetectorRef, forwardRef, ComponentFactoryResolver,
ViewChild, ViewChildren, ElementRef, Injector, OnDestroy, QueryList, AfterViewInit
} from '@angular/core';
import * as sqlops from 'sqlops';
import Event, { Emitter } from 'vs/base/common/event';
import { ComponentBase } from 'sql/parts/modelComponents/componentBase';
import { IComponent, IComponentDescriptor, IModelStore, ComponentEventType } from 'sql/parts/modelComponents/interfaces';
import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service';
@Component({
selector: 'label',
template: `
<p>{{getValue()}}</p>`
})
export default class TextComponent extends ComponentBase implements IComponent, OnDestroy, AfterViewInit {
@Input() descriptor: IComponentDescriptor;
@Input() modelStore: IModelStore;
constructor(
@Inject(forwardRef(() => CommonServiceInterface)) private _commonService: CommonServiceInterface,
@Inject(forwardRef(() => ChangeDetectorRef)) changeRef: ChangeDetectorRef) {
super(changeRef);
}
ngOnInit(): void {
this.baseInit();
}
ngAfterViewInit(): void {
}
ngOnDestroy(): void {
this.baseDestroy();
}
/// IComponent implementation
public layout(): void {
this._changeRef.detectChanges();
}
public setLayout(layout: any): void {
// TODO allow configuring the look and feel
this.layout();
}
public set value(newValue: string) {
this.setPropertyFromUI<sqlops.TextComponentProperties, string>((properties, value) => { properties.value = value; }, newValue);
}
public get value(): string {
return this.getPropertyOrDefault<sqlops.TextComponentProperties, string>((props) => props.value, '');
}
public getValue(): string {
return this.value;
}
}

View File

@@ -22,6 +22,7 @@ declare module 'sqlops' {
inputBox(): ComponentBuilder<InputBoxComponent>;
checkBox(): ComponentBuilder<CheckBoxComponent>;
radioButton(): ComponentBuilder<RadioButtonComponent>;
text(): ComponentBuilder<TextComponent>;
button(): ComponentBuilder<ButtonComponent>;
dropDown(): ComponentBuilder<DropDownComponent>;
dashboardWidget(widgetId: string): ComponentBuilder<WidgetComponent>;
@@ -262,6 +263,10 @@ declare module 'sqlops' {
checked?: boolean;
}
export interface TextComponentProperties {
value?: string;
}
export interface DropDownProperties {
value?: string;
values?: string[];
@@ -279,6 +284,10 @@ declare module 'sqlops' {
onDidActionClick: vscode.Event<ActionDescriptor>;
}
export interface TextComponent extends Component {
value: string;
}
export interface InputBoxComponent extends Component, InputBoxProperties {
onTextChanged: vscode.Event<any>;
}

View File

@@ -72,6 +72,7 @@ export enum ModelComponentTypes {
Button,
CheckBox,
RadioButton,
Text,
DashboardWidget,
DashboardWebview,
Form

View File

@@ -59,6 +59,13 @@ class ModelBuilderImpl implements sqlops.ModelBuilder {
return builder;
}
text(): sqlops.ComponentBuilder<sqlops.TextComponent> {
let id = this.getNextComponentId();
let builder: ComponentBuilderImpl<sqlops.TextComponent> = this.getComponentBuilder(new TextComponentWrapper(this._proxy, this._handle, id), id);
this._componentBuilders.set(id, builder);
return builder;
}
radioButton(): sqlops.ComponentBuilder<sqlops.RadioButtonComponent> {
let id = this.getNextComponentId();
let builder: ComponentBuilderImpl<sqlops.RadioButtonComponent> = this.getComponentBuilder(new RadioButtonWrapper(this._proxy, this._handle, id), id);
@@ -557,6 +564,21 @@ class RadioButtonWrapper extends ComponentWrapper implements sqlops.RadioButtonC
}
}
class TextComponentWrapper extends ComponentWrapper implements sqlops.TextComponentProperties {
constructor(proxy: MainThreadModelViewShape, handle: number, id: string) {
super(proxy, handle, ModelComponentTypes.Text, id);
this.properties = {};
}
public get value(): string {
return this.properties['value'];
}
public set value(v: string) {
this.setProperty('value', v);
}
}
class DropDownWrapper extends ComponentWrapper implements sqlops.DropDownComponent {
constructor(proxy: MainThreadModelViewShape, handle: number, id: string) {