Skip to content

Commit

Permalink
feat(core/reports): add pipe to build string from string identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
trik committed Dec 4, 2020
1 parent 3fa1ceb commit 2c585f5
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core/reports/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export * from './interface/widgets-instances/text-widget-instance';
export * from './interface/widgets-instances/widget-instance';
export * from './interface/widgets-instances/widget-with-content-instance';
export * from './report';
export * from './report-string-identifier';
export * from './reports-module';
export * from './serializers/aggregation-serializer';
export * from './serializers/dataset-serializer';
Expand Down
34 changes: 34 additions & 0 deletions src/core/reports/report-string-identifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license
* Copyright (C) Gnucoop soc. coop.
*
* This file is part of the Advanced JSON forms (ajf).
*
* Advanced JSON forms (ajf) is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Advanced JSON forms (ajf) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Advanced JSON forms (ajf).
* If not, see http://www.gnu.org/licenses/.
*
*/

import {AjfContext, BuildStringIdentifierOpts} from '@ajf/core/common';
import {Pipe, PipeTransform} from '@angular/core';

import {AjfReport} from './interface/reports/report';
import {buildReportStringIdentifier} from './utils/reports/build-report-string-identifier';

@Pipe({name: 'ajfReportStringIdentifier'})
export class AjfReportStringIdentifierPipe implements PipeTransform {
transform(report: AjfReport, context: AjfContext, opts?: BuildStringIdentifierOpts): string {
return buildReportStringIdentifier(report, context, opts);
}
}
7 changes: 6 additions & 1 deletion src/core/reports/reports-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@ import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';

import {AjfGetColumnContentPipe} from './get-column-content';
import {AjfReportStringIdentifierPipe} from './report-string-identifier';
import {AjfWidgetExport} from './widget-export';
import {AjfWidgetHost} from './widget-host';

@NgModule({
declarations: [
AjfGetColumnContentPipe,
AjfReportStringIdentifierPipe,
AjfWidgetHost,
AjfWidgetExport,
],
imports: [CommonModule],
imports: [
CommonModule,
],
exports: [
AjfGetColumnContentPipe,
AjfReportStringIdentifierPipe,
AjfWidgetHost,
AjfWidgetExport,
],
Expand Down
41 changes: 41 additions & 0 deletions src/core/reports/utils/reports/build-report-string-identifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @license
* Copyright (C) Gnucoop soc. coop.
*
* This file is part of the Advanced JSON forms (ajf).
*
* Advanced JSON forms (ajf) is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Advanced JSON forms (ajf) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Advanced JSON forms (ajf).
* If not, see http://www.gnu.org/licenses/.
*
*/

import {
AjfContext,
buildStringIdentifier,
BuildStringIdentifierOpts,
} from '@ajf/core/common';

import {AjfReport} from '../../interface/reports/report';

export const buildReportStringIdentifier =
(report: AjfReport, context: AjfContext, opts?: BuildStringIdentifierOpts): string => {
if (report == null) {
return '';
}
const stringIdentifier = report.stringIdentifier || [];
if (stringIdentifier.length === 0) {
return '';
}
return buildStringIdentifier(stringIdentifier, context, opts);
};
8 changes: 7 additions & 1 deletion tools/public_api_guard/core/reports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,17 @@ export declare class AjfReportSerializer {

export declare class AjfReportsModule {
static ɵinj: i0.ɵɵInjectorDef<AjfReportsModule>;
static ɵmod: i0.ɵɵNgModuleDefWithMeta<AjfReportsModule, [typeof i1.AjfGetColumnContentPipe, typeof i2.AjfWidgetHost, typeof i3.AjfWidgetExport], [typeof i4.CommonModule], [typeof i1.AjfGetColumnContentPipe, typeof i2.AjfWidgetHost, typeof i3.AjfWidgetExport]>;
static ɵmod: i0.ɵɵNgModuleDefWithMeta<AjfReportsModule, [typeof i1.AjfGetColumnContentPipe, typeof i2.AjfReportStringIdentifierPipe, typeof i3.AjfWidgetHost, typeof i4.AjfWidgetExport], [typeof i5.CommonModule], [typeof i1.AjfGetColumnContentPipe, typeof i2.AjfReportStringIdentifierPipe, typeof i3.AjfWidgetHost, typeof i4.AjfWidgetExport]>;
}

export declare type AjfReportStringIdentifier = AjfStringIdentifier;

export declare class AjfReportStringIdentifierPipe implements PipeTransform {
transform(report: AjfReport, context: AjfContext, opts?: BuildStringIdentifierOpts): string;
static ɵfac: i0.ɵɵFactoryDef<AjfReportStringIdentifierPipe, never>;
static ɵpipe: i0.ɵɵPipeDefWithMeta<AjfReportStringIdentifierPipe, "ajfReportStringIdentifier">;
}

export interface AjfReportVariable {
formula: AjfFormula;
name: string;
Expand Down

0 comments on commit 2c585f5

Please sign in to comment.