Commit inicial

Ya habia trabajado pero tuve que separar los repositorios y se perdio la
historia para mi pena :c
This commit is contained in:
Daniel Cortes
2020-05-22 00:04:10 -04:00
commit 446ea8a4cf
41 changed files with 14250 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }

View File

@@ -0,0 +1,66 @@
<nav class="navbar is-primary" role="navigation" aria-label="main navigation">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item" href="/"><h1 class="title is-4 has-text-white">MusicList</h1></a>
</div>
<div class="navbar-menu">
<div class="navbar-start">
</div>
<div class="navbar-end">
<div class="navbar-item">
<div class="buttons">
<a class="button is-info">
<strong>Sign up</strong>
</a>
<a class="button is-primary">Log in</a>
</div>
</div>
</div>
</div>
</div>
</nav>
<section class="hero is-primary">
<div class="hero-body">
<div class="container">
<h1 class="title">Busca la musica que disfrutas!</h1>
<app-search></app-search>
</div>
</div>
</section>
<section class="section">
<div class="container">
<h1 class="is-size-4 ">Artistas populares</h1>
<div class="columns">
<div class="column" *ngFor="let _ of ' '.repeat(4).split(' ')">
<div class="card">
<div class="card-header">
<p class="card-header-title">Mago de oz</p>
</div>
<div class="card-image">
<figure class="image is-1by1">
<img src="https://ia801007.us.archive.org/9/items/mbid-fdf58ef9-c533-4335-bac6-28634f131a73/mbid-fdf58ef9-c533-4335-bac6-28634f131a73-23273731083.jpg">
</figure>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="section">
<div class="container">
<h1 class="is-size-4 ">Ultimas opiniones</h1>
<div class="columns">
<div class="column" *ngFor="let _ of ' '.repeat(2).split(' ')">
<div class="card">
<div class="card-header">
<p class="card-header-title">Jhon</p>
</div>
<div class="card-content">
Facere esse corrupti modi qui aut commodi. Saepe culpa corporis ut doloribus excepturi temporibus commodi
animi. Est ut ut enim dolorem fugit voluptatem. Qui sunt earum vel excepturi aliquam dolor numquam...
</div>
</div>
</div>
</div>
</div>
</section>

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,35 @@
import { TestBed, async } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
AppComponent
],
}).compileComponents();
}));
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it(`should have as title 'client'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('client');
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(compiled.querySelector('.content span').textContent).toContain('client app is running!');
});
});

10
src/app/app.component.ts Normal file
View File

@@ -0,0 +1,10 @@
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'client';
}

22
src/app/app.module.ts Normal file
View File

@@ -0,0 +1,22 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { SearchComponent } from './search/search.component';
import {HttpClientModule} from "@angular/common/http";
@NgModule({
declarations: [
AppComponent,
SearchComponent
],
imports: [
HttpClientModule,
BrowserModule,
AppRoutingModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { BrainzService } from './brainz.service';
describe('BrainzService', () => {
let service: BrainzService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(BrainzService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

60
src/app/brainz.service.ts Normal file
View File

@@ -0,0 +1,60 @@
import {Injectable} from '@angular/core';
import {HttpClient, HttpErrorResponse, HttpHeaders} from '@angular/common/http';
import {Observable, of} from 'rxjs';
import {catchError, map, tap} from 'rxjs/operators';
import {BrainzError, Artist, BrowseReleaseGroup, CoverArt, ReleaseGroup} from './models/brainz';
@Injectable({
providedIn: 'root'
})
export class BrainzService {
private httpOptions = {
headers: new HttpHeaders({'content-type': 'application/json'})
};
private url = 'http://127.0.0.1:8000/api/brainz';
constructor(private http: HttpClient) {
}
private log(message: string) {
console.log(`BrainzService: ${message}`);
}
private handleError(operation: string) {
return (error: HttpErrorResponse): Observable<BrainzError> => {
const brainzError = error.error as BrainzError;
this.log(`${operation} failed: ${brainzError.status} - ${brainzError.error}`);
return of(brainzError);
};
}
getArtist(id: string): Observable<Artist | BrainzError> {
const url = `${this.url}/get/artist/${id}/`;
this.log(`Querying ${url}`);
return this.http.get<Artist>(url).pipe(
tap(artist => this.log(`getArtist found`)),
tap(artist => console.log(artist)),
catchError(this.handleError('getArtist'))
);
}
getDiscography(artistID: string): Observable<ReleaseGroup[] | BrainzError> {
const url = `${this.url}/browse/release-group/?artist=${artistID}&limit=10`;
this.log(`Querying ${url}`);
return this.http.get<BrowseReleaseGroup>(url).pipe(
map(discography => discography.release_groups),
tap(d => this.log(`getDiscography found`)),
tap(d => console.log(d)),
catchError(this.handleError('getDiscography'))
);
}
getCoverReleaseGroup(id: string): Observable<CoverArt | BrainzError> {
const url = `${this.url}/coverart/release-group/${id}/`;
return this.http.get<CoverArt>(url).pipe(
tap(cover => this.log(`cover found for ${id}`)),
catchError(this.handleError('getCoverReleaseGroup '))
);
};
}

62
src/app/models/brainz.ts Normal file
View File

@@ -0,0 +1,62 @@
export interface BrainzError {
status: number;
error: string;
}
export function isBrainzError(object: any): boolean {
return 'status' in object && 'error' in object;
}
export interface LifeSpan {
begin: number;
end: number;
ended: boolean;
}
export interface Area {
id: string;
type: string;
type_id: string;
name: string;
sort_name: string;
iso_3166_1_codes: string[];
disambiguation: string;
}
export interface Artist {
id: string;
isnis: string;
ipis: string;
name: string;
sort_name: string;
area: Area;
begin_area: Area;
end_area: Area;
country: string;
life_span: LifeSpan;
gender: string;
gender_id: string;
type: string;
disambiguation: string;
}
export interface ReleaseGroup {
id: string;
title: string;
first_release_date: string;
disambiguation: string;
primary_type: string;
primary_type_id: string;
secondary_types: string[];
secondary_type_ids: string[];
}
export interface BrowseReleaseGroup {
release_groups: ReleaseGroup[];
release_group_count: number;
release_group_offset: number;
}
export interface CoverArt {
link: string;
}

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { SearchService } from './search.service';
describe('SearchService', () => {
let service: SearchService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(SearchService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

30
src/app/search.service.ts Normal file
View File

@@ -0,0 +1,30 @@
import {Injectable} from '@angular/core';
import {Observable, of} from "rxjs";
import {HttpClient} from "@angular/common/http";
import {debounceTime, distinctUntilChanged, switchMap} from "rxjs/operators";
@Injectable({
providedIn: 'root'
})
export class SearchService {
baseUrl: string = 'https://api.cdnjs.com/libraries';
queryUrl: string = '?search=';
constructor(private http: HttpClient) {
}
search(terms: Observable<string>): Observable<any> {
return terms.pipe(
debounceTime(400),
distinctUntilChanged(),
switchMap(term => this.searchEntries(term))
);
}
private searchEntries(term: string) {
if(!term){
return of({results: []});
}
return this.http.get(this.baseUrl + this.queryUrl + term);
}
}

View File

@@ -0,0 +1,14 @@
<div class="field has-addons">
<div class="control is-expanded">
<input #searchbox class="input" type="search" (input)="searchTerm$.next(searchbox.value)" (focus)="setFocus(true)" (blur)="setFocus(false)" >
</div>
<div class="control">
<a class="button is-white"><span class="icon"><i class="fas fa-search"></i></span></a>
</div>
</div>
<ul *ngIf="results.length !== 0 && isFocused" class="autocomplete">
<li *ngFor="let result of results | slice:0:9">
{{ result.name }}
</li>
</ul>

View File

@@ -0,0 +1,30 @@
@import "~bulma";
.field:not(:last-child){
margin-bottom: 0;
}
.autocomplete {
position: absolute;
z-index: 2;
margin-top: 1em;
width: 40ch;
max-height: 30ch;
overflow-y: auto;
background-color: $body-background-color;
color: $text;
border: 1px solid $border;
}
.autocomplete li {
padding-top: 1em;
padding-bottom: 1em;
padding-left: 1em;
}
.autocomplete li:not(:last-child) {
border-bottom: 1px solid $border;
}
.autocomplete li:hover {
background-color: $warning;
}

View File

@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SearchComponent } from './search.component';
describe('SearchComponent', () => {
let component: SearchComponent;
let fixture: ComponentFixture<SearchComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SearchComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SearchComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,26 @@
import { Component, OnInit } from '@angular/core';
import {Subject} from "rxjs";
import {SearchService} from "../search.service";
@Component({
selector: 'app-search',
templateUrl: './search.component.html',
styleUrls: ['./search.component.scss']
})
export class SearchComponent implements OnInit {
results: Object[] = [];
searchTerm$ = new Subject<string>();
isFocused: boolean = false;
constructor(private searchService: SearchService) {
this.searchService.search(this.searchTerm$).subscribe(results => this.results = results.results);
}
setFocus(status: boolean): void {
this.isFocused = status;
}
ngOnInit(): void {
}
}

View File

@@ -0,0 +1,8 @@
<svg width="400" height="400" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="#9281FF"/>
<circle cx="50%" cy="50%" r="40%" fill="white" />
<circle cx="50%" cy="50%" r="15%" fill="#9281FF" />
<circle cx="50%" cy="50%" r="12%" fill="white" />
<circle cx="50%" cy="50%" r="8%" fill="#9281FF" />
</svg>

After

Width:  |  Height:  |  Size: 337 B

View File

@@ -0,0 +1,8 @@
<svg width="400" height="400" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="#eaeaea"/>
<circle cx="50%" cy="50%" r="40%" fill="white" />
<circle cx="50%" cy="50%" r="15%" fill="#eaeaea" />
<circle cx="50%" cy="50%" r="12%" fill="white" />
<circle cx="50%" cy="50%" r="8%" fill="#eaeaea" />
</svg>

After

Width:  |  Height:  |  Size: 337 B

View File

@@ -0,0 +1,3 @@
export const environment = {
production: true
};

View File

@@ -0,0 +1,16 @@
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
export const environment = {
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/dist/zone-error'; // Included with Angular CLI.

BIN
src/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 948 B

13
src/index.html Normal file
View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Client</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/svg+xml" href="assets/svg/favicon.svg">
</head>
<body>
<app-root></app-root>
</body>
</html>

12
src/main.ts Normal file
View File

@@ -0,0 +1,12 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));

63
src/polyfills.ts Normal file
View File

@@ -0,0 +1,63 @@
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.
/**
* Web Animations `@angular/platform-browser/animations`
* 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`.
/**
* 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 default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/

14
src/styles.scss Normal file
View File

@@ -0,0 +1,14 @@
$purple: hsl(249, 100%, 75%);
$purple: #9380ff;
$blue: hsl(215, 100%, 74%);
$pink: hsl(272, 100%, 74%);
$yellow: hsl(49, 100%, 67%);
$primary: $purple;
$info: $blue;
$warning: $yellow;
@import "~bulma";
@import "~@fortawesome/fontawesome-free/css/all.css";

25
src/test.ts Normal file
View File

@@ -0,0 +1,25 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(path: string, deep?: boolean, filter?: RegExp): {
keys(): string[];
<T>(id: string): T;
};
};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);