Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ReportPostPayoad to accept a label string #142

Merged
merged 3 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-iotile-cloud",
"version": "0.25.0",
"version": "0.26.0",
"description": "Build an Angular library compatible with AoT compilation and Tree shaking",
"main": "./bundles/ng-iotile-cloud.umd.js",
"module": "./modules/ng-iotile-cloud.es5.js",
Expand Down Expand Up @@ -31,6 +31,7 @@
],
"license": "MIT",
"devDependencies": {
"@angular/animations": "6.0.3",
"@angular/common": "6.0.3",
"@angular/compiler": "6.0.3",
"@angular/compiler-cli": "6.0.3",
Expand All @@ -39,7 +40,6 @@
"@angular/platform-browser": "6.0.3",
"@angular/platform-browser-dynamic": "6.0.3",
"@angular/platform-server": "6.0.3",
"@angular/animations": "6.0.3",
"@compodoc/compodoc": "1.1.2",
"@types/jasmine": "2.5.52",
"@types/node": "8.0.1",
Expand All @@ -55,6 +55,9 @@
"karma-sourcemap-loader": "0.3.7",
"karma-spec-reporter": "0.0.31",
"karma-webpack": "3.0.0",
"lodash": "^4.17.11",
"mime": "^2.4.0",
"parsejson": "0.0.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use these libraries?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use them directly, but I am trying to fix the github security warning alerts. In reality, the real fix is to upgrade the packages we do use, but that requires more time I can put on it right now:

https://github.com/iotile/ng-iotile-cloud/network/alerts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh ok! PR looks good then!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you remove these 2 lines of code? they use the old version of observable and break the new library
https://github.com/iotile/ng-iotile-cloud/blob/master/src/cloud.service.ts#L6
https://github.com/iotile/ng-iotile-cloud/blob/master/src/cloud.service.ts#L7

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean be remove? They are used. How do I remove them? Can I just upgrade the rs library?

Copy link
Contributor

@fil-forti fil-forti Dec 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you just delete those two lines of code, rs library has already been updated and ForkJoin has already been imported on line 5 and of is not being used.
These two lines don't break the webapp because it includes the package rxjs-compat for backward compatibility, but that package is not included in the new library

"reflect-metadata": "0.1.10",
"rollup": "0.43.0",
"rollup-plugin-local-resolve": "^1.0.7",
Expand Down
12 changes: 10 additions & 2 deletions src/models/generated-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { User } from './user';
export interface ReportPostPayoad {
slug: string;
template: string;
label?: string;
args?: Object;
}

Expand All @@ -25,7 +26,6 @@ export class GeneratedReport {

constructor(data: any = {}) {
this.id = data['id'] || '';
this.label = data['label'] || '';
this.sourceRef = data['source_ref'] || '';
this.createdOn = new Date(data['created_on']) || new Date();
this.createdBy = data['created_by'] || '';
Expand Down Expand Up @@ -55,19 +55,27 @@ export class GeneratedReport {
delete this.args;
}

if ('label' in data) {
this.label = data['label'];
} else if (this.template && this.sourceRef) {
this.label = this.template + ': ' + this.sourceRef;
} else {
this.label = 'Generated Report';
}
}

public getSchedulPostPayload(): ReportPostPayoad {
let payload: ReportPostPayoad = {
slug: this.sourceRef,
label: this.label,
template: this.template
};

if (this.args) {
payload.args = this.args;
}

if (!payload.slug || !payload.template) {
if (!payload.slug || !payload.template || !payload.label) {
throw new Error(`Payload cannot be returned because of missing fields: ${JSON.stringify(payload, null, 2)}.`);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/models/generated-report.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ describe('GeneratedGeneratedReport', () => {
it('checks basic getPostPayload', () => {
let report: GeneratedReport = new GeneratedReport({
"source_ref": "b--0008-0000-0000-053a",
"label": "My label",
"template": "shipment_overview"
});

let payload: ReportPostPayoad = report.getSchedulPostPayload();

expect('args' in payload).toBeFalsy();
expect(payload.slug).toEqual('b--0008-0000-0000-053a');
expect(payload.label).toEqual('My label');
expect(payload.template).toEqual('shipment_overview');
});

Expand All @@ -88,6 +90,8 @@ describe('GeneratedGeneratedReport', () => {

expect(payload.args).toEqual({'field': 'value'});
expect(payload.slug).toEqual('b--0008-0000-0000-053a');
// If label not set, crate default
expect(payload.label).toEqual('shipment_overview: b--0008-0000-0000-053a');
expect(payload.template).toEqual('shipment_overview');
});

Expand Down