mirror of
https://github.com/house-of-vanity/hexound.ru.git
synced 2025-07-07 06:44:07 +00:00
wtf
This commit is contained in:
6
src/app/lazyload.ts
Normal file
6
src/app/lazyload.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export const lazyload = [
|
||||||
|
{
|
||||||
|
path: 'song',
|
||||||
|
loadChildren: './modules/song/song.module#SongModule',
|
||||||
|
}
|
||||||
|
];
|
6
src/app/models/song.models.ts
Normal file
6
src/app/models/song.models.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export class ModelSongs {
|
||||||
|
songName: string;
|
||||||
|
id: number;
|
||||||
|
md5: string;
|
||||||
|
time: string;
|
||||||
|
}
|
7
src/app/models/urls.models.ts
Normal file
7
src/app/models/urls.models.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export class Urls {
|
||||||
|
|
||||||
|
static get song() {
|
||||||
|
return 'http://192.168.43.30:5000/mods'
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
82
src/app/modules/material/material.module.ts
Normal file
82
src/app/modules/material/material.module.ts
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import {
|
||||||
|
MatBadgeModule,
|
||||||
|
MatProgressSpinnerModule,
|
||||||
|
MatCheckboxModule,
|
||||||
|
MatAutocompleteModule,
|
||||||
|
MatFormFieldModule,
|
||||||
|
MatButtonModule,
|
||||||
|
MatButtonToggleModule,
|
||||||
|
MatCardModule,
|
||||||
|
MatChipsModule,
|
||||||
|
MatDatepickerModule,
|
||||||
|
MatDialogModule,
|
||||||
|
MatExpansionModule,
|
||||||
|
MatGridListModule,
|
||||||
|
MatIconModule,
|
||||||
|
MatInputModule,
|
||||||
|
MatListModule,
|
||||||
|
MatMenuModule,
|
||||||
|
MatNativeDateModule,
|
||||||
|
MatPaginatorModule,
|
||||||
|
MatProgressBarModule,
|
||||||
|
MatRadioModule,
|
||||||
|
MatRippleModule,
|
||||||
|
MatSelectModule,
|
||||||
|
MatSidenavModule,
|
||||||
|
MatSliderModule,
|
||||||
|
MatSlideToggleModule,
|
||||||
|
MatSnackBarModule,
|
||||||
|
MatSortModule,
|
||||||
|
MatTableModule,
|
||||||
|
MatTabsModule,
|
||||||
|
MatToolbarModule,
|
||||||
|
MatTooltipModule,
|
||||||
|
} from '@angular/material';
|
||||||
|
|
||||||
|
const material = [
|
||||||
|
MatBadgeModule,
|
||||||
|
MatProgressSpinnerModule,
|
||||||
|
MatCheckboxModule,
|
||||||
|
MatAutocompleteModule,
|
||||||
|
MatButtonModule,
|
||||||
|
MatButtonToggleModule,
|
||||||
|
MatCardModule,
|
||||||
|
MatCheckboxModule,
|
||||||
|
MatChipsModule,
|
||||||
|
MatFormFieldModule,
|
||||||
|
MatDatepickerModule,
|
||||||
|
MatDialogModule,
|
||||||
|
MatExpansionModule,
|
||||||
|
MatGridListModule,
|
||||||
|
MatIconModule,
|
||||||
|
MatInputModule,
|
||||||
|
MatListModule,
|
||||||
|
MatMenuModule,
|
||||||
|
MatNativeDateModule,
|
||||||
|
MatPaginatorModule,
|
||||||
|
MatProgressBarModule,
|
||||||
|
MatRadioModule,
|
||||||
|
MatRippleModule,
|
||||||
|
MatSelectModule,
|
||||||
|
MatSidenavModule,
|
||||||
|
MatSliderModule,
|
||||||
|
MatSlideToggleModule,
|
||||||
|
MatSnackBarModule,
|
||||||
|
MatSortModule,
|
||||||
|
MatTableModule,
|
||||||
|
MatTabsModule,
|
||||||
|
MatToolbarModule,
|
||||||
|
MatTooltipModule,
|
||||||
|
];
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
...material
|
||||||
|
],
|
||||||
|
exports: material,
|
||||||
|
declarations: []
|
||||||
|
})
|
||||||
|
export class MaterialModule { }
|
0
src/app/modules/song/song.component.css
Normal file
0
src/app/modules/song/song.component.css
Normal file
16
src/app/modules/song/song.component.html
Normal file
16
src/app/modules/song/song.component.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<div style="text-align: center">
|
||||||
|
<table style="margin: 0 auto" *ngFor="let song of commonService.songArray" class="mat-elevation-z8">
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<th>No.</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Time</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td> {{song.id}} </td>
|
||||||
|
<td style="width: 500px; text-align: center"> {{song.songName}} </td>
|
||||||
|
<td> {{song.time}} </td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
</div>
|
5
src/app/modules/song/song.component.scss
Normal file
5
src/app/modules/song/song.component.scss
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
table {
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
25
src/app/modules/song/song.component.spec.ts
Normal file
25
src/app/modules/song/song.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { SongComponent } from './song.component';
|
||||||
|
|
||||||
|
describe('SongComponent', () => {
|
||||||
|
let component: SongComponent;
|
||||||
|
let fixture: ComponentFixture<SongComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ SongComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(SongComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
33
src/app/modules/song/song.component.ts
Normal file
33
src/app/modules/song/song.component.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import {RestService} from '../../services/rest.services';
|
||||||
|
import {Urls} from '../../models/urls.models';
|
||||||
|
import {CommonService} from '../../services/common.service';
|
||||||
|
import {ModelSongs} from '../../models/song.models';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-song',
|
||||||
|
templateUrl: './song.component.html',
|
||||||
|
styleUrls: ['./song.component.scss']
|
||||||
|
})
|
||||||
|
export class SongComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private restService: RestService,
|
||||||
|
public commonService: CommonService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.restService.get(Urls.song).subscribe((response) => {
|
||||||
|
this.commonService.songArray = response.map(song => {
|
||||||
|
let result = new ModelSongs();
|
||||||
|
result.songName = song.filename;
|
||||||
|
result.id = song.id;
|
||||||
|
result.md5 = song.md5;
|
||||||
|
result.time = song.time;
|
||||||
|
return result
|
||||||
|
})
|
||||||
|
console.log(this.commonService.songArray)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
23
src/app/modules/song/song.module.ts
Normal file
23
src/app/modules/song/song.module.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { RouterModule } from '@angular/router';
|
||||||
|
import {routesSong} from './song.route';
|
||||||
|
import {SongComponent} from './song.component';
|
||||||
|
import {MaterialModule} from '../material/material.module';
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
MaterialModule,
|
||||||
|
RouterModule.forChild(routesSong),
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
SongComponent
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
SongComponent
|
||||||
|
],
|
||||||
|
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
||||||
|
providers: [],
|
||||||
|
})
|
||||||
|
export class SongModule { }
|
11
src/app/modules/song/song.route.ts
Normal file
11
src/app/modules/song/song.route.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Routes } from "@angular/router"
|
||||||
|
import {SongComponent} from './song.component';
|
||||||
|
|
||||||
|
|
||||||
|
export const routesSong: Routes = [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
component: SongComponent,
|
||||||
|
children: []
|
||||||
|
}
|
||||||
|
];
|
11
src/app/routers.register.ts
Normal file
11
src/app/routers.register.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { lazyload } from './lazyload'
|
||||||
|
import { Routes } from '@angular/router';
|
||||||
|
|
||||||
|
export const appRoutes: Routes = [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
redirectTo: '/',
|
||||||
|
pathMatch: 'full'
|
||||||
|
},
|
||||||
|
...lazyload
|
||||||
|
];
|
12
src/app/services/common.service.ts
Normal file
12
src/app/services/common.service.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
// import { Http, Response, Headers, RequestOptions } from "@angular/http";
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CommonService {
|
||||||
|
|
||||||
|
songArray: Array<any> = [];
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
}
|
112
src/app/services/rest.services.ts
Normal file
112
src/app/services/rest.services.ts
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Http, Response, Headers, RequestOptions } from "@angular/http";
|
||||||
|
|
||||||
|
import { Observable } from 'rxjs/Observable'
|
||||||
|
import 'rxjs/add/operator/map'
|
||||||
|
import "rxjs/add/operator/catch"
|
||||||
|
import "rxjs/add/operator/finally"
|
||||||
|
import "rxjs/add/observable/throw"
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class RestService {
|
||||||
|
|
||||||
|
public flagLoading = false;
|
||||||
|
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private http: Http,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
// Отправка заголовка
|
||||||
|
getHeaders(headers={}): Headers {
|
||||||
|
let a: undefined = undefined
|
||||||
|
if (headers == 'rocket') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let _headers = new Headers();
|
||||||
|
if (Object.values(headers)[0]){
|
||||||
|
let token = Object.values(headers)[0];
|
||||||
|
let lang = Object.values(headers)[1];
|
||||||
|
if (lang) _headers.append('lang', lang.toString());
|
||||||
|
_headers.append('Authorization', token.toString());
|
||||||
|
_headers.append('Content-Type', 'application/json');
|
||||||
|
}
|
||||||
|
else if (Object.values(headers)) {
|
||||||
|
let token = Object.values(headers);
|
||||||
|
_headers.append('Authorization', token.toString());
|
||||||
|
_headers.append('Content-Type', 'application/json');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Object.entries(headers).forEach((k, v) => {
|
||||||
|
_headers.append(k.toString(), v.toString());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return _headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
getHeadersRocket(headers={}): Headers {
|
||||||
|
let token = Object.values(headers)[0];
|
||||||
|
let id = Object.values(headers)[1];
|
||||||
|
let _headers = new Headers();
|
||||||
|
_headers.append('x-auth-token', token.toString());
|
||||||
|
_headers.append('x-user-id', id.toString());
|
||||||
|
return _headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Get запрос
|
||||||
|
get(url, data = {}, headers={}): Observable<any> {
|
||||||
|
if (Object.keys(data).length) {
|
||||||
|
url = url + "?" + Object.entries(data).map(([k, v]) => {return `${k}=${v}`}).join(";")
|
||||||
|
}
|
||||||
|
this.flagLoading = true;
|
||||||
|
return this.http.get(encodeURI(url), new RequestOptions({headers: this.getHeaders(headers)}))
|
||||||
|
.map(this.mapper)
|
||||||
|
.catch(this.handleError)
|
||||||
|
.finally(()=>this.flagLoading = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Post запрос
|
||||||
|
post(url, body={}, headers={}):Observable<any> {
|
||||||
|
this.flagLoading = true;
|
||||||
|
return this.http.post(
|
||||||
|
encodeURI(url),
|
||||||
|
body,
|
||||||
|
new RequestOptions({headers: this.getHeaders(headers)}))
|
||||||
|
.map(this.mapper)
|
||||||
|
.catch(this.handleError)
|
||||||
|
.finally(()=>this.flagLoading = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
getRocket(url, data = {}, headers={}): Observable<any> {
|
||||||
|
if (Object.keys(data).length) {
|
||||||
|
url = url + "?" + Object.entries(data).map(([k, v]) => {return `${k}=${v}`}).join("&")
|
||||||
|
}
|
||||||
|
this.flagLoading = true;
|
||||||
|
return this.http.get(encodeURI(url), new RequestOptions({headers: this.getHeadersRocket(headers)}))
|
||||||
|
.map(this.mapper)
|
||||||
|
.catch(this.handleError)
|
||||||
|
.finally(()=>this.flagLoading = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
postRocket(url, body={}, headers={}):Observable<any> {
|
||||||
|
this.flagLoading = true;
|
||||||
|
return this.http.post(
|
||||||
|
encodeURI(url),
|
||||||
|
body,
|
||||||
|
new RequestOptions({headers: this.getHeadersRocket(headers)}))
|
||||||
|
.map(this.mapper)
|
||||||
|
.catch(this.handleError)
|
||||||
|
.finally(()=>this.flagLoading = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleError(error): Observable<any> {
|
||||||
|
return Observable.throw(error.message || error)
|
||||||
|
}
|
||||||
|
|
||||||
|
private mapper(res: Response): any {
|
||||||
|
const body: any = res.json();
|
||||||
|
return body || {}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user