From 5aa9e72ab02b05eee02d2b78f20e6a8d68ee1ade Mon Sep 17 00:00:00 2001 From: "Maxence G. de Montauzan" Date: Sat, 2 Jun 2018 15:47:01 +0200 Subject: [PATCH] Update to Angular 6 Fix little bug on last added query --- dashboard/.angular-cli.json | 61 -------------- dashboard/angular.json | 134 +++++++++++++++++++++++++++++++ dashboard/karma.conf.js | 6 +- dashboard/package.json | 31 +++---- dashboard/src/app/els.service.ts | 75 +++++++++++------ dashboard/src/tsconfig.spec.json | 3 +- dashboard/tslint.json | 3 +- 7 files changed, 206 insertions(+), 107 deletions(-) delete mode 100644 dashboard/.angular-cli.json create mode 100644 dashboard/angular.json diff --git a/dashboard/.angular-cli.json b/dashboard/.angular-cli.json deleted file mode 100644 index 588d53d..0000000 --- a/dashboard/.angular-cli.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "$schema": "./node_modules/@angular/cli/lib/config/schema.json", - "project": { - "name": "dashboard" - }, - "apps": [ - { - "root": "src", - "outDir": "dist", - "assets": [ - "assets", - "favicon.ico" - ], - "index": "index.html", - "main": "main.ts", - "polyfills": "polyfills.ts", - "test": "test.ts", - "tsconfig": "tsconfig.app.json", - "testTsconfig": "tsconfig.spec.json", - "prefix": "app", - "styles": [ - "styles.css", - "../node_modules/bootstrap/dist/css/bootstrap.min.css" - ], - "scripts": [], - "environmentSource": "environments/environment.ts", - "environments": { - "dev": "environments/environment.ts", - "prod": "environments/environment.prod.ts" - } - } - ], - "e2e": { - "protractor": { - "config": "./protractor.conf.js" - } - }, - "lint": [ - { - "project": "src/tsconfig.app.json", - "exclude": "**/node_modules/**" - }, - { - "project": "src/tsconfig.spec.json", - "exclude": "**/node_modules/**" - }, - { - "project": "e2e/tsconfig.e2e.json", - "exclude": "**/node_modules/**" - } - ], - "test": { - "karma": { - "config": "./karma.conf.js" - } - }, - "defaults": { - "styleExt": "css", - "component": {} - } -} diff --git a/dashboard/angular.json b/dashboard/angular.json new file mode 100644 index 0000000..f887234 --- /dev/null +++ b/dashboard/angular.json @@ -0,0 +1,134 @@ +{ + "$schema": "./node_modules/@angular/cli/lib/config/schema.json", + "version": 1, + "newProjectRoot": "projects", + "projects": { + "dashboard": { + "root": "", + "sourceRoot": "src", + "projectType": "application", + "architect": { + "build": { + "builder": "@angular-devkit/build-angular:browser", + "options": { + "outputPath": "dist", + "index": "src/index.html", + "main": "src/main.ts", + "tsConfig": "src/tsconfig.app.json", + "polyfills": "src/polyfills.ts", + "assets": [ + "src/assets", + "src/favicon.ico" + ], + "styles": [ + "src/styles.css", + "node_modules/bootstrap/dist/css/bootstrap.min.css" + ], + "scripts": [] + }, + "configurations": { + "production": { + "optimization": true, + "outputHashing": "all", + "sourceMap": false, + "extractCss": true, + "namedChunks": false, + "aot": true, + "extractLicenses": true, + "vendorChunk": false, + "buildOptimizer": true, + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.prod.ts" + } + ] + } + } + }, + "serve": { + "builder": "@angular-devkit/build-angular:dev-server", + "options": { + "browserTarget": "dashboard:build" + }, + "configurations": { + "production": { + "browserTarget": "dashboard:build:production" + } + } + }, + "extract-i18n": { + "builder": "@angular-devkit/build-angular:extract-i18n", + "options": { + "browserTarget": "dashboard:build" + } + }, + "test": { + "builder": "@angular-devkit/build-angular:karma", + "options": { + "main": "src/test.ts", + "karmaConfig": "./karma.conf.js", + "polyfills": "src/polyfills.ts", + "tsConfig": "src/tsconfig.spec.json", + "scripts": [], + "styles": [ + "src/styles.css", + "node_modules/bootstrap/dist/css/bootstrap.min.css" + ], + "assets": [ + "src/assets", + "src/favicon.ico" + ] + } + }, + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "src/tsconfig.app.json", + "src/tsconfig.spec.json" + ], + "exclude": [ + "**/node_modules/**" + ] + } + } + } + }, + "dashboard-e2e": { + "root": "", + "sourceRoot": "", + "projectType": "application", + "architect": { + "e2e": { + "builder": "@angular-devkit/build-angular:protractor", + "options": { + "protractorConfig": "./protractor.conf.js", + "devServerTarget": "dashboard:serve" + } + }, + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "e2e/tsconfig.e2e.json" + ], + "exclude": [ + "**/node_modules/**" + ] + } + } + } + } + }, + "defaultProject": "dashboard", + "schematics": { + "@schematics/angular:component": { + "prefix": "app", + "styleext": "css" + }, + "@schematics/angular:directive": { + "prefix": "app" + } + } +} \ No newline at end of file diff --git a/dashboard/karma.conf.js b/dashboard/karma.conf.js index af139fa..84af9d1 100644 --- a/dashboard/karma.conf.js +++ b/dashboard/karma.conf.js @@ -4,19 +4,19 @@ module.exports = function (config) { config.set({ basePath: '', - frameworks: ['jasmine', '@angular/cli'], + frameworks: ['jasmine', '@angular-devkit/build-angular'], plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), require('karma-jasmine-html-reporter'), require('karma-coverage-istanbul-reporter'), - require('@angular/cli/plugins/karma') + require('@angular-devkit/build-angular/plugins/karma') ], client:{ clearContext: false // leave Jasmine Spec Runner output visible in browser }, coverageIstanbulReporter: { - reports: [ 'html', 'lcovonly' ], + dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ], fixWebpackSourcePaths: true }, angularCli: { diff --git a/dashboard/package.json b/dashboard/package.json index 18aa359..95c6964 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -12,24 +12,24 @@ }, "private": true, "dependencies": { - "@angular/animations": "5.2.9", - "@angular/common": "5.2.9", - "@angular/compiler": "5.2.9", - "@angular/core": "5.2.9", - "@angular/forms": "5.2.9", - "@angular/http": "5.2.9", - "@angular/platform-browser": "5.2.9", - "@angular/platform-browser-dynamic": "5.2.9", - "@angular/router": "5.2.9", + "@angular/animations": "6.0.3", + "@angular/common": "6.0.3", + "@angular/compiler": "6.0.3", + "@angular/core": "6.0.3", + "@angular/forms": "6.0.3", + "@angular/http": "6.0.3", + "@angular/platform-browser": "6.0.3", + "@angular/platform-browser-dynamic": "6.0.3", + "@angular/router": "6.0.3", "core-js": "^2.4.1", - "rxjs": "^5.5.7", - "zone.js": "^0.8.20", + "rxjs": "^6.2.0", + "zone.js": "^0.8.26", "bootstrap": "3.3.7" }, "devDependencies": { - "@angular/cli": "1.7.3", - "@angular/compiler-cli": "5.2.9", - "@angular/language-service": "5.2.9", + "@angular/cli": "^6.0.7", + "@angular/compiler-cli": "6.0.3", + "@angular/language-service": "6.0.3", "@types/jasmine": "~2.5.53", "@types/jasminewd2": "~2.0.2", "@types/node": "~6.0.60", @@ -45,6 +45,7 @@ "protractor": "~5.1.2", "ts-node": "~3.2.0", "tslint": "~5.3.2", - "typescript": "2.6.2" + "typescript": "2.7.2", + "@angular-devkit/build-angular": "~0.6.6" } } diff --git a/dashboard/src/app/els.service.ts b/dashboard/src/app/els.service.ts index 1ebb046..b633f04 100644 --- a/dashboard/src/app/els.service.ts +++ b/dashboard/src/app/els.service.ts @@ -1,9 +1,8 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http' -import { Observable } from 'rxjs/Observable'; -import 'rxjs/add/operator/toPromise'; -import 'rxjs/add/operator/map'; +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; import { Song } from './model/song'; import { Album } from './model/album'; @@ -111,7 +110,9 @@ export class ElsService { } ], 'size': 5 }), {headers: this.headers}) - .map(res => this.responseToSongs(res)); + .pipe( + map(res => this.responseToSongs(res)) + ); } /** @@ -146,7 +147,9 @@ export class ElsService { } ] }), {headers: this.headers}) - .map(res => this.responseToAlbums(res)); + .pipe( + map(res => this.responseToAlbums(res)) + ); } getMostPlayedArtistNaive(): Promise { @@ -175,7 +178,9 @@ export class ElsService { ], 'size': 100 }), {headers: this.headers}) - .map(res => this.responseToArtists(res)); + .pipe( + map(res => this.responseToArtists(res)) + ); } getAlbumSongs(albumName: string, from: number = 0): Observable { @@ -189,7 +194,9 @@ export class ElsService { 'size': ElsService.DEFAULT_SIZE, 'from': from }), {headers: this.headers}) - .map(res => this.responseToSongs(res)); + .pipe( + map(res => this.responseToSongs(res)) + ); } getGenreSongs(genreName: string, from: number = 0): Observable { @@ -204,7 +211,9 @@ export class ElsService { 'size': ElsService.DEFAULT_SIZE, 'from': from }), {headers: this.headers}) - .map(res => this.responseToSongs(res)); + .pipe( + map(res => this.responseToSongs(res)) + ); } getArtistSongs(artistName: string, from: number = 0): Observable { @@ -223,7 +232,9 @@ export class ElsService { 'size': ElsService.DEFAULT_SIZE, 'from': from }), {headers: this.headers}) - .map(res => this.responseToSongs(res)); + .pipe( + map(res => this.responseToSongs(res)) + ); } getAlbum(albumName: string): Observable { @@ -235,7 +246,9 @@ export class ElsService { }, 'size': ElsService.DEFAULT_SIZE }), {headers: this.headers}) - .map(res => this.responseToOneTypedResult(res, albumName)); + .pipe( + map(res => this.responseToOneTypedResult(res, albumName)) + ); } getArtist(artistName: string): Observable { @@ -247,7 +260,9 @@ export class ElsService { }, 'size': ElsService.DEFAULT_SIZE }), {headers: this.headers}) - .map(res => this.responseToOneTypedResult(res, artistName)); + .pipe( + map(res => this.responseToOneTypedResult(res, artistName)) + ); } getGenres(ordering: string = 'desc'): Observable { @@ -266,7 +281,9 @@ export class ElsService { }, 'size': 0 }), {headers: this.headers}) - .map(res => this.responseAggregationToBucket(res, 'genres')); + .pipe( + map(res => this.responseAggregationToBucket(res, 'genres')) + ); } getGenreCount(): Observable { @@ -283,7 +300,9 @@ export class ElsService { }, 'size': 0 }), {headers: this.headers}) - .map(res => res.aggregations.genres.value); + .pipe( + map(res => res.aggregations.genres.value) + ); } getLastAddedAlbums(month: number): Observable { @@ -293,7 +312,7 @@ export class ElsService { 'query': { 'range' : { 'Date Added' : { - 'gte' : 'now-3M/d', + 'gte' : 'now-' + month + 'M/d', 'lte' : 'now/d' } } @@ -316,7 +335,9 @@ export class ElsService { } } }), {headers: this.headers}) - .map(res => this.responseSubAggregationToBucket(res, 'date')); + .pipe( + map(res => this.responseSubAggregationToBucket(res, 'date')) + ); // TODO Take in consideration "sum_other_doc_count" } @@ -330,15 +351,17 @@ export class ElsService { } } }), {headers: this.headers}) - .map(res => res.hits.hits) - .map((hits: Array) => { - // TODO Use a method (duplicated code ?) - const result: Array = []; - hits.forEach((hit) => { - result.push(hit._source); - }); - return result; - }); + .pipe( + map(res => res.hits.hits), + map((hits: Array) => { + // TODO Use a method (duplicated code ?) + const result: Array = []; + hits.forEach((hit) => { + result.push(hit._source); + }); + return result; + }) + ); } getCountArtistSong(artistName: string): Observable { @@ -355,7 +378,9 @@ export class ElsService { } } }), {headers: this.headers}) - .map(res => res.count as number); + .pipe( + map(res => res.count as number) + ); } /** Process a result to return just one result. diff --git a/dashboard/src/tsconfig.spec.json b/dashboard/src/tsconfig.spec.json index 63d89ff..18bad40 100644 --- a/dashboard/src/tsconfig.spec.json +++ b/dashboard/src/tsconfig.spec.json @@ -11,7 +11,8 @@ ] }, "files": [ - "test.ts" + "test.ts", + "polyfills.ts" ], "include": [ "**/*.spec.ts", diff --git a/dashboard/tslint.json b/dashboard/tslint.json index cb76b40..c62d562 100644 --- a/dashboard/tslint.json +++ b/dashboard/tslint.json @@ -14,8 +14,7 @@ "eofline": true, "forin": true, "import-blacklist": [ - true, - "rxjs" + true ], "import-spacing": true, "indent": [