mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
@@ -0,0 +1,9 @@
|
||||
<div [formGroup]="formGroup">
|
||||
<mat-checkbox
|
||||
color="primary"
|
||||
formControlName="{{controllerName}}"
|
||||
[id]="field.id"
|
||||
[checked]="field.value"
|
||||
[(ngModel)]="field.value"
|
||||
(ngModelChange)="changeValue(field)">{{field.nameKey | translate}}</mat-checkbox>
|
||||
</div>
|
@@ -0,0 +1,44 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
/* tslint:disable:component-selector */
|
||||
|
||||
/* tslint:disable:no-access-missing-member */
|
||||
import { Component, ElementRef, Input, ViewEncapsulation } from '@angular/core';
|
||||
import { FormGroup } from '@angular/forms';
|
||||
import { WidgetComponent } from './../widget.component';
|
||||
|
||||
@Component({
|
||||
selector: 'analytics-checkbox-widget',
|
||||
templateUrl: './checkbox.widget.html',
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class CheckboxWidgetAanalyticsComponent extends WidgetComponent {
|
||||
|
||||
@Input()
|
||||
field: any;
|
||||
|
||||
@Input('group')
|
||||
public formGroup: FormGroup;
|
||||
|
||||
@Input('controllerName')
|
||||
public controllerName: string;
|
||||
|
||||
constructor(public elementRef: ElementRef) {
|
||||
super();
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
<label>{{field.nameKey | translate}}</label><br>
|
||||
<div [formGroup]="dateRange">
|
||||
<small *ngIf="isStartDateGreaterThanEndDate()" class="adf-date-range-analytics-text-danger">
|
||||
{{'DATE-WIDGET.MESSAGES.START-LESS-THAN-END-DATE' | translate}}
|
||||
</small>
|
||||
<small *ngIf="isStartDateEmpty()" class="adf-date-range-analytics-text-danger">
|
||||
{{'DATE-WIDGET.MESSAGES.START-DATE-REQUIRED' | translate}}
|
||||
</small>
|
||||
|
||||
<mat-grid-list cols="2" rowHeight="80px">
|
||||
<mat-grid-tile>
|
||||
<mat-form-field>
|
||||
<input
|
||||
matInput
|
||||
[min]="minDate"
|
||||
[max]="maxDate"
|
||||
formControlName="startDate"
|
||||
[matDatepicker]="startDate"
|
||||
[value]="startDatePicker"
|
||||
(keydown)="true"
|
||||
(dateChange)="onGroupValueChanged()"
|
||||
placeholder="{{'DATE-WIDGET.START-DATE' | translate}}"
|
||||
id="startDate_id"
|
||||
required>
|
||||
<mat-datepicker-toggle matSuffix [for]="startDate" ></mat-datepicker-toggle>
|
||||
</mat-form-field>
|
||||
<mat-datepicker
|
||||
#startDate
|
||||
[touchUi]="true">
|
||||
</mat-datepicker>
|
||||
</mat-grid-tile>
|
||||
<mat-grid-tile>
|
||||
<mat-form-field>
|
||||
<input
|
||||
matInput
|
||||
[min]="minDate"
|
||||
[max]="maxDate"
|
||||
formControlName="endDate"
|
||||
[matDatepicker]="endDate"
|
||||
[value]="endDatePicker"
|
||||
(keydown)="true"
|
||||
(dateChange)="onGroupValueChanged()"
|
||||
placeholder="{{'DATE-WIDGET.END-DATE' | translate}}"
|
||||
id="endDate_id"
|
||||
required>
|
||||
<mat-datepicker-toggle matSuffix [for]="endDate" ></mat-datepicker-toggle>
|
||||
</mat-form-field>
|
||||
<mat-datepicker
|
||||
#endDate
|
||||
[touchUi]="true">
|
||||
</mat-datepicker>
|
||||
</mat-grid-tile>
|
||||
</mat-grid-list>
|
||||
</div>
|
@@ -0,0 +1,7 @@
|
||||
@mixin adf-analytics-date-range-widget-theme($theme) {
|
||||
$warn: map-get($theme, warn);
|
||||
|
||||
.adf-date-range-analytics-text-danger {
|
||||
color: mat-color($warn);
|
||||
}
|
||||
}
|
@@ -0,0 +1,113 @@
|
||||
/*!
|
||||
* @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 { MOMENT_DATE_FORMATS, MomentDateAdapter, UserPreferencesService } from '@alfresco/core';
|
||||
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
|
||||
import { AbstractControl, FormControl, FormGroup, Validators } from '@angular/forms';
|
||||
import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material';
|
||||
import * as moment from 'moment';
|
||||
import { Moment } from 'moment';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-date-range-widget',
|
||||
templateUrl: './date-range.widget.html',
|
||||
providers: [
|
||||
{provide: DateAdapter, useClass: MomentDateAdapter},
|
||||
{provide: MAT_DATE_FORMATS, useValue: MOMENT_DATE_FORMATS}],
|
||||
styleUrls: ['./date-range.widget.scss'],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class DateRangeWidgetComponent implements OnInit {
|
||||
|
||||
public FORMAT_DATE_ACTIVITI: string = 'YYYY-MM-DD';
|
||||
public SHOW_FORMAT: string = 'DD/MM/YYYY';
|
||||
|
||||
@Input('group')
|
||||
public dateRange: FormGroup;
|
||||
|
||||
@Input()
|
||||
field: any;
|
||||
|
||||
@Output()
|
||||
dateRangeChanged: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
minDate: Moment;
|
||||
maxDate: Moment;
|
||||
startDatePicker: Moment = moment();
|
||||
endDatePicker: Moment = moment();
|
||||
|
||||
constructor(
|
||||
private dateAdapter: DateAdapter<Moment>,
|
||||
private preferences: UserPreferencesService) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.preferences.locale$.subscribe( (locale) => {
|
||||
this.dateAdapter.setLocale(locale);
|
||||
});
|
||||
let momentDateAdapter = <MomentDateAdapter> this.dateAdapter;
|
||||
momentDateAdapter.overrideDisplyaFormat = this.SHOW_FORMAT;
|
||||
|
||||
if (this.field) {
|
||||
if (this.field.value && this.field.value.startDate) {
|
||||
this.startDatePicker = moment(this.field.value.startDate, this.FORMAT_DATE_ACTIVITI);
|
||||
}
|
||||
|
||||
if (this.field.value && this.field.value.endDate) {
|
||||
this.endDatePicker = moment(this.field.value.endDate, this.FORMAT_DATE_ACTIVITI);
|
||||
}
|
||||
}
|
||||
|
||||
let startDateControl = new FormControl(this.startDatePicker);
|
||||
startDateControl.setValidators(Validators.required);
|
||||
this.dateRange.addControl('startDate', startDateControl);
|
||||
|
||||
let endDateControl = new FormControl(this.endDatePicker);
|
||||
endDateControl.setValidators(Validators.required);
|
||||
this.dateRange.addControl('endDate', endDateControl);
|
||||
|
||||
this.dateRange.setValidators(this.dateCheck);
|
||||
this.dateRange.valueChanges.subscribe(() => this.onGroupValueChanged());
|
||||
}
|
||||
|
||||
onGroupValueChanged() {
|
||||
if (this.dateRange.valid) {
|
||||
let dateStart = this.convertToMomentDateWithTime(this.dateRange.controls.startDate.value);
|
||||
let endStart = this.convertToMomentDateWithTime(this.dateRange.controls.endDate.value);
|
||||
this.dateRangeChanged.emit({startDate: dateStart, endDate: endStart});
|
||||
}
|
||||
}
|
||||
|
||||
convertToMomentDateWithTime(date: string) {
|
||||
return moment(date, this.FORMAT_DATE_ACTIVITI, true).format(this.FORMAT_DATE_ACTIVITI) + 'T00:00:00.000Z';
|
||||
}
|
||||
|
||||
dateCheck(formControl: AbstractControl) {
|
||||
let startDate = moment(formControl.get('startDate').value);
|
||||
let endDate = moment(formControl.get('endDate').value);
|
||||
let result = startDate.isAfter(endDate);
|
||||
return result ? {'greaterThan': true} : null;
|
||||
}
|
||||
|
||||
isStartDateGreaterThanEndDate() {
|
||||
return this.dateRange && this.dateRange.errors && this.dateRange.errors.greaterThan;
|
||||
}
|
||||
|
||||
isStartDateEmpty() {
|
||||
return this.dateRange && this.dateRange.controls.startDate && !this.dateRange.controls.startDate.valid;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
<div class="adf-dropdown-widget" [formGroup]="formGroup">
|
||||
<label class="adf-dropdown-widget__label" [attr.for]="field.id">{{field.nameKey | translate}}</label>
|
||||
<select [formControlName]="controllerName"
|
||||
[attr.id]="'select-' + field.id"
|
||||
class="adf-dropdown-widget__select"
|
||||
[(ngModel)]="field.value"
|
||||
(ngModelChange)="changeValue($event)">
|
||||
<option *ngIf="showDefaultOption" value="null">{{defaultOptionText}}</option>
|
||||
<option *ngFor="let opt of field.options" [value]="opt.id">{{opt.label}}</option>
|
||||
</select>
|
||||
</div>
|
@@ -0,0 +1,19 @@
|
||||
.adf-dropdown-widget {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.adf-dropdown-widget__select {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.adf-dropdown-widget__invalid .adf-dropdown-widget__select {
|
||||
border-color: #d50000;
|
||||
}
|
||||
|
||||
.adf-dropdown-widget__invalid .adf-dropdown-widget__label {
|
||||
color: #d50000;
|
||||
}
|
||||
|
||||
.adf-dropdown-widget__invalid .adf-dropdown-widget__label:after {
|
||||
background-color: #d50000;
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
/* tslint:disable:component-selector */
|
||||
|
||||
/* tslint:disable::no-access-missing-member */
|
||||
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
|
||||
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
||||
import { WidgetComponent } from './../widget.component';
|
||||
|
||||
@Component({
|
||||
selector: 'analytics-dropdown-widget',
|
||||
templateUrl: './dropdown.widget.html',
|
||||
styleUrls: ['./dropdown.widget.scss'],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class DropdownWidgetAanalyticsComponent extends WidgetComponent implements OnInit {
|
||||
|
||||
@Input()
|
||||
field: any;
|
||||
|
||||
@Input('group')
|
||||
public formGroup: FormGroup;
|
||||
|
||||
@Input('controllerName')
|
||||
public controllerName: string;
|
||||
|
||||
@Output()
|
||||
fieldChanged: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
@Input()
|
||||
showDefaultOption: boolean = true;
|
||||
|
||||
@Input()
|
||||
required: boolean = false;
|
||||
|
||||
@Input()
|
||||
defaultOptionText: string = 'Choose One';
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
if (this.required) {
|
||||
this.formGroup.get(this.controllerName).setValidators(Validators.compose(this.buildValidatorList()));
|
||||
}
|
||||
}
|
||||
|
||||
validateDropDown(controller: FormControl) {
|
||||
return controller.value !== 'null' ? null : { controllerName: false };
|
||||
}
|
||||
|
||||
buildValidatorList() {
|
||||
let validatorList = [];
|
||||
validatorList.push(Validators.required);
|
||||
if (this.showDefaultOption) {
|
||||
validatorList.push(this.validateDropDown);
|
||||
}
|
||||
return validatorList;
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
<div class="adf-duration-widget-grid">
|
||||
<div class="adf-duration-widget-cell">
|
||||
<div class="adf-number-widget">
|
||||
<mat-form-field class="example-full-width" floatPlaceholder="always">
|
||||
<input matInput
|
||||
placeholder="{{field.nameKey | translate}}"
|
||||
type="text"
|
||||
pattern="-?[0-9]*(\.[0-9]+)?"
|
||||
[id]="field.id"
|
||||
[value]="field.value"
|
||||
[(ngModel)]="field.value"
|
||||
(ngModelChange)="calculateDuration()">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
<div class="adf-duration-widget-cell">
|
||||
<div class="dropdown-container">
|
||||
<analytics-dropdown-widget [field]="duration" [group]="formGroup" [controllerName]="'timeType'"
|
||||
[showDefaultOption]="false"
|
||||
(fieldChanged)="calculateDuration()"></analytics-dropdown-widget>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@@ -0,0 +1,20 @@
|
||||
.adf-duration-widget-grid {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.adf-duration-widget-cell {
|
||||
width: 49%;
|
||||
}
|
||||
|
||||
.adf-number-widget {
|
||||
width: 100%;
|
||||
|
||||
.mat-form-field {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.dropdown-container {
|
||||
margin-top: 30px;
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
/* tslint:disable:component-selector */
|
||||
|
||||
/* tslint:disable::no-access-missing-member */
|
||||
import { Component, ElementRef, Input, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
||||
import { ParameterValueModel, ReportParameterDetailsModel } from '../../../../diagram';
|
||||
import { NumberWidgetAanlyticsComponent } from './../number/number.widget';
|
||||
|
||||
@Component({
|
||||
selector: 'duration-widget',
|
||||
templateUrl: './duration.widget.html',
|
||||
styleUrls: ['./duration.widget.scss'],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class DurationWidgetComponent extends NumberWidgetAanlyticsComponent implements OnInit {
|
||||
|
||||
@Input()
|
||||
field: any;
|
||||
|
||||
@Input('group')
|
||||
public formGroup: FormGroup;
|
||||
|
||||
@Input('controllerName')
|
||||
public controllerName: string;
|
||||
|
||||
@Input()
|
||||
required: boolean = false;
|
||||
|
||||
duration: ReportParameterDetailsModel;
|
||||
currentValue: number;
|
||||
|
||||
public selectionGroup: FormGroup;
|
||||
|
||||
constructor(public elementRef: ElementRef) {
|
||||
super(elementRef);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
let timeType = new FormControl();
|
||||
this.formGroup.addControl('timeType', timeType);
|
||||
|
||||
if (this.required) {
|
||||
this.formGroup.get(this.controllerName).setValidators(Validators.required);
|
||||
}
|
||||
if (this.field.value === null) {
|
||||
this.field.value = 0;
|
||||
}
|
||||
|
||||
let paramOptions: ParameterValueModel[] = [];
|
||||
paramOptions.push(new ParameterValueModel({id: '1', name: 'Seconds'}));
|
||||
paramOptions.push(new ParameterValueModel({id: '60', name: 'Minutes'}));
|
||||
paramOptions.push(new ParameterValueModel({id: '3600', name: 'Hours'}));
|
||||
paramOptions.push(new ParameterValueModel({id: '86400', name: 'Days', selected: true}));
|
||||
|
||||
this.duration = new ReportParameterDetailsModel({id: 'duration', name: 'duration', options: paramOptions});
|
||||
this.duration.value = paramOptions[0].id;
|
||||
}
|
||||
|
||||
public calculateDuration() {
|
||||
if (this.field && this.duration.value ) {
|
||||
this.currentValue = parseInt(this.field.value, 10) * parseInt(this.duration.value, 10);
|
||||
this.formGroup.get(this.controllerName).setValue(this.currentValue);
|
||||
this.fieldChanged.emit({value: this.currentValue});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
37
lib/insights/analytics-process/components/widgets/index.ts
Normal file
37
lib/insights/analytics-process/components/widgets/index.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/*!
|
||||
* @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 { CheckboxWidgetAanalyticsComponent } from './checkbox/checkbox.widget';
|
||||
import { DateRangeWidgetComponent } from './date-range/date-range.widget';
|
||||
import { DropdownWidgetAanalyticsComponent } from './dropdown/dropdown.widget';
|
||||
import { DurationWidgetComponent } from './duration/duration.widget';
|
||||
import { NumberWidgetAanlyticsComponent } from './number/number.widget';
|
||||
|
||||
// primitives
|
||||
export * from './dropdown/dropdown.widget';
|
||||
export * from './number/number.widget';
|
||||
export * from './duration/duration.widget';
|
||||
export * from './checkbox/checkbox.widget';
|
||||
export * from './date-range/date-range.widget';
|
||||
|
||||
export const WIDGET_ANALYTICS_DIRECTIVES: any[] = [
|
||||
DropdownWidgetAanalyticsComponent,
|
||||
NumberWidgetAanlyticsComponent,
|
||||
DurationWidgetComponent,
|
||||
CheckboxWidgetAanalyticsComponent,
|
||||
DateRangeWidgetComponent
|
||||
];
|
@@ -0,0 +1,13 @@
|
||||
<div class="adf-number-widget" [formGroup]="formGroup">
|
||||
<mat-form-field class="example-full-width" floatPlaceholder="always">
|
||||
<input matInput
|
||||
placeholder="{{field.nameKey | translate}}"
|
||||
formControlName="{{controllerName}}"
|
||||
type="text"
|
||||
pattern="-?[0-9]*(\.[0-9]+)?"
|
||||
[id]="field.id"
|
||||
[value]="field.value"
|
||||
[(ngModel)]="field.value"
|
||||
(ngModelChange)="changeValue(field)">
|
||||
</mat-form-field>
|
||||
</div>
|
@@ -0,0 +1,7 @@
|
||||
.adf-number-widget {
|
||||
width: 100%;
|
||||
|
||||
.mat-form-field {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
/* tslint:disable:component-selector */
|
||||
|
||||
/* tslint:disable::no-access-missing-member */
|
||||
import { Component, ElementRef, Input, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { FormGroup, Validators } from '@angular/forms';
|
||||
import { WidgetComponent } from './../widget.component';
|
||||
|
||||
@Component({
|
||||
selector: 'analytics-number-widget',
|
||||
templateUrl: './number.widget.html',
|
||||
styleUrls: ['./number.widget.scss'],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class NumberWidgetAanlyticsComponent extends WidgetComponent implements OnInit {
|
||||
|
||||
@Input()
|
||||
field: any;
|
||||
|
||||
@Input('group')
|
||||
public formGroup: FormGroup;
|
||||
|
||||
@Input('controllerName')
|
||||
public controllerName: string;
|
||||
|
||||
@Input()
|
||||
required: boolean = false;
|
||||
|
||||
constructor(public elementRef: ElementRef) {
|
||||
super();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
if (this.required) {
|
||||
this.formGroup.get(this.controllerName).setValidators(Validators.required);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
/*!
|
||||
* @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 { EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
|
||||
|
||||
export class WidgetComponent implements OnChanges {
|
||||
|
||||
@Input()
|
||||
field: any;
|
||||
|
||||
@Output()
|
||||
fieldChanged: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
let field = changes['field'];
|
||||
if (field && field.currentValue) {
|
||||
this.fieldChanged.emit(field.currentValue.value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
hasField() {
|
||||
return this.field ? true : false;
|
||||
}
|
||||
|
||||
hasValue(): boolean {
|
||||
return this.field &&
|
||||
this.field.value !== null &&
|
||||
this.field.value !== undefined;
|
||||
}
|
||||
|
||||
changeValue(field: any) {
|
||||
this.fieldChanged.emit(field);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user