app/core/services/row-resolver.service.ts
Methods |
|
constructor(constantService: ConstantsService, util: UtilService)
|
|||||||||
Defined in app/core/services/row-resolver.service.ts:6
|
|||||||||
Parameters :
|
Public transform | ||||||
transform(entities, region)
|
||||||
Defined in app/core/services/row-resolver.service.ts:13
|
||||||
Parameters :
Returns :
{}
|
import { Injectable } from '@angular/core';
import { ConstantsService } from 'src/app/shared/constants/constants.service';
import { UtilService } from './util-service/util.service';
@Injectable()
export class RowResolverService {
constructor(
private constantService: ConstantsService,
private util: UtilService
) { }
public transform(entities, region) {
const regionRows = [];
let row = [];
let columns = 0;
entities.forEach((entity, ind, entityArr) => {
const entityName = this.util.extract(entity, 'MvcData', 'ViewName');
const bootstrapClass = this.constantService.BOOTSTRAP_CLASSES_FOR_DXA_ENTITIES[region][entityName];
if (!bootstrapClass) { // If entity not found, put it on its own row
if (row.length > 0) {
regionRows.push(row);
}
regionRows.push([entity]);
row = [];
columns = 0;
return false;
}
const colSpace = +bootstrapClass.split('-')[2];
if (columns + colSpace > 12) {
regionRows.push(row);
row = [entity];
columns = colSpace;
} else if (columns + colSpace === 12) {
row.push(entity);
regionRows.push(row);
row = [];
columns = 0;
} else {
row.push(entity);
columns += colSpace;
}
if (ind === entityArr.length - 1 && row.length > 0) { // Last element
regionRows.push(row);
}
});
return regionRows;
}
}