feat(data): update data module, add new mock data (#1960)

This commit is contained in:
Denis Strigo 2019-01-08 16:17:20 +03:00 committed by GitHub
parent 773c14e74a
commit 47d232b606
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 635 additions and 256 deletions

View file

@ -0,0 +1,28 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';
@Injectable()
export class CountryOrderService {
private countriesCategories = [
'Sofas',
'Furniture',
'Lighting',
'Tables',
'Textiles',
];
private countriesCategoriesLength = this.countriesCategories.length;
private generateRandomData(nPoints: number): number[] {
return Array.from(Array(nPoints)).map(() => {
return Math.round(Math.random() * 20);
});
}
getCountriesCategories(): Observable<string[]> {
return observableOf(this.countriesCategories);
}
getCountriesCategoriesData(): Observable<number[]> {
return observableOf(this.generateRandomData(this.countriesCategoriesLength));
}
}

View file

@ -3,9 +3,7 @@ import { CommonModule } from '@angular/common';
import { UserService } from './users.service';
import { ElectricityService } from './electricity.service';
import { StateService } from './state.service';
import { SmartTableService } from './smart-table.service';
import { PlayerService } from './player.service';
import { UserActivityService } from './user-activity.service';
import { OrdersChartService } from './orders-chart.service';
import { ProfitChartService } from './profit-chart.service';
@ -15,14 +13,19 @@ import { EarningService } from './earning.service';
import { OrdersProfitChartService } from './orders-profit-chart.service';
import { TrafficBarService } from './traffic-bar.service';
import { ProfitBarAnimationChartService } from './profit-bar-animation-chart.service';
import { LayoutService } from './layout.service';
import { TemperatureHumidityService } from './temperature-humidity.service';
import { SolarService } from './solar.service';
import { TrafficChartService } from './traffic-chart.service';
import { StatsBarService } from './stats-bar.service';
import { CountryOrderService } from './country-order.service';
import { StatsProgressBarService } from './stats-progress-bar.service';
import { VisitorsAnalyticsService } from './visitors-analytics.service';
import { SecurityCamerasService } from './security-cameras.service';
const SERVICES = [
UserService,
ElectricityService,
StateService,
SmartTableService,
PlayerService,
UserActivityService,
OrdersChartService,
ProfitChartService,
@ -32,7 +35,14 @@ const SERVICES = [
OrdersProfitChartService,
TrafficBarService,
ProfitBarAnimationChartService,
LayoutService,
TemperatureHumidityService,
SolarService,
TrafficChartService,
StatsBarService,
CountryOrderService,
StatsProgressBarService,
VisitorsAnalyticsService,
SecurityCamerasService,
];
@NgModule({

View file

@ -1,9 +1,29 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';
class Month {
month: string;
delta: string;
down: boolean;
kWatts: string;
cost: string;
}
export class Electricity {
title: string;
active?: boolean;
months: Month[];
}
export class ElectricityChart {
label: string;
value: number;
}
@Injectable()
export class ElectricityService {
private data = [
private listData: Electricity[] = [
{
title: '2015',
months: [
@ -58,11 +78,35 @@ export class ElectricityService {
},
];
private chartPoints = [
490, 490, 495, 500,
505, 510, 520, 530,
550, 580, 630, 720,
800, 840, 860, 870,
870, 860, 840, 800,
720, 200, 145, 130,
130, 145, 200, 570,
635, 660, 670, 670,
660, 630, 580, 460,
380, 350, 340, 340,
340, 340, 340, 340,
340, 340, 340,
];
chartData: ElectricityChart[];
constructor() {
this.chartData = this.chartPoints.map((p, index) => ({
label: (index % 5 === 3) ? `${Math.round(index / 5)}` : '',
value: p,
}));
}
// TODO: observables
getData() {
return this.data;
getListData(): Observable<Electricity[]> {
return observableOf(this.listData);
}
getChartData(): Observable<ElectricityChart[]> {
return observableOf(this.chartData);
}
}

View file

@ -1,20 +0,0 @@
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),
);
}
}

View file

@ -1,66 +0,0 @@
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];
}
}

View file

@ -35,7 +35,7 @@ export class ProfitBarAnimationChartService {
return Array.from(Array(nPoints));
}
getChartData(): Observable<{ firstLine: number[]; secondLine: number[] }> {
getChartData(): Observable<{ firstLine: number[]; secondLine: number[]; }> {
return observableOf(this.data);
}
}

View file

@ -0,0 +1,34 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';
export class Camera {
title: string;
source: string;
}
@Injectable()
export class SecurityCamerasService {
private cameras: Camera[] = [
{
title: 'Camera #1',
source: 'assets/images/camera1.jpg',
},
{
title: 'Camera #2',
source: 'assets/images/camera2.jpg',
},
{
title: 'Camera #3',
source: 'assets/images/camera3.jpg',
},
{
title: 'Camera #4',
source: 'assets/images/camera4.jpg',
},
];
getCamerasData(): Observable<Camera[]> {
return observableOf(this.cameras);
}
}

View file

@ -0,0 +1,11 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';
@Injectable()
export class SolarService {
private value = 42;
getSolarData(): Observable<number> {
return observableOf(this.value);
}
}

View file

@ -1,92 +0,0 @@
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();
}
}

View file

@ -0,0 +1,15 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';
@Injectable()
export class StatsBarService {
private statsBarData: number[] = [
300, 520, 435, 530,
730, 620, 660, 860,
];
getStatsBarData(): Observable<number[]> {
return observableOf(this.statsBarData);
}
}

View file

@ -0,0 +1,37 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';
export class ProgressInfo {
title: string;
value: number;
activeProgress: number;
description: string;
}
@Injectable()
export class StatsProgressBarService {
private progressInfoData: ProgressInfo[] = [
{
title: 'Todays Profit',
value: 572900,
activeProgress: 70,
description: 'Better than last week (70%)',
},
{
title: 'New Orders',
value: 6378,
activeProgress: 30,
description: 'Better than last week (30%)',
},
{
title: 'New Comments',
value: 200,
activeProgress: 55,
description: 'Better than last week (55%)',
},
];
getProgressInfoData(): Observable<ProgressInfo[]> {
return observableOf(this.progressInfoData);
}
}

View file

@ -0,0 +1,32 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';
export class Temperature {
value: number;
min: number;
max: number;
}
@Injectable()
export class TemperatureHumidityService {
private temperatureDate: Temperature = {
value: 24,
min: 12,
max: 30,
};
private humidityDate: Temperature = {
value: 87,
min: 0,
max: 100,
};
getTemperatureData(): Observable<Temperature> {
return observableOf(this.temperatureDate);
}
getHumidityData(): Observable<Temperature> {
return observableOf(this.humidityDate);
}
}

View file

@ -0,0 +1,16 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';
@Injectable()
export class TrafficChartService {
private data: number[] = [
300, 520, 435, 530,
730, 620, 660, 860,
];
getTrafficChartData(): Observable<number[]> {
return observableOf(this.data);
}
}

View file

@ -13,6 +13,14 @@ export class UserActive {
export class UserActivityService {
private getRandom = (roundTo: number) => Math.round(Math.random() * roundTo);
private generateUserActivityRandomData(date) {
return {
date,
pagesVisitCount: this.getRandom(1000),
deltaUp: this.getRandom(1) % 2 === 0,
newVisits: this.getRandom(100),
};
}
data = {};
@ -26,38 +34,25 @@ export class UserActivityService {
private getDataWeek(): UserActive[] {
return this.periods.getWeeks().map((week) => {
return {
date: week,
pagesVisitCount: this.getRandom(1000),
deltaUp: this.getRandom(1) % 2 === 0,
newVisits: this.getRandom(100),
};
return this.generateUserActivityRandomData(week);
});
}
private getDataMonth(): UserActive[] {
const date = new Date();
const days = date.getDate();
const month = this.periods.getMonths()[date.getMonth()];
const currentDate = new Date();
const days = currentDate.getDate();
const month = this.periods.getMonths()[currentDate.getMonth()];
return Array.from(Array(days)).map((_, index) => {
return {
date: `${index + 1} ${month}`,
pagesVisitCount: this.getRandom(1000),
deltaUp: this.getRandom(1) % 2 === 0,
newVisits: this.getRandom(100),
};
const date = `${index + 1} ${month}`;
return this.generateUserActivityRandomData(date);
});
}
private getDataYear(): UserActive[] {
return this.periods.getYears().map((year) => {
return {
date: year,
pagesVisitCount: this.getRandom(1000),
deltaUp: this.getRandom(1) % 2 === 0,
newVisits: this.getRandom(100),
};
return this.generateUserActivityRandomData(year);
});
}

View file

@ -2,12 +2,25 @@
import { of as observableOf, Observable } from 'rxjs';
import { Injectable } from '@angular/core';
class User {
name: string;
picture: string;
}
let counter = 0;
export class Contacts {
user: User;
type: string;
}
export class RecentUsers extends Contacts {
time: number;
}
@Injectable()
export class UserService {
private time: Date = new Date;
private users = {
nick: { name: 'Nick Jones', picture: 'assets/images/nick.png' },
eva: { name: 'Eva Moor', picture: 'assets/images/eva.png' },
@ -16,23 +29,39 @@ export class UserService {
alan: { name: 'Alan Thompson', picture: 'assets/images/alan.png' },
kate: { name: 'Kate Martinez', picture: 'assets/images/kate.png' },
};
private userArray: any[];
constructor() {
// this.userArray = Object.values(this.users);
}
private types = {
mobile: 'mobile',
home: 'home',
work: 'work',
};
private contacts: Contacts[] = [
{ user: this.users.nick, type: this.types.mobile },
{ user: this.users.eva, type: this.types.home },
{ user: this.users.jack, type: this.types.mobile },
{ user: this.users.lee, type: this.types.mobile },
{ user: this.users.alan, type: this.types.home },
{ user: this.users.kate, type: this.types.work },
];
private recentUsers: RecentUsers[] = [
{ user: this.users.alan, type: this.types.home, time: this.time.setHours(21, 12)},
{ user: this.users.eva, type: this.types.home, time: this.time.setHours(17, 45)},
{ user: this.users.nick, type: this.types.mobile, time: this.time.setHours(5, 29)},
{ user: this.users.lee, type: this.types.mobile, time: this.time.setHours(11, 24)},
{ user: this.users.jack, type: this.types.mobile, time: this.time.setHours(10, 45)},
{ user: this.users.kate, type: this.types.work, time: this.time.setHours(9, 42)},
{ user: this.users.kate, type: this.types.work, time: this.time.setHours(9, 31)},
{ user: this.users.jack, type: this.types.mobile, time: this.time.setHours(8, 0)},
];
getUsers(): Observable<any> {
return observableOf(this.users);
}
getUserArray(): Observable<any[]> {
return observableOf(this.userArray);
getContacts(): Observable<Contacts[]> {
return observableOf(this.contacts);
}
getUser(): Observable<any> {
counter = (counter + 1) % this.userArray.length;
return observableOf(this.userArray[counter]);
getRecentUsers(): Observable<RecentUsers[]> {
return observableOf(this.recentUsers);
}
}

View file

@ -0,0 +1,60 @@
import { Injectable } from '@angular/core';
import { of as observableOf, Observable } from 'rxjs';
import { PeriodsService } from './periods.service';
export class OutlineData {
label: string;
value: number;
}
@Injectable()
export class VisitorsAnalyticsService {
constructor(private periodService: PeriodsService) {
}
private pieChartValue = 75;
private innerLinePoints: number[] = [
94, 188, 225, 244, 253, 254, 249, 235, 208,
173, 141, 118, 105, 97, 94, 96, 104, 121, 147,
183, 224, 265, 302, 333, 358, 375, 388, 395,
400, 400, 397, 390, 377, 360, 338, 310, 278,
241, 204, 166, 130, 98, 71, 49, 32, 20, 13, 9,
];
private outerLinePoints: number[] = [
85, 71, 59, 50, 45, 42, 41, 44 , 58, 88,
136 , 199, 267, 326, 367, 391, 400, 397,
376, 319, 200, 104, 60, 41, 36, 37, 44,
55, 74, 100 , 131, 159, 180, 193, 199, 200,
195, 184, 164, 135, 103, 73, 50, 33, 22, 15, 11,
];
private generateOutlineLineData(): OutlineData[] {
const months = this.periodService.getMonths();
const outerLinePointsLength = this.outerLinePoints.length;
const monthsLength = months.length;
return this.outerLinePoints.map((p, index) => {
const monthIndex = Math.round(index / 4);
const label = (index % Math.round(outerLinePointsLength / monthsLength) === 0)
? months[monthIndex]
: '';
return {
label,
value: p,
};
});
}
getInnerLineChartData(): Observable<number[]> {
return observableOf(this.innerLinePoints);
}
getOutlineLineChartData(): Observable<OutlineData[]> {
return observableOf(this.generateOutlineLineData());
}
getPieChartData(): Observable<number> {
return observableOf(this.pieChartValue);
}
}