|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import {
|
|
|
|
|
ABP,
|
|
|
|
|
ConfigStateService,
|
|
|
|
|
getShortDateFormat,
|
|
|
|
|
getShortDateShortTimeFormat,
|
|
|
|
@ -29,7 +30,8 @@ import { EntityActionList } from '../../models/entity-actions';
|
|
|
|
|
import { EntityProp, EntityPropList } from '../../models/entity-props';
|
|
|
|
|
import { PropData } from '../../models/props';
|
|
|
|
|
import { ExtensionsService } from '../../services/extensions.service';
|
|
|
|
|
import { EXTENSIONS_IDENTIFIER } from '../../tokens/extensions.token';
|
|
|
|
|
import { EXTENSIONS_IDENTIFIER, PROP_DATA_STREAM } from '../../tokens/extensions.token';
|
|
|
|
|
|
|
|
|
|
const DEFAULT_ACTIONS_COLUMN_WIDTH = 150;
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@ -71,7 +73,7 @@ export class ExtensibleTableComponent<R = any> implements OnChanges {
|
|
|
|
|
constructor(
|
|
|
|
|
@Inject(LOCALE_ID) private locale: string,
|
|
|
|
|
private config: ConfigStateService,
|
|
|
|
|
injector: Injector,
|
|
|
|
|
private injector: Injector,
|
|
|
|
|
) {
|
|
|
|
|
this.getInjected = injector.get.bind(injector);
|
|
|
|
|
const extensions = injector.get(ExtensionsService);
|
|
|
|
@ -106,6 +108,12 @@ export class ExtensibleTableComponent<R = any> implements OnChanges {
|
|
|
|
|
: '<div class="text-center text-danger"><i class="fa fa-times"></i></div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getEnum(rowValue: any, list: Array<ABP.Option<any>>) {
|
|
|
|
|
if (!list) return rowValue;
|
|
|
|
|
const { key } = list.find(({ value }) => value === rowValue);
|
|
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getContent(prop: EntityProp<R>, data: PropData): Observable<string> {
|
|
|
|
|
return prop.valueResolver(data).pipe(
|
|
|
|
|
map(value => {
|
|
|
|
@ -118,6 +126,8 @@ export class ExtensibleTableComponent<R = any> implements OnChanges {
|
|
|
|
|
return this.getDate(value, getShortTimeFormat(this.config));
|
|
|
|
|
case ePropType.DateTime:
|
|
|
|
|
return this.getDate(value, getShortDateShortTimeFormat(this.config));
|
|
|
|
|
case ePropType.Enum:
|
|
|
|
|
return this.getEnum(value, prop.enumList);
|
|
|
|
|
default:
|
|
|
|
|
return value;
|
|
|
|
|
// More types can be handled in the future
|
|
|
|
@ -132,10 +142,26 @@ export class ExtensibleTableComponent<R = any> implements OnChanges {
|
|
|
|
|
this.data = data.currentValue.map((record, index) => {
|
|
|
|
|
this.propList.forEach(prop => {
|
|
|
|
|
const propData = { getInjected: this.getInjected, record, index } as any;
|
|
|
|
|
record[`_${prop.value.name}`] = {
|
|
|
|
|
const value = this.getContent(prop.value, propData);
|
|
|
|
|
|
|
|
|
|
const propKey = `_${prop.value.name}`;
|
|
|
|
|
record[propKey] = {
|
|
|
|
|
visible: prop.value.visible(propData),
|
|
|
|
|
value: this.getContent(prop.value, propData),
|
|
|
|
|
value,
|
|
|
|
|
};
|
|
|
|
|
if (prop.value.component) {
|
|
|
|
|
const injector = Injector.create(
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
provide: PROP_DATA_STREAM,
|
|
|
|
|
useValue: value,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
this.injector,
|
|
|
|
|
);
|
|
|
|
|
record[propKey].injector = injector;
|
|
|
|
|
record[propKey].component = prop.value.component;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return record;
|
|
|
|
|