import {Component, OnInit} from '@angular/core';
import {Task1Service} from '../service/task1.service';
import {distance, Task1Module} from '../module/task1.module';
import {map} from 'rxjs/operators';
import {Observable} from 'rxjs';
@Component({
selector: 'app-task1',
templateUrl: './task1.component.html',
styleUrls: ['./task1.component.css']
})
export class Task1Component implements OnInit {
data: Task1Module[] = [];
i = 0;
data1: distance[] = [];
constructor(private http: Task1Service) {
}
ngOnInit() {
this.http.GetData().subscribe((obj) => {
this.data = obj;
for (let a of this.data) {
switch (this.data[this.i].distance[0].unit) {
case 'cm': // Переводим сантиметры
switch (a.convert_to) {
case'm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 100);
case'in':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 25.4);
case 'ft':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 304.8);
case 'yr':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 304.8);
case 'mm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 304.8);
}
case 'in':// Переводим дюймы
switch (a.convert_to) {
case 'm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 25.4 / 10 / 100);
case 'cm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 25.4 / 10);
case 'ft':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 25.4 / 304.8);
case 'yr':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 304.8);
case 'mm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 304.8);
}
case 'ft': // Переводим футы
switch (a.convert_to) {
case 'm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 304.8 / 10 / 100);
case 'cm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 304.8 / 10);
case 'in':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 304.8 / 25.4);
case 'yr':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 304.8);
case 'mm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 304.8);
}
case 'm': // Переводим метры
switch (a.convert_to) {
case 'ft':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 100 * 10 / 304.8);
case 'cm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 100);
case'in':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 100 * 10 / 25.4);
case 'yr':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 304.8);
case 'mm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 304.8);
}
case 'yr': // Переводим ярды
switch (a.convert_to) {
case 'ft':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 100 * 10 / 304.8);
case 'cm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 100);
case'in':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 100 * 10 / 25.4);
case 'm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 304.8);
case 'mm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 304.8);
}
case 'mm': // Переводим милиметры
switch (a.convert_to) {
case 'ft':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 100 * 10 / 304.8);
case 'cm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 100);
case'in':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value * 100 * 10 / 25.4);
case 'm':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 304.8);
case 'yr':
this.data1[this.i] = new distance(a.convert_to, this.data[this.i].distance[0].value / 10 / 304.8);
}
}
this.i = this.i + 1;
}
console.log(this.data1);
});
}
}
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {Observable} from 'rxjs';
@NgModule({
declarations: [],
imports: [
CommonModule
]
})
export class Task1Module {
constructor(
public distance:Array<distance>,
public convert_to:string
) {
}
}
export class distance{
constructor(
public unit:string,
public value: number
) {
}
}
export class Tickets {
constructor(
public email: string,
public payeer: string,
public win: boolean = false,
public date_buy: any = new Date(2018, 6, 12),
public date_game: any = new Date(2018, 6, 12),
public id?: number
) {
}
}
date_buy:1528718593833
date_game:1528718593833
email:"sgraerg@gmail.com"
id:1
payeer:"PA12345"
win:true