Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { LabService } from '@services'
- import { MongoService } from 'wacom'
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.css']
- })
- export class AppComponent {
- public option: any = {
- surname: [],
- title: [],
- year: [],
- selected: {
- surname: "",
- title: "",
- year: "",
- minYear: ""
- }
- }
- public edit: any = {}
- public books: any = []
- public create: any = {}
- public properties = ['surname', 'initials', 'title', 'year']
- constructor(public lab: LabService, private mongo: MongoService) {
- this.mongo.on('lab', ()=>{
- this.lab.lab.forEach(item => {
- this.edit[item._id] = {
- _id: item._id
- }
- if(this.option.surname.indexOf(item.surname) == -1) {
- this.option.surname.push(item.surname)
- }
- if(this.option.title.indexOf(item.title) == -1) {
- this.option.title.push(item.title)
- }
- if(this.option.year.indexOf(item.year) == -1) {
- this.option.year.push(Number(item.year))
- }
- })
- this.books = this.lab.lab.concat()
- console.log(this.edit);
- });
- }
- addBook() {
- this.create.surname = this.create.pib.split(' ')[0]
- this.create.initials = this.create.pib.split(' ')[1]
- delete this.create.pib
- delete this.create.add
- this.lab.create(this.create)
- }
- sort(value) {
- if(this.option.selected[value] == '') {
- this.books = this.lab.lab.concat()
- return
- }
- this.books.splice(0, this.books.length)
- if(value == 'minYear') {
- this.lab.lab.forEach(item => {
- if(item.year >= this.option.selected.minYear) {
- this.books.push(item)
- }
- })
- return
- }
- this.lab.lab.forEach(item => {
- console.log(this.option.selected[value]);
- console.log(Object.values(item));
- if(Object.values(item).indexOf(this.option.selected[value]) != -1) {
- this.books.push(item)
- }
- })
- }
- ngOnInit(): void {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement