mirror of
https://github.com/akveo/ngx-admin.git
synced 2026-02-19 06:28:06 +01:00
feat(data): update data module, add new mock data (#1960)
This commit is contained in:
parent
773c14e74a
commit
47d232b606
53 changed files with 635 additions and 256 deletions
11
src/app/@core/utils/index.ts
Normal file
11
src/app/@core/utils/index.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { LayoutService } from './layout.service';
|
||||
import { AnalyticsService } from './analytics.service';
|
||||
import { PlayerService } from './player.service';
|
||||
import { StateService } from './state.service';
|
||||
|
||||
export {
|
||||
LayoutService,
|
||||
AnalyticsService,
|
||||
PlayerService,
|
||||
StateService,
|
||||
};
|
||||
20
src/app/@core/utils/layout.service.ts
Normal file
20
src/app/@core/utils/layout.service.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { delay, share } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class LayoutService {
|
||||
|
||||
protected layoutSize$ = new Subject();
|
||||
|
||||
changeLayoutSize() {
|
||||
this.layoutSize$.next();
|
||||
}
|
||||
|
||||
onChangeLayoutSize(): Observable<any> {
|
||||
return this.layoutSize$.pipe(
|
||||
share(),
|
||||
delay(1),
|
||||
);
|
||||
}
|
||||
}
|
||||
66
src/app/@core/utils/player.service.ts
Normal file
66
src/app/@core/utils/player.service.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
|
||||
export class Track {
|
||||
name: string;
|
||||
artist: string;
|
||||
url: string;
|
||||
cover: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class PlayerService {
|
||||
current: number;
|
||||
playlist: Track[] = [
|
||||
{
|
||||
name: 'Don\'t Wanna Fight',
|
||||
artist: 'Alabama Shakes',
|
||||
url: 'https://p.scdn.co/mp3-preview/6156cdbca425a894972c02fca9d76c0b70e001af',
|
||||
cover: 'assets/images/cover1.jpg',
|
||||
},
|
||||
{
|
||||
name: 'Harder',
|
||||
artist: 'Daft Punk',
|
||||
url: 'https://p.scdn.co/mp3-preview/92a04c7c0e96bf93a1b1b1cae7dfff1921969a7b',
|
||||
cover: 'assets/images/cover2.jpg',
|
||||
},
|
||||
{
|
||||
name: 'Come Together',
|
||||
artist: 'Beatles',
|
||||
url: 'https://p.scdn.co/mp3-preview/83090a4db6899eaca689ae35f69126dbe65d94c9',
|
||||
cover: 'assets/images/cover3.jpg',
|
||||
},
|
||||
];
|
||||
|
||||
random(): Track {
|
||||
this.current = Math.floor(Math.random() * this.playlist.length);
|
||||
return this.playlist[this.current];
|
||||
}
|
||||
|
||||
next(): Track {
|
||||
return this.getNextTrack();
|
||||
}
|
||||
|
||||
prev() {
|
||||
return this.getPrevTrack();
|
||||
}
|
||||
|
||||
private getNextTrack(): Track {
|
||||
if (this.current === this.playlist.length - 1) {
|
||||
this.current = 0;
|
||||
} else {
|
||||
this.current++;
|
||||
}
|
||||
|
||||
return this.playlist[this.current];
|
||||
}
|
||||
|
||||
private getPrevTrack(): Track {
|
||||
if (this.current === 0) {
|
||||
this.current = this.playlist.length - 1;
|
||||
} else {
|
||||
this.current--;
|
||||
}
|
||||
|
||||
return this.playlist[this.current];
|
||||
}
|
||||
}
|
||||
92
src/app/@core/utils/state.service.ts
Normal file
92
src/app/@core/utils/state.service.ts
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
import { Injectable, OnDestroy } from '@angular/core';
|
||||
import { of as observableOf, Observable, BehaviorSubject } from 'rxjs';
|
||||
import { takeWhile } from 'rxjs/operators';
|
||||
|
||||
import { NbLayoutDirectionService, NbLayoutDirection } from '@nebular/theme';
|
||||
|
||||
@Injectable()
|
||||
export class StateService implements OnDestroy {
|
||||
|
||||
protected layouts: any = [
|
||||
{
|
||||
name: 'One Column',
|
||||
icon: 'nb-layout-default',
|
||||
id: 'one-column',
|
||||
selected: true,
|
||||
},
|
||||
{
|
||||
name: 'Two Column',
|
||||
icon: 'nb-layout-two-column',
|
||||
id: 'two-column',
|
||||
},
|
||||
{
|
||||
name: 'Center Column',
|
||||
icon: 'nb-layout-centre',
|
||||
id: 'center-column',
|
||||
},
|
||||
];
|
||||
|
||||
protected sidebars: any = [
|
||||
{
|
||||
name: 'Sidebar at layout start',
|
||||
icon: 'nb-layout-sidebar-left',
|
||||
id: 'start',
|
||||
selected: true,
|
||||
},
|
||||
{
|
||||
name: 'Sidebar at layout end',
|
||||
icon: 'nb-layout-sidebar-right',
|
||||
id: 'end',
|
||||
},
|
||||
];
|
||||
|
||||
protected layoutState$ = new BehaviorSubject(this.layouts[0]);
|
||||
protected sidebarState$ = new BehaviorSubject(this.sidebars[0]);
|
||||
|
||||
alive = true;
|
||||
|
||||
constructor(directionService: NbLayoutDirectionService) {
|
||||
directionService.onDirectionChange()
|
||||
.pipe(takeWhile(() => this.alive))
|
||||
.subscribe(direction => this.updateSidebarIcons(direction));
|
||||
|
||||
this.updateSidebarIcons(directionService.getDirection());
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.alive = false;
|
||||
}
|
||||
|
||||
private updateSidebarIcons(direction: NbLayoutDirection) {
|
||||
const [ startSidebar, endSidebar ] = this.sidebars;
|
||||
const isLtr = direction === NbLayoutDirection.LTR;
|
||||
const startIconClass = isLtr ? 'nb-layout-sidebar-left' : 'nb-layout-sidebar-right';
|
||||
const endIconClass = isLtr ? 'nb-layout-sidebar-right' : 'nb-layout-sidebar-left';
|
||||
startSidebar.icon = startIconClass;
|
||||
endSidebar.icon = endIconClass;
|
||||
}
|
||||
|
||||
setLayoutState(state: any): any {
|
||||
this.layoutState$.next(state);
|
||||
}
|
||||
|
||||
getLayoutStates(): Observable<any[]> {
|
||||
return observableOf(this.layouts);
|
||||
}
|
||||
|
||||
onLayoutState(): Observable<any> {
|
||||
return this.layoutState$.asObservable();
|
||||
}
|
||||
|
||||
setSidebarState(state: any): any {
|
||||
this.sidebarState$.next(state);
|
||||
}
|
||||
|
||||
getSidebarStates(): Observable<any[]> {
|
||||
return observableOf(this.sidebars);
|
||||
}
|
||||
|
||||
onSidebarState(): Observable<any> {
|
||||
return this.sidebarState$.asObservable();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue