mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Code improvements
- shared global declarations - reduced hyperlink-related repetitive code
This commit is contained in:
@@ -28,8 +28,6 @@ import { FormService } from './../services/form.service';
|
|||||||
import { NodeService } from './../services/node.service';
|
import { NodeService } from './../services/node.service';
|
||||||
import { FormModel, FormOutcomeModel, FormValues, FormFieldModel, FormOutcomeEvent } from './widgets/core/index';
|
import { FormModel, FormOutcomeModel, FormValues, FormFieldModel, FormOutcomeEvent } from './widgets/core/index';
|
||||||
|
|
||||||
declare var componentHandler;
|
|
||||||
|
|
||||||
import { WidgetVisibilityService } from './../services/widget-visibility.service';
|
import { WidgetVisibilityService } from './../services/widget-visibility.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -22,9 +22,6 @@ import { ExternalContent } from '../core/external-content';
|
|||||||
import { ExternalContentLink } from '../core/external-content-link';
|
import { ExternalContentLink } from '../core/external-content-link';
|
||||||
import { FormFieldModel } from '../core/form-field.model';
|
import { FormFieldModel } from '../core/form-field.model';
|
||||||
|
|
||||||
declare var componentHandler;
|
|
||||||
declare let dialogPolyfill: any;
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
selector: 'attach-widget',
|
selector: 'attach-widget',
|
||||||
|
@@ -18,8 +18,6 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { WidgetComponent } from './../widget.component';
|
import { WidgetComponent } from './../widget.component';
|
||||||
|
|
||||||
declare var componentHandler;
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
selector: 'checkbox-widget',
|
selector: 'checkbox-widget',
|
||||||
|
@@ -18,8 +18,6 @@
|
|||||||
import { Component, Input, AfterViewInit, Output, EventEmitter } from '@angular/core';
|
import { Component, Input, AfterViewInit, Output, EventEmitter } from '@angular/core';
|
||||||
import { ContainerModel, FormFieldModel } from './../core/index';
|
import { ContainerModel, FormFieldModel } from './../core/index';
|
||||||
|
|
||||||
declare var componentHandler;
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
selector: 'container-widget',
|
selector: 'container-widget',
|
||||||
|
@@ -18,8 +18,6 @@
|
|||||||
import { FormFieldModel } from './form-field.model';
|
import { FormFieldModel } from './form-field.model';
|
||||||
import { FormFieldTypes } from './form-field-types';
|
import { FormFieldTypes } from './form-field-types';
|
||||||
|
|
||||||
declare var moment: any;
|
|
||||||
|
|
||||||
export interface FormFieldValidator {
|
export interface FormFieldValidator {
|
||||||
|
|
||||||
isSupported(field: FormFieldModel): boolean;
|
isSupported(field: FormFieldModel): boolean;
|
||||||
|
@@ -18,8 +18,6 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { WidgetComponent } from './../widget.component';
|
import { WidgetComponent } from './../widget.component';
|
||||||
|
|
||||||
declare var componentHandler;
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
selector: 'display-text-widget',
|
selector: 'display-text-widget',
|
||||||
|
@@ -21,9 +21,6 @@ import { FormFieldTypes } from '../core/form-field-types';
|
|||||||
import { FormService } from '../../../services/form.service';
|
import { FormService } from '../../../services/form.service';
|
||||||
import { FormFieldOption } from './../core/form-field-option';
|
import { FormFieldOption } from './../core/form-field-option';
|
||||||
|
|
||||||
declare var componentHandler;
|
|
||||||
declare var moment: any;
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
selector: 'display-value-widget',
|
selector: 'display-value-widget',
|
||||||
@@ -32,11 +29,10 @@ declare var moment: any;
|
|||||||
})
|
})
|
||||||
export class DisplayValueWidget extends WidgetComponent implements OnInit {
|
export class DisplayValueWidget extends WidgetComponent implements OnInit {
|
||||||
|
|
||||||
DEFAULT_URL: string = '#';
|
|
||||||
DEFAULT_URL_SCHEME: string = 'http://';
|
|
||||||
|
|
||||||
value: any;
|
value: any;
|
||||||
fieldType: string;
|
fieldType: string;
|
||||||
|
linkUrl: string;
|
||||||
|
linkText: string;
|
||||||
|
|
||||||
constructor(private formService: FormService) {
|
constructor(private formService: FormService) {
|
||||||
super();
|
super();
|
||||||
@@ -99,6 +95,12 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit {
|
|||||||
this.value = `${currency} ${this.field.value}`;
|
this.value = `${currency} ${this.field.value}`;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case FormFieldTypes.HYPERLINK:
|
||||||
|
if (this.value) {
|
||||||
|
this.linkUrl = this.getHyperlinkUrl(this.field);
|
||||||
|
this.linkText = this.getHyperlinkText(this.field);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
this.value = this.field.value;
|
this.value = this.field.value;
|
||||||
break;
|
break;
|
||||||
@@ -137,27 +139,4 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: TAKEN FROM hyperlink WIDGET, OPTIMIZE
|
|
||||||
get linkUrl(): string {
|
|
||||||
let url = this.DEFAULT_URL;
|
|
||||||
|
|
||||||
if (this.field && this.field.hyperlinkUrl) {
|
|
||||||
url = this.field.hyperlinkUrl;
|
|
||||||
if (!/^https?:\/\//i.test(url)) {
|
|
||||||
url = this.DEFAULT_URL_SCHEME + url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: TAKEN FROM hyperlink WIDGET, OPTIMIZE
|
|
||||||
get linkText(): string {
|
|
||||||
if (this.field) {
|
|
||||||
return this.field.displayText || this.field.hyperlinkUrl;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -64,7 +64,7 @@ describe('HyperlinkWidget', () => {
|
|||||||
|
|
||||||
it('should return default url for missing field', () => {
|
it('should return default url for missing field', () => {
|
||||||
widget.field = null;
|
widget.field = null;
|
||||||
expect(widget.linkUrl).toBe(HyperlinkWidget.DEFAULT_URL);
|
expect(widget.linkUrl).toBe(HyperlinkWidget.DEFAULT_HYPERLINK_URL);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return default url for missing field property', () => {
|
it('should return default url for missing field property', () => {
|
||||||
@@ -72,7 +72,7 @@ describe('HyperlinkWidget', () => {
|
|||||||
hyperlinkUrl: null
|
hyperlinkUrl: null
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(widget.linkUrl).toBe(HyperlinkWidget.DEFAULT_URL);
|
expect(widget.linkUrl).toBe(HyperlinkWidget.DEFAULT_HYPERLINK_URL);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should prepend url with scheme', () => {
|
it('should prepend url with scheme', () => {
|
||||||
@@ -81,7 +81,7 @@ describe('HyperlinkWidget', () => {
|
|||||||
hyperlinkUrl: url
|
hyperlinkUrl: url
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(widget.linkUrl).toBe(`${HyperlinkWidget.DEFAULT_URL_SCHEME}${url}`);
|
expect(widget.linkUrl).toBe(`${HyperlinkWidget.DEFAULT_HYPERLINK_SCHEME}${url}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not prepend url with scheme', () => {
|
it('should not prepend url with scheme', () => {
|
||||||
|
@@ -15,40 +15,25 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { WidgetComponent } from './../widget.component';
|
import { WidgetComponent } from './../widget.component';
|
||||||
|
|
||||||
declare var componentHandler;
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
selector: 'hyperlink-widget',
|
selector: 'hyperlink-widget',
|
||||||
templateUrl: './hyperlink.widget.html',
|
templateUrl: './hyperlink.widget.html',
|
||||||
styleUrls: ['./hyperlink.widget.css']
|
styleUrls: ['./hyperlink.widget.css']
|
||||||
})
|
})
|
||||||
export class HyperlinkWidget extends WidgetComponent {
|
export class HyperlinkWidget extends WidgetComponent implements OnInit {
|
||||||
|
|
||||||
static DEFAULT_URL: string = '#';
|
linkUrl: string;
|
||||||
static DEFAULT_URL_SCHEME: string = 'http://';
|
linkText: string;
|
||||||
|
|
||||||
get linkUrl(): string {
|
ngOnInit() {
|
||||||
let url = HyperlinkWidget.DEFAULT_URL;
|
|
||||||
|
|
||||||
if (this.field && this.field.hyperlinkUrl) {
|
|
||||||
url = this.field.hyperlinkUrl;
|
|
||||||
if (!/^https?:\/\//i.test(url)) {
|
|
||||||
url = HyperlinkWidget.DEFAULT_URL_SCHEME + url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
get linkText(): string {
|
|
||||||
if (this.field) {
|
if (this.field) {
|
||||||
return this.field.displayText || this.field.hyperlinkUrl;
|
this.linkUrl = this.getHyperlinkUrl(this.field);
|
||||||
|
this.linkText = this.getHyperlinkText(this.field);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -20,8 +20,6 @@ import { WidgetComponent } from './../widget.component';
|
|||||||
import { FormService } from '../../../services/form.service';
|
import { FormService } from '../../../services/form.service';
|
||||||
import { FormFieldOption } from './../core/form-field-option';
|
import { FormFieldOption } from './../core/form-field-option';
|
||||||
|
|
||||||
declare var componentHandler;
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
selector: 'radio-buttons-widget',
|
selector: 'radio-buttons-widget',
|
||||||
|
@@ -18,8 +18,6 @@
|
|||||||
import { Component, Input, AfterViewInit, EventEmitter, Output } from '@angular/core';
|
import { Component, Input, AfterViewInit, EventEmitter, Output } from '@angular/core';
|
||||||
import { TabModel, FormFieldModel } from './../core/index';
|
import { TabModel, FormFieldModel } from './../core/index';
|
||||||
|
|
||||||
declare var componentHandler;
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
selector: 'tabs-widget',
|
selector: 'tabs-widget',
|
||||||
|
@@ -20,8 +20,6 @@ import { FormService } from './../../../services/form.service';
|
|||||||
import { WidgetComponent } from './../widget.component';
|
import { WidgetComponent } from './../widget.component';
|
||||||
import { FormFieldOption } from './../core/form-field-option';
|
import { FormFieldOption } from './../core/form-field-option';
|
||||||
|
|
||||||
declare var componentHandler;
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
selector: 'typeahead-widget',
|
selector: 'typeahead-widget',
|
||||||
|
@@ -19,8 +19,6 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
import { WidgetComponent } from './../widget.component';
|
import { WidgetComponent } from './../widget.component';
|
||||||
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||||
|
|
||||||
declare var componentHandler;
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
selector: 'upload-widget',
|
selector: 'upload-widget',
|
||||||
|
@@ -18,14 +18,14 @@
|
|||||||
import { Input, AfterViewInit, Output, EventEmitter } from '@angular/core';
|
import { Input, AfterViewInit, Output, EventEmitter } from '@angular/core';
|
||||||
import { FormFieldModel } from './core/index';
|
import { FormFieldModel } from './core/index';
|
||||||
|
|
||||||
declare let __moduleName: string;
|
|
||||||
declare var componentHandler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base widget component.
|
* Base widget component.
|
||||||
*/
|
*/
|
||||||
export class WidgetComponent implements AfterViewInit {
|
export class WidgetComponent implements AfterViewInit {
|
||||||
|
|
||||||
|
static DEFAULT_HYPERLINK_URL: string = '#';
|
||||||
|
static DEFAULT_HYPERLINK_SCHEME: string = 'http://';
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
field: FormFieldModel;
|
field: FormFieldModel;
|
||||||
|
|
||||||
@@ -67,4 +67,22 @@ export class WidgetComponent implements AfterViewInit {
|
|||||||
this.fieldChanged.emit(field);
|
this.fieldChanged.emit(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected getHyperlinkUrl(field: FormFieldModel) {
|
||||||
|
let url = WidgetComponent.DEFAULT_HYPERLINK_URL;
|
||||||
|
if (field && field.hyperlinkUrl) {
|
||||||
|
url = field.hyperlinkUrl;
|
||||||
|
if (!/^https?:\/\//i.test(url)) {
|
||||||
|
url = `${WidgetComponent.DEFAULT_HYPERLINK_SCHEME}${url}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getHyperlinkText(field: FormFieldModel) {
|
||||||
|
if (field) {
|
||||||
|
return field.displayText || field.hyperlinkUrl;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
23
ng2-components/ng2-activiti-form/src/declarations.d.ts
vendored
Normal file
23
ng2-components/ng2-activiti-form/src/declarations.d.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*!
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare var module: any;
|
||||||
|
declare var moment: any;
|
||||||
|
|
||||||
|
// MDL
|
||||||
|
declare var componentHandler: any;
|
||||||
|
declare let dialogPolyfill: any;
|
@@ -8,14 +8,13 @@
|
|||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"removeComments": true,
|
"removeComments": true,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"outDir": "dist"
|
"outDir": "dist",
|
||||||
|
"types": ["core-js", "jasmine"]
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"demo",
|
"demo",
|
||||||
"dist",
|
"dist",
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"typings/main",
|
|
||||||
"typings/main.d.ts",
|
|
||||||
"dist"
|
"dist"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user