mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1986] Content matadata editing phase II. (#2796)
* Aspects collection * Fetch only those metadata aspects which are defined in the application config * Aspect property filtering first round * Addig wildcard support for preset, default preset fallback to wildcard, and logging * Add white list service * Renaming services * ContentMetadataService and CardViewItemDispatcherComponent update * Observables... Observables everywhere... * Propers CardViewAspect * Defining more interfaces * Dummy data and expansions panels * Fix build attempt & proper panel expansion * Folder restructuring * Add different type mappings * Restructuring Card view component * Fix build * More ECM types supported * Validators first phase, extraction of interfaces, world domination preparation * Validators phase II. * Integer and float validators * Hide empty text items and validation message foundation * Validation error messages for text item view, small style changes * Update date item * bool item component * Datetimepicker npm module * Datetime model * Add mapping for datetime * Small fixes * Passing down preset * Adding forgotten package.json entry * Adding some tests for wrapper card component * content-metadata.component tests * Covering some edge cases, adding some tests * Fix cardview component's test * Add datetimepicker to demoshell * card view component show empty values by default * displayEmpty dependency injection * remove table like design from cardview * Using alfresco-js-api instead of spike * Remove spike folder and contents * Fix test * Cardview updated docs * Content metadata md * Fix review issues * Fix the packagr issue
This commit is contained in:
committed by
Eugenio Romano
parent
994041fb23
commit
783f7f0497
85
lib/core/card-view/models/card-view-baseitem.model.spec.ts
Normal file
85
lib/core/card-view/models/card-view-baseitem.model.spec.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
/*!
|
||||
* @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 { CardViewItemProperties } from '../interfaces/card-view.interfaces';
|
||||
import { CardViewBaseItemModel } from './card-view-baseitem.model';
|
||||
import { CardViewItemValidator } from '../interfaces/card-view.interfaces';
|
||||
|
||||
class CarViewCustomItemModel extends CardViewBaseItemModel {}
|
||||
|
||||
describe('CardViewBaseItemModel', () => {
|
||||
|
||||
let properties: CardViewItemProperties;
|
||||
|
||||
beforeEach(() => {
|
||||
properties = {
|
||||
label: 'Tribe',
|
||||
value: 'Oseram',
|
||||
key: 'tribe'
|
||||
};
|
||||
});
|
||||
|
||||
describe('isValid & Validation errors', () => {
|
||||
|
||||
it('should be true when no validators are set', () => {
|
||||
const itemModel = new CarViewCustomItemModel(properties);
|
||||
|
||||
const isValid = itemModel.isValid(null);
|
||||
|
||||
expect(isValid).toBe(true);
|
||||
});
|
||||
|
||||
it('should call the registered validators to validate', () => {
|
||||
const validator1: CardViewItemValidator = { isValid: () => true, message: 'validator 1' };
|
||||
const validator2: CardViewItemValidator = { isValid: () => true, message: 'validator 2' };
|
||||
spyOn(validator1, 'isValid');
|
||||
spyOn(validator2, 'isValid');
|
||||
properties.validators = [ validator1, validator2 ];
|
||||
const itemModel = new CarViewCustomItemModel(properties);
|
||||
|
||||
itemModel.isValid('test-against-this');
|
||||
|
||||
expect(validator1.isValid).toHaveBeenCalledWith('test-against-this');
|
||||
expect(validator2.isValid).toHaveBeenCalledWith('test-against-this');
|
||||
});
|
||||
|
||||
it('should return the registered validators\' common decision (case true)', () => {
|
||||
const validator1: CardViewItemValidator = { isValid: () => true, message: 'validator 1' };
|
||||
const validator2: CardViewItemValidator = { isValid: () => true, message: 'validator 2' };
|
||||
properties.validators = [ validator1, validator2 ];
|
||||
const itemModel = new CarViewCustomItemModel(properties);
|
||||
|
||||
const isValid = itemModel.isValid('test-against-this');
|
||||
|
||||
expect(isValid).toBe(true);
|
||||
expect(itemModel.getValidationErrors('test-against-this')).toEqual([]);
|
||||
});
|
||||
|
||||
it('should return the registered validators\' common decision (case false)', () => {
|
||||
const validator1: CardViewItemValidator = { isValid: () => false, message: 'validator 1' };
|
||||
const validator2: CardViewItemValidator = { isValid: () => true, message: 'validator 2' };
|
||||
const validator3: CardViewItemValidator = { isValid: () => false, message: 'validator 3' };
|
||||
properties.validators = [ validator1, validator2, validator3 ];
|
||||
const itemModel = new CarViewCustomItemModel(properties);
|
||||
|
||||
const isValid = itemModel.isValid('test-against-this');
|
||||
|
||||
expect(isValid).toBe(false);
|
||||
expect(itemModel.getValidationErrors('test-against-this')).toEqual(['validator 1', 'validator 3']);
|
||||
});
|
||||
});
|
||||
});
|
62
lib/core/card-view/models/card-view-baseitem.model.ts
Normal file
62
lib/core/card-view/models/card-view-baseitem.model.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
/*!
|
||||
* @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 { CardViewItemProperties, CardViewItemValidator } from '../interfaces/card-view.interfaces';
|
||||
|
||||
export abstract class CardViewBaseItemModel {
|
||||
label: string;
|
||||
value: any;
|
||||
key: any;
|
||||
default: any;
|
||||
editable: boolean;
|
||||
clickable: boolean;
|
||||
validators?: CardViewItemValidator[];
|
||||
|
||||
constructor(obj: CardViewItemProperties) {
|
||||
this.label = obj.label || '';
|
||||
this.value = obj.value;
|
||||
this.key = obj.key;
|
||||
this.default = obj.default;
|
||||
this.editable = !!obj.editable;
|
||||
this.clickable = !!obj.clickable;
|
||||
this.validators = obj.validators || [];
|
||||
}
|
||||
|
||||
isEmpty(): boolean {
|
||||
return this.value === undefined || this.value === null || this.value === '';
|
||||
}
|
||||
|
||||
isValid(newValue: any): boolean {
|
||||
if (!this.validators.length) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.validators
|
||||
.map((validator) => validator.isValid(newValue))
|
||||
.reduce((isValidUntilNow, isValid) => isValidUntilNow && isValid, true);
|
||||
}
|
||||
|
||||
getValidationErrors(value): string[] {
|
||||
if (!this.validators.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return this.validators
|
||||
.filter((validator) => !validator.isValid(value))
|
||||
.map((validator) => validator.message);
|
||||
}
|
||||
}
|
88
lib/core/card-view/models/card-view-boolitem.model.spec.ts
Normal file
88
lib/core/card-view/models/card-view-boolitem.model.spec.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
/*!
|
||||
* @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 { CardViewBoolItemModel } from './card-view-boolitem.model';
|
||||
import { CardViewBoolItemProperties } from '../interfaces/card-view.interfaces';
|
||||
|
||||
describe('CardViewFloatItemModel', () => {
|
||||
|
||||
let properties: CardViewBoolItemProperties;
|
||||
|
||||
beforeEach(() => {
|
||||
properties = {
|
||||
label: 'Tribe',
|
||||
value: undefined,
|
||||
key: 'tribe'
|
||||
};
|
||||
});
|
||||
|
||||
it('true should be parsed as true', () => {
|
||||
properties.value = true;
|
||||
const itemModel = new CardViewBoolItemModel(properties);
|
||||
|
||||
expect(itemModel.value).toBe(true);
|
||||
});
|
||||
|
||||
it('"true" should be parsed as true', () => {
|
||||
properties.value = 'true';
|
||||
const itemModel = new CardViewBoolItemModel(properties);
|
||||
|
||||
expect(itemModel.value).toBe(true);
|
||||
});
|
||||
|
||||
it('1 should be parsed as true', () => {
|
||||
properties.value = 1;
|
||||
const itemModel = new CardViewBoolItemModel(properties);
|
||||
|
||||
expect(itemModel.value).toBe(true);
|
||||
});
|
||||
|
||||
it('"1" should be parsed as true', () => {
|
||||
properties.value = '1';
|
||||
const itemModel = new CardViewBoolItemModel(properties);
|
||||
|
||||
expect(itemModel.value).toBe(true);
|
||||
});
|
||||
|
||||
it('"false" should be parsed as false', () => {
|
||||
properties.value = 'false';
|
||||
const itemModel = new CardViewBoolItemModel(properties);
|
||||
|
||||
expect(itemModel.value).toBe(false);
|
||||
});
|
||||
|
||||
it('false should be parsed as false', () => {
|
||||
properties.value = 'false';
|
||||
const itemModel = new CardViewBoolItemModel(properties);
|
||||
|
||||
expect(itemModel.value).toBe(false);
|
||||
});
|
||||
|
||||
it('undefined should be parsed as false', () => {
|
||||
properties.value = undefined;
|
||||
const itemModel = new CardViewBoolItemModel(properties);
|
||||
|
||||
expect(itemModel.value).toBe(false);
|
||||
});
|
||||
|
||||
it('null should be parsed as false', () => {
|
||||
properties.value = null;
|
||||
const itemModel = new CardViewBoolItemModel(properties);
|
||||
|
||||
expect(itemModel.value).toBe(false);
|
||||
});
|
||||
});
|
43
lib/core/card-view/models/card-view-boolitem.model.ts
Normal file
43
lib/core/card-view/models/card-view-boolitem.model.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/*!
|
||||
* @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 { CardViewItem } from '../interfaces/card-view-item.interface';
|
||||
import { DynamicComponentModel } from '../../services/dynamic-component-mapper.service';
|
||||
import { CardViewBaseItemModel } from './card-view-baseitem.model';
|
||||
import { CardViewBoolItemProperties } from '../interfaces/card-view.interfaces';
|
||||
|
||||
export class CardViewBoolItemModel extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
||||
type: string = 'bool';
|
||||
value: boolean = false;
|
||||
default: boolean;
|
||||
|
||||
constructor(obj: CardViewBoolItemProperties) {
|
||||
super(obj);
|
||||
|
||||
if (obj.value !== undefined) {
|
||||
this.value = !!JSON.parse(obj.value);
|
||||
}
|
||||
}
|
||||
|
||||
get displayValue() {
|
||||
if (this.isEmpty()) {
|
||||
return this.default;
|
||||
} else {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
}
|
44
lib/core/card-view/models/card-view-dateitem.model.ts
Normal file
44
lib/core/card-view/models/card-view-dateitem.model.ts
Normal file
@@ -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.
|
||||
*/
|
||||
|
||||
import moment from 'moment-es6';
|
||||
import { CardViewItem } from '../interfaces/card-view-item.interface';
|
||||
import { DynamicComponentModel } from '../../services/dynamic-component-mapper.service';
|
||||
import { CardViewBaseItemModel } from './card-view-baseitem.model';
|
||||
import { CardViewDateItemProperties } from '../interfaces/card-view.interfaces';
|
||||
|
||||
export class CardViewDateItemModel extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
||||
type: string = 'date';
|
||||
format: string = 'MMM DD YYYY';
|
||||
|
||||
constructor(obj: CardViewDateItemProperties) {
|
||||
super(obj);
|
||||
|
||||
if (obj.format) {
|
||||
this.format = obj.format;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
get displayValue() {
|
||||
if (!this.value) {
|
||||
return this.default;
|
||||
} else {
|
||||
return moment(this.value).format(this.format);
|
||||
}
|
||||
}
|
||||
}
|
25
lib/core/card-view/models/card-view-datetimeitem.model.ts
Normal file
25
lib/core/card-view/models/card-view-datetimeitem.model.ts
Normal 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.
|
||||
*/
|
||||
|
||||
import { CardViewItem } from '../interfaces/card-view-item.interface';
|
||||
import { DynamicComponentModel } from '../../services/dynamic-component-mapper.service';
|
||||
import { CardViewDateItemModel } from './card-view-dateitem.model';
|
||||
|
||||
export class CardViewDatetimeItemModel extends CardViewDateItemModel implements CardViewItem, DynamicComponentModel {
|
||||
type: string = 'datetime';
|
||||
format: string = 'MMM DD YYYY HH:mm';
|
||||
}
|
59
lib/core/card-view/models/card-view-floatitem.model.spec.ts
Normal file
59
lib/core/card-view/models/card-view-floatitem.model.spec.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
/*!
|
||||
* @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 { CardViewFloatItemModel } from './card-view-floatitem.model';
|
||||
import { CardViewTextItemProperties } from '../interfaces/card-view.interfaces';
|
||||
|
||||
describe('CardViewFloatItemModel', () => {
|
||||
|
||||
let properties: CardViewTextItemProperties;
|
||||
|
||||
beforeEach(() => {
|
||||
properties = {
|
||||
label: 'Tribe',
|
||||
value: '42.42',
|
||||
key: 'tribe'
|
||||
};
|
||||
});
|
||||
|
||||
it('value should be parsed as float', () => {
|
||||
const itemModel = new CardViewFloatItemModel(properties);
|
||||
|
||||
expect(itemModel.value).toBe(42.42);
|
||||
});
|
||||
|
||||
it('value should be parsed as float only if there is a value', () => {
|
||||
properties.value = undefined;
|
||||
const itemModel = new CardViewFloatItemModel(properties);
|
||||
|
||||
expect(itemModel.value).toBe(undefined);
|
||||
});
|
||||
|
||||
it('isValid should return the validator\'s value', () => {
|
||||
const itemModel = new CardViewFloatItemModel(properties);
|
||||
|
||||
expect(itemModel.isValid(42)).toBe(true, 'For 42 it should be true');
|
||||
expect(itemModel.isValid(42.0)).toBe(true, 'For 42.0 it should be true');
|
||||
expect(itemModel.isValid('42')).toBe(true, 'For "42" it should be true');
|
||||
expect(itemModel.isValid('42.0')).toBe(true, 'For "42.0" it should be true');
|
||||
expect(itemModel.isValid('4e2')).toBe(true, 'For "4e2" it should be true');
|
||||
expect(itemModel.isValid('4g2')).toBe(false, 'For "4g2" it should be false');
|
||||
expect(itemModel.isValid(42.3)).toBe(true, 'For 42.3 it should be true');
|
||||
expect(itemModel.isValid('42.3')).toBe(true, 'For "42.3" it should be true');
|
||||
expect(itemModel.isValid('test')).toBe(false, 'For "test" it should be false');
|
||||
});
|
||||
});
|
35
lib/core/card-view/models/card-view-floatitem.model.ts
Normal file
35
lib/core/card-view/models/card-view-floatitem.model.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
/*!
|
||||
* @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 { CardViewItem } from '../interfaces/card-view-item.interface';
|
||||
import { DynamicComponentModel } from '../../services/dynamic-component-mapper.service';
|
||||
import { CardViewTextItemModel } from './card-view-textitem.model';
|
||||
import { CardViewTextItemProperties } from '../interfaces/card-view.interfaces';
|
||||
import { CardViewItemFloatValidator } from '..//validators/card-view.validators';
|
||||
|
||||
export class CardViewFloatItemModel extends CardViewTextItemModel implements CardViewItem, DynamicComponentModel {
|
||||
type: string = 'float';
|
||||
|
||||
constructor(obj: CardViewTextItemProperties) {
|
||||
super(obj);
|
||||
|
||||
this.validators.push(new CardViewItemFloatValidator());
|
||||
if (obj.value) {
|
||||
this.value = parseFloat(obj.value);
|
||||
}
|
||||
}
|
||||
}
|
59
lib/core/card-view/models/card-view-intitem.model.spec.ts
Normal file
59
lib/core/card-view/models/card-view-intitem.model.spec.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
/*!
|
||||
* @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 { CardViewIntItemModel } from './card-view-intitem.model';
|
||||
import { CardViewTextItemProperties } from '../interfaces/card-view.interfaces';
|
||||
|
||||
describe('CardViewIntItemModel', () => {
|
||||
|
||||
let properties: CardViewTextItemProperties;
|
||||
|
||||
beforeEach(() => {
|
||||
properties = {
|
||||
label: 'Tribe',
|
||||
value: '42',
|
||||
key: 'tribe'
|
||||
};
|
||||
});
|
||||
|
||||
it('value should be parsed as integer', () => {
|
||||
const itemModel = new CardViewIntItemModel(properties);
|
||||
|
||||
expect(itemModel.value).toBe(42);
|
||||
});
|
||||
|
||||
it('value should be parsed as integer only if there is a value', () => {
|
||||
properties.value = undefined;
|
||||
const itemModel = new CardViewIntItemModel(properties);
|
||||
|
||||
expect(itemModel.value).toBe(undefined);
|
||||
});
|
||||
|
||||
it('isValid should return the validator\'s value', () => {
|
||||
const itemModel = new CardViewIntItemModel(properties);
|
||||
|
||||
expect(itemModel.isValid(42)).toBe(true, 'For 42 it should be true');
|
||||
expect(itemModel.isValid(42.0)).toBe(true, 'For 42.0 it should be true');
|
||||
expect(itemModel.isValid('42')).toBe(true, 'For "42" it should be true');
|
||||
expect(itemModel.isValid('42.0')).toBe(true, 'For "42.0" it should be true');
|
||||
expect(itemModel.isValid('4e2')).toBe(true, 'For "4e2" it should be true');
|
||||
expect(itemModel.isValid('4g2')).toBe(false, 'For "4g2" it should be false');
|
||||
expect(itemModel.isValid(42.3)).toBe(false, 'For 42.3 it should be false');
|
||||
expect(itemModel.isValid('42.3')).toBe(false, 'For "42.3" it should be false');
|
||||
expect(itemModel.isValid('test')).toBe(false, 'For "test" it should be false');
|
||||
});
|
||||
});
|
35
lib/core/card-view/models/card-view-intitem.model.ts
Normal file
35
lib/core/card-view/models/card-view-intitem.model.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
/*!
|
||||
* @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 { CardViewItem } from '../interfaces/card-view-item.interface';
|
||||
import { DynamicComponentModel } from '../../services/dynamic-component-mapper.service';
|
||||
import { CardViewTextItemModel } from './card-view-textitem.model';
|
||||
import { CardViewTextItemProperties } from '../interfaces/card-view.interfaces';
|
||||
import { CardViewItemIntValidator } from '../validators/card-view.validators';
|
||||
|
||||
export class CardViewIntItemModel extends CardViewTextItemModel implements CardViewItem, DynamicComponentModel {
|
||||
type: string = 'int';
|
||||
|
||||
constructor(obj: CardViewTextItemProperties) {
|
||||
super(obj);
|
||||
|
||||
this.validators.push(new CardViewItemIntValidator());
|
||||
if (obj.value) {
|
||||
this.value = parseInt(obj.value, 10);
|
||||
}
|
||||
}
|
||||
}
|
33
lib/core/card-view/models/card-view-mapitem.model.ts
Normal file
33
lib/core/card-view/models/card-view-mapitem.model.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/*!
|
||||
* @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 { CardViewItem } from '../interfaces/card-view-item.interface';
|
||||
import { DynamicComponentModel } from '../../services/dynamic-component-mapper.service';
|
||||
import { CardViewBaseItemModel } from './card-view-baseitem.model';
|
||||
|
||||
export class CardViewMapItemModel extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
||||
type: string = 'map';
|
||||
value: Map<string, string>;
|
||||
|
||||
get displayValue() {
|
||||
if (this.value && this.value.size > 0) {
|
||||
return this.value.values().next().value;
|
||||
} else {
|
||||
return this.default;
|
||||
}
|
||||
}
|
||||
}
|
87
lib/core/card-view/models/card-view-textitem.model.spec.ts
Normal file
87
lib/core/card-view/models/card-view-textitem.model.spec.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
/*!
|
||||
* @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 { PipeTransform } from '@angular/core';
|
||||
import { CardViewTextItemModel } from './card-view-textitem.model';
|
||||
import { CardViewTextItemProperties } from '../interfaces/card-view.interfaces';
|
||||
|
||||
class TestPipe implements PipeTransform {
|
||||
transform(value: string, pipeParam: string): string {
|
||||
const paramPostFix = pipeParam ? `-${pipeParam}` : '';
|
||||
return `testpiped-${value}${paramPostFix}`;
|
||||
}
|
||||
}
|
||||
|
||||
describe('CardViewTextItemModel', () => {
|
||||
|
||||
let properties: CardViewTextItemProperties;
|
||||
|
||||
beforeEach(() => {
|
||||
properties = {
|
||||
label: 'Tribe',
|
||||
value: 'Banuk',
|
||||
key: 'tribe'
|
||||
};
|
||||
});
|
||||
|
||||
describe('displayValue', () => {
|
||||
|
||||
it('should return the value if it is present', () => {
|
||||
const itemModel = new CardViewTextItemModel(properties);
|
||||
|
||||
expect(itemModel.displayValue).toBe('Banuk');
|
||||
});
|
||||
|
||||
it('should return the default value if the value is not present', () => {
|
||||
properties.value = undefined;
|
||||
properties.default = 'default-value';
|
||||
const itemModel = new CardViewTextItemModel(properties);
|
||||
|
||||
expect(itemModel.displayValue).toBe('default-value');
|
||||
});
|
||||
|
||||
it('should apply a pipe on the value if it is present', () => {
|
||||
properties.pipes = [
|
||||
{ pipe: new TestPipe() }
|
||||
];
|
||||
const itemModel = new CardViewTextItemModel(properties);
|
||||
|
||||
expect(itemModel.displayValue).toBe('testpiped-Banuk');
|
||||
});
|
||||
|
||||
it('should apply a pipe on the value with parameters if those are present', () => {
|
||||
properties.pipes = [
|
||||
{ pipe: new TestPipe(), params: ['withParams'] }
|
||||
];
|
||||
const itemModel = new CardViewTextItemModel(properties);
|
||||
|
||||
expect(itemModel.displayValue).toBe('testpiped-Banuk-withParams');
|
||||
});
|
||||
|
||||
it('should apply more pipes on the value with parameters if those are present', () => {
|
||||
const pipe: PipeTransform = new TestPipe();
|
||||
properties.pipes = [
|
||||
{ pipe, params: ['1'] },
|
||||
{ pipe, params: ['2'] },
|
||||
{ pipe, params: ['3'] }
|
||||
];
|
||||
const itemModel = new CardViewTextItemModel(properties);
|
||||
|
||||
expect(itemModel.displayValue).toBe('testpiped-testpiped-testpiped-Banuk-1-2-3');
|
||||
});
|
||||
});
|
||||
});
|
51
lib/core/card-view/models/card-view-textitem.model.ts
Normal file
51
lib/core/card-view/models/card-view-textitem.model.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/*!
|
||||
* @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 { CardViewItem } from '../interfaces/card-view-item.interface';
|
||||
import { DynamicComponentModel } from '../../services/dynamic-component-mapper.service';
|
||||
import { CardViewBaseItemModel } from './card-view-baseitem.model';
|
||||
import { CardViewTextItemPipeProperty, CardViewTextItemProperties } from '../interfaces/card-view.interfaces';
|
||||
|
||||
export class CardViewTextItemModel extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
||||
type: string = 'text';
|
||||
multiline?: boolean;
|
||||
pipes?: CardViewTextItemPipeProperty[];
|
||||
|
||||
constructor(obj: CardViewTextItemProperties) {
|
||||
super(obj);
|
||||
this.multiline = !!obj.multiline ;
|
||||
this.pipes = obj.pipes || [];
|
||||
}
|
||||
|
||||
get displayValue() {
|
||||
if (this.isEmpty()) {
|
||||
return this.default;
|
||||
} else {
|
||||
return this.applyPipes(this.value);
|
||||
}
|
||||
}
|
||||
|
||||
private applyPipes(displayValue) {
|
||||
if (this.pipes.length) {
|
||||
displayValue = this.pipes.reduce((accumulator, { pipe, params }) => {
|
||||
return pipe.transform(accumulator, ...params);
|
||||
}, displayValue);
|
||||
}
|
||||
|
||||
return displayValue;
|
||||
}
|
||||
}
|
25
lib/core/card-view/models/card-view.models.ts
Normal file
25
lib/core/card-view/models/card-view.models.ts
Normal 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.
|
||||
*/
|
||||
|
||||
export * from './card-view-baseitem.model';
|
||||
export * from './card-view-boolitem.model';
|
||||
export * from './card-view-dateitem.model';
|
||||
export * from './card-view-datetimeitem.model';
|
||||
export * from './card-view-floatitem.model';
|
||||
export * from './card-view-intitem.model';
|
||||
export * from './card-view-mapitem.model';
|
||||
export * from './card-view-textitem.model';
|
Reference in New Issue
Block a user