Refactor demo shell as CLI project (#2501)

* split interfaces

* angular cli demo refactoring

* fix test import

* fix demo script

* fix demo script

* fix demo script

* fix demo script
This commit is contained in:
Mario Romano
2017-10-22 00:02:41 +01:00
committed by Eugenio Romano
parent 9ac0c06acd
commit 167336f245
184 changed files with 3898 additions and 3832 deletions

View File

@@ -50,12 +50,13 @@ export * from './src/events/index';
export { FORM_FIELD_VALIDATORS } from './src/components/widgets/core/form-field-validator';
// Old deprecated import
import {FormComponent as ActivitiForm } from './src/components/form.component';
import {StartFormComponent as ActivitiStartForm } from './src/components/start-form.component';
import {ContentWidgetComponent as ActivitiContent } from './src/components/widgets/content/content.widget';
export {FormComponent as ActivitiForm} from './src/components/form.component';
export {ContentWidgetComponent as ActivitiContent} from './src/components/widgets/content/content.widget';
export {StartFormComponent as ActivitiStartForm} from './src/components/start-form.component';
import { FormComponent as ActivitiForm } from './src/components/form.component';
import { StartFormComponent as ActivitiStartForm } from './src/components/start-form.component';
import { ContentWidgetComponent as ActivitiContent } from './src/components/widgets/content/content.widget';
export { FormComponent as ActivitiForm } from './src/components/form.component';
export { ContentWidgetComponent as ActivitiContent } from './src/components/widgets/content/content.widget';
export { StartFormComponent as ActivitiStartForm } from './src/components/start-form.component';
export { DynamicTableRow } from './src/components/widgets/dynamic-table/dynamic-table-row.model';
export const ACTIVITI_FORM_DIRECTIVES: any[] = [
FormComponent,
@@ -116,4 +117,5 @@ export const ACTIVITI_FORM_PROVIDERS: any[] = [
MaterialModule
]
})
export class ActivitiFormModule {}
export class ActivitiFormModule {
}

View File

@@ -0,0 +1,29 @@
/*!
* @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 */
import { DynamicTableColumn } from './dynamic-table-column.model'
import { DynamicTableRow } from './dynamic-table-row.model'
import { DynamicRowValidationSummary } from './dynamic-row-validation-summary.model'
export interface CellValidator {
isSupported(column: DynamicTableColumn): boolean;
validate(row: DynamicTableRow, column: DynamicTableColumn, summary?: DynamicRowValidationSummary): boolean;
}

View File

@@ -0,0 +1,52 @@
/*!
* @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 */
import * as moment from 'moment';
import { CellValidator } from './cell-validator.model';
import { DynamicRowValidationSummary } from './dynamic-row-validation-summary.model';
import { DynamicTableColumn } from './dynamic-table-column.model';
import { DynamicTableRow } from './dynamic-table-row.model';
export class DateCellValidator implements CellValidator {
private supportedTypes: string[] = [
'Date'
];
isSupported(column: DynamicTableColumn): boolean {
return column && column.editable && this.supportedTypes.indexOf(column.type) > -1;
}
validate(row: DynamicTableRow, column: DynamicTableColumn, summary?: DynamicRowValidationSummary): boolean {
if (this.isSupported(column)) {
let value = row.value[column.id];
let dateValue = moment(value, 'D-M-YYYY');
if (!dateValue.isValid()) {
if (summary) {
summary.isValid = false;
summary.text = `Invalid '${column.name}' format.`;
}
return false;
}
}
return true;
}
}

View File

@@ -0,0 +1,25 @@
/*!
* @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 */
export interface DynamicRowValidationSummary {
isValid: boolean;
text: string;
}

View File

@@ -0,0 +1,24 @@
/*!
* @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 */
// maps to: com.activiti.model.editor.form.OptionRepresentation
export interface DynamicTableColumnOption {
id: string;
name: string;
}

View File

@@ -0,0 +1,46 @@
/*!
* @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 */
import { DynamicTableColumnOption } from './dynamic-table-column-option.model';
// maps to: com.activiti.model.editor.form.ColumnDefinitionRepresentation
export interface DynamicTableColumn {
id: string;
name: string;
type: string;
value: any;
optionType: string;
options: DynamicTableColumnOption[];
restResponsePath: string;
restUrl: string;
restIdProperty: string;
restLabelProperty: string;
amountCurrency: string;
amountEnableFractions: boolean;
required: boolean;
editable: boolean;
sortable: boolean;
visible: boolean;
// TODO: com.activiti.domain.idm.EndpointConfiguration.EndpointConfigurationRepresentation
endpoint: any;
// TODO: com.activiti.model.editor.form.RequestHeaderRepresentation
requestHeaders: any;
}

View File

@@ -0,0 +1,24 @@
/*!
* @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 */
export interface DynamicTableRow {
isNew: boolean;
selected: boolean;
value: any;
}

View File

@@ -22,6 +22,13 @@ import { ValidateDynamicTableRowEvent } from '../../../events/validate-dynamic-t
import { FormService } from './../../../services/form.service';
import { FormFieldModel } from './../core/form-field.model';
import { FormWidgetModel } from './../core/form-widget.model';
import { CellValidator } from './cell-validator.model';
import { DateCellValidator } from './date-cell-validator-model';
import { DynamicRowValidationSummary } from './dynamic-row-validation-summary.model';
import { DynamicTableColumn } from './dynamic-table-column.model';
import { DynamicTableRow } from './dynamic-table-row.model';
import { NumberCellValidator } from './number-cell-validator.model';
import { RequiredCellValidator } from './required-cell-validator.model';
export class DynamicTableModel extends FormWidgetModel {
@@ -194,155 +201,3 @@ export class DynamicTableModel extends FormWidgetModel {
return result;
}
}
export interface DynamicRowValidationSummary {
isValid: boolean;
text: string;
}
export interface CellValidator {
isSupported(column: DynamicTableColumn): boolean;
validate(row: DynamicTableRow, column: DynamicTableColumn, summary?: DynamicRowValidationSummary): boolean;
}
export class RequiredCellValidator implements CellValidator {
private supportedTypes: string[] = [
'String',
'Number',
'Amount',
'Date',
'Dropdown'
];
isSupported(column: DynamicTableColumn): boolean {
return column && column.required && this.supportedTypes.indexOf(column.type) > -1;
}
validate(row: DynamicTableRow, column: DynamicTableColumn, summary?: DynamicRowValidationSummary): boolean {
if (this.isSupported(column)) {
let value = row.value[column.id];
if (column.required) {
if (value === null || value === undefined || value === '') {
if (summary) {
summary.isValid = false;
summary.text = `Field '${column.name}' is required.`;
}
return false;
}
}
}
return true;
}
}
export class DateCellValidator implements CellValidator {
private supportedTypes: string[] = [
'Date'
];
isSupported(column: DynamicTableColumn): boolean {
return column && column.editable && this.supportedTypes.indexOf(column.type) > -1;
}
validate(row: DynamicTableRow, column: DynamicTableColumn, summary?: DynamicRowValidationSummary): boolean {
if (this.isSupported(column)) {
let value = row.value[column.id];
let dateValue = moment(value, 'D-M-YYYY');
if (!dateValue.isValid()) {
if (summary) {
summary.isValid = false;
summary.text = `Invalid '${column.name}' format.`;
}
return false;
}
}
return true;
}
}
export class NumberCellValidator implements CellValidator {
private supportedTypes: string[] = [
'Number',
'Amount'
];
isSupported(column: DynamicTableColumn): boolean {
return column && column.required && this.supportedTypes.indexOf(column.type) > -1;
}
isNumber(value: any): boolean {
if (value === null || value === undefined || value === '') {
return false;
}
return !isNaN(+value);
}
validate(row: DynamicTableRow, column: DynamicTableColumn, summary?: DynamicRowValidationSummary): boolean {
if (this.isSupported(column)) {
let value = row.value[column.id];
if (value === null ||
value === undefined ||
value === '' ||
this.isNumber(value)) {
return true;
}
if (summary) {
summary.isValid = false;
summary.text = `Field '${column.name}' must be a number.`;
}
return false;
}
return true;
}
}
// maps to: com.activiti.model.editor.form.ColumnDefinitionRepresentation
export interface DynamicTableColumn {
id: string;
name: string;
type: string;
value: any;
optionType: string;
options: DynamicTableColumnOption[];
restResponsePath: string;
restUrl: string;
restIdProperty: string;
restLabelProperty: string;
amountCurrency: string;
amountEnableFractions: boolean;
required: boolean;
editable: boolean;
sortable: boolean;
visible: boolean;
// TODO: com.activiti.domain.idm.EndpointConfiguration.EndpointConfigurationRepresentation
endpoint: any;
// TODO: com.activiti.model.editor.form.RequestHeaderRepresentation
requestHeaders: any;
}
// maps to: com.activiti.model.editor.form.OptionRepresentation
export interface DynamicTableColumnOption {
id: string;
name: string;
}
export interface DynamicTableRow {
isNew: boolean;
selected: boolean;
value: any;
}

View File

@@ -25,7 +25,12 @@ import { EcmModelService } from './../../../services/ecm-model.service';
import { FormService } from './../../../services/form.service';
import { FormFieldModel, FormFieldTypes, FormModel } from './../core/index';
import { DynamicTableWidgetComponent } from './dynamic-table.widget';
import { DynamicTableColumn, DynamicTableModel, DynamicTableRow } from './dynamic-table.widget.model';
import { DynamicTableModel } from './dynamic-table.widget.model';
import { DynamicTableColumn } from './dynamic-table-column.model';
import { DynamicTableRow } from './dynamic-table-row.model';
import { BooleanEditorComponent } from './editors/boolean/boolean.editor';
import { DateEditorComponent } from './editors/date/date.editor';
import { DropdownEditorComponent } from './editors/dropdown/dropdown.editor';

View File

@@ -15,14 +15,16 @@
* limitations under the License.
*/
/* tslint:disable:component-selector */
/* tslint:disable:component-selector */
import { ChangeDetectorRef, Component, ElementRef, OnInit, ViewEncapsulation } from '@angular/core';
import { LogService } from 'ng2-alfresco-core';
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
import { FormService } from './../../../services/form.service';
import { baseHost , WidgetComponent } from './../widget.component';
import { DynamicTableColumn, DynamicTableModel, DynamicTableRow } from './dynamic-table.widget.model';
import { baseHost, WidgetComponent } from './../widget.component';
import { DynamicTableColumn } from './dynamic-table-column.model';
import { DynamicTableRow } from './dynamic-table-row.model';
import { DynamicTableModel } from './dynamic-table.widget.model';
@Component({
selector: 'dynamic-table-widget',
@@ -47,7 +49,7 @@ export class DynamicTableWidgetComponent extends WidgetComponent implements OnIn
private visibilityService: WidgetVisibilityService,
private logService: LogService,
private cd: ChangeDetectorRef) {
super(formService);
super(formService);
}
ngOnInit() {

View File

@@ -15,7 +15,11 @@
* limitations under the License.
*/
import { DynamicTableColumn, DynamicTableRow } from './../../dynamic-table.widget.model';
import { DynamicTableColumn } from './../../dynamic-table-column.model';
import { DynamicTableRow } from './../../dynamic-table-row.model';
import { BooleanEditorComponent } from './boolean.editor';
describe('BooleanEditorComponent', () => {

View File

@@ -15,10 +15,12 @@
* limitations under the License.
*/
/* tslint:disable:component-selector */
/* tslint:disable:component-selector */
import { Component, Input } from '@angular/core';
import { DynamicTableColumn, DynamicTableModel, DynamicTableRow } from './../../dynamic-table.widget.model';
import { DynamicTableColumn } from './../../dynamic-table-column.model';
import { DynamicTableRow } from './../../dynamic-table-row.model';
import { DynamicTableModel } from './../../dynamic-table.widget.model';
@Component({
selector: 'adf-boolean-editor',

View File

@@ -21,7 +21,12 @@ import * as moment from 'moment';
import { CoreModule } from 'ng2-alfresco-core';
import { MaterialModule } from '../../../../material.module';
import { FormFieldModel, FormModel } from '../../../index';
import { DynamicTableColumn, DynamicTableModel, DynamicTableRow } from './../../dynamic-table.widget.model';
import { DynamicTableModel } from './../../dynamic-table.widget.model';
import { DynamicTableColumn } from './../../dynamic-table-column.model';
import { DynamicTableRow } from './../../dynamic-table-row.model';
import { DateEditorComponent } from './date.editor';
describe('DateEditorComponent', () => {

View File

@@ -15,14 +15,16 @@
* limitations under the License.
*/
/* tslint:disable:component-selector */
/* tslint:disable:component-selector */
import { Component, Input, OnInit } from '@angular/core';
import { DateAdapter, MAT_DATE_FORMATS } from '@angular/material';
import * as moment from 'moment';
import { Moment } from 'moment';
import { MOMENT_DATE_FORMATS, MomentDateAdapter, UserPreferencesService } from 'ng2-alfresco-core';
import { DynamicTableColumn, DynamicTableModel, DynamicTableRow } from './../../dynamic-table.widget.model';
import { DynamicTableColumn } from './../../dynamic-table-column.model';
import { DynamicTableRow } from './../../dynamic-table-row.model';
import { DynamicTableModel } from './../../dynamic-table.widget.model';
@Component({
selector: 'adf-date-editor',
@@ -50,19 +52,18 @@ export class DateEditorComponent implements OnInit {
minDate: Moment;
maxDate: Moment;
constructor(
private dateAdapter: DateAdapter<Moment>,
private preferences: UserPreferencesService) {
constructor(private dateAdapter: DateAdapter<Moment>,
private preferences: UserPreferencesService) {
}
ngOnInit() {
this.preferences.locale$.subscribe( (locale) => {
this.preferences.locale$.subscribe((locale) => {
this.dateAdapter.setLocale(locale);
});
let momentDateAdapter = <MomentDateAdapter> this.dateAdapter;
momentDateAdapter.overrideDisplyaFormat = this.DATE_FORMAT;
this.value = moment(this.table.getCellValue(this.row, this.column), this.DATE_FORMAT);
this.value = moment(this.table.getCellValue(this.row, this.column), this.DATE_FORMAT);
}
onDateChanged(newDateValue) {
@@ -70,8 +71,8 @@ export class DateEditorComponent implements OnInit {
let momentDate = moment(newDateValue, this.DATE_FORMAT, true);
if (!momentDate.isValid()) {
this.row.value[this.column.id] = '';
}else {
this.row.value[this.column.id] = '';
} else {
this.row.value[this.column.id] = `${momentDate.format('YYYY-MM-DD')}T00:00:00.000Z`;
this.table.flushValue();
}

View File

@@ -23,12 +23,11 @@ import { EcmModelService } from '../../../../../services/ecm-model.service';
import { MaterialModule } from '../../../../material.module';
import { FormService } from './../../../../../services/form.service';
import { FormFieldModel, FormModel } from './../../../core/index';
import {
DynamicTableColumn,
DynamicTableColumnOption,
DynamicTableModel,
DynamicTableRow
} from './../../dynamic-table.widget.model';
import { DynamicTableModel } from './../../dynamic-table.widget.model';
import { DynamicTableColumn } from './../../dynamic-table-column.model';
import { DynamicTableColumnOption } from './../../dynamic-table-column-option.model';
import { DynamicTableRow } from './../../dynamic-table-row.model';
import { DropdownEditorComponent } from './dropdown.editor';
describe('DropdownEditorComponent', () => {

View File

@@ -20,7 +20,10 @@
import { Component, Input, OnInit } from '@angular/core';
import { LogService } from 'ng2-alfresco-core';
import { FormService } from './../../../../../services/form.service';
import { DynamicTableColumn, DynamicTableColumnOption, DynamicTableModel, DynamicTableRow } from './../../dynamic-table.widget.model';
import { DynamicTableColumnOption } from './../../dynamic-table-column-option.model';
import { DynamicTableColumn } from './../../dynamic-table-column.model';
import { DynamicTableRow } from './../../dynamic-table-row.model';
import { DynamicTableModel } from './../../dynamic-table.widget.model';
@Component({
selector: 'adf-dropdown-editor',

View File

@@ -17,8 +17,11 @@
import { FormFieldModel, FormModel } from '../../index';
import { FormService } from './../../../../services/form.service';
import { DynamicRowValidationSummary, DynamicTableColumn, DynamicTableModel, DynamicTableRow } from './../dynamic-table.widget.model';
import { RowEditorComponent } from './row.editor';
import { DynamicTableModel } from './../dynamic-table.widget.model';
import { DynamicTableColumn } from './../dynamic-table-column.model';
import { DynamicRowValidationSummary } from './../dynamic-row-validation-summary.model';
import { DynamicTableRow } from './../dynamic-table-row.model';
describe('RowEditorComponent', () => {
@@ -28,7 +31,7 @@ describe('RowEditorComponent', () => {
component = new RowEditorComponent();
const field = new FormFieldModel(new FormModel());
component.table = new DynamicTableModel(field, new FormService(null, null, null));
component.row = <DynamicTableRow> {};
component.row = <DynamicTableRow> {};
component.column = <DynamicTableColumn> {};
});
@@ -55,7 +58,7 @@ describe('RowEditorComponent', () => {
it('should emit [save] event', (done) => {
spyOn(component.table, 'validateRow').and.returnValue(
<DynamicRowValidationSummary> { isValid: true, text: null }
<DynamicRowValidationSummary> {isValid: true, text: null}
);
component.save.subscribe(e => {
expect(e.table).toBe(component.table);
@@ -68,7 +71,7 @@ describe('RowEditorComponent', () => {
it('should not emit [save] event for invalid row', () => {
spyOn(component.table, 'validateRow').and.returnValue(
<DynamicRowValidationSummary> { isValid: false, text: 'error' }
<DynamicRowValidationSummary> {isValid: false, text: 'error'}
);
let raised = false;
component.save.subscribe(e => raised = true);

View File

@@ -18,7 +18,10 @@
/* tslint:disable:component-selector */
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { DynamicRowValidationSummary, DynamicTableColumn, DynamicTableModel, DynamicTableRow } from './../dynamic-table.widget.model';
import { DynamicRowValidationSummary } from './../dynamic-row-validation-summary.model';
import { DynamicTableColumn } from './../dynamic-table-column.model';
import { DynamicTableRow } from './../dynamic-table-row.model';
import { DynamicTableModel } from './../dynamic-table.widget.model';
@Component({
selector: 'row-editor',

View File

@@ -15,7 +15,8 @@
* limitations under the License.
*/
import { DynamicTableColumn, DynamicTableRow } from './../../dynamic-table.widget.model';
import { DynamicTableColumn } from './../../dynamic-table-column.model';
import { DynamicTableRow } from './../../dynamic-table-row.model';
import { TextEditorComponent } from './text.editor';
describe('TextEditorComponent', () => {

View File

@@ -15,10 +15,12 @@
* limitations under the License.
*/
/* tslint:disable:component-selector */
/* tslint:disable:component-selector */
import { Component, Input, OnInit } from '@angular/core';
import { DynamicTableColumn, DynamicTableModel, DynamicTableRow } from './../../dynamic-table.widget.model';
import { DynamicTableColumn } from './../../dynamic-table-column.model';
import { DynamicTableRow } from './../../dynamic-table-row.model';
import { DynamicTableModel } from './../../dynamic-table.widget.model';
@Component({
selector: 'adf-text-editor',

View File

@@ -0,0 +1,63 @@
/*!
* @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 */
import { CellValidator } from './cell-validator.model';
import { DynamicRowValidationSummary } from './dynamic-row-validation-summary.model';
import { DynamicTableColumn } from './dynamic-table-column.model';
import { DynamicTableRow } from './dynamic-table-row.model';
export class NumberCellValidator implements CellValidator {
private supportedTypes: string[] = [
'Number',
'Amount'
];
isSupported(column: DynamicTableColumn): boolean {
return column && column.required && this.supportedTypes.indexOf(column.type) > -1;
}
isNumber(value: any): boolean {
if (value === null || value === undefined || value === '') {
return false;
}
return !isNaN(+value);
}
validate(row: DynamicTableRow, column: DynamicTableColumn, summary?: DynamicRowValidationSummary): boolean {
if (this.isSupported(column)) {
let value = row.value[column.id];
if (value === null ||
value === undefined ||
value === '' ||
this.isNumber(value)) {
return true;
}
if (summary) {
summary.isValid = false;
summary.text = `Field '${column.name}' must be a number.`;
}
return false;
}
return true;
}
}

View File

@@ -0,0 +1,55 @@
/*!
* @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 */
import { CellValidator } from './cell-validator.model';
import { DynamicRowValidationSummary } from './dynamic-row-validation-summary.model';
import { DynamicTableColumn } from './dynamic-table-column.model';
import { DynamicTableRow } from './dynamic-table-row.model';
export class RequiredCellValidator implements CellValidator {
private supportedTypes: string[] = [
'String',
'Number',
'Amount',
'Date',
'Dropdown'
];
isSupported(column: DynamicTableColumn): boolean {
return column && column.required && this.supportedTypes.indexOf(column.type) > -1;
}
validate(row: DynamicTableRow, column: DynamicTableColumn, summary?: DynamicRowValidationSummary): boolean {
if (this.isSupported(column)) {
let value = row.value[column.id];
if (column.required) {
if (value === null || value === undefined || value === '') {
if (summary) {
summary.isValid = false;
summary.text = `Field '${column.name}' is required.`;
}
return false;
}
}
}
return true;
}
}

View File

@@ -15,7 +15,9 @@
* limitations under the License.
*/
import { DynamicRowValidationSummary, DynamicTableRow } from '../components/widgets/dynamic-table/dynamic-table.widget.model';
import { DynamicRowValidationSummary } from '../components/widgets/dynamic-table/dynamic-row-validation-summary.model';
import { DynamicTableRow } from '../components/widgets/dynamic-table/dynamic-table-row.model';
import { FormFieldModel, FormModel } from './../components/widgets/core/index';
import { FormFieldEvent } from './form-field.event';

View File

@@ -90,7 +90,7 @@ export class StartTaskComponent implements OnInit {
public start(): void {
if (this.startTaskmodel.name) {
if(this.appId) {
if (this.appId) {
this.startTaskmodel.category = this.appId.toString();
}
this.taskService.createNewTask(new TaskDetailsModel(this.startTaskmodel))

View File

@@ -16,7 +16,8 @@
*/
import { BaseEvent } from 'ng2-alfresco-core';
import { DataColumn, DataRow } from '../../data/datatable-adapter';
import { DataColumn } from '../../data/data-column.model';
import { DataRow } from '../../data/data-row.model';
export class DataCellEvent extends BaseEvent<DataCellEventModel> {

View File

@@ -16,7 +16,7 @@
*/
import { BaseEvent } from 'ng2-alfresco-core';
import { DataRow } from '../../data/datatable-adapter';
import { DataRow } from '../../data/data-row.model';
export class DataRowActionEvent extends BaseEvent<DataRowActionModel> {

View File

@@ -16,7 +16,9 @@
*/
import { ChangeDetectionStrategy, Component, Input, OnInit, ViewEncapsulation } from '@angular/core';
import { DataColumn, DataRow, DataTableAdapter } from '../../data/datatable-adapter';
import { DataColumn } from '../../data/data-column.model';
import { DataRow } from '../../data/data-row.model';
import { DataTableAdapter } from '../../data/datatable-adapter';
@Component({
selector: 'adf-datatable-cell, alfresco-datatable-cell',

View File

@@ -22,7 +22,12 @@ import {
import { MatCheckboxChange } from '@angular/material';
import { DataColumnListComponent } from 'ng2-alfresco-core';
import { Observable, Observer, Subscription } from 'rxjs/Rx';
import { DataColumn, DataRow, DataRowEvent, DataSorting, DataTableAdapter } from '../../data/datatable-adapter';
import { DataColumn } from '../../data/data-column.model';
import { DataRowEvent } from '../../data/data-row-event.model';
import { DataRow } from '../../data/data-row.model';
import { DataSorting } from '../../data/data-sorting.model';
import { DataTableAdapter } from '../../data/datatable-adapter';
import { ObjectDataRow, ObjectDataTableAdapter } from '../../data/object-datatable-adapter';
import { DataCellEvent } from './data-cell.event';
import { DataRowActionEvent } from './data-row-action.event';

View File

@@ -0,0 +1,30 @@
/*!
* @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 { TemplateRef } from '@angular/core';
export interface DataColumn {
key: string;
type: string; // text|image|date
format?: string;
sortable?: boolean;
title?: string;
srTitle?: string;
cssClass?: string;
template?: TemplateRef<any>;
formatTooltip?: Function;
}

View File

@@ -0,0 +1,32 @@
/*!
* @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 { BaseUIEvent } from 'ng2-alfresco-core';
import { DataRow } from './data-row.model';
export class DataRowEvent extends BaseUIEvent<DataRow> {
sender: any;
constructor(value: DataRow, domEvent: Event, sender?: any) {
super();
this.value = value;
this.event = domEvent;
this.sender = sender;
}
}

View File

@@ -0,0 +1,24 @@
/*!
* @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.
*/
export interface DataRow {
isSelected: boolean;
isDropTarget?: boolean;
cssClass?: string;
hasValue(key: string): boolean;
getValue(key: string): any;
}

View 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.
*/
export class DataSorting {
constructor(
public key?: string,
public direction?: string) {
}
}

View File

@@ -15,8 +15,9 @@
* limitations under the License.
*/
import { TemplateRef } from '@angular/core';
import { BaseUIEvent } from 'ng2-alfresco-core';
import { DataColumn } from './data-column.model';
import { DataRow } from './data-row.model';
import { DataSorting } from './data-sorting.model';
export interface DataTableAdapter {
selectedRow: DataRow;
@@ -29,43 +30,3 @@ export interface DataTableAdapter {
setSorting(sorting: DataSorting): void;
sort(key?: string, direction?: string): void;
}
export interface DataRow {
isSelected: boolean;
isDropTarget?: boolean;
cssClass?: string;
hasValue(key: string): boolean;
getValue(key: string): any;
}
export interface DataColumn {
key: string;
type: string; // text|image|date
format?: string;
sortable?: boolean;
title?: string;
srTitle?: string;
cssClass?: string;
template?: TemplateRef<any>;
formatTooltip?: Function;
}
export class DataSorting {
constructor(
public key?: string,
public direction?: string) {
}
}
export class DataRowEvent extends BaseUIEvent<DataRow> {
sender: any;
constructor(value: DataRow, domEvent: Event, sender?: any) {
super();
this.value = value;
this.event = domEvent;
this.sender = sender;
}
}

View File

@@ -15,5 +15,9 @@
* limitations under the License.
*/
export { DataColumn, DataRow, DataRowEvent, DataSorting, DataTableAdapter } from './datatable-adapter';
export { DataTableAdapter } from './datatable-adapter';
export { ObjectDataColumn, ObjectDataRow, ObjectDataTableAdapter } from './object-datatable-adapter';
export { DataRow } from './data-row.model';
export { DataRowEvent } from './data-row-event.model';
export { DataColumn } from './data-column.model';
export { DataSorting } from './data-sorting.model';

View File

@@ -15,7 +15,9 @@
* limitations under the License.
*/
import { DataColumn, DataRow, DataSorting } from './datatable-adapter';
import { DataColumn } from './data-column.model';
import { DataRow } from './data-row.model';
import { DataSorting } from './data-sorting.model';
import { ObjectDataColumn, ObjectDataRow, ObjectDataTableAdapter } from './object-datatable-adapter';
describe('ObjectDataTableAdapter', () => {

View File

@@ -19,7 +19,10 @@ import { DatePipe } from '@angular/common';
import { TemplateRef } from '@angular/core';
import { ObjectUtils, TimeAgoPipe } from 'ng2-alfresco-core';
import { DataColumn, DataRow, DataSorting, DataTableAdapter } from './datatable-adapter';
import { DataColumn } from './data-column.model';
import { DataRow } from './data-row.model';
import { DataSorting } from './data-sorting.model';
import { DataTableAdapter } from './datatable-adapter';
// Simple implementation of the DataTableAdapter interface.
export class ObjectDataTableAdapter implements DataTableAdapter {

View File

@@ -19,7 +19,8 @@ import { Component, EventEmitter, Inject, Input, OnInit, Optional, Output, ViewC
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
import { MinimalNodeEntryEntity, NodePaging, Pagination } from 'alfresco-js-api';
import { AlfrescoContentService, HighlightDirective, SiteModel } from 'ng2-alfresco-core';
import { ImageResolver, RowFilter } from '../../data/share-datatable-adapter';
import { ImageResolver } from '../../data/image-resolver.model';
import { RowFilter } from '../../data/row-filter.model';
import { DocumentListComponent, PaginationStrategy } from '../document-list.component';
import { ContentNodeSelectorService } from './content-node-selector.service';
@@ -130,7 +131,7 @@ export class ContentNodeSelectorComponent implements OnInit {
/**
* Returns the actually selected|entered folder node or null in case of searching for the breadcrumb
*/
get breadcrumbFolderNode(): MinimalNodeEntryEntity|null {
get breadcrumbFolderNode(): MinimalNodeEntryEntity | null {
if (this.showingSearchResults && this.chosenNode) {
return this.chosenNode;
} else {

View File

@@ -32,7 +32,10 @@ import {
import { MaterialModule } from '../material.module';
import { ContentActionModel } from '../models/content-action.model';
import { NodeMinimal, NodeMinimalEntry, NodePaging } from '../models/document-library.model';
import { ImageResolver, RowFilter } from './../data/share-datatable-adapter';
import { ImageResolver } from './../data/image-resolver.model';
import { RowFilter } from './../data/row-filter.model';
import { DocumentListService } from './../services/document-list.service';
import { DocumentListComponent } from './document-list.component';

View File

@@ -24,7 +24,11 @@ import { AlfrescoApiService, AppConfigService, DataColumnListComponent, UserPref
import { DataCellEvent, DataColumn, DataRowActionEvent, DataSorting, DataTableComponent, ObjectDataColumn } from 'ng2-alfresco-datatable';
import { Observable, Subject } from 'rxjs/Rx';
import { presetsDefaultModel } from '../models/preset.model';
import { ImageResolver, RowFilter, ShareDataRow, ShareDataTableAdapter } from './../data/share-datatable-adapter';
import { ImageResolver } from './../data/image-resolver.model';
import { RowFilter } from './../data/row-filter.model';
import { ShareDataRow } from './../data/share-data-row.model';
import { ShareDataTableAdapter } from './../data/share-datatable-adapter';
import { ContentActionModel } from './../models/content-action.model';
import { PermissionStyleModel } from './../models/permissions-style.model';
import { DocumentListService } from './../services/document-list.service';

View File

@@ -0,0 +1,20 @@
/*!
* @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 { DataColumn, DataRow } from 'ng2-alfresco-datatable';
export type ImageResolver = (row: DataRow, column: DataColumn) => string;

View File

@@ -0,0 +1,20 @@
/*!
* @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 { ShareDataRow } from './share-data-row.model';
export type RowFilter = (value: ShareDataRow, index: number, array: ShareDataRow[]) => any;

View File

@@ -0,0 +1,97 @@
/*!
* @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 { MinimalNode, MinimalNodeEntity } from 'alfresco-js-api';
import { ObjectUtils } from 'ng2-alfresco-core';
import { DataRow } from 'ng2-alfresco-datatable';
import { PermissionStyleModel } from './../models/permissions-style.model';
import { DocumentListService } from './../services/document-list.service';
export class ShareDataRow implements DataRow {
static ERR_OBJECT_NOT_FOUND: string = 'Object source not found';
cache: { [key: string]: any } = {};
isSelected: boolean = false;
isDropTarget: boolean;
cssClass: string = '';
get node(): MinimalNodeEntity {
return this.obj;
}
constructor(private obj: MinimalNodeEntity, private documentListService: DocumentListService, private permissionsStyle: PermissionStyleModel[]) {
if (!obj) {
throw new Error(ShareDataRow.ERR_OBJECT_NOT_FOUND);
}
this.isDropTarget = this.isFolderAndHasPermissionToUpload(obj);
if (permissionsStyle) {
this.cssClass = this.getPermissionClass(obj);
}
}
getPermissionClass(nodeEntity: MinimalNodeEntity): string {
let permissionsClasses = '';
this.permissionsStyle.forEach((currentPermissionsStyle: PermissionStyleModel) => {
if (this.applyPermissionStyleToFolder(nodeEntity.entry, currentPermissionsStyle) || this.applyPermissionStyleToFile(nodeEntity.entry, currentPermissionsStyle)) {
if (this.documentListService.hasPermission(nodeEntity.entry, currentPermissionsStyle.permission)) {
permissionsClasses += ` ${currentPermissionsStyle.css}`;
}
}
});
return permissionsClasses;
}
private applyPermissionStyleToFile(node: MinimalNode, currentPermissionsStyle: PermissionStyleModel): boolean {
return (currentPermissionsStyle.isFile && node.isFile);
}
private applyPermissionStyleToFolder(node: MinimalNode, currentPermissionsStyle: PermissionStyleModel): boolean {
return (currentPermissionsStyle.isFolder && node.isFolder);
}
isFolderAndHasPermissionToUpload(obj: MinimalNodeEntity): boolean {
return this.isFolder(obj) && this.documentListService.hasPermission(obj.entry, 'create');
}
isFolder(obj: MinimalNodeEntity): boolean {
return obj.entry && obj.entry.isFolder;
}
cacheValue(key: string, value: any): any {
this.cache[key] = value;
return value;
}
getValue(key: string): any {
if (this.cache[key] !== undefined) {
return this.cache[key];
}
return ObjectUtils.getValue(this.obj.entry, key);
}
hasValue(key: string): boolean {
return this.getValue(key) !== undefined;
}
}

View File

@@ -20,7 +20,8 @@ import { CoreModule } from 'ng2-alfresco-core';
import { DataColumn, DataRow, DataSorting } from 'ng2-alfresco-datatable';
import { FileNode, FolderNode } from './../assets/document-library.model.mock';
import { DocumentListService } from './../services/document-list.service';
import { ShareDataRow, ShareDataTableAdapter } from './share-datatable-adapter';
import { ShareDataTableAdapter } from './share-datatable-adapter';
import { ShareDataRow } from './share-data-row.model';
describe('ShareDataTableAdapter', () => {

View File

@@ -16,11 +16,14 @@
*/
import { DatePipe } from '@angular/common';
import { MinimalNode, MinimalNodeEntity, NodePaging } from 'alfresco-js-api';
import { ObjectUtils, TimeAgoPipe } from 'ng2-alfresco-core';
import { NodePaging } from 'alfresco-js-api';
import { TimeAgoPipe } from 'ng2-alfresco-core';
import { DataColumn, DataRow, DataSorting, DataTableAdapter } from 'ng2-alfresco-datatable';
import { PermissionStyleModel } from './../models/permissions-style.model';
import { DocumentListService } from './../services/document-list.service';
import { ImageResolver } from './image-resolver.model';
import { RowFilter } from './row-filter.model';
import { ShareDataRow } from './share-data-row.model';
export class ShareDataTableAdapter implements DataTableAdapter {
@@ -239,82 +242,3 @@ export class ShareDataTableAdapter implements DataTableAdapter {
}
}
}
export class ShareDataRow implements DataRow {
static ERR_OBJECT_NOT_FOUND: string = 'Object source not found';
cache: { [key: string]: any } = {};
isSelected: boolean = false;
isDropTarget: boolean;
cssClass: string = '';
get node(): MinimalNodeEntity {
return this.obj;
}
constructor(private obj: MinimalNodeEntity, private documentListService: DocumentListService, private permissionsStyle: PermissionStyleModel[]) {
if (!obj) {
throw new Error(ShareDataRow.ERR_OBJECT_NOT_FOUND);
}
this.isDropTarget = this.isFolderAndHasPermissionToUpload(obj);
if (permissionsStyle) {
this.cssClass = this.getPermissionClass(obj);
}
}
getPermissionClass(nodeEntity: MinimalNodeEntity): string {
let permissionsClasses = '';
this.permissionsStyle.forEach((currentPermissionsStyle: PermissionStyleModel) => {
if (this.applyPermissionStyleToFolder(nodeEntity.entry, currentPermissionsStyle) || this.applyPermissionStyleToFile(nodeEntity.entry, currentPermissionsStyle)) {
if (this.documentListService.hasPermission(nodeEntity.entry, currentPermissionsStyle.permission)) {
permissionsClasses += ` ${currentPermissionsStyle.css}`;
}
}
});
return permissionsClasses;
}
private applyPermissionStyleToFile(node: MinimalNode, currentPermissionsStyle: PermissionStyleModel): boolean {
return (currentPermissionsStyle.isFile && node.isFile);
}
private applyPermissionStyleToFolder(node: MinimalNode, currentPermissionsStyle: PermissionStyleModel): boolean {
return (currentPermissionsStyle.isFolder && node.isFolder);
}
isFolderAndHasPermissionToUpload(obj: MinimalNodeEntity): boolean {
return this.isFolder(obj) && this.documentListService.hasPermission(obj.entry, 'create');
}
isFolder(obj: MinimalNodeEntity): boolean {
return obj.entry && obj.entry.isFolder;
}
cacheValue(key: string, value: any): any {
this.cache[key] = value;
return value;
}
getValue(key: string): any {
if (this.cache[key] !== undefined) {
return this.cache[key];
}
return ObjectUtils.getValue(this.obj.entry, key);
}
hasValue(key: string): boolean {
return this.getValue(key) !== undefined;
}
}
export type RowFilter = (value: ShareDataRow, index: number, array: ShareDataRow[]) => any;
export type ImageResolver = (row: DataRow, column: DataColumn) => string;

View File

@@ -22,7 +22,7 @@ import { AlfrescoContentService } from 'ng2-alfresco-core';
import { DataColumn } from 'ng2-alfresco-datatable';
import { Subject } from 'rxjs/Rx';
import { ContentNodeSelectorComponent, ContentNodeSelectorComponentData } from '../components/content-node-selector/content-node-selector.component';
import { ShareDataRow } from '../data/share-datatable-adapter';
import { ShareDataRow } from '../data/share-data-row.model';
import { DocumentListService } from './document-list.service';
@Injectable()