Advertisement
Ahlushko

Untitled

Jun 25th, 2020
1,391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import { LabService } from '@services'
  3. import { MongoService } from 'wacom'
  4. @Component({
  5.     selector: 'app-root',
  6.     templateUrl: './app.component.html',
  7.     styleUrls: ['./app.component.css']
  8. })
  9. export class AppComponent {
  10.     public option: any = {
  11.         surname: [],
  12.         title: [],
  13.         year: [],
  14.         selected: {
  15.             surname: "",
  16.             title: "",
  17.             year: "",
  18.             minYear: ""
  19.         }
  20.     }
  21.     public edit: any = {}
  22.     public books: any = []
  23.     public create: any = {}
  24.     public properties = ['surname', 'initials', 'title', 'year']
  25.     constructor(public lab: LabService, private mongo: MongoService) {
  26.         this.mongo.on('lab', ()=>{
  27.             this.lab.lab.forEach(item => {
  28.                 this.edit[item._id] = {
  29.                     _id: item._id
  30.                 }
  31.                 if(this.option.surname.indexOf(item.surname) == -1) {
  32.                     this.option.surname.push(item.surname)
  33.                 }
  34.                 if(this.option.title.indexOf(item.title) == -1) {
  35.                     this.option.title.push(item.title)
  36.                 }
  37.                 if(this.option.year.indexOf(item.year) == -1) {
  38.                     this.option.year.push(Number(item.year))
  39.                 }
  40.             })
  41.             this.books = this.lab.lab.concat()
  42.             console.log(this.edit);
  43.         });
  44.     }
  45.     addBook() {
  46.         this.create.surname = this.create.pib.split(' ')[0]
  47.         this.create.initials = this.create.pib.split(' ')[1]
  48.         delete this.create.pib
  49.         delete this.create.add
  50.         this.lab.create(this.create)
  51.     }
  52.     sort(value) {
  53.         if(this.option.selected[value] == '') {
  54.             this.books = this.lab.lab.concat()
  55.             return
  56.         }
  57.         this.books.splice(0, this.books.length)
  58.         if(value == 'minYear') {
  59.             this.lab.lab.forEach(item => {
  60.                 if(item.year >= this.option.selected.minYear) {
  61.                     this.books.push(item)
  62.                 }
  63.             })
  64.             return
  65.         }
  66.         this.lab.lab.forEach(item => {
  67.             console.log(this.option.selected[value]);
  68.             console.log(Object.values(item));
  69.             if(Object.values(item).indexOf(this.option.selected[value]) != -1) {
  70.                 this.books.push(item)
  71.             }
  72.         })
  73.     }
  74.     ngOnInit(): void {
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement