From 697ae9ced1c6f39571517f0115fb18ad5373967d Mon Sep 17 00:00:00 2001 From: Severin Beauvais Date: Fri, 23 Mar 2018 13:18:51 -0700 Subject: [PATCH] NOBUG: misc cleanup before further dev --- karma.conf.js | 81 +++++++++---------- package.json | 2 +- protractor.conf.js | 4 +- .../add-edit-user/add-edit-user.component.ts | 7 +- .../application-add-edit.component.ts | 15 ++-- .../select-organization.component.ts | 63 +++++++-------- .../add-edit-comment-period.component.ts | 9 +-- .../manage-comment-periods.component.ts | 4 +- .../add-comment/add-comment.component.ts | 7 +- src/app/services/application.service.ts | 29 ++++--- src/app/services/commentperiod.service.ts | 2 +- src/app/services/search.service.ts | 4 +- src/tsconfig.spec.json | 2 +- tsconfig.json | 2 +- tslint.json | 27 +++++-- 15 files changed, 139 insertions(+), 119 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 5c9eccaa..aa9e65ae 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -2,44 +2,43 @@ // https://karma-runner.github.io/0.13/config/configuration-file.html module.exports = function (config) { - config.set({ - basePath: '', - frameworks: ['jasmine', '@angular/cli'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage-istanbul-reporter'), - require('@angular/cli/plugins/karma') - ], - client: { - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, - files: [ - { pattern: './src/test.ts', watched: false } - ], - preprocessors: { - './src/test.ts': ['@angular/cli'] - }, - mime: { - 'text/x-typescript': ['ts', 'tsx'] - }, - coverageIstanbulReporter: { - reports: ['html', 'lcovonly'], - fixWebpackSourcePaths: true - }, - angularCli: { - environment: 'dev' - }, - reporters: config.angularCli && config.angularCli.codeCoverage - ? ['progress', 'coverage-istanbul'] - : ['progress', 'kjhtml'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, - browsers: ['ChromeHeadless'], - singleRun: false - }); - }; - \ No newline at end of file + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular/cli'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter'), + require('karma-coverage-istanbul-reporter'), + require('@angular/cli/plugins/karma') + ], + client: { + clearContext: false // leave Jasmine Spec Runner output visible in browser + }, + files: [ + { pattern: './src/test.ts', watched: false } + ], + preprocessors: { + './src/test.ts': ['@angular/cli'] + }, + mime: { + 'text/x-typescript': ['ts', 'tsx'] + }, + coverageIstanbulReporter: { + reports: ['html', 'lcovonly'], + fixWebpackSourcePaths: true + }, + angularCli: { + environment: 'dev' + }, + reporters: config.angularCli && config.angularCli.codeCoverage + ? ['progress', 'coverage-istanbul'] + : ['progress', 'kjhtml'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['ChromeHeadless'], + singleRun: false + }); +}; diff --git a/package.json b/package.json index b46791b3..240aee9e 100644 --- a/package.json +++ b/package.json @@ -68,4 +68,4 @@ "tslint": "4.5.0", "typescript": "<2.4.0" } -} +} \ No newline at end of file diff --git a/protractor.conf.js b/protractor.conf.js index 1c5e1e5a..f60cff23 100644 --- a/protractor.conf.js +++ b/protractor.conf.js @@ -17,9 +17,9 @@ exports.config = { jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: 30000, - print: function() {} + print: function () { } }, - beforeLaunch: function() { + beforeLaunch: function () { require('ts-node').register({ project: 'e2e/tsconfig.e2e.json' }); diff --git a/src/app/administration/users/add-edit-user/add-edit-user.component.ts b/src/app/administration/users/add-edit-user/add-edit-user.component.ts index 8968a0ab..60d9de66 100644 --- a/src/app/administration/users/add-edit-user/add-edit-user.component.ts +++ b/src/app/administration/users/add-edit-user/add-edit-user.component.ts @@ -1,4 +1,4 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { DialogComponent, DialogService } from 'ng2-bootstrap-modal'; import { User } from 'app/models/user'; @@ -15,7 +15,9 @@ export interface DataModel { styleUrls: ['./add-edit-user.component.scss'] }) -export class AddEditUserComponent extends DialogComponent implements DataModel { +// NOTE: dialog components must not implement OnDestroy +// otherwise they don't return a result +export class AddEditUserComponent extends DialogComponent implements DataModel, OnInit { title: string; message: string; model: User; @@ -29,7 +31,6 @@ export class AddEditUserComponent extends DialogComponent im super(dialogService); } - // tslint:disable-next-line:use-life-cycle-interface ngOnInit() { // console.log("this.model:", this.user); // TODO: Current is simple method of assigning roles diff --git a/src/app/applications/application-add-edit/application-add-edit.component.ts b/src/app/applications/application-add-edit/application-add-edit.component.ts index f4eac19a..33c75e65 100644 --- a/src/app/applications/application-add-edit/application-add-edit.component.ts +++ b/src/app/applications/application-add-edit/application-add-edit.component.ts @@ -9,7 +9,7 @@ import * as moment from 'moment-timezone'; import * as _ from 'lodash'; import { Constants } from 'app/utils/constants'; -import { SelectOrganizationComponent } from '../select-organization/select-organization.component'; +import { SelectOrganizationComponent } from 'app/applications/select-organization/select-organization.component'; import { ConfirmComponent } from 'app/confirm/confirm.component'; import { Application } from 'app/models/application'; import { Document } from 'app/models/document'; @@ -187,11 +187,16 @@ export class ApplicationAddEditComponent implements OnInit, OnDestroy { backdropColor: 'rgba(0, 0, 0, 0.5)' }) .takeUntil(this.ngUnsubscribe) - .subscribe((clientString: string) => { - if (clientString) { - self.application.client = clientString; + .subscribe( + clientString => { + if (clientString && clientString.length > 0) { + self.application.client = clientString; + } + }, + error => { + console.log('error =', error); } - }); + ); } saveApplication() { diff --git a/src/app/applications/select-organization/select-organization.component.ts b/src/app/applications/select-organization/select-organization.component.ts index 183ef9e3..1ca49ba4 100644 --- a/src/app/applications/select-organization/select-organization.component.ts +++ b/src/app/applications/select-organization/select-organization.component.ts @@ -1,15 +1,13 @@ import { Component, OnInit } from '@angular/core'; import { DialogComponent, DialogService } from 'ng2-bootstrap-modal'; import { Router, ActivatedRoute } from '@angular/router'; -import { OrganizationService } from 'app/services/organization.service'; +import * as _ from 'lodash'; + import { SearchService } from 'app/services/search.service'; -import { Organization } from 'app/models/organization'; import { Client } from 'app/models/client'; -import * as _ from 'lodash'; export interface DataModel { dispositionId: number; - interestedPartyId: number; } @Component({ @@ -17,41 +15,21 @@ export interface DataModel { templateUrl: './select-organization.component.html', styleUrls: ['./select-organization.component.scss'] }) + +// NOTE: dialog components must not implement OnDestroy +// otherwise they don't return a result export class SelectOrganizationComponent extends DialogComponent implements DataModel, OnInit { - public dispositionId: number; - public interestedPartyId: number; - public clients: Client[] = []; - public selectedClients: string[]; + public dispositionId: number = null; + public clients: Array = []; + public selectedClients: Array = []; public page = 1; - public selectedOrg: Organization = null; constructor( public dialogService: DialogService, private router: Router, - private orgService: OrganizationService, private searchService: SearchService ) { super(dialogService); - this.selectedClients = []; - } - - toggleClient(client) { - if (this.isClientSelected(client)) { - _.remove(this.selectedClients, client); - } else { - this.selectedClients.push(client); - } - } - - isClientSelected(client) { - const foundClient = _.find(this.selectedClients, function (c) { - return (c === client); - }); - if (foundClient) { - return true; - } else { - return false; - } } ngOnInit() { @@ -61,19 +39,35 @@ export class SelectOrganizationComponent extends DialogComponent { _.each(data, function (i) { self.clients.push(new Client(i)); - // Pre-select the existing org if it's in the list + // Pre-select the existing clients if they're in the list // if (i._id === self.dispositionId) { - // self.selectedOrg = i; + // self.selectedClients = i; // } }); }, error => { // if 403, redir to login page if (error.startsWith('403')) { this.router.navigate(['/login']); } - alert('Error loading users'); + alert('Error loading clients'); }); } + toggleClient(client: Client) { + if (this.isClientSelected(client)) { + _.remove(this.selectedClients, client); + } else { + this.selectedClients.push(client); + } + } + + isClientSelected(client: Client): boolean { + // TODO: this should be debounced as it's called a lot! (mouse over clickable row to see this) + const foundClient = _.find(this.selectedClients, function (c) { + return (c === client); + }); + return foundClient ? true : false; + } + save() { let res = ''; _.each(this.selectedClients, function (client) { @@ -88,9 +82,8 @@ export class SelectOrganizationComponent extends DialogComponent implements DataModel { +// NOTE: dialog components must not implement OnDestroy +// otherwise they don't return a result +export class AddEditCommentPeriodComponent extends DialogComponent implements DataModel, OnInit { public title: string; public message: string; public commentPeriod: CommentPeriod; @@ -38,7 +40,6 @@ export class AddEditCommentPeriodComponent extends DialogComponent { + .subscribe(result => { if (result) { // HACK: refresh UI because template item isn't being refreshed otherwise this.refreshUI(); @@ -137,7 +137,7 @@ export class ManageCommentPeriodsComponent implements OnInit, OnDestroy { backdropColor: 'rgba(0, 0, 0, 0.5)' }) .takeUntil(this.ngUnsubscribe) - .subscribe((result: boolean) => { + .subscribe(result => { if (result) { // HACK: refresh UI because template item isn't being refreshed otherwise this.refreshUI(); diff --git a/src/app/commenting/review-comments/add-comment/add-comment.component.ts b/src/app/commenting/review-comments/add-comment/add-comment.component.ts index eb0d8514..20d87930 100644 --- a/src/app/commenting/review-comments/add-comment/add-comment.component.ts +++ b/src/app/commenting/review-comments/add-comment/add-comment.component.ts @@ -1,4 +1,4 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { NgbDateStruct } from '@ng-bootstrap/ng-bootstrap'; import { DialogComponent, DialogService } from 'ng2-bootstrap-modal'; @@ -16,7 +16,9 @@ export interface DataModel { styleUrls: ['./add-comment.component.scss'] }) -export class AddCommentComponent extends DialogComponent implements DataModel { +// NOTE: dialog components must not implement OnDestroy +// otherwise they don't return a result +export class AddCommentComponent extends DialogComponent implements DataModel, OnInit { public title: string; public message: string; public periodId: string; @@ -33,7 +35,6 @@ export class AddCommentComponent extends DialogComponent imp this.showAlert = false; } - // tslint:disable-next-line:use-life-cycle-interface ngOnInit() { console.log('period id=', this.periodId); } diff --git a/src/app/services/application.service.ts b/src/app/services/application.service.ts index eb2cb9bd..33c9a532 100644 --- a/src/app/services/application.service.ts +++ b/src/app/services/application.service.ts @@ -200,16 +200,23 @@ export class ApplicationService { .catch(this.api.handleError); } + // create new application + // mandatory fields: + // - disp ID (and related data) + // - description + // - client addApplication(item: any): Observable { + const app = this.sanitizeApplication(item); + // replace newlines with \\n (JSON format) - if (item.description) { - item.description = item.description.replace(/\n/g, '\\n'); + if (app.description) { + app.description = app.description.replace(/\n/g, '\\n'); } - if (item.legalDescription) { - item.legalDescription = item.legalDescription.replace(/\n/g, '\\n'); + if (app.legalDescription) { + app.legalDescription = app.legalDescription.replace(/\n/g, '\\n'); } - return this.api.addApplication(this.sanitizeApplication(item)) + return this.api.addApplication(app) .map(res => { const application = res.text() ? res.json() : []; return new Application(application); @@ -257,17 +264,17 @@ export class ApplicationService { save(orig: Application): Observable { // make a (deep) copy of the passed-in application so we don't change it - const application = _.cloneDeep(orig); + const app = _.cloneDeep(orig); // replace newlines with \\n (JSON format) - if (application.description) { - application.description = application.description.replace(/\n/g, '\\n'); + if (app.description) { + app.description = app.description.replace(/\n/g, '\\n'); } - if (application.legalDescription) { - application.legalDescription = application.legalDescription.replace(/\n/g, '\\n'); + if (app.legalDescription) { + app.legalDescription = app.legalDescription.replace(/\n/g, '\\n'); } - return this.api.saveApplication(application) + return this.api.saveApplication(app) .map(res => { const a = res.text() ? res.json() : null; return a ? new Application(a) : null; diff --git a/src/app/services/commentperiod.service.ts b/src/app/services/commentperiod.service.ts index 067c28f0..23bdb5c7 100644 --- a/src/app/services/commentperiod.service.ts +++ b/src/app/services/commentperiod.service.ts @@ -12,7 +12,7 @@ import { CommentPeriod } from 'app/models/commentperiod'; @Injectable() export class CommentPeriodService { private commentPeriod: CommentPeriod = null; - commentStatuses = {}; + public commentStatuses = {}; constructor(private api: ApiService) { this.commentStatuses['NOT STARTED'] = 'Commenting Not Started'; diff --git a/src/app/services/search.service.ts b/src/app/services/search.service.ts index 96dff492..ec55ba7a 100644 --- a/src/app/services/search.service.ts +++ b/src/app/services/search.service.ts @@ -11,9 +11,9 @@ import { Client } from 'app/models/client'; @Injectable() export class SearchService { + private clients: Array = null; private search: Search = null; - private features: Feature[] = null; - private clients: Client[] = null; + private features: Array = null; constructor(private api: ApiService) { } diff --git a/src/tsconfig.spec.json b/src/tsconfig.spec.json index cd5bc679..e4cbe0c0 100644 --- a/src/tsconfig.spec.json +++ b/src/tsconfig.spec.json @@ -18,4 +18,4 @@ "**/*.spec.ts", "**/*.d.ts" ] -} +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index a35a8ee3..07938ce7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,4 +17,4 @@ "dom" ] } -} +} \ No newline at end of file diff --git a/tslint.json b/tslint.json index a320bb54..82cc690e 100644 --- a/tslint.json +++ b/tslint.json @@ -12,7 +12,10 @@ "curly": true, "eofline": true, "forin": true, - "import-blacklist": [true, "rxjs"], + "import-blacklist": [ + true, + "rxjs" + ], "import-spacing": true, "indent": [ true, @@ -46,7 +49,10 @@ "no-empty": false, "no-empty-interface": true, "no-eval": true, - "no-inferrable-types": [true, "ignore-params"], + "no-inferrable-types": [ + true, + "ignore-params" + ], "no-shadowed-variable": true, "no-string-literal": false, "no-string-throw": true, @@ -97,9 +103,18 @@ "check-separator", "check-type" ], - - "directive-selector": [true, "attribute", "app", "camelCase"], - "component-selector": [true, "element", "app", "kebab-case"], + "directive-selector": [ + true, + "attribute", + "app", + "camelCase" + ], + "component-selector": [ + true, + "element", + "app", + "kebab-case" + ], "use-input-property-decorator": true, "use-output-property-decorator": true, "use-host-property-decorator": true, @@ -113,4 +128,4 @@ "templates-use-public": true, "invoke-injectable": true } -} +} \ No newline at end of file