Compare commits
42 Commits
fix-els7-w
...
feature/im
| Author | SHA1 | Date | |
|---|---|---|---|
| 95534c92b2 | |||
| 0230bf260b | |||
| 928efb659e | |||
| 88025347ec | |||
| 67e1f8bd0c | |||
| 042c2558ae | |||
| ad0487943a | |||
| 56050d0a49 | |||
| bb51af68cd | |||
| 5ee9781463 | |||
| 00a5427950 | |||
| fada5f475b | |||
| d307012aca | |||
| 755f5e5c24 | |||
| f40ee2b6d2 | |||
| d011d5738f | |||
| e5de38b9d9 | |||
| f37ce410eb | |||
| 124a30ad8c | |||
| 52a0cde401 | |||
| 5fbcfbae68 | |||
| 74c6f99fa5 | |||
| 60e1fb2e74 | |||
| 520d0be595 | |||
| 8121f3d751 | |||
| 436edaf3f2 | |||
| 797c88f946 | |||
| 1f427749cf | |||
| 153ca835cb | |||
| 8e79bee1c4 | |||
| 66dc29be92 | |||
| fb620f582f | |||
| 57e1c18a7f | |||
| 050270e890 | |||
| 541fd96a45 | |||
| 93272d5894 | |||
| 7e6cc36750 | |||
| 285ab197e8 | |||
| c92fb73e91 | |||
| 748e3b8c38 | |||
| d2cca5107b | |||
| 9b522866ea |
27
dashboard/README.md
Normal file
27
dashboard/README.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Dashboard
|
||||||
|
|
||||||
|
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.0.4.
|
||||||
|
|
||||||
|
## Development server
|
||||||
|
|
||||||
|
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
|
||||||
|
|
||||||
|
## Code scaffolding
|
||||||
|
|
||||||
|
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
|
||||||
|
|
||||||
|
## Running unit tests
|
||||||
|
|
||||||
|
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
||||||
|
|
||||||
|
## Running end-to-end tests
|
||||||
|
|
||||||
|
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
|
||||||
|
|
||||||
|
## Further help
|
||||||
|
|
||||||
|
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
||||||
@@ -4,17 +4,19 @@
|
|||||||
"newProjectRoot": "projects",
|
"newProjectRoot": "projects",
|
||||||
"projects": {
|
"projects": {
|
||||||
"dashboard": {
|
"dashboard": {
|
||||||
|
"projectType": "application",
|
||||||
|
"schematics": {},
|
||||||
"root": "",
|
"root": "",
|
||||||
"sourceRoot": "src",
|
"sourceRoot": "src",
|
||||||
"projectType": "application",
|
"prefix": "app",
|
||||||
"architect": {
|
"architect": {
|
||||||
"build": {
|
"build": {
|
||||||
"builder": "@angular-devkit/build-angular:browser",
|
"builder": "@angular-devkit/build-angular:browser",
|
||||||
"options": {
|
"options": {
|
||||||
"outputPath": "dist",
|
"outputPath": "dist/dashboard",
|
||||||
"index": "src/index.html",
|
"index": "src/index.html",
|
||||||
"main": "src/main.ts",
|
"main": "src/main.ts",
|
||||||
"tsConfig": "src/tsconfig.app.json",
|
"tsConfig": "tsconfig.app.json",
|
||||||
"polyfills": "src/polyfills.ts",
|
"polyfills": "src/polyfills.ts",
|
||||||
"assets": [
|
"assets": [
|
||||||
"src/assets",
|
"src/assets",
|
||||||
@@ -24,27 +26,44 @@
|
|||||||
"src/styles.css",
|
"src/styles.css",
|
||||||
"node_modules/bootstrap/dist/css/bootstrap.min.css"
|
"node_modules/bootstrap/dist/css/bootstrap.min.css"
|
||||||
],
|
],
|
||||||
"scripts": []
|
"scripts": [],
|
||||||
|
"vendorChunk": true,
|
||||||
|
"extractLicenses": false,
|
||||||
|
"buildOptimizer": false,
|
||||||
|
"sourceMap": true,
|
||||||
|
"optimization": false,
|
||||||
|
"namedChunks": true
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
"optimization": true,
|
|
||||||
"outputHashing": "all",
|
|
||||||
"sourceMap": false,
|
|
||||||
"extractCss": true,
|
|
||||||
"namedChunks": false,
|
|
||||||
"aot": true,
|
|
||||||
"extractLicenses": true,
|
|
||||||
"vendorChunk": false,
|
|
||||||
"buildOptimizer": true,
|
|
||||||
"fileReplacements": [
|
"fileReplacements": [
|
||||||
{
|
{
|
||||||
"replace": "src/environments/environment.ts",
|
"replace": "src/environments/environment.ts",
|
||||||
"with": "src/environments/environment.prod.ts"
|
"with": "src/environments/environment.prod.ts"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"optimization": true,
|
||||||
|
"outputHashing": "all",
|
||||||
|
"sourceMap": false,
|
||||||
|
"namedChunks": false,
|
||||||
|
"extractLicenses": true,
|
||||||
|
"vendorChunk": false,
|
||||||
|
"buildOptimizer": true,
|
||||||
|
"budgets": [
|
||||||
|
{
|
||||||
|
"type": "initial",
|
||||||
|
"maximumWarning": "2mb",
|
||||||
|
"maximumError": "5mb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "anyComponentStyle",
|
||||||
|
"maximumWarning": "6kb",
|
||||||
|
"maximumError": "10kb"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"defaultConfiguration": ""
|
||||||
},
|
},
|
||||||
"serve": {
|
"serve": {
|
||||||
"builder": "@angular-devkit/build-angular:dev-server",
|
"builder": "@angular-devkit/build-angular:dev-server",
|
||||||
@@ -67,68 +86,47 @@
|
|||||||
"builder": "@angular-devkit/build-angular:karma",
|
"builder": "@angular-devkit/build-angular:karma",
|
||||||
"options": {
|
"options": {
|
||||||
"main": "src/test.ts",
|
"main": "src/test.ts",
|
||||||
"karmaConfig": "./karma.conf.js",
|
|
||||||
"polyfills": "src/polyfills.ts",
|
"polyfills": "src/polyfills.ts",
|
||||||
"tsConfig": "src/tsconfig.spec.json",
|
"tsConfig": "tsconfig.spec.json",
|
||||||
"scripts": [],
|
"karmaConfig": "karma.conf.js",
|
||||||
|
"assets": [
|
||||||
|
"src/assets",
|
||||||
|
"src/favicon.ico"
|
||||||
|
],
|
||||||
"styles": [
|
"styles": [
|
||||||
"src/styles.css",
|
"src/styles.css",
|
||||||
"node_modules/bootstrap/dist/css/bootstrap.min.css"
|
"node_modules/bootstrap/dist/css/bootstrap.min.css"
|
||||||
],
|
],
|
||||||
"assets": [
|
"scripts": []
|
||||||
"src/assets",
|
|
||||||
"src/favicon.ico"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"lint": {
|
"lint": {
|
||||||
"builder": "@angular-devkit/build-angular:tslint",
|
"builder": "@angular-devkit/build-angular:tslint",
|
||||||
"options": {
|
"options": {
|
||||||
"tsConfig": [
|
"tsConfig": [
|
||||||
"src/tsconfig.app.json",
|
"tsconfig.app.json",
|
||||||
"src/tsconfig.spec.json"
|
"tsconfig.spec.json",
|
||||||
|
"e2e/tsconfig.json"
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"**/node_modules/**"
|
"**/node_modules/**"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
},
|
|
||||||
"dashboard-e2e": {
|
|
||||||
"root": "",
|
|
||||||
"sourceRoot": "",
|
|
||||||
"projectType": "application",
|
|
||||||
"architect": {
|
|
||||||
"e2e": {
|
"e2e": {
|
||||||
"builder": "@angular-devkit/build-angular:protractor",
|
"builder": "@angular-devkit/build-angular:protractor",
|
||||||
"options": {
|
"options": {
|
||||||
"protractorConfig": "./protractor.conf.js",
|
"protractorConfig": "e2e/protractor.conf.js",
|
||||||
"devServerTarget": "dashboard:serve"
|
"devServerTarget": "dashboard:serve"
|
||||||
}
|
},
|
||||||
},
|
"configurations": {
|
||||||
"lint": {
|
"production": {
|
||||||
"builder": "@angular-devkit/build-angular:tslint",
|
"devServerTarget": "dashboard:serve:production"
|
||||||
"options": {
|
}
|
||||||
"tsConfig": [
|
|
||||||
"e2e/tsconfig.e2e.json"
|
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"**/node_modules/**"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"defaultProject": "dashboard",
|
"defaultProject": "dashboard"
|
||||||
"schematics": {
|
}
|
||||||
"@schematics/angular:component": {
|
|
||||||
"prefix": "app",
|
|
||||||
"styleext": "css"
|
|
||||||
},
|
|
||||||
"@schematics/angular:directive": {
|
|
||||||
"prefix": "app"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
import { AppPage } from './app.po';
|
|
||||||
|
|
||||||
describe('dashboard App', () => {
|
|
||||||
let page: AppPage;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
page = new AppPage();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should display welcome message', () => {
|
|
||||||
page.navigateTo();
|
|
||||||
expect(page.getParagraphText()).toEqual('Welcome to app!');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { browser, by, element } from 'protractor';
|
|
||||||
|
|
||||||
export class AppPage {
|
|
||||||
navigateTo() {
|
|
||||||
return browser.get('/');
|
|
||||||
}
|
|
||||||
|
|
||||||
getParagraphText() {
|
|
||||||
return element(by.css('app-root h1')).getText();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
23
dashboard/e2e/src/app.e2e-spec.ts
Normal file
23
dashboard/e2e/src/app.e2e-spec.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { AppPage } from './app.po';
|
||||||
|
import { browser, logging } from 'protractor';
|
||||||
|
|
||||||
|
describe('workspace-project App', () => {
|
||||||
|
let page: AppPage;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
page = new AppPage();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should display welcome message', async () => {
|
||||||
|
await page.navigateTo();
|
||||||
|
expect(await page.getTitleText()).toEqual('dashboard app is running!');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
// Assert that there are no errors emitted from the browser
|
||||||
|
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
|
||||||
|
expect(logs).not.toContain(jasmine.objectContaining({
|
||||||
|
level: logging.Level.SEVERE,
|
||||||
|
} as logging.Entry));
|
||||||
|
});
|
||||||
|
});
|
||||||
11
dashboard/e2e/src/app.po.ts
Normal file
11
dashboard/e2e/src/app.po.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { browser, by, element } from 'protractor';
|
||||||
|
|
||||||
|
export class AppPage {
|
||||||
|
async navigateTo(): Promise<unknown> {
|
||||||
|
return browser.get(browser.baseUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getTitleText(): Promise<string> {
|
||||||
|
return element(by.css('app-root .content span')).getText();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
|
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||||
{
|
{
|
||||||
"extends": "../tsconfig.json",
|
"extends": "../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "../out-tsc/e2e",
|
"outDir": "../out-tsc/e2e",
|
||||||
"baseUrl": "./",
|
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"target": "es5",
|
"target": "es2018",
|
||||||
"types": [
|
"types": [
|
||||||
"jasmine",
|
"jasmine",
|
||||||
"jasminewd2",
|
|
||||||
"node"
|
"node"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -9,18 +9,28 @@ module.exports = function (config) {
|
|||||||
require('karma-jasmine'),
|
require('karma-jasmine'),
|
||||||
require('karma-chrome-launcher'),
|
require('karma-chrome-launcher'),
|
||||||
require('karma-jasmine-html-reporter'),
|
require('karma-jasmine-html-reporter'),
|
||||||
require('karma-coverage-istanbul-reporter'),
|
require('karma-coverage'),
|
||||||
require('@angular-devkit/build-angular/plugins/karma')
|
require('@angular-devkit/build-angular/plugins/karma')
|
||||||
],
|
],
|
||||||
client:{
|
client: {
|
||||||
|
jasmine: {
|
||||||
|
// you can add configuration options for Jasmine here
|
||||||
|
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
|
||||||
|
// for example, you can disable the random execution with `random: false`
|
||||||
|
// or set a specific seed with `seed: 4321`
|
||||||
|
},
|
||||||
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
||||||
},
|
},
|
||||||
coverageIstanbulReporter: {
|
jasmineHtmlReporter: {
|
||||||
dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ],
|
suppressAll: true // removes the duplicated traces
|
||||||
fixWebpackSourcePaths: true
|
|
||||||
},
|
},
|
||||||
angularCli: {
|
coverageReporter: {
|
||||||
environment: 'dev'
|
dir: require('path').join(__dirname, './coverage/dashboard'),
|
||||||
|
subdir: '.',
|
||||||
|
reporters: [
|
||||||
|
{ type: 'html' },
|
||||||
|
{ type: 'text-summary' }
|
||||||
|
]
|
||||||
},
|
},
|
||||||
reporters: ['progress', 'kjhtml'],
|
reporters: ['progress', 'kjhtml'],
|
||||||
port: 9876,
|
port: 9876,
|
||||||
@@ -28,6 +38,7 @@ module.exports = function (config) {
|
|||||||
logLevel: config.LOG_INFO,
|
logLevel: config.LOG_INFO,
|
||||||
autoWatch: true,
|
autoWatch: true,
|
||||||
browsers: ['Chrome'],
|
browsers: ['Chrome'],
|
||||||
singleRun: false
|
singleRun: false,
|
||||||
|
restartOnFileChange: true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
40022
dashboard/package-lock.json
generated
40022
dashboard/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dashboard",
|
"name": "dashboard",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"license": "MIT",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "ng serve",
|
"start": "ng serve",
|
||||||
@@ -12,40 +11,39 @@
|
|||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/animations": "6.0.3",
|
"@angular/animations": "~12.2.2",
|
||||||
"@angular/common": "6.0.3",
|
"@angular/common": "~12.2.2",
|
||||||
"@angular/compiler": "6.0.3",
|
"@angular/compiler": "~12.2.2",
|
||||||
"@angular/core": "6.0.3",
|
"@angular/core": "~12.2.2",
|
||||||
"@angular/forms": "6.0.3",
|
"@angular/forms": "~12.2.2",
|
||||||
"@angular/http": "6.0.3",
|
"@angular/localize": "~12.2.2",
|
||||||
"@angular/platform-browser": "6.0.3",
|
"@angular/platform-browser": "~12.2.2",
|
||||||
"@angular/platform-browser-dynamic": "6.0.3",
|
"@angular/platform-browser-dynamic": "~12.2.2",
|
||||||
"@angular/router": "6.0.3",
|
"@angular/router": "~12.2.2",
|
||||||
"core-js": "^2.4.1",
|
"@ng-bootstrap/ng-bootstrap": "^10.0.0",
|
||||||
"rxjs": "^6.2.0",
|
"bootstrap": "^3.3.7",
|
||||||
"zone.js": "^0.8.26",
|
"rxjs": "~6.6.0",
|
||||||
"bootstrap": "3.3.7"
|
"tslib": "^2.0.0",
|
||||||
|
"zone.js": "~0.11.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular-devkit/build-angular": "~0.6.6",
|
"@angular-devkit/build-angular": "~12.2.2",
|
||||||
"@angular/cli": "^6.0.7",
|
"@angular/cli": "~12.2.2",
|
||||||
"@angular/compiler-cli": "6.0.3",
|
"@angular/compiler-cli": "~12.2.2",
|
||||||
"@angular/language-service": "6.0.3",
|
"@angular/localize": "^12.2.2",
|
||||||
"@types/jasmine": "~2.5.53",
|
"@types/jasmine": "~3.6.0",
|
||||||
"@types/jasminewd2": "~2.0.2",
|
"@types/node": "^12.11.1",
|
||||||
"@types/node": "~6.0.60",
|
"codelyzer": "^6.0.0",
|
||||||
"codelyzer": "~3.1.1",
|
"jasmine-core": "~3.6.0",
|
||||||
"jasmine-core": "~2.6.2",
|
"jasmine-spec-reporter": "~5.0.0",
|
||||||
"jasmine-spec-reporter": "~4.1.0",
|
"karma": "~6.3.4",
|
||||||
"karma": "^2.0.2",
|
"karma-chrome-launcher": "~3.1.0",
|
||||||
"karma-chrome-launcher": "~2.1.1",
|
"karma-coverage": "~2.0.3",
|
||||||
"karma-cli": "~1.0.1",
|
"karma-jasmine": "~4.0.0",
|
||||||
"karma-coverage-istanbul-reporter": "^1.2.1",
|
"karma-jasmine-html-reporter": "^1.5.0",
|
||||||
"karma-jasmine": "~1.1.0",
|
"protractor": "~7.0.0",
|
||||||
"karma-jasmine-html-reporter": "^0.2.2",
|
"ts-node": "~8.3.0",
|
||||||
"protractor": "^5.3.2",
|
"tslint": "~6.1.0",
|
||||||
"ts-node": "~3.2.0",
|
"typescript": "~4.3.5"
|
||||||
"tslint": "~5.3.2",
|
|
||||||
"typescript": "2.7.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
// Protractor configuration file, see link for more information
|
|
||||||
// https://github.com/angular/protractor/blob/master/lib/config.ts
|
|
||||||
|
|
||||||
const { SpecReporter } = require('jasmine-spec-reporter');
|
|
||||||
|
|
||||||
exports.config = {
|
|
||||||
allScriptsTimeout: 11000,
|
|
||||||
specs: [
|
|
||||||
'./e2e/**/*.e2e-spec.ts'
|
|
||||||
],
|
|
||||||
capabilities: {
|
|
||||||
'browserName': 'chrome'
|
|
||||||
},
|
|
||||||
directConnect: true,
|
|
||||||
baseUrl: 'http://localhost:4200/',
|
|
||||||
framework: 'jasmine',
|
|
||||||
jasmineNodeOpts: {
|
|
||||||
showColors: true,
|
|
||||||
defaultTimeoutInterval: 30000,
|
|
||||||
print: function() {}
|
|
||||||
},
|
|
||||||
onPrepare() {
|
|
||||||
require('ts-node').register({
|
|
||||||
project: 'e2e/tsconfig.e2e.json'
|
|
||||||
});
|
|
||||||
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
34
dashboard/src/app/albums/albums.component.css
Normal file
34
dashboard/src/app/albums/albums.component.css
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*** BOTTOM BUTTON PART ***/
|
||||||
|
/* Thank to https://codyhouse.co/gem/back-to-top/ */
|
||||||
|
.btn-top {
|
||||||
|
display: inline-block;
|
||||||
|
height: 40px;
|
||||||
|
width: 40px;
|
||||||
|
position: fixed;
|
||||||
|
bottom: 20px;
|
||||||
|
right: 20px;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
|
||||||
|
/* image replacement properties */
|
||||||
|
/*overflow: hidden;*/
|
||||||
|
/*text-indent: 100%;*/
|
||||||
|
/*white-space: nowrap;*/
|
||||||
|
/*background: rgba(232, 98, 86, 0.8);*/
|
||||||
|
/*background: #ff9000;*/
|
||||||
|
visibility: hidden;
|
||||||
|
opacity: 0;
|
||||||
|
-webkit-transition: opacity .3s 0s, visibility 0s .3s;
|
||||||
|
-moz-transition: opacity .3s 0s, visibility 0s .3s;
|
||||||
|
transition: opacity .3s 0s, visibility 0s .3s;
|
||||||
|
}
|
||||||
|
.btn-top.btn-top-is-visible, .no-touch .btn-top:hover {
|
||||||
|
-webkit-transition: opacity .3s 0s, visibility 0s 0s;
|
||||||
|
-moz-transition: opacity .3s 0s, visibility 0s 0s;
|
||||||
|
transition: opacity .3s 0s, visibility 0s 0s;
|
||||||
|
}
|
||||||
|
.btn-top.btn-top-is-visible {
|
||||||
|
/* the button becomes visible */
|
||||||
|
visibility: visible;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** END BOTTOM BUTTON PART ***/
|
||||||
74
dashboard/src/app/albums/albums.component.html
Normal file
74
dashboard/src/app/albums/albums.component.html
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<div class="container">
|
||||||
|
<h1>Albums - {{this.albums.length}}</h1>
|
||||||
|
|
||||||
|
<div class="col-md-12">
|
||||||
|
<table class="table table-striped" style="white-space: nowrap;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Album</th>
|
||||||
|
<th>Track Count</th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
<th>Artist/Album Artist</th>
|
||||||
|
<th>Avg Bit Rate (min)</th>
|
||||||
|
<th>Play Count</th>
|
||||||
|
<th>Rating</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr *ngFor="let album of albums">
|
||||||
|
<td>
|
||||||
|
<a [routerLink]="['/album', album.Album]">{{album.Album}}</a>
|
||||||
|
<span class="glyphicon glyphicon-remove-circle" style="cursor:pointer;color:red;" (click)="exlude('Album', album)"></span>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>{{album['Track Count']}}</td>
|
||||||
|
|
||||||
|
<ng-template [ngIf]="album['Album Artist']" [ngIfElse]="artistSection">
|
||||||
|
<td>
|
||||||
|
<span class="glyphicon glyphicon-ban-circle" style="cursor:pointer;color:red;" (click)="exlude('Album Artist', album)"></span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="glyphicon glyphicon-zoom-in" style="cursor:pointer;" (click)="select('Album Artist', album)"></span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a [routerLink]="['/artist', album['Album Artist']]">{{album['Album Artist']}}</a>
|
||||||
|
</td>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<ng-template #artistSection>
|
||||||
|
<td>
|
||||||
|
<span class="glyphicon glyphicon-ban-circle" style="cursor:pointer;color:red;" (click)="exlude('Artist', album)"></span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="glyphicon glyphicon-zoom-in" style="cursor:pointer;" (click)="select('Artist', album)"></span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a [routerLink]="['/artist', album.Artist[0]]">{{album.Artist}}</a>
|
||||||
|
</td>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
{{album['Avg Bit Rate']}}
|
||||||
|
<span *ngIf="album['Avg Bit Rate'] != album['Min Bit Rate']">({{album['Min Bit Rate']}})</span>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
{{album['Play Count']}} ({{album['Play Count']/album['Track Count'] | number:'1.0-0'}}/songs)
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td class="star" [title]="(album['Album Rating Computed']?'Computed Rating: ':'Rating: ') + album['Album Rating']">
|
||||||
|
<span *ngFor="let item of numberToArray(album['Album Rating'], 20)">
|
||||||
|
<span class="glyphicon" [ngClass]="album['Album Rating Computed']?'glyphicon-star-empty':'glyphicon-star'"></span>
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="button" class="btn btn-danger btn-top" [class.btn-top-is-visible]="queryEdited"
|
||||||
|
aria-label="Reset filters" (click)="resetQuery()" title="Reset filters and reload datas">
|
||||||
|
<span class="glyphicon glyphicon-refresh" aria-hidden="true"></span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
25
dashboard/src/app/albums/albums.component.spec.ts
Normal file
25
dashboard/src/app/albums/albums.component.spec.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { AlbumsComponent } from './albums.component';
|
||||||
|
|
||||||
|
describe('AlbumsComponent', () => {
|
||||||
|
let component: AlbumsComponent;
|
||||||
|
let fixture: ComponentFixture<AlbumsComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ AlbumsComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(AlbumsComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
71
dashboard/src/app/albums/albums.component.ts
Normal file
71
dashboard/src/app/albums/albums.component.ts
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { ElsAlbumService } from '../els-album.service';
|
||||||
|
|
||||||
|
import { Album } from '../model/album';
|
||||||
|
|
||||||
|
import { Utils } from '../utils';
|
||||||
|
|
||||||
|
enum query_edit_type {
|
||||||
|
exclude = 'must_not',
|
||||||
|
select = 'must'
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-albums',
|
||||||
|
templateUrl: './albums.component.html',
|
||||||
|
styleUrls: ['./albums.component.css']
|
||||||
|
})
|
||||||
|
export class AlbumsComponent implements OnInit {
|
||||||
|
numberToArray = Utils.numberToArray;
|
||||||
|
albums: Album[] = [];
|
||||||
|
filterQuery = Object.assign({}, ElsAlbumService.GET_ALBUMS_DEFAULT_QUERY);
|
||||||
|
queryEdited = false;
|
||||||
|
|
||||||
|
constructor(private elsService : ElsAlbumService) { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.loadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private editQuery(field: string, value: Album, type: query_edit_type): void {
|
||||||
|
// TODO Move this method to a service
|
||||||
|
if (value[field] instanceof Array) {
|
||||||
|
value[field] = value[field][0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// If firt edit, add needed fields in ELS Query
|
||||||
|
if (!this.filterQuery['query']) {
|
||||||
|
this.filterQuery['query']['bool'][type].push({ 'must': [] })
|
||||||
|
this.filterQuery['query']['bool'][type].push({ 'must_not': [] })
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.filterQuery['query']['bool'][type].push({
|
||||||
|
'match_phrase': {
|
||||||
|
[field]: value[field]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.queryEdited = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
exlude(field: string, value: Album): void {
|
||||||
|
this.editQuery(field, value, query_edit_type.exclude)
|
||||||
|
this.loadData()
|
||||||
|
}
|
||||||
|
|
||||||
|
select(field: string, value: Album): void {
|
||||||
|
this.editQuery(field, value, query_edit_type.select)
|
||||||
|
this.loadData()
|
||||||
|
}
|
||||||
|
|
||||||
|
resetQuery(): void {
|
||||||
|
this.filterQuery = Object.assign({}, ElsAlbumService.GET_ALBUMS_DEFAULT_QUERY);
|
||||||
|
this.loadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
loadData(): void {
|
||||||
|
// console.log(JSON.stringify(this.filterQuery))
|
||||||
|
this.elsService.getAlbums(this.filterQuery).subscribe(data => this.albums = data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,17 +5,19 @@ import { DashboardComponent } from './dashboard/dashboard.component';
|
|||||||
import { AlbumComponent } from './album/album.component';
|
import { AlbumComponent } from './album/album.component';
|
||||||
import { ArtistComponent } from './artist/artist.component';
|
import { ArtistComponent } from './artist/artist.component';
|
||||||
import { GenreComponent } from './genre/genre.component';
|
import { GenreComponent } from './genre/genre.component';
|
||||||
import { LastAddedComponent } from './last-added/last-added.component';
|
|
||||||
import { TopPlayedComponent } from './top-played/top-played.component';
|
import { TopPlayedComponent } from './top-played/top-played.component';
|
||||||
|
import { AlbumsComponent } from './albums/albums.component';
|
||||||
|
import { ToSortComponent } from './to-sort/to-sort.component';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
|
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
|
||||||
{ path: 'dashboard', component: DashboardComponent },
|
{ path: 'dashboard', component: DashboardComponent },
|
||||||
{ path: 'album/:name', component: AlbumComponent },
|
{ path: 'album/:name', component: AlbumComponent },
|
||||||
|
{ path: 'album', component: AlbumsComponent },
|
||||||
{ path: 'artist/:name', component: ArtistComponent },
|
{ path: 'artist/:name', component: ArtistComponent },
|
||||||
{ path: 'genre/:name', component: GenreComponent },
|
{ path: 'genre/:name', component: GenreComponent },
|
||||||
{ path: 'lastAdded', component: LastAddedComponent },
|
{ path: 'top-played', component: TopPlayedComponent },
|
||||||
{ path: 'top-played', component: TopPlayedComponent }
|
{ path: 'to-sort', component: ToSortComponent }
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ nav a.active {
|
|||||||
|
|
||||||
/* FIXME Code Repetition */
|
/* FIXME Code Repetition */
|
||||||
.btn-top {
|
.btn-top {
|
||||||
display: inline-block;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
-webkit-transition: opacity .3s 0s, visibility 0s 0s;
|
-webkit-transition: opacity .3s 0s, visibility 0s 0s;
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
<nav>
|
<nav>
|
||||||
<a class="btn-top" routerLink="/dashboard" routerLinkActive="active"><span class="glyphicon glyphicon-home"></span></a>
|
<div class="btn-top">
|
||||||
|
<a routerLink="/dashboard" routerLinkActive="active"><span class="glyphicon glyphicon-home"></span></a><br />
|
||||||
|
<a routerLink="/album" routerLinkActive="active"><span class="glyphicon glyphicon-cd"></span></a>
|
||||||
|
<a routerLink="/to-sort" routerLinkActive="active"><span class="glyphicon glyphicon-sort"></span></a>
|
||||||
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<router-outlet></router-outlet>
|
<router-outlet></router-outlet>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
import { HttpClientModule } from '@angular/common/http';
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
|
import { FormsModule } from '@angular/forms'; // <-- NgModel lives here
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { DashboardComponent } from './dashboard/dashboard.component';
|
import { DashboardComponent } from './dashboard/dashboard.component';
|
||||||
@@ -8,10 +9,10 @@ import { AlbumComponent } from './album/album.component';
|
|||||||
import { ArtistComponent } from './artist/artist.component';
|
import { ArtistComponent } from './artist/artist.component';
|
||||||
import { GenreComponent } from './genre/genre.component';
|
import { GenreComponent } from './genre/genre.component';
|
||||||
import { SongTableComponent } from './song-table/song-table.component';
|
import { SongTableComponent } from './song-table/song-table.component';
|
||||||
import { LastAddedComponent } from './last-added/last-added.component';
|
|
||||||
import { TopPlayedComponent } from './top-played/top-played.component';
|
import { TopPlayedComponent } from './top-played/top-played.component';
|
||||||
|
|
||||||
import { ElsService } from './els.service';
|
import { ElsService } from './els.service';
|
||||||
|
import { ElsAlbumService } from './els-album.service';
|
||||||
|
|
||||||
import { AppRoutingModule } from './app-routing.module';
|
import { AppRoutingModule } from './app-routing.module';
|
||||||
|
|
||||||
@@ -20,30 +21,38 @@ import { ConvertMoreExactPipe } from './pipes/convert-more-exact.pipe';
|
|||||||
import { SortByPipe } from './pipes/sort-by.pipe';
|
import { SortByPipe } from './pipes/sort-by.pipe';
|
||||||
import { ConvertSizeToStringPipe } from './pipes/convert-size-to-string.pipe';
|
import { ConvertSizeToStringPipe } from './pipes/convert-size-to-string.pipe';
|
||||||
import { RoundPipe } from './pipes/round.pipe';
|
import { RoundPipe } from './pipes/round.pipe';
|
||||||
|
import { AlbumsComponent } from './albums/albums.component';
|
||||||
|
import { ToSortComponent } from './to-sort/to-sort.component';
|
||||||
|
|
||||||
|
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
HttpClientModule,
|
HttpClientModule,
|
||||||
AppRoutingModule
|
FormsModule,
|
||||||
|
AppRoutingModule,
|
||||||
|
NgbModule
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
AppComponent,
|
AppComponent,
|
||||||
DashboardComponent,
|
DashboardComponent,
|
||||||
AlbumComponent,
|
AlbumComponent,
|
||||||
|
AlbumsComponent,
|
||||||
ArtistComponent,
|
ArtistComponent,
|
||||||
GenreComponent,
|
GenreComponent,
|
||||||
SongTableComponent,
|
SongTableComponent,
|
||||||
LastAddedComponent,
|
|
||||||
ConvertMsPipe,
|
ConvertMsPipe,
|
||||||
ConvertMoreExactPipe,
|
ConvertMoreExactPipe,
|
||||||
SortByPipe,
|
SortByPipe,
|
||||||
ConvertSizeToStringPipe,
|
ConvertSizeToStringPipe,
|
||||||
TopPlayedComponent,
|
TopPlayedComponent,
|
||||||
RoundPipe
|
RoundPipe,
|
||||||
|
ToSortComponent
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
ElsService
|
ElsService,
|
||||||
|
ElsAlbumService
|
||||||
],
|
],
|
||||||
bootstrap: [ AppComponent ]
|
bootstrap: [ AppComponent ]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -34,5 +34,44 @@
|
|||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background-color: #9b59b6;
|
background-color: #9b59b6;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Style for autocompletion */
|
||||||
|
/* Stolen from https://ng-bootstrap.github.io/#/components/typeahead/examples */
|
||||||
|
::ng-deep .dropdown-item {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
padding: .25rem 1.5rem;
|
||||||
|
clear: both;
|
||||||
|
font-weight: 400;
|
||||||
|
color: #212529;
|
||||||
|
text-align: inherit;
|
||||||
|
white-space: nowrap;
|
||||||
|
background-color: transparent;
|
||||||
|
border: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
::ng-deep .dropdown-item:focus,
|
||||||
|
::ng-deep .dropdown-item:hover {
|
||||||
|
color: #16181b;
|
||||||
|
text-decoration: none;
|
||||||
|
background-color: #f8f9fa
|
||||||
|
}
|
||||||
|
|
||||||
|
::ng-deep .dropdown-item.active,
|
||||||
|
::ng-deep .dropdown-item:active {
|
||||||
|
color: #fff;
|
||||||
|
text-decoration: none;
|
||||||
|
background-color: #007bff
|
||||||
|
}
|
||||||
|
|
||||||
|
::ng-deep .dropdown-item.disabled,
|
||||||
|
::ng-deep .dropdown-item:disabled {
|
||||||
|
color: #6c757d;
|
||||||
|
pointer-events: none;
|
||||||
|
background-color: transparent
|
||||||
|
}
|
||||||
|
|
||||||
|
::ng-deep .dropdown-menu.show {
|
||||||
|
display: block
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,9 +77,31 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-12">
|
<ng-template #rt let-r="result" let-t="term">
|
||||||
<h3><a [routerLink]="['/lastAdded']">Last Added</a></h3>
|
<!-- glyphicon glyphicon-cd -->
|
||||||
|
<span *ngIf="r.type == 'artist'" class="glyphicon glyphicon-user"></span>
|
||||||
|
<span *ngIf="r.type == 'album'" class="glyphicon glyphicon-cd"></span>
|
||||||
|
<ngb-highlight [result]="r.name" [term]="t"></ngb-highlight>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
|
||||||
|
<form class="navbar-form">
|
||||||
|
<div class="form-group" style="display:inline;">
|
||||||
|
<div class="input-group" style="display:table;">
|
||||||
|
<span class="input-group-addon" style="width:1%;">
|
||||||
|
<span class="glyphicon glyphicon-search"></span>
|
||||||
|
</span>
|
||||||
|
<input class="form-control" type="text" name="search" placeholder="Search Here" autocomplete="off" autofocus="autofocus"
|
||||||
|
id="searchSuggest"
|
||||||
|
[(ngModel)]="searchTerm"
|
||||||
|
[ngbTypeahead]="search"
|
||||||
|
[resultTemplate]="rt"
|
||||||
|
(selectItem)="onSelectSearch($event)">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="col-md-12">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -98,6 +120,8 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<input type="button" class="btn btn-primary btn-lg btn-block" value="All Albums" routerLink="/album">
|
||||||
|
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h3>Top Played Songs</h3>
|
<h3>Top Played Songs</h3>
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
import { ElsService } from './../els.service';
|
import { ElsService } from './../els.service';
|
||||||
import { Song } from './../model/song';
|
import { Song } from './../model/song';
|
||||||
import { Bucket } from './../model/bucket';
|
import { Bucket } from './../model/bucket';
|
||||||
import { Album } from './../model/album';
|
import { Suggested } from '../model/suggested';
|
||||||
import { Artist } from './../model/artist';
|
|
||||||
|
import {Observable, of, OperatorFunction} from 'rxjs';
|
||||||
|
import {catchError, debounceTime, distinctUntilChanged, map, tap, switchMap} from 'rxjs/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-dashboard',
|
selector: 'app-dashboard',
|
||||||
templateUrl: './dashboard.component.html',
|
templateUrl: './dashboard.component.html',
|
||||||
styleUrls: [ './dashboard.component.css' ]
|
styleUrls: [ './dashboard.component.css' ]
|
||||||
})
|
})
|
||||||
|
|
||||||
export class DashboardComponent implements OnInit {
|
export class DashboardComponent implements OnInit {
|
||||||
totalTime = 0;
|
totalTime = 0;
|
||||||
totalSize = 0;
|
totalSize = 0;
|
||||||
@@ -30,7 +32,10 @@ export class DashboardComponent implements OnInit {
|
|||||||
lastAddedAlbums: Bucket[] = [];
|
lastAddedAlbums: Bucket[] = [];
|
||||||
albumArtists = [];
|
albumArtists = [];
|
||||||
|
|
||||||
constructor(private elsService: ElsService) { }
|
searchTerm = ''
|
||||||
|
suggested : Suggested[] = []
|
||||||
|
|
||||||
|
constructor(private elsService: ElsService, private route: Router) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.elsService.getTime().then(result => {
|
this.elsService.getTime().then(result => {
|
||||||
@@ -113,4 +118,27 @@ export class DashboardComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSelectSearch($event) {
|
||||||
|
this.route.navigate(['/' + $event.item.type + '/' + $event.item.name])
|
||||||
|
}
|
||||||
|
|
||||||
|
searching = false;
|
||||||
|
searchFailed = false;
|
||||||
|
|
||||||
|
search: OperatorFunction<string, readonly string[]> = (text$: Observable<string>) =>
|
||||||
|
text$.pipe(
|
||||||
|
debounceTime(300),
|
||||||
|
distinctUntilChanged(),
|
||||||
|
tap(() => this.searching = true),
|
||||||
|
switchMap(term =>
|
||||||
|
this.elsService.getSuggest(term).pipe(
|
||||||
|
tap(() => this.searchFailed = false),
|
||||||
|
catchError(() => {
|
||||||
|
this.searchFailed = true;
|
||||||
|
return of([]);
|
||||||
|
}))
|
||||||
|
),
|
||||||
|
tap(() => this.searching = false)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
16
dashboard/src/app/els-album.service.spec.ts
Normal file
16
dashboard/src/app/els-album.service.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ElsAlbumService } from './els-album.service';
|
||||||
|
|
||||||
|
describe('ElsAlbumService', () => {
|
||||||
|
let service: ElsAlbumService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(ElsAlbumService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
96
dashboard/src/app/els-album.service.ts
Normal file
96
dashboard/src/app/els-album.service.ts
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { HttpClient, HttpHeaders } from '@angular/common/http'
|
||||||
|
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { map, catchError } from 'rxjs/operators';
|
||||||
|
|
||||||
|
import { Album } from './model/album';
|
||||||
|
import { ElsService } from './els.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ElsAlbumService extends ElsService {
|
||||||
|
public static readonly GET_ALBUMS_DEFAULT_QUERY = {
|
||||||
|
'query': {
|
||||||
|
'bool': {
|
||||||
|
'must': [],
|
||||||
|
'must_not': [],
|
||||||
|
'filter': [
|
||||||
|
{ 'range': { 'Avg Bit Rate': { 'lte': '128'}}}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'sort': [ {
|
||||||
|
'_script' : {
|
||||||
|
'type' : 'number',
|
||||||
|
'script' : {
|
||||||
|
'lang': 'painless',
|
||||||
|
'source': 'doc[\'Play Count\'].value / doc[\'Track Count\'].value'
|
||||||
|
},
|
||||||
|
'order' : 'desc'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
'Avg Bit Rate': {
|
||||||
|
'order': 'asc'
|
||||||
|
}
|
||||||
|
} ],
|
||||||
|
'size': 500
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(protected http: HttpClient) {
|
||||||
|
super(http);
|
||||||
|
}
|
||||||
|
|
||||||
|
getAlbums(query: any): Observable<Album[]> {
|
||||||
|
console.info('getAlbums');
|
||||||
|
console.info(query);
|
||||||
|
return this.http
|
||||||
|
.post(this.elsUrl + ElsService.ALBUM_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||||
|
JSON.stringify(query), {headers: this.headers})
|
||||||
|
.pipe(
|
||||||
|
map(res => this.responseToAlbums(res)),
|
||||||
|
catchError(error => this.handleError(error, 'getAlbums'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getAlbumsFiltered(size: number): Observable<Album[]> {
|
||||||
|
// http://localhost:9200/itunes-albums/_search
|
||||||
|
console.info('getAlbums');
|
||||||
|
return this.http
|
||||||
|
.post(this.elsUrl + ElsService.ALBUM_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||||
|
JSON.stringify({
|
||||||
|
'sort': [ {
|
||||||
|
'Avg Bit Rate': {
|
||||||
|
'order': 'asc'
|
||||||
|
}
|
||||||
|
} ],
|
||||||
|
'size': size,
|
||||||
|
'query': {
|
||||||
|
'bool': {
|
||||||
|
'must': [],
|
||||||
|
'filter': [
|
||||||
|
{
|
||||||
|
'match_all': {}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'should': [],
|
||||||
|
'must_not': [
|
||||||
|
{
|
||||||
|
'match_phrase': {
|
||||||
|
'Artist': 'François Pérusse'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'match_phrase': {
|
||||||
|
'Album Artist': 'Comédiens'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}), {headers: this.headers})
|
||||||
|
.pipe(
|
||||||
|
map(res => this.responseToAlbums(res)),
|
||||||
|
catchError(error => this.handleError(error, 'getAlbums'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
16
dashboard/src/app/els-sort.service.spec.ts
Normal file
16
dashboard/src/app/els-sort.service.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ElsSortService } from './els-sort.service';
|
||||||
|
|
||||||
|
describe('ElsSortService', () => {
|
||||||
|
let service: ElsSortService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(ElsSortService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
147
dashboard/src/app/els-sort.service.ts
Normal file
147
dashboard/src/app/els-sort.service.ts
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { map, catchError } from 'rxjs/operators';
|
||||||
|
import { ElsService } from './els.service';
|
||||||
|
import { Album } from './model/album';
|
||||||
|
import { Bucket } from './model/bucket';
|
||||||
|
import { Song } from './model/song';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class ElsSortService extends ElsService {
|
||||||
|
|
||||||
|
constructor(protected http: HttpClient) {
|
||||||
|
super(http);
|
||||||
|
}
|
||||||
|
|
||||||
|
getTime(): Promise<number> {
|
||||||
|
return this.http
|
||||||
|
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
bool: {
|
||||||
|
must_not: [
|
||||||
|
{
|
||||||
|
term: {
|
||||||
|
"Location.tree": "/F:/Musique"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
aggs: {
|
||||||
|
sum_time: {
|
||||||
|
sum: { field: 'Total Time'}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': 0
|
||||||
|
}), {headers: this.headers})
|
||||||
|
.toPromise()
|
||||||
|
.then(res => res.aggregations.sum_time.value as number)
|
||||||
|
.catch(error => this.handleError(error, 'getTime()'));
|
||||||
|
}
|
||||||
|
|
||||||
|
getSize(): Promise<number> {
|
||||||
|
return this.http
|
||||||
|
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
bool: {
|
||||||
|
must_not: [
|
||||||
|
{
|
||||||
|
term: {
|
||||||
|
"Location.tree": "/F:/Musique"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
aggs: {
|
||||||
|
sum_time: {
|
||||||
|
sum: { field: 'Size' }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': 0
|
||||||
|
}), {headers: this.headers})
|
||||||
|
.toPromise()
|
||||||
|
.then(res => res.aggregations.sum_time.value as number)
|
||||||
|
.catch(error => this.handleError(error, 'getSize()'));
|
||||||
|
}
|
||||||
|
|
||||||
|
getCountSong(): Promise<number> {
|
||||||
|
return this.http
|
||||||
|
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_COUNT,
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
bool: {
|
||||||
|
must_not: [
|
||||||
|
{
|
||||||
|
term: {
|
||||||
|
"Location.tree": "/F:/Musique"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}), {headers: this.headers})
|
||||||
|
.toPromise()
|
||||||
|
.then(res => res.count as number)
|
||||||
|
.catch(error => this.handleError(error, 'getCountSong()'));
|
||||||
|
}
|
||||||
|
|
||||||
|
getCountNeverListenSong(): Promise<number> {
|
||||||
|
return this.http
|
||||||
|
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_COUNT,
|
||||||
|
JSON.stringify({
|
||||||
|
'query': {
|
||||||
|
'bool': {
|
||||||
|
'must_not': [
|
||||||
|
{
|
||||||
|
'exists': { 'field': 'Play Count'}
|
||||||
|
}, {
|
||||||
|
term: {
|
||||||
|
"Location.tree": "/F:/Musique"
|
||||||
|
} }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}), {headers: this.headers})
|
||||||
|
.toPromise()
|
||||||
|
.then(res => res.count as number)
|
||||||
|
.catch(error => this.handleError(error, 'getCountNeverListenSong()'));
|
||||||
|
}
|
||||||
|
|
||||||
|
getAlbums(): Observable<Bucket[]> {
|
||||||
|
return this.http
|
||||||
|
.post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||||
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
bool: {
|
||||||
|
must_not: [
|
||||||
|
{
|
||||||
|
term: {
|
||||||
|
"Location.tree": "/F:/Musique"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'size': 0,
|
||||||
|
'aggs': {
|
||||||
|
'albums' : {
|
||||||
|
'terms': {
|
||||||
|
'field' : 'Album.raw',
|
||||||
|
'order': { '_term': 'asc' },
|
||||||
|
'size': 50
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}), {headers: this.headers})
|
||||||
|
.pipe(
|
||||||
|
map(res => this.responseAggregationToBucket(res, "albums")),
|
||||||
|
catchError(error => this.handleError(error, 'getAlbums'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import { Song } from './model/song';
|
|||||||
import { Album } from './model/album';
|
import { Album } from './model/album';
|
||||||
import { Artist } from './model/artist';
|
import { Artist } from './model/artist';
|
||||||
import { Bucket } from './model/bucket';
|
import { Bucket } from './model/bucket';
|
||||||
|
import { Suggested } from './model/suggested';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ElsService {
|
export class ElsService {
|
||||||
@@ -15,14 +16,15 @@ export class ElsService {
|
|||||||
public static readonly SONG_INDEX_NAME = '/itunes-songs';
|
public static readonly SONG_INDEX_NAME = '/itunes-songs';
|
||||||
public static readonly ARTIST_INDEX_NAME = '/itunes-artists';
|
public static readonly ARTIST_INDEX_NAME = '/itunes-artists';
|
||||||
public static readonly ALBUM_INDEX_NAME = '/itunes-albums';
|
public static readonly ALBUM_INDEX_NAME = '/itunes-albums';
|
||||||
|
public static readonly SUGGEST_INDEX_NAME = '/itunes-suggest';
|
||||||
|
|
||||||
private static readonly ACTION_SEARCH = '/_search';
|
protected static readonly ACTION_SEARCH = '/_search';
|
||||||
private static readonly ACTION_COUNT = '/_count';
|
protected static readonly ACTION_COUNT = '/_count';
|
||||||
|
|
||||||
private elsUrl = 'http://localhost:9200';
|
protected elsUrl = 'http://localhost:9200';
|
||||||
private headers = new HttpHeaders({'Content-Type': 'application/json'});
|
protected headers = new HttpHeaders({'Content-Type': 'application/json'});
|
||||||
|
|
||||||
constructor(private http: HttpClient) { }
|
constructor(protected http: HttpClient) { }
|
||||||
|
|
||||||
getTime(): Promise<number> {
|
getTime(): Promise<number> {
|
||||||
return this.http
|
return this.http
|
||||||
@@ -337,7 +339,7 @@ export class ElsService {
|
|||||||
// TODO Take in consideration "sum_other_doc_count"
|
// TODO Take in consideration "sum_other_doc_count"
|
||||||
}
|
}
|
||||||
|
|
||||||
getArtistFromAlbumName(albumname: string): Observable<Album[]> {
|
getArtistFromAlbumName(albumname: string): Observable<Album[]> { // TODO Rename ?
|
||||||
return this.http
|
return this.http
|
||||||
.post<any>(this.elsUrl + ElsService.ALBUM_INDEX_NAME + ElsService.ACTION_SEARCH,
|
.post<any>(this.elsUrl + ElsService.ALBUM_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -381,6 +383,34 @@ export class ElsService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSuggest(text: string): Observable<Suggested[]> {
|
||||||
|
console.log('search sugget: ' + text);
|
||||||
|
return this.http
|
||||||
|
.post<any>(this.elsUrl + ElsService.SUGGEST_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||||
|
JSON.stringify({
|
||||||
|
'_source': ['album', 'artist'],
|
||||||
|
'suggest': {
|
||||||
|
'album-suggest': {
|
||||||
|
'prefix': text,
|
||||||
|
'completion': {
|
||||||
|
'field': 'album_suggest'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'artist-suggest': {
|
||||||
|
'prefix': text,
|
||||||
|
'completion': {
|
||||||
|
'field': 'artist_suggest'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}), {headers: this.headers})
|
||||||
|
.pipe(
|
||||||
|
map(res => this.responseSuggesterToSuggested(res, 'album-suggest', 'artist-suggest')),
|
||||||
|
catchError(error => this.handleError(error, 'getSuggest(' + text + ')'))
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/** Process a result to return just one result.
|
/** Process a result to return just one result.
|
||||||
* Used to get an album or an artist.
|
* Used to get an album or an artist.
|
||||||
* Take a name to put in console output if no result or more than one result.
|
* Take a name to put in console output if no result or more than one result.
|
||||||
@@ -406,7 +436,7 @@ export class ElsService {
|
|||||||
*
|
*
|
||||||
* @param res Response to process
|
* @param res Response to process
|
||||||
*/
|
*/
|
||||||
private responseToSongs(res: any): Song[] {
|
protected responseToSongs(res: any): Song[] {
|
||||||
const result: Array<Song> = [];
|
const result: Array<Song> = [];
|
||||||
res.hits.hits.forEach((hit) => {
|
res.hits.hits.forEach((hit) => {
|
||||||
result.push(hit._source);
|
result.push(hit._source);
|
||||||
@@ -418,7 +448,7 @@ export class ElsService {
|
|||||||
*
|
*
|
||||||
* @param res Response to process
|
* @param res Response to process
|
||||||
*/
|
*/
|
||||||
private responseToAlbums(res: any): Album[] {
|
protected responseToAlbums(res: any): Album[] {
|
||||||
const result: Array<Album> = [];
|
const result: Array<Album> = [];
|
||||||
res.hits.hits.forEach((hit) => {
|
res.hits.hits.forEach((hit) => {
|
||||||
result.push(hit._source);
|
result.push(hit._source);
|
||||||
@@ -444,7 +474,7 @@ export class ElsService {
|
|||||||
* @param res Response to process
|
* @param res Response to process
|
||||||
* @param name Name of aggregation
|
* @param name Name of aggregation
|
||||||
*/
|
*/
|
||||||
private responseAggregationToBucket(res: any, name: string): Bucket[] {
|
protected responseAggregationToBucket(res: any, name: string): Bucket[] {
|
||||||
const result: Array<Bucket> = [];
|
const result: Array<Bucket> = [];
|
||||||
res.aggregations[name].buckets.forEach((bucket) => {
|
res.aggregations[name].buckets.forEach((bucket) => {
|
||||||
result.push(bucket);
|
result.push(bucket);
|
||||||
@@ -462,7 +492,21 @@ export class ElsService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleError(error: any, origin: string): Promise<any> {
|
protected responseSuggesterToSuggested(res: any, ...suggestName: string[]): Suggested[] {
|
||||||
|
const result: Array<Suggested> = []
|
||||||
|
suggestName.forEach(sname => {
|
||||||
|
res['suggest'][sname][0]['options'].forEach(option => {
|
||||||
|
let suggest = new Suggested()
|
||||||
|
// TODO If more than one key, raise exception
|
||||||
|
suggest.type = String(Object.keys(option['_source']))
|
||||||
|
suggest.name = option['_source'][suggest.type]
|
||||||
|
result.push(suggest)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected handleError(error: any, origin: string): Promise<any> {
|
||||||
console.error('An error occurred!');
|
console.error('An error occurred!');
|
||||||
console.error('Origin function: ', origin);
|
console.error('Origin function: ', origin);
|
||||||
console.error('An error occurred!', error); // for demo purposes only
|
console.error('An error occurred!', error); // for demo purposes only
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
<div class="container">
|
|
||||||
</div>
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
|
||||||
|
|
||||||
import { LastAddedComponent } from './last-added.component';
|
|
||||||
|
|
||||||
describe('LastAddedComponent', () => {
|
|
||||||
let component: LastAddedComponent;
|
|
||||||
let fixture: ComponentFixture<LastAddedComponent>;
|
|
||||||
|
|
||||||
beforeEach(async(() => {
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
declarations: [ LastAddedComponent ]
|
|
||||||
})
|
|
||||||
.compileComponents();
|
|
||||||
}));
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(LastAddedComponent);
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be created', () => {
|
|
||||||
expect(component).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'app-last-added',
|
|
||||||
templateUrl: './last-added.component.html',
|
|
||||||
styleUrls: ['./last-added.component.css']
|
|
||||||
})
|
|
||||||
export class LastAddedComponent implements OnInit {
|
|
||||||
|
|
||||||
constructor() { }
|
|
||||||
|
|
||||||
ngOnInit() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
4
dashboard/src/app/model/suggested.ts
Normal file
4
dashboard/src/app/model/suggested.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export class Suggested {
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
@@ -43,16 +43,6 @@
|
|||||||
}
|
}
|
||||||
/*** END BOTTOM BUTTON PART ***/
|
/*** END BOTTOM BUTTON PART ***/
|
||||||
|
|
||||||
|
|
||||||
/*** RATING STAR ***/
|
|
||||||
.star {
|
|
||||||
color:rgb(38, 135, 251);
|
|
||||||
}
|
|
||||||
.table tbody > tr > td.star {
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*** HEART ***/
|
/*** HEART ***/
|
||||||
.heart {
|
.heart {
|
||||||
color: rgb(251, 18, 79);
|
color: rgb(251, 18, 79);
|
||||||
|
|||||||
@@ -32,20 +32,11 @@
|
|||||||
<td [title]="song['Bit Rate']">
|
<td [title]="song['Bit Rate']">
|
||||||
<span [class]="'signal signal-' + roundBitRate(song['Bit Rate'])"></span>
|
<span [class]="'signal signal-' + roundBitRate(song['Bit Rate'])"></span>
|
||||||
</td>
|
</td>
|
||||||
<td *ngIf="!song['Rating Computed']" [title]="'Rating: ' + song.Rating" class="star">
|
<td class="star" [title]="(song['Rating Computed']?'Computed Rating: ':'Rating: ') + song.Rating">
|
||||||
<span *ngIf="song.Rating >= 20" class="glyphicon glyphicon-star"></span>
|
<span *ngFor="let item of numberToArray(song.Rating, 20)">
|
||||||
<span *ngIf="song.Rating >= 40" class="glyphicon glyphicon-star"></span>
|
<span class="glyphicon" [ngClass]="song['Rating Computed']?'glyphicon-star-empty':'glyphicon-star'"></span>
|
||||||
<span *ngIf="song.Rating >= 60" class="glyphicon glyphicon-star"></span>
|
</span>
|
||||||
<span *ngIf="song.Rating >= 80" class="glyphicon glyphicon-star"></span>
|
</td>
|
||||||
<span *ngIf="song.Rating >= 100" class="glyphicon glyphicon-star"></span>
|
|
||||||
</td>
|
|
||||||
<td *ngIf="song['Rating Computed']" [title]="'Computed Rating: ' + song.Rating" class="star">
|
|
||||||
<span *ngIf="song.Rating >= 20" class="glyphicon glyphicon-star-empty"></span>
|
|
||||||
<span *ngIf="song.Rating >= 40" class="glyphicon glyphicon-star-empty"></span>
|
|
||||||
<span *ngIf="song.Rating >= 60" class="glyphicon glyphicon-star-empty"></span>
|
|
||||||
<span *ngIf="song.Rating >= 80" class="glyphicon glyphicon-star-empty"></span>
|
|
||||||
<span *ngIf="song.Rating >= 100" class="glyphicon glyphicon-star-empty"></span>
|
|
||||||
</td>
|
|
||||||
<td *ngIf="song.Loved" class="loved">
|
<td *ngIf="song.Loved" class="loved">
|
||||||
<span class="glyphicon glyphicon-heart heart"></span>
|
<span class="glyphicon glyphicon-heart heart"></span>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||||
|
import { Utils } from '../utils';
|
||||||
|
|
||||||
import { Song } from './../model/song';
|
import { Song } from './../model/song';
|
||||||
import { SortByPipe } from './../pipes/sort-by.pipe';
|
import { SortByPipe } from './../pipes/sort-by.pipe';
|
||||||
@@ -9,6 +10,7 @@ import { SortByPipe } from './../pipes/sort-by.pipe';
|
|||||||
styleUrls: ['./song-table.component.css']
|
styleUrls: ['./song-table.component.css']
|
||||||
})
|
})
|
||||||
export class SongTableComponent {
|
export class SongTableComponent {
|
||||||
|
numberToArray = Utils.numberToArray;
|
||||||
@Input() songs: Array<Song> = [];
|
@Input() songs: Array<Song> = [];
|
||||||
@Output() private atBottom = new EventEmitter();
|
@Output() private atBottom = new EventEmitter();
|
||||||
|
|
||||||
@@ -25,7 +27,7 @@ export class SongTableComponent {
|
|||||||
*
|
*
|
||||||
* @param event scroll event
|
* @param event scroll event
|
||||||
*/
|
*/
|
||||||
private onScroll(event: any) {
|
onScroll(event: any) {
|
||||||
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
|
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
|
||||||
this.atBottom.emit();
|
this.atBottom.emit();
|
||||||
}
|
}
|
||||||
|
|||||||
38
dashboard/src/app/to-sort/to-sort.component.css
Normal file
38
dashboard/src/app/to-sort/to-sort.component.css
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
.panel-stat {
|
||||||
|
min-height: 102px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-green {
|
||||||
|
background-color: #16a085;
|
||||||
|
color:white;
|
||||||
|
}
|
||||||
|
.panel-yellow {
|
||||||
|
background-color: #f1c40f;
|
||||||
|
color:white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-red {
|
||||||
|
background-color: #d9534f;
|
||||||
|
color:white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-purple {
|
||||||
|
background-color: #9b59b6;
|
||||||
|
color:white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-blue {
|
||||||
|
background-color: #3498db;
|
||||||
|
color:white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats_icon {
|
||||||
|
font-size: 3em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.circle {
|
||||||
|
border-radius: 50%;
|
||||||
|
background-color: #9b59b6;
|
||||||
|
margin: 0 auto;
|
||||||
|
|
||||||
|
}
|
||||||
130
dashboard/src/app/to-sort/to-sort.component.html
Normal file
130
dashboard/src/app/to-sort/to-sort.component.html
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
<div class="container">
|
||||||
|
<h1>To sort Songs - </h1>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<div class="row cardAdmin">
|
||||||
|
<div class="col-lg-3 col-md-3">
|
||||||
|
<div class="panel panel-blue">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-3">
|
||||||
|
<span class="glyphicon glyphicon-time stats_icon"></span>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-9 text-right">
|
||||||
|
<div>
|
||||||
|
<h3 *ngIf="!totalTime"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||||
|
<h3 *ngIf="totalTime">{{totalTime | convertMs}}</h3>
|
||||||
|
</div>
|
||||||
|
<div><br>Total time ({{totalTime | convertMoreExact}})</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-3 col-md-3">
|
||||||
|
<div class="panel panel-green">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-3">
|
||||||
|
<span class="glyphicon glyphicon-hdd stats_icon"></span>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-9 text-right">
|
||||||
|
<div>
|
||||||
|
<h3 *ngIf="!totalSize"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||||
|
<h3 *ngIf="totalSize">{{totalSize | convertSizeToString}}</h3>
|
||||||
|
</div>
|
||||||
|
<div><br>Total size</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-3 col-md-3">
|
||||||
|
<div class="panel panel-yellow">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-3">
|
||||||
|
<span class="glyphicon glyphicon-play stats_icon"></span>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-9 text-right">
|
||||||
|
<div>
|
||||||
|
<h3 *ngIf="!trackCountSong"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||||
|
<h3 *ngIf="trackCountSong">{{trackCountSong}}</h3>
|
||||||
|
</div>
|
||||||
|
<div><br>Total Songs</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-3 col-md-3">
|
||||||
|
<div class="panel panel-red">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-3">
|
||||||
|
<span class="glyphicon glyphicon-stop stats_icon"></span>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-9 text-right">
|
||||||
|
<div>
|
||||||
|
<h3 *ngIf="!neverListenSong"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||||
|
<h3 *ngIf="neverListenSong">{{neverListenSong}}</h3>
|
||||||
|
</div>
|
||||||
|
<div><br>Never list. songs (~{{neverListenSong / trackCountSong * 100 | round}}%)</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-12">
|
||||||
|
<table class="table table-striped" style="white-space: nowrap;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Album</th>
|
||||||
|
<th>Track Count</th>
|
||||||
|
<th>Artist/Album Artist</th>
|
||||||
|
<th>Play Count</th>
|
||||||
|
<th>Rating</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr *ngFor="let album of toSortAlbum">
|
||||||
|
<td>
|
||||||
|
<a [routerLink]="['/album', album.key]">{{album.key}}</a>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>{{albums[album.key]['Track Count']}}</td>
|
||||||
|
|
||||||
|
<ng-template [ngIf]="albums[album.key]['Album Artist']" [ngIfElse]="artistSection">
|
||||||
|
<td>
|
||||||
|
<a [routerLink]="['/artist', albums[album.key]['Album Artist']]">{{albums[album.key]['Album Artist']}}</a>
|
||||||
|
</td>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<ng-template #artistSection>
|
||||||
|
<td>
|
||||||
|
<a [routerLink]="['/artist', albums[album.key].Artist[0]]">{{albums[album.key].Artist}}</a>
|
||||||
|
</td>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<ng-template #artistSection>
|
||||||
|
<td>
|
||||||
|
<a [routerLink]="['/artist', albums[album.key].Artist[0]]">{{albums[album.key].Artist}}</a>
|
||||||
|
</td>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
{{albums[album.key]['Play Count']}} ({{albums[album.key]['Play Count']/albums[album.key]['Track Count'] | number:'1.0-0'}}/songs)
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td class="star" [title]="(albums[album.key]['Album Rating Computed']?'Computed Rating: ':'Rating: ') + albums[album.key]['Album Rating']">
|
||||||
|
<span *ngFor="let item of numberToArray(albums[album.key]['Album Rating'], 20)">
|
||||||
|
<span class="glyphicon" [ngClass]="albums[album.key]['Album Rating Computed']?'glyphicon-star-empty':'glyphicon-star'"></span>
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
25
dashboard/src/app/to-sort/to-sort.component.spec.ts
Normal file
25
dashboard/src/app/to-sort/to-sort.component.spec.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ToSortComponent } from './to-sort.component';
|
||||||
|
|
||||||
|
describe('ToSortComponent', () => {
|
||||||
|
let component: ToSortComponent;
|
||||||
|
let fixture: ComponentFixture<ToSortComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ ToSortComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(ToSortComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
89
dashboard/src/app/to-sort/to-sort.component.ts
Normal file
89
dashboard/src/app/to-sort/to-sort.component.ts
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { ElsSortService } from '../els-sort.service';
|
||||||
|
import { Album } from '../model/album';
|
||||||
|
import { Bucket } from '../model/bucket';
|
||||||
|
import { Song } from '../model/song';
|
||||||
|
|
||||||
|
import { Utils } from '../utils';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-to-sort',
|
||||||
|
templateUrl: './to-sort.component.html',
|
||||||
|
styleUrls: ['./to-sort.component.css']
|
||||||
|
})
|
||||||
|
export class ToSortComponent implements OnInit {
|
||||||
|
numberToArray = Utils.numberToArray;
|
||||||
|
// Stats var
|
||||||
|
totalTime = 0;
|
||||||
|
totalSize = 0;
|
||||||
|
trackCountSong = 0;
|
||||||
|
neverListenSong = 0;
|
||||||
|
|
||||||
|
// Global var
|
||||||
|
toSortAlbum: Bucket[] = [];
|
||||||
|
albums = []
|
||||||
|
|
||||||
|
constructor(private elsService: ElsSortService) { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
// **** GET STATS ****//
|
||||||
|
this.elsService.getTime().then(result => this.totalTime = result);
|
||||||
|
this.elsService.getSize().then(result => this.totalSize = result);
|
||||||
|
this.elsService.getCountSong().then(result => this.trackCountSong = result);
|
||||||
|
this.elsService.getCountNeverListenSong().then(result => this.neverListenSong = result);
|
||||||
|
|
||||||
|
// **** GET ALBUMS ****//
|
||||||
|
const tmpToSortAlbums: Bucket[] = [];
|
||||||
|
this.elsService.getAlbums().subscribe(buckets => {
|
||||||
|
buckets.forEach(bucket => {
|
||||||
|
if (tmpToSortAlbums.length === 0) {
|
||||||
|
tmpToSortAlbums.push(bucket);
|
||||||
|
} else {
|
||||||
|
let found = false;
|
||||||
|
tmpToSortAlbums.forEach(element => {
|
||||||
|
if (element.key === bucket.key) {
|
||||||
|
element.doc_count += bucket.doc_count;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!found) {
|
||||||
|
tmpToSortAlbums.push(bucket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.toSortAlbum = tmpToSortAlbums;
|
||||||
|
this.toSortAlbum.forEach(bucket => this.getAlbum(bucket));
|
||||||
|
// console.log(this.toSortAlbum)
|
||||||
|
// console.log(this.albums)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private getAlbum(albumBucket: Bucket) {
|
||||||
|
// For each bucket.key (album name), get Album document
|
||||||
|
// Use track count to compare
|
||||||
|
this.elsService.getArtistFromAlbumName(albumBucket.key).subscribe(albums => {
|
||||||
|
// Identification of the good album
|
||||||
|
let goodAlbum;
|
||||||
|
if (albums.length > 1) {
|
||||||
|
// More than one result for an album name: search good by track count
|
||||||
|
albums.forEach(album => {
|
||||||
|
if (album['Track Count'] === albumBucket.doc_count) {
|
||||||
|
goodAlbum = album;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Just one result for album name
|
||||||
|
goodAlbum = albums[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Crap security if no good album found
|
||||||
|
if (goodAlbum == undefined) {
|
||||||
|
goodAlbum = albums[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
this.albums[albumBucket.key] = goodAlbum;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
7
dashboard/src/app/utils.spec.ts
Normal file
7
dashboard/src/app/utils.spec.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { Utils } from './utils';
|
||||||
|
|
||||||
|
describe('Utils', () => {
|
||||||
|
it('should create an instance', () => {
|
||||||
|
expect(new Utils()).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
16
dashboard/src/app/utils.ts
Normal file
16
dashboard/src/app/utils.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
export class Utils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a number to an array.
|
||||||
|
* Mainly used for rating: need to convert the number to use a ngFor
|
||||||
|
* @param n number to convert on a array of n cases
|
||||||
|
* @param d if you want to divide number, e.g. by 20 for rating (rating is one value out of one hundred)
|
||||||
|
*/
|
||||||
|
public static numberToArray(n: number, d: number = 1): any[] {
|
||||||
|
if (!n) {
|
||||||
|
return Array(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array(n / d);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,16 @@
|
|||||||
// The file contents for the current environment will overwrite these during build.
|
// This file can be replaced during build by using the `fileReplacements` array.
|
||||||
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
|
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
|
||||||
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
|
// The list of file replacements can be found in `angular.json`.
|
||||||
// The list of which env maps to which file can be found in `.angular-cli.json`.
|
|
||||||
|
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: false
|
production: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For easier debugging in development mode, you can import the following file
|
||||||
|
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
|
||||||
|
*
|
||||||
|
* This import should be commented out in production mode because it will have a negative impact
|
||||||
|
* on performance if an error is thrown.
|
||||||
|
*/
|
||||||
|
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
|
||||||
|
|||||||
60
dashboard/src/fontello.css
vendored
Normal file
60
dashboard/src/fontello.css
vendored
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
@font-face {
|
||||||
|
font-family: 'fontello';
|
||||||
|
src: url('./assets/fonts/fontello/fontello.eot?59321355');
|
||||||
|
src: url('./assets/fonts/fontello/fontello.eot?59321355#iefix') format('embedded-opentype'),
|
||||||
|
url('./assets/fonts/fontello/fontello.woff2?59321355') format('woff2'),
|
||||||
|
url('./assets/fonts/fontello/fontello.woff?59321355') format('woff'),
|
||||||
|
url('./assets/fonts/fontello/fontello.ttf?59321355') format('truetype'),
|
||||||
|
url('./assets/fonts/fontello/fontello.svg?59321355#fontello') format('svg');
|
||||||
|
font-weight: normal;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
/* Chrome hack: SVG is rendered more smooth in Windozze. 100% magic, uncomment if you need it. */
|
||||||
|
/* Note, that will break hinting! In other OS-es font will be not as sharp as it could be */
|
||||||
|
/*
|
||||||
|
@media screen and (-webkit-min-device-pixel-ratio:0) {
|
||||||
|
@font-face {
|
||||||
|
font-family: 'fontello';
|
||||||
|
src: url('../font/fontello.svg?59321355#fontello') format('svg');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
[class^="icon-"]:before, [class*=" icon-"]:before {
|
||||||
|
font-family: "fontello";
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: normal;
|
||||||
|
speak: none;
|
||||||
|
|
||||||
|
display: inline-block;
|
||||||
|
text-decoration: inherit;
|
||||||
|
width: 1em;
|
||||||
|
margin-right: .2em;
|
||||||
|
text-align: center;
|
||||||
|
/* opacity: .8; */
|
||||||
|
|
||||||
|
/* For safety - reset parent styles, that can break glyph codes*/
|
||||||
|
font-variant: normal;
|
||||||
|
text-transform: none;
|
||||||
|
|
||||||
|
/* fix buttons height, for twitter bootstrap */
|
||||||
|
line-height: 1em;
|
||||||
|
|
||||||
|
/* Animation center compensation - margins should be symmetric */
|
||||||
|
/* remove if not needed */
|
||||||
|
margin-left: .2em;
|
||||||
|
|
||||||
|
/* you can be more comfortable with increased icons size */
|
||||||
|
font-size: 130%;
|
||||||
|
|
||||||
|
/* Font smoothing. That was taken from TWBS */
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
|
||||||
|
/* Uncomment for 3D effect */
|
||||||
|
/* text-shadow: 1px 1px 1px rgba(127, 127, 127, 0.3); */
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-videocam:before { content: '\e800'; } /* '' */
|
||||||
|
.icon-tv:before { content: '\e801'; } /* '' */
|
||||||
|
.icon-user:before { content: '\e802'; } /* '' */
|
||||||
@@ -8,4 +8,5 @@ if (environment.production) {
|
|||||||
enableProdMode();
|
enableProdMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
platformBrowserDynamic().bootstrapModule(AppModule)
|
||||||
|
.catch(err => console.error(err));
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
/***************************************************************************************************
|
||||||
|
* Load `$localize` onto the global scope - used if i18n tags appear in Angular templates.
|
||||||
|
*/
|
||||||
|
import '@angular/localize/init';
|
||||||
/**
|
/**
|
||||||
* This file includes polyfills needed by Angular and is loaded before the app.
|
* This file includes polyfills needed by Angular and is loaded before the app.
|
||||||
* You can add your own extra polyfills to this file.
|
* You can add your own extra polyfills to this file.
|
||||||
@@ -11,62 +15,53 @@
|
|||||||
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
|
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
|
||||||
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
|
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
|
||||||
*
|
*
|
||||||
* Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
|
* Learn more in https://angular.io/guide/browser-support
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/***************************************************************************************************
|
/***************************************************************************************************
|
||||||
* BROWSER POLYFILLS
|
* BROWSER POLYFILLS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
|
/** IE11 requires the following for NgClass support on SVG elements */
|
||||||
// import 'core-js/es6/symbol';
|
|
||||||
// import 'core-js/es6/object';
|
|
||||||
// import 'core-js/es6/function';
|
|
||||||
// import 'core-js/es6/parse-int';
|
|
||||||
// import 'core-js/es6/parse-float';
|
|
||||||
// import 'core-js/es6/number';
|
|
||||||
// import 'core-js/es6/math';
|
|
||||||
// import 'core-js/es6/string';
|
|
||||||
// import 'core-js/es6/date';
|
|
||||||
// import 'core-js/es6/array';
|
|
||||||
// import 'core-js/es6/regexp';
|
|
||||||
// import 'core-js/es6/map';
|
|
||||||
// import 'core-js/es6/weak-map';
|
|
||||||
// import 'core-js/es6/set';
|
|
||||||
|
|
||||||
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
|
|
||||||
// import 'classlist.js'; // Run `npm install --save classlist.js`.
|
// import 'classlist.js'; // Run `npm install --save classlist.js`.
|
||||||
|
|
||||||
/** Evergreen browsers require these. **/
|
|
||||||
import 'core-js/es6/reflect';
|
|
||||||
import 'core-js/es7/reflect';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required to support Web Animations `@angular/animation`.
|
* Web Animations `@angular/platform-browser/animations`
|
||||||
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
|
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
|
||||||
**/
|
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
|
||||||
|
*/
|
||||||
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
|
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, zone.js will patch all possible macroTask and DomEvents
|
||||||
|
* user can disable parts of macroTask/DomEvents patch by setting following flags
|
||||||
|
* because those flags need to be set before `zone.js` being loaded, and webpack
|
||||||
|
* will put import in the top of bundle, so user need to create a separate file
|
||||||
|
* in this directory (for example: zone-flags.ts), and put the following flags
|
||||||
|
* into that file, and then add the following code before importing zone.js.
|
||||||
|
* import './zone-flags';
|
||||||
|
*
|
||||||
|
* The flags allowed in zone-flags.ts are listed here.
|
||||||
|
*
|
||||||
|
* The following flags will work for all browsers.
|
||||||
|
*
|
||||||
|
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
|
||||||
|
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
|
||||||
|
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
|
||||||
|
*
|
||||||
|
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
|
||||||
|
* with the following flag, it will bypass `zone.js` patch for IE/Edge
|
||||||
|
*
|
||||||
|
* (window as any).__Zone_enable_cross_context_check = true;
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
/***************************************************************************************************
|
/***************************************************************************************************
|
||||||
* Zone JS is required by Angular itself.
|
* Zone JS is required by default for Angular itself.
|
||||||
*/
|
*/
|
||||||
import 'zone.js/dist/zone'; // Included with Angular CLI.
|
import 'zone.js'; // Included with Angular CLI.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************************************
|
/***************************************************************************************************
|
||||||
* APPLICATION IMPORTS
|
* APPLICATION IMPORTS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Date, currency, decimal and percent pipes.
|
|
||||||
* Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
|
|
||||||
*/
|
|
||||||
// import 'intl'; // Run `npm install --save intl`.
|
|
||||||
/**
|
|
||||||
* Need to import at least one locale-data with intl.
|
|
||||||
*/
|
|
||||||
// import 'intl/locale-data/jsonp/en';
|
|
||||||
|
|||||||
@@ -30,6 +30,13 @@ body, input[text], button {
|
|||||||
to { -webkit-transform: rotate(360deg);}
|
to { -webkit-transform: rotate(360deg);}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*** RATING STAR ***/
|
||||||
|
.star {
|
||||||
|
color:rgb(38, 135, 251);
|
||||||
|
}
|
||||||
|
.table tbody > tr > td.star {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
/* . . . */
|
/* . . . */
|
||||||
/* everywhere else */
|
/* everywhere else */
|
||||||
|
|||||||
@@ -1,23 +1,18 @@
|
|||||||
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
||||||
|
|
||||||
import 'zone.js/dist/long-stack-trace-zone';
|
import 'zone.js/testing';
|
||||||
import 'zone.js/dist/proxy.js';
|
|
||||||
import 'zone.js/dist/sync-test';
|
|
||||||
import 'zone.js/dist/jasmine-patch';
|
|
||||||
import 'zone.js/dist/async-test';
|
|
||||||
import 'zone.js/dist/fake-async-test';
|
|
||||||
import { getTestBed } from '@angular/core/testing';
|
import { getTestBed } from '@angular/core/testing';
|
||||||
import {
|
import {
|
||||||
BrowserDynamicTestingModule,
|
BrowserDynamicTestingModule,
|
||||||
platformBrowserDynamicTesting
|
platformBrowserDynamicTesting
|
||||||
} from '@angular/platform-browser-dynamic/testing';
|
} from '@angular/platform-browser-dynamic/testing';
|
||||||
|
|
||||||
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
|
declare const require: {
|
||||||
declare const __karma__: any;
|
context(path: string, deep?: boolean, filter?: RegExp): {
|
||||||
declare const require: any;
|
keys(): string[];
|
||||||
|
<T>(id: string): T;
|
||||||
// Prevent Karma from running prematurely.
|
};
|
||||||
__karma__.loaded = function () {};
|
};
|
||||||
|
|
||||||
// First, initialize the Angular testing environment.
|
// First, initialize the Angular testing environment.
|
||||||
getTestBed().initTestEnvironment(
|
getTestBed().initTestEnvironment(
|
||||||
@@ -28,5 +23,3 @@ getTestBed().initTestEnvironment(
|
|||||||
const context = require.context('./', true, /\.spec\.ts$/);
|
const context = require.context('./', true, /\.spec\.ts$/);
|
||||||
// And load the modules.
|
// And load the modules.
|
||||||
context.keys().map(context);
|
context.keys().map(context);
|
||||||
// Finally, start Karma to run the tests.
|
|
||||||
__karma__.start();
|
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "../out-tsc/app",
|
|
||||||
"baseUrl": "./",
|
|
||||||
"module": "es2015",
|
|
||||||
"types": []
|
|
||||||
},
|
|
||||||
"exclude": [
|
|
||||||
"test.ts",
|
|
||||||
"**/*.spec.ts"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "../out-tsc/spec",
|
|
||||||
"baseUrl": "./",
|
|
||||||
"module": "commonjs",
|
|
||||||
"target": "es5",
|
|
||||||
"types": [
|
|
||||||
"jasmine",
|
|
||||||
"node"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"test.ts",
|
|
||||||
"polyfills.ts"
|
|
||||||
],
|
|
||||||
"include": [
|
|
||||||
"**/*.spec.ts",
|
|
||||||
"**/*.d.ts"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
5
dashboard/src/typings.d.ts
vendored
5
dashboard/src/typings.d.ts
vendored
@@ -1,5 +0,0 @@
|
|||||||
/* SystemJS module definition */
|
|
||||||
declare var module: NodeModule;
|
|
||||||
interface NodeModule {
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
15
dashboard/tsconfig.app.json
Normal file
15
dashboard/tsconfig.app.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./out-tsc/app",
|
||||||
|
"types": []
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/main.ts",
|
||||||
|
"src/polyfills.ts"
|
||||||
|
],
|
||||||
|
"include": [
|
||||||
|
"src/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,19 +1,23 @@
|
|||||||
|
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||||
{
|
{
|
||||||
"compileOnSave": false,
|
"compileOnSave": false,
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"baseUrl": "./",
|
||||||
"outDir": "./dist/out-tsc",
|
"outDir": "./dist/out-tsc",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"declaration": false,
|
"declaration": false,
|
||||||
"moduleResolution": "node",
|
"downlevelIteration": true,
|
||||||
"emitDecoratorMetadata": true,
|
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"target": "es5",
|
"moduleResolution": "node",
|
||||||
"typeRoots": [
|
"importHelpers": true,
|
||||||
"node_modules/@types"
|
"target": "es2015",
|
||||||
],
|
"module": "es2020",
|
||||||
"lib": [
|
"lib": [
|
||||||
"es2017",
|
"es2018",
|
||||||
"dom"
|
"dom"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"angularCompilerOptions": {
|
||||||
|
"strictTemplates": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
dashboard/tsconfig.spec.json
Normal file
18
dashboard/tsconfig.spec.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./out-tsc/spec",
|
||||||
|
"types": [
|
||||||
|
"jasmine"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/test.ts",
|
||||||
|
"src/polyfills.ts"
|
||||||
|
],
|
||||||
|
"include": [
|
||||||
|
"src/**/*.spec.ts",
|
||||||
|
"src/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,33 +1,37 @@
|
|||||||
{
|
{
|
||||||
|
"extends": "tslint:recommended",
|
||||||
"rulesDirectory": [
|
"rulesDirectory": [
|
||||||
"node_modules/codelyzer"
|
"codelyzer"
|
||||||
],
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
|
"align": {
|
||||||
|
"options": [
|
||||||
|
"parameters",
|
||||||
|
"statements"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"array-type": false,
|
||||||
"arrow-return-shorthand": true,
|
"arrow-return-shorthand": true,
|
||||||
"callable-types": true,
|
|
||||||
"class-name": true,
|
|
||||||
"comment-format": [
|
|
||||||
true,
|
|
||||||
"check-space"
|
|
||||||
],
|
|
||||||
"curly": true,
|
"curly": true,
|
||||||
|
"deprecation": {
|
||||||
|
"severity": "warning"
|
||||||
|
},
|
||||||
"eofline": true,
|
"eofline": true,
|
||||||
"forin": true,
|
|
||||||
"import-blacklist": [
|
"import-blacklist": [
|
||||||
true
|
true,
|
||||||
|
"rxjs/Rx"
|
||||||
],
|
],
|
||||||
"import-spacing": true,
|
"import-spacing": true,
|
||||||
"indent": [
|
"indent": {
|
||||||
true,
|
"options": [
|
||||||
"spaces"
|
"spaces"
|
||||||
],
|
]
|
||||||
"interface-over-type-literal": true,
|
},
|
||||||
"label-position": true,
|
"max-classes-per-file": false,
|
||||||
"max-line-length": [
|
"max-line-length": [
|
||||||
true,
|
true,
|
||||||
140
|
140
|
||||||
],
|
],
|
||||||
"member-access": false,
|
|
||||||
"member-ordering": [
|
"member-ordering": [
|
||||||
true,
|
true,
|
||||||
{
|
{
|
||||||
@@ -39,79 +43,99 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"no-arg": true,
|
|
||||||
"no-bitwise": true,
|
|
||||||
"no-console": [
|
"no-console": [
|
||||||
true,
|
true,
|
||||||
"debug",
|
"debug",
|
||||||
|
"info",
|
||||||
"time",
|
"time",
|
||||||
"timeEnd",
|
"timeEnd",
|
||||||
"trace"
|
"trace"
|
||||||
],
|
],
|
||||||
"no-construct": true,
|
|
||||||
"no-debugger": true,
|
|
||||||
"no-duplicate-super": true,
|
|
||||||
"no-empty": false,
|
"no-empty": false,
|
||||||
"no-empty-interface": true,
|
|
||||||
"no-eval": true,
|
|
||||||
"no-inferrable-types": [
|
"no-inferrable-types": [
|
||||||
true,
|
true,
|
||||||
"ignore-params"
|
"ignore-params"
|
||||||
],
|
],
|
||||||
"no-misused-new": true,
|
|
||||||
"no-non-null-assertion": true,
|
"no-non-null-assertion": true,
|
||||||
"no-shadowed-variable": true,
|
"no-redundant-jsdoc": true,
|
||||||
"no-string-literal": false,
|
|
||||||
"no-string-throw": true,
|
|
||||||
"no-switch-case-fall-through": true,
|
"no-switch-case-fall-through": true,
|
||||||
"no-trailing-whitespace": true,
|
"no-var-requires": false,
|
||||||
"no-unnecessary-initializer": true,
|
"object-literal-key-quotes": [
|
||||||
"no-unused-expression": true,
|
|
||||||
"no-use-before-declare": true,
|
|
||||||
"no-var-keyword": true,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"one-line": [
|
|
||||||
true,
|
true,
|
||||||
"check-open-brace",
|
"as-needed"
|
||||||
"check-catch",
|
|
||||||
"check-else",
|
|
||||||
"check-whitespace"
|
|
||||||
],
|
],
|
||||||
"prefer-const": true,
|
|
||||||
"quotemark": [
|
"quotemark": [
|
||||||
true,
|
true,
|
||||||
"single"
|
"single"
|
||||||
],
|
],
|
||||||
"radix": true,
|
"semicolon": {
|
||||||
"semicolon": [
|
"options": [
|
||||||
true,
|
"always"
|
||||||
"always"
|
]
|
||||||
],
|
},
|
||||||
"triple-equals": [
|
"space-before-function-paren": {
|
||||||
true,
|
"options": {
|
||||||
"allow-null-check"
|
"anonymous": "never",
|
||||||
],
|
"asyncArrow": "always",
|
||||||
"typedef-whitespace": [
|
"constructor": "never",
|
||||||
true,
|
"method": "never",
|
||||||
{
|
"named": "never"
|
||||||
"call-signature": "nospace",
|
|
||||||
"index-signature": "nospace",
|
|
||||||
"parameter": "nospace",
|
|
||||||
"property-declaration": "nospace",
|
|
||||||
"variable-declaration": "nospace"
|
|
||||||
}
|
}
|
||||||
],
|
},
|
||||||
"typeof-compare": true,
|
"typedef": [
|
||||||
"unified-signatures": true,
|
|
||||||
"variable-name": false,
|
|
||||||
"whitespace": [
|
|
||||||
true,
|
true,
|
||||||
"check-branch",
|
"call-signature"
|
||||||
"check-decl",
|
|
||||||
"check-operator",
|
|
||||||
"check-separator",
|
|
||||||
"check-type"
|
|
||||||
],
|
],
|
||||||
|
"typedef-whitespace": {
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"call-signature": "nospace",
|
||||||
|
"index-signature": "nospace",
|
||||||
|
"parameter": "nospace",
|
||||||
|
"property-declaration": "nospace",
|
||||||
|
"variable-declaration": "nospace"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"call-signature": "onespace",
|
||||||
|
"index-signature": "onespace",
|
||||||
|
"parameter": "onespace",
|
||||||
|
"property-declaration": "onespace",
|
||||||
|
"variable-declaration": "onespace"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"variable-name": {
|
||||||
|
"options": [
|
||||||
|
"ban-keywords",
|
||||||
|
"check-format",
|
||||||
|
"allow-pascal-case"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"whitespace": {
|
||||||
|
"options": [
|
||||||
|
"check-branch",
|
||||||
|
"check-decl",
|
||||||
|
"check-operator",
|
||||||
|
"check-separator",
|
||||||
|
"check-type",
|
||||||
|
"check-typecast"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"component-class-suffix": true,
|
||||||
|
"contextual-lifecycle": true,
|
||||||
|
"directive-class-suffix": true,
|
||||||
|
"no-conflicting-lifecycle": true,
|
||||||
|
"no-host-metadata-property": true,
|
||||||
|
"no-input-rename": true,
|
||||||
|
"no-inputs-metadata-property": true,
|
||||||
|
"no-output-native": true,
|
||||||
|
"no-output-on-prefix": true,
|
||||||
|
"no-output-rename": true,
|
||||||
|
"no-outputs-metadata-property": true,
|
||||||
|
"template-banana-in-box": true,
|
||||||
|
"template-no-negated-async": true,
|
||||||
|
"use-lifecycle-interface": true,
|
||||||
|
"use-pipe-transform-interface": true,
|
||||||
"directive-selector": [
|
"directive-selector": [
|
||||||
true,
|
true,
|
||||||
"attribute",
|
"attribute",
|
||||||
@@ -123,18 +147,6 @@
|
|||||||
"element",
|
"element",
|
||||||
"app",
|
"app",
|
||||||
"kebab-case"
|
"kebab-case"
|
||||||
],
|
]
|
||||||
"use-input-property-decorator": true,
|
|
||||||
"use-output-property-decorator": true,
|
|
||||||
"use-host-property-decorator": true,
|
|
||||||
"no-input-rename": true,
|
|
||||||
"no-output-rename": true,
|
|
||||||
"use-life-cycle-interface": true,
|
|
||||||
"use-pipe-transform-interface": true,
|
|
||||||
"component-class-suffix": true,
|
|
||||||
"directive-class-suffix": true,
|
|
||||||
"no-access-missing-member": true,
|
|
||||||
"templates-use-public": true,
|
|
||||||
"invoke-injectable": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,14 +147,15 @@ class ITunesParser:
|
|||||||
'Play Count': 0,
|
'Play Count': 0,
|
||||||
'Rating': 0,
|
'Rating': 0,
|
||||||
'Genre': set(),
|
'Genre': set(),
|
||||||
'Album': set()
|
'Album': set(),
|
||||||
|
'Album Artist': set()
|
||||||
}
|
}
|
||||||
|
|
||||||
# Compute information
|
# Compute information
|
||||||
play_count = track['Play Count'] if 'Play Count' in track else 0
|
play_count = track['Play Count'] if 'Play Count' in track else 0
|
||||||
|
|
||||||
rating = track['Rating'] if 'Rating' in track else 0
|
rating = track['Rating'] if 'Rating' in track else 0
|
||||||
rating = self.calc_rating(rating, self._artists[akey]['Rating'], self._artists[akey]['Track Count'])
|
rating = self.calc_average(rating, self._artists[akey]['Rating'], self._artists[akey]['Track Count'])
|
||||||
|
|
||||||
self._artists[akey]['Track Count'] += 1
|
self._artists[akey]['Track Count'] += 1
|
||||||
self._artists[akey]['Rating'] = rating
|
self._artists[akey]['Rating'] = rating
|
||||||
@@ -168,6 +169,9 @@ class ITunesParser:
|
|||||||
if 'Album' in track:
|
if 'Album' in track:
|
||||||
self._artists[akey]['Album'].add(track['Album'])
|
self._artists[akey]['Album'].add(track['Album'])
|
||||||
|
|
||||||
|
if 'Album Artist' in track:
|
||||||
|
self._artists[akey]['Album Artist'].add(track['Artist'])
|
||||||
|
|
||||||
def _process_album(self, track):
|
def _process_album(self, track):
|
||||||
"""
|
"""
|
||||||
Process albums in the track part of library and return a JSON formated for a bulk ELS request
|
Process albums in the track part of library and return a JSON formated for a bulk ELS request
|
||||||
@@ -187,9 +191,10 @@ class ITunesParser:
|
|||||||
'Album': akey,
|
'Album': akey,
|
||||||
'Track Count': 0,
|
'Track Count': 0,
|
||||||
'Play Count': 0,
|
'Play Count': 0,
|
||||||
'Rating': 0,
|
|
||||||
'Genre': set(),
|
'Genre': set(),
|
||||||
'Artist': set(),
|
'Artist': set(),
|
||||||
|
'Avg Bit Rate': track['Bit Rate'],
|
||||||
|
'Min Bit Rate': track['Bit Rate'],
|
||||||
# 'Album Artist': '',
|
# 'Album Artist': '',
|
||||||
'Total Time': 0
|
'Total Time': 0
|
||||||
}
|
}
|
||||||
@@ -197,16 +202,18 @@ class ITunesParser:
|
|||||||
# Compute information
|
# Compute information
|
||||||
play_count = track['Play Count'] if 'Play Count' in track else 0
|
play_count = track['Play Count'] if 'Play Count' in track else 0
|
||||||
|
|
||||||
rating = track['Rating'] if 'Rating' in track else 0
|
|
||||||
rating = self.calc_rating(rating, self._albums[akey]['Rating'], self._albums[akey]['Track Count'])
|
|
||||||
|
|
||||||
total_time = track['Total Time'] if 'Total Time' in track else 0
|
total_time = track['Total Time'] if 'Total Time' in track else 0
|
||||||
|
|
||||||
|
avg_bitrate = self.calc_average(track['Bit Rate'], self._albums[akey]['Avg Bit Rate'], self._albums[akey]['Track Count'])
|
||||||
|
|
||||||
|
self._albums[akey]['Avg Bit Rate'] = avg_bitrate
|
||||||
self._albums[akey]['Track Count'] += 1
|
self._albums[akey]['Track Count'] += 1
|
||||||
self._albums[akey]['Rating'] = rating
|
|
||||||
self._albums[akey]['Play Count'] += play_count
|
self._albums[akey]['Play Count'] += play_count
|
||||||
self._albums[akey]['Total Time'] += total_time
|
self._albums[akey]['Total Time'] += total_time
|
||||||
|
|
||||||
|
if self._albums[akey]['Min Bit Rate'] > track['Bit Rate']:
|
||||||
|
self._albums[akey]['Min Bit Rate'] = track['Bit Rate']
|
||||||
|
|
||||||
if 'Genre' in track:
|
if 'Genre' in track:
|
||||||
# Split up the Genres
|
# Split up the Genres
|
||||||
genre_parts = track['Genre'].split('/')
|
genre_parts = track['Genre'].split('/')
|
||||||
@@ -217,17 +224,19 @@ class ITunesParser:
|
|||||||
|
|
||||||
if 'Album Rating' in track:
|
if 'Album Rating' in track:
|
||||||
self._albums[akey]['Album Rating'] = track['Album Rating']
|
self._albums[akey]['Album Rating'] = track['Album Rating']
|
||||||
self._albums[akey]['Album Rating Computed'] = True
|
|
||||||
|
if 'Album Rating Computed' in track:
|
||||||
|
self._albums[akey]['Album Rating Computed'] = track['Album Rating Computed']
|
||||||
|
|
||||||
if 'Album Artist' in track:
|
if 'Album Artist' in track:
|
||||||
self._albums[akey]['Album Artist'] = track['Album Artist']
|
self._albums[akey]['Album Artist'] = track['Album Artist']
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def calc_rating(cls, added_value, current_rating, count):
|
def calc_average(cls, added_value, current_value, nb_values):
|
||||||
"""
|
"""
|
||||||
Calculate average rating from a current rating, a rating value to add and the number of elements
|
Calculate average value from a current value, a value to add and the number of values
|
||||||
"""
|
"""
|
||||||
return (current_rating * count + added_value) / (count + 1)
|
return (current_value * nb_values + added_value) / (nb_values + 1)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def calc_id(cls, key):
|
def calc_id(cls, key):
|
||||||
@@ -270,7 +279,7 @@ class WriteElsJson:
|
|||||||
file_albums = io.open(output_file, 'wb')
|
file_albums = io.open(output_file, 'wb')
|
||||||
for _, album in albums.items():
|
for _, album in albums.items():
|
||||||
persistent_id = album['Persistent ID']
|
persistent_id = album['Persistent ID']
|
||||||
album['Rating'] = round(album['Rating'])
|
album['Avg Bit Rate'] = round(album['Avg Bit Rate'])
|
||||||
|
|
||||||
json_track_index = {
|
json_track_index = {
|
||||||
"index": {"_index": ITunesParser.ALBUM_INDEX, "_id": persistent_id}
|
"index": {"_index": ITunesParser.ALBUM_INDEX, "_id": persistent_id}
|
||||||
|
|||||||
@@ -1,4 +1,28 @@
|
|||||||
{
|
{
|
||||||
|
"settings": {
|
||||||
|
"analysis": {
|
||||||
|
"analyzer": {
|
||||||
|
"custom_path_tree": {
|
||||||
|
"tokenizer": "custom_hierarchy"
|
||||||
|
},
|
||||||
|
"custom_path_tree_reversed": {
|
||||||
|
"tokenizer": "custom_hierarchy_reversed"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tokenizer": {
|
||||||
|
"custom_hierarchy": {
|
||||||
|
"type": "path_hierarchy",
|
||||||
|
"delimiter": "/",
|
||||||
|
"skip": 3
|
||||||
|
},
|
||||||
|
"custom_hierarchy_reversed": {
|
||||||
|
"type": "path_hierarchy",
|
||||||
|
"delimiter": "/",
|
||||||
|
"reverse": "true"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"mappings" : {
|
"mappings" : {
|
||||||
"properties": {
|
"properties": {
|
||||||
"Artist": {
|
"Artist": {
|
||||||
@@ -27,6 +51,19 @@
|
|||||||
},
|
},
|
||||||
"Kind": {
|
"Kind": {
|
||||||
"type": "keyword"
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"Location": {
|
||||||
|
"type": "text",
|
||||||
|
"fields": {
|
||||||
|
"tree": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "custom_path_tree"
|
||||||
|
},
|
||||||
|
"tree_reversed": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "custom_path_tree_reversed"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
48
mapping.suggest.json
Normal file
48
mapping.suggest.json
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
"settings": {
|
||||||
|
"index": {
|
||||||
|
"number_of_replicas": 0
|
||||||
|
},
|
||||||
|
"analysis": {
|
||||||
|
"filter": {
|
||||||
|
"french_stop": {
|
||||||
|
"type": "stop",
|
||||||
|
"stopwords": "_french_"
|
||||||
|
},
|
||||||
|
"english_stop": {
|
||||||
|
"type": "stop",
|
||||||
|
"stopwords": "_english_"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"analyzer": {
|
||||||
|
"names": {
|
||||||
|
"tokenizer": "standard",
|
||||||
|
"filter": [
|
||||||
|
"lowercase",
|
||||||
|
"asciifolding",
|
||||||
|
"french_stop",
|
||||||
|
"english_stop"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mappings": {
|
||||||
|
"properties": {
|
||||||
|
"artist_suggest": {
|
||||||
|
"type": "completion",
|
||||||
|
"search_analyzer": "names"
|
||||||
|
},
|
||||||
|
"artist": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"album_suggest": {
|
||||||
|
"type": "completion",
|
||||||
|
"search_analyzer": "names"
|
||||||
|
},
|
||||||
|
"album": {
|
||||||
|
"type": "keyword"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
141
send_data.py
141
send_data.py
@@ -10,17 +10,32 @@ import json
|
|||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from suggester import process_file
|
||||||
|
|
||||||
|
class bcolors:
|
||||||
|
HEADER = '\033[95m'
|
||||||
|
OKBLUE = '\033[94m'
|
||||||
|
OKCYAN = '\033[96m'
|
||||||
|
OKGREEN = '\033[92m'
|
||||||
|
WARNING = '\033[93m'
|
||||||
|
FAIL = '\033[91m'
|
||||||
|
ENDC = '\033[0m'
|
||||||
|
BOLD = '\033[1m'
|
||||||
|
UNDERLINE = '\033[4m'
|
||||||
|
|
||||||
# Default file names
|
# Default file names
|
||||||
DEFAULT_SONG_FILE = 'es-songs.json'
|
SONG_FILE = 'es-songs.json'
|
||||||
DEFAULT_ALBUM_FILE = 'es-albums.json'
|
ALBUM_FILE = 'es-albums.json'
|
||||||
DEFAULT_ARTIST_FILE = 'es-artists.json'
|
ARTIST_FILE = 'es-artists.json'
|
||||||
DEFAULT_MAPPING_SONGS_FILE = 'mapping.songs.json'
|
MAPPING_SONGS_FILE = 'mapping.songs.json'
|
||||||
DEFAULT_MAPPING_ARTISTS_FILE = 'mapping.artists.json'
|
MAPPING_ARTISTS_FILE = 'mapping.artists.json'
|
||||||
DEFAULT_MAPPING_ALBUMS_FILE = 'mapping.albums.json'
|
MAPPING_ALBUMS_FILE = 'mapping.albums.json'
|
||||||
|
MAPPING_SUGGEST_FILE = 'mapping.suggest.json'
|
||||||
|
|
||||||
SONG_INDEX = 'itunes-songs'
|
SONG_INDEX = 'itunes-songs'
|
||||||
ALBUM_INDEX = 'itunes-albums'
|
ALBUM_INDEX = 'itunes-albums'
|
||||||
ARTIST_INDEX = 'itunes-artists'
|
ARTIST_INDEX = 'itunes-artists'
|
||||||
|
SUGGEST_INDEX = 'itunes-suggest'
|
||||||
# TODO Put variables in a config files or in a python library
|
# TODO Put variables in a config files or in a python library
|
||||||
|
|
||||||
# Global values / set as default values
|
# Global values / set as default values
|
||||||
@@ -36,8 +51,8 @@ def main():
|
|||||||
|
|
||||||
args = create_args_parser().parse_args()
|
args = create_args_parser().parse_args()
|
||||||
|
|
||||||
if not args.song and args.ALL:
|
if args.ALL and args.no_song:
|
||||||
print(__file__ + ': error: argument -A/--ALL: not allowed with argument -s/--song')
|
print(__file__ + ': error: argument -A/--ALL: not allowed with argument --no-song')
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
# Overloaded setting value
|
# Overloaded setting value
|
||||||
@@ -57,16 +72,16 @@ def main():
|
|||||||
check_is_ok = []
|
check_is_ok = []
|
||||||
|
|
||||||
# Send song data
|
# Send song data
|
||||||
if args.song or args.ALL:
|
if not args.no_song:
|
||||||
if args.DELETE:
|
if args.DELETE:
|
||||||
mapping_song = load_file(args.mapping_song, DEFAULT_MAPPING_SONGS_FILE)
|
mapping_song = load_file(args.mapping_song, MAPPING_SONGS_FILE)
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
print("Mapping of song index file: '{}'".format(mapping_song.name))
|
print("Mapping of song index file: '{}'".format(mapping_song.name))
|
||||||
|
|
||||||
delete_index(SONG_INDEX, args.quiet)
|
delete_index(SONG_INDEX, args.quiet)
|
||||||
put_mapping(SONG_INDEX, mapping_song, args.quiet)
|
put_mapping(SONG_INDEX, mapping_song, args.quiet)
|
||||||
|
|
||||||
song_file = load_file(args.song_file, DEFAULT_SONG_FILE)
|
song_file = load_file(args.song_file, SONG_FILE)
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
print("Song file: '{}'".format(song_file.name))
|
print("Song file: '{}'".format(song_file.name))
|
||||||
|
|
||||||
@@ -85,7 +100,7 @@ def main():
|
|||||||
# Send artist data
|
# Send artist data
|
||||||
if args.artist_file or args.ALL:
|
if args.artist_file or args.ALL:
|
||||||
if args.DELETE:
|
if args.DELETE:
|
||||||
mapping_artist = load_file(args.mapping_artist, DEFAULT_MAPPING_ARTISTS_FILE)
|
mapping_artist = load_file(args.mapping_artist, MAPPING_ARTISTS_FILE)
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
print("Mapping of artist index file: '{}'".format(mapping_artist.name))
|
print("Mapping of artist index file: '{}'".format(mapping_artist.name))
|
||||||
|
|
||||||
@@ -96,7 +111,7 @@ def main():
|
|||||||
if not artist_file:
|
if not artist_file:
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
print('No artist file specified, take default file...')
|
print('No artist file specified, take default file...')
|
||||||
artist_file = open(DEFAULT_ARTIST_FILE, 'r')
|
artist_file = open(ARTIST_FILE, 'r')
|
||||||
|
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
print("Artist file: '{}'".format(artist_file.name))
|
print("Artist file: '{}'".format(artist_file.name))
|
||||||
@@ -111,7 +126,7 @@ def main():
|
|||||||
|
|
||||||
if args.album_file or args.ALL:
|
if args.album_file or args.ALL:
|
||||||
if args.DELETE:
|
if args.DELETE:
|
||||||
mapping_album = load_file(args.mapping_album, DEFAULT_MAPPING_ALBUMS_FILE)
|
mapping_album = load_file(args.mapping_album, MAPPING_ALBUMS_FILE)
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
print("Mapping of artist index file: '{}'".format(mapping_album.name))
|
print("Mapping of artist index file: '{}'".format(mapping_album.name))
|
||||||
|
|
||||||
@@ -122,7 +137,7 @@ def main():
|
|||||||
if not album_file:
|
if not album_file:
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
print('No album file specified, take default file...')
|
print('No album file specified, take default file...')
|
||||||
album_file = open(DEFAULT_ALBUM_FILE, 'r')
|
album_file = open(ALBUM_FILE, 'r')
|
||||||
|
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
print("Take file '{}' to send song data".format(album_file.name))
|
print("Take file '{}' to send song data".format(album_file.name))
|
||||||
@@ -134,6 +149,28 @@ def main():
|
|||||||
else:
|
else:
|
||||||
print('Album sent')
|
print('Album sent')
|
||||||
|
|
||||||
|
if not args.no_suggest:
|
||||||
|
print("Process suggestion:")
|
||||||
|
if args.DELETE:
|
||||||
|
delete_index(SUGGEST_INDEX, args.quiet)
|
||||||
|
|
||||||
|
if not args.ALL and not args.album_file and not args.artist_file:
|
||||||
|
print('Only song file processed. No suggestion to process.')
|
||||||
|
else:
|
||||||
|
if args.DELETE:
|
||||||
|
mapping_suggest = load_file(args.mapping_suggest, MAPPING_SUGGEST_FILE)
|
||||||
|
if not args.quiet:
|
||||||
|
print("Mapping of suggest index file: '{}'".format(mapping_suggest.name))
|
||||||
|
put_mapping(SUGGEST_INDEX, mapping_suggest, args.quiet)
|
||||||
|
|
||||||
|
suggs_docs = 0
|
||||||
|
if args.album_file or args.ALL:
|
||||||
|
suggs_docs += process_file(ALBUM_FILE, 'Album')
|
||||||
|
print('Created suggestion documents: ' + str(suggs_docs))
|
||||||
|
if args.artist_file or args.ALL:
|
||||||
|
suggs_docs += process_file(ARTIST_FILE, 'Artist', 'Album Artist')
|
||||||
|
print('Created suggestion documents: ' + str(suggs_docs))
|
||||||
|
|
||||||
print("I'm done!")
|
print("I'm done!")
|
||||||
if check_is_ok.count(False) > 0:
|
if check_is_ok.count(False) > 0:
|
||||||
print('Some problems occurs')
|
print('Some problems occurs')
|
||||||
@@ -162,15 +199,14 @@ def create_args_parser():
|
|||||||
# TODO rewrit description with multi-index phylosophie
|
# TODO rewrit description with multi-index phylosophie
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='''
|
description='''
|
||||||
Send JSON files formated for bulk Elasticsearch operation to an Elasticsearch.
|
Send JSON files formated for bulk Elasticsearch operation to an Elasticsearch.
|
||||||
|
|
||||||
By default: send song data enable, send album & artist data disabled.
|
By default: send only song data. See option to send album/artist/suggest data.
|
||||||
Check that all the data has been sent.
|
|
||||||
|
|
||||||
Detect if index doesn't exist and create it with a mapping file (see -map and -idx argument).
|
Create index if -D option activated with a mapping file (see -map).
|
||||||
Remeber : it's cumulative! If you want to remove songs/artits/albums,
|
|
||||||
you have to delete and re-create the index (use -D option).
|
It's cumulative! If you want to remove songs/artits/albums, you have to delete and re-create the index (use -D option).''',
|
||||||
'''
|
formatter_class=argparse.RawTextHelpFormatter
|
||||||
)
|
)
|
||||||
# Bulk
|
# Bulk
|
||||||
parser.add_argument('-q', '--quiet', action='store_true',
|
parser.add_argument('-q', '--quiet', action='store_true',
|
||||||
@@ -179,38 +215,43 @@ def create_args_parser():
|
|||||||
sending_group = parser.add_argument_group("Sending options")
|
sending_group = parser.add_argument_group("Sending options")
|
||||||
song_group = sending_group.add_mutually_exclusive_group()
|
song_group = sending_group.add_mutually_exclusive_group()
|
||||||
song_group.add_argument('-sf', '--song-file', type=argparse.FileType('r'),
|
song_group.add_argument('-sf', '--song-file', type=argparse.FileType('r'),
|
||||||
help='Song file data to send (default: \'{}\').'.format(DEFAULT_SONG_FILE))
|
help='Song file data to send (default: \'{}\').'.format(SONG_FILE))
|
||||||
sending_group.add_argument('-al', '--album-file', nargs='?', type=argparse.FileType('r'), const=DEFAULT_ALBUM_FILE,
|
sending_group.add_argument('-al', '--album-file', nargs='?', type=argparse.FileType('r'), const=ALBUM_FILE,
|
||||||
help='Enable sending album data. Optionally, precise the album data file (default: \'{}\')'
|
help='Enable sending album data. Optionally, precise the album data file (default: \'{}\')'
|
||||||
.format(DEFAULT_ALBUM_FILE))
|
.format(ALBUM_FILE))
|
||||||
sending_group.add_argument('-ar', '--artist-file', nargs='?', type=argparse.FileType('r'), const=DEFAULT_ARTIST_FILE,
|
sending_group.add_argument('-ar', '--artist-file', nargs='?', type=argparse.FileType('r'), const=ARTIST_FILE,
|
||||||
help='Enable sending artist data. Optionally, precise the artist data file (default: \'{}\')'
|
help='Enable sending artist data. Optionally, precise the artist data file (default: \'{}\')'
|
||||||
.format(DEFAULT_ARTIST_FILE))
|
.format(ARTIST_FILE))
|
||||||
song_group.add_argument('-s', '--song', action='store_false',
|
|
||||||
help='Disable sending song data')
|
|
||||||
|
|
||||||
# Mode
|
# Mode
|
||||||
mode_group = parser.add_argument_group('Mode')
|
mode_group = parser.add_argument_group('Mode')
|
||||||
mode_group.add_argument('-A', '--ALL', action='store_true',
|
mode_group.add_argument('-A', '--ALL', action='store_true',
|
||||||
help='Send all possible data: song, artist and album')
|
help='Send all possible data: song, artist, album and suggest. Use default file if not specified')
|
||||||
mode_group.add_argument('-D', '--DELETE', action='store_true',
|
mode_group.add_argument('-D', '--DELETE', action='store_true',
|
||||||
help='''Delete old index and create a new.
|
help='Delete index and create new. See -map arguement to set mapping file')
|
||||||
See -idx argument to set index name.
|
mode_group.add_argument('--no-song', action='store_true',
|
||||||
See -map arguement to set mapping file.''')
|
help='''Disable sending song data.
|
||||||
|
Not allowed with -A option.''')
|
||||||
|
mode_group.add_argument('--no-suggest', action='store_true',
|
||||||
|
help='Disable sending suggest data. Allowed with -A option')
|
||||||
|
|
||||||
# Mapping
|
# Mapping
|
||||||
mapping_group = parser.add_argument_group('Mapping files')
|
mapping_group = parser.add_argument_group('Mapping files')
|
||||||
mode_group.add_argument('-ms', '--mapping-song', type=argparse.FileType('r'), const=DEFAULT_MAPPING_SONGS_FILE, nargs='?',
|
# CAUTION default values cannot be used because they necessarily activate the option
|
||||||
help='Mapping file for songs (default: \'{}\')'.format(DEFAULT_MAPPING_SONGS_FILE))
|
# QUESTION Use a for with a list of default mapping file?
|
||||||
mode_group.add_argument('-mr', '--mapping-artist', type=argparse.FileType('r'), const=DEFAULT_ARTIST_FILE, nargs='?',
|
mapping_group.add_argument('-ms', '--mapping-song', type=argparse.FileType('r'), const=MAPPING_SONGS_FILE, nargs='?',
|
||||||
help='Mapping file for artists (default: \'{}\')'.format(DEFAULT_MAPPING_ARTISTS_FILE))
|
help='Mapping file for songs (default: \'{}\')'.format(MAPPING_SONGS_FILE))
|
||||||
mode_group.add_argument('-ml', '--mapping-album', type=argparse.FileType('r'), const=DEFAULT_MAPPING_ALBUMS_FILE, nargs='?',
|
mapping_group.add_argument('-mr', '--mapping-artist', type=argparse.FileType('r'), const=ARTIST_FILE, nargs='?',
|
||||||
help='Mapping file for albums (default: \'{}\')'.format(DEFAULT_MAPPING_ALBUMS_FILE))
|
help='Mapping file for artists (default: \'{}\')'.format(MAPPING_ARTISTS_FILE))
|
||||||
|
mapping_group.add_argument('-ml', '--mapping-album', type=argparse.FileType('r'), const=MAPPING_ALBUMS_FILE, nargs='?',
|
||||||
|
help='Mapping file for albums (default: \'{}\')'.format(MAPPING_ALBUMS_FILE))
|
||||||
|
mapping_group.add_argument('-mg', '--mapping-suggest', type=argparse.FileType('r'), const=MAPPING_SUGGEST_FILE, nargs='?',
|
||||||
|
help='Mapping file for suggest (default: \'{}\')'.format(MAPPING_SUGGEST_FILE))
|
||||||
|
|
||||||
# Global Settings
|
# Global Settings
|
||||||
g_settings_group = parser.add_argument_group('Global Settings')
|
g_settings_group = parser.add_argument_group('Global Settings')
|
||||||
g_settings_group.add_argument('-els', '--elasticsearch-url', default=ELASTICSEARCH_URL, nargs='?',
|
g_settings_group.add_argument('-els', '--elasticsearch-url', default=ELASTICSEARCH_URL, nargs='?',
|
||||||
help="Elasticsearch URL (default: \'{}\')".format(ELASTICSEARCH_URL))
|
help="Elasticsearch URL.")
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@@ -231,7 +272,7 @@ def send_data(file, quiet=False):
|
|||||||
print(res.text)
|
print(res.text)
|
||||||
else:
|
else:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print("File '{}' sent to Elasticsearch!".format(file.name))
|
print(bcolors.OKGREEN + "File '{}' sent to Elasticsearch!".format(file.name) + bcolors.ENDC)
|
||||||
|
|
||||||
def delete_index(index_name, quiet=False):
|
def delete_index(index_name, quiet=False):
|
||||||
"""
|
"""
|
||||||
@@ -242,9 +283,9 @@ def delete_index(index_name, quiet=False):
|
|||||||
res = requests.delete(url=ELASTICSEARCH_URL + index_name)
|
res = requests.delete(url=ELASTICSEARCH_URL + index_name)
|
||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print("Deleted!")
|
print(bcolors.OKGREEN + "Index '{}' deleted!".format(index_name) + bcolors.ENDC)
|
||||||
else:
|
else:
|
||||||
print("An error occured")
|
print(bcolors.FAIL + "An error occured" + bcolors.ENDC)
|
||||||
if res.json()['error']['type'] == 'index_not_found_exception':
|
if res.json()['error']['type'] == 'index_not_found_exception':
|
||||||
print("Index '{}' doesn't exist and can't be deleted".format(index_name))
|
print("Index '{}' doesn't exist and can't be deleted".format(index_name))
|
||||||
else:
|
else:
|
||||||
@@ -261,11 +302,11 @@ def put_mapping(index_name, mapping_file, quiet=False):
|
|||||||
data=mapping_file,
|
data=mapping_file,
|
||||||
headers={'Content-Type': 'application/json'})
|
headers={'Content-Type': 'application/json'})
|
||||||
if res.status_code != 200:
|
if res.status_code != 200:
|
||||||
print("An error occured")
|
print(bcolors.FAIL + "An error occured")
|
||||||
print(res.text)
|
print(res.text + bcolors.ENDC)
|
||||||
else:
|
else:
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print("File '{}' sent to Elasticsearch!".format(mapping_file.name))
|
print(bcolors.OKGREEN + "Mapping for '{}' sent".format(index_name) + bcolors.ENDC)
|
||||||
|
|
||||||
put_setting(index_name, 0, quiet)
|
put_setting(index_name, 0, quiet)
|
||||||
|
|
||||||
@@ -292,8 +333,8 @@ def check_all_data_is_saved(data_file, index_name, quiet=False):
|
|||||||
data=json.dumps(payload),
|
data=json.dumps(payload),
|
||||||
headers={'Content-Type': 'application/x-ndjson'})
|
headers={'Content-Type': 'application/x-ndjson'})
|
||||||
if res.status_code != 200:
|
if res.status_code != 200:
|
||||||
print("An error occured")
|
print(bcolors.FAIL + "An error occured")
|
||||||
print(res.text)
|
print(res.text + bcolors.ENDC)
|
||||||
|
|
||||||
els_nb_doc = res.json()['hits']['total']['value']
|
els_nb_doc = res.json()['hits']['total']['value']
|
||||||
|
|
||||||
@@ -301,9 +342,9 @@ def check_all_data_is_saved(data_file, index_name, quiet=False):
|
|||||||
print("\tFound: {} documents in index '{}' in ELS".format(els_nb_doc, index_name))
|
print("\tFound: {} documents in index '{}' in ELS".format(els_nb_doc, index_name))
|
||||||
|
|
||||||
if file_nb_line != els_nb_doc:
|
if file_nb_line != els_nb_doc:
|
||||||
print('Look out! Not all the data has been found in ELS')
|
print(bcolors.WARNING + 'Look out! Not all the data has been found in ELS' + bcolors.ENDC)
|
||||||
elif not quiet:
|
elif not quiet:
|
||||||
print('All data is in ELS, it\'s ok')
|
print(bcolors.OKGREEN + 'All data is in ELS, it\'s ok' + bcolors.ENDC)
|
||||||
|
|
||||||
return file_nb_line == els_nb_doc
|
return file_nb_line == els_nb_doc
|
||||||
|
|
||||||
|
|||||||
93
suggester.es
Normal file
93
suggester.es
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
DELETE itunes-suggest
|
||||||
|
|
||||||
|
PUT /itunes-suggest
|
||||||
|
!./mapping.suggest.json
|
||||||
|
|
||||||
|
// Also possible to specify analyze for ingesting => https://stackoverflow.com/questions/48304499/elasticsearch-completion-suggester-not-working-with-whitespace-analyzer
|
||||||
|
|
||||||
|
// Problem with word EP, SP
|
||||||
|
|
||||||
|
GET itunes-suggest/_analyze
|
||||||
|
{
|
||||||
|
"analyzer": "names",
|
||||||
|
"text": "the servent"
|
||||||
|
}
|
||||||
|
|
||||||
|
GET itunes-suggest/_search
|
||||||
|
|
||||||
|
GET itunes-suggest/_search
|
||||||
|
{
|
||||||
|
"_source" : "artist",
|
||||||
|
"suggest": {
|
||||||
|
"name-suggest": {
|
||||||
|
"prefix": "sou",
|
||||||
|
"completion": {
|
||||||
|
"field": "artist_suggest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GET itunes-suggest/_search
|
||||||
|
{
|
||||||
|
"_source" : "album",
|
||||||
|
"suggest": {
|
||||||
|
"name-suggest": {
|
||||||
|
"prefix": "new",
|
||||||
|
"completion": {
|
||||||
|
"field": "album_suggest",
|
||||||
|
"size": 20
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GET itunes-suggest/_search
|
||||||
|
{
|
||||||
|
"_source": ["album", "artist"],
|
||||||
|
"suggest": {
|
||||||
|
"alb-suggest": {
|
||||||
|
"prefix": "sou",
|
||||||
|
"completion": {
|
||||||
|
"field": "album_suggest"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ar-suggest": {
|
||||||
|
"prefix": "sou",
|
||||||
|
"completion": {
|
||||||
|
"field": "artist_suggest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GET itunes-suggest/_search
|
||||||
|
{
|
||||||
|
"_source": ["album", "artist"],
|
||||||
|
"suggest": {
|
||||||
|
"alb-suggest": {
|
||||||
|
"prefix": "Francois",
|
||||||
|
"completion": {
|
||||||
|
"field": "album_suggest"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ar-suggest": {
|
||||||
|
"prefix": "Francois",
|
||||||
|
"completion": {
|
||||||
|
"field": "artist_suggest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GET itunes-suggest/_search
|
||||||
|
{
|
||||||
|
"suggest": {
|
||||||
|
"ar-suggest": {
|
||||||
|
"prefix": "Femme",
|
||||||
|
"completion": {
|
||||||
|
"field": "artist_suggest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
142
suggester.py
Normal file
142
suggester.py
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
"""
|
||||||
|
Process files generated by iTunesParser to fill a suggester index.
|
||||||
|
Suggester index in ELS must be created before use.
|
||||||
|
|
||||||
|
Found suggester.es query to create index.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
import requests
|
||||||
|
|
||||||
|
ELS_URL = 'http://localhost:9200'
|
||||||
|
INDEX = 'itunes-suggest'
|
||||||
|
|
||||||
|
class NoGoodDataException(Exception):
|
||||||
|
""" Raise when data can't be correctly analyzed """
|
||||||
|
|
||||||
|
def get_tokens(data: str) -> list:
|
||||||
|
"""
|
||||||
|
Query Elasticsearch to get token for a string with a specific analyzer.
|
||||||
|
Throw an exception if no token found in ELS response.
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
data: string
|
||||||
|
String to be analysed to obtain the tokens
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
list
|
||||||
|
A list of token
|
||||||
|
Raises
|
||||||
|
------
|
||||||
|
NoGoodDataException
|
||||||
|
If no tokens are found in the ELS responses, consider that the data is not correct for analysis.
|
||||||
|
"""
|
||||||
|
if not data:
|
||||||
|
return []
|
||||||
|
query = {
|
||||||
|
"analyzer": "names", # TODO Parameterize analyzer ?
|
||||||
|
"text" : data
|
||||||
|
}
|
||||||
|
|
||||||
|
url = '{}/{}/_analyze'.format(ELS_URL, INDEX)
|
||||||
|
req = requests.get(url, json=query)
|
||||||
|
|
||||||
|
if not 'tokens' in req.json():
|
||||||
|
print('ERROR: Not tokens in result')
|
||||||
|
print('Input: ' + str(data))
|
||||||
|
print('Request: ' + str(req.json()))
|
||||||
|
raise NoGoodDataException('Data is not correct to get tokens')
|
||||||
|
return [t['token'] for t in req.json()['tokens']]
|
||||||
|
|
||||||
|
def post_document(main_field_value: str, input_terms: list, main_field_name: str) -> str:
|
||||||
|
"""
|
||||||
|
Create suggestion document in Elasticsearch.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
main_field_value : str
|
||||||
|
Value to put in the main field named by `main_field_name`
|
||||||
|
input_terms : list
|
||||||
|
List of suggestion term to put in document
|
||||||
|
main_field_name : str
|
||||||
|
Name of the main field, to fill with `main_field_value`
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
str
|
||||||
|
Success: ID of created document
|
||||||
|
Fail (ret. status <> 201): None
|
||||||
|
"""
|
||||||
|
suggest_name = main_field_name + '_suggest'
|
||||||
|
element = {
|
||||||
|
main_field_name: main_field_value,
|
||||||
|
suggest_name: input_terms
|
||||||
|
}
|
||||||
|
|
||||||
|
# Filter empty keys
|
||||||
|
# element = {k: v for k, v in element.items() if v}
|
||||||
|
|
||||||
|
url = '{}/{}/_doc'.format(ELS_URL, INDEX)
|
||||||
|
resp = requests.post(url, json=element)
|
||||||
|
if resp.status_code != 201:
|
||||||
|
print('ELS Response KO')
|
||||||
|
print(resp.status_code)
|
||||||
|
print(resp.text)
|
||||||
|
return None
|
||||||
|
|
||||||
|
el_id = resp.json()['_id']
|
||||||
|
# print('Post_element - Element created: ' + el_id)
|
||||||
|
return el_id
|
||||||
|
|
||||||
|
def process_file(file_name: str, field_name: str, array_file: str = None) -> int:
|
||||||
|
"""
|
||||||
|
Process a JSON file with data
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
file_name: string
|
||||||
|
Path and name of file to analyze
|
||||||
|
field_name: string
|
||||||
|
Name of the field where to find the data to create the suggestion entries
|
||||||
|
array_file: string, Default: None
|
||||||
|
Name of an array field to analyze to create more suggestion entries.
|
||||||
|
Nothing if None
|
||||||
|
"""
|
||||||
|
print('Process file: ' + file_name)
|
||||||
|
with open(file_name, 'r') as o_file:
|
||||||
|
lines = o_file.readlines()
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
i = 0
|
||||||
|
for line in lines:
|
||||||
|
i += 1
|
||||||
|
sys.stdout.write(str(int((i/len(lines))*100)) + '%')
|
||||||
|
sys.stdout.flush()
|
||||||
|
sys.stdout.write("\b" * (40+1)) # return to start of line, after '['
|
||||||
|
data = json.loads(line)
|
||||||
|
if not "index" in data: # Exclude index line
|
||||||
|
try:
|
||||||
|
suggests_entries = get_tokens(data[field_name])
|
||||||
|
|
||||||
|
if array_file and array_file in data and data[array_file]:
|
||||||
|
for key in data[array_file]:
|
||||||
|
suggests_entries.extend(get_tokens(key))
|
||||||
|
|
||||||
|
# TODO Input have the same value several times ==> use to process a score
|
||||||
|
post_document(main_field_value=data[field_name], input_terms=suggests_entries, main_field_name=field_name.lower())
|
||||||
|
count += 1
|
||||||
|
except NoGoodDataException:
|
||||||
|
print('ERROR WITH DATA')
|
||||||
|
print(str(data))
|
||||||
|
print('File processed\n')
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
created_docs = 0
|
||||||
|
created_docs += process_file('/home/budd/workspace/iTunes/es-albums.json', 'Album')
|
||||||
|
print('Created documents: ' + str(created_docs))
|
||||||
|
created_docs += process_file('/home/budd/workspace/iTunes/es-artists.json', 'Artist', 'Album Artist')
|
||||||
|
print('Created documents: ' + str(created_docs))
|
||||||
|
# TODO Created doc <> nb doc in ELS
|
||||||
Reference in New Issue
Block a user