aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_elements/folder/folder.component.ts
blob: 34c8db82d78cbe0b361cbbe44e11748c19920f4d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import Dataset from 'src/app/_data/Dataset';
import Model from 'src/app/_data/Model';

@Component({
  selector: 'app-folder',
  templateUrl: './folder.component.html',
  styleUrls: ['./folder.component.css']
})
export class FolderComponent implements OnInit {

  @Input() folderName: string = 'Moji podaci';

  @Input() files!: (Dataset | Model)[]

  newFile!: Dataset | Model;

  @Input() type: FolderType = FolderType.Dataset;

  newFileSelected: boolean = true;

  selectedFileIndex: number = -1;
  hoveringOverFileIndex: number = -1;

  fileToDisplay?: (Dataset | Model);

  @Output() selectedFileChanged: EventEmitter<(Dataset | Model)> = new EventEmitter();

  constructor() {
    //PLACEHOLDER
    this.files = [
      new Dataset('Titanik'),
      new Dataset('Dijamanti'),
      new Dataset('Filmovi'),
    ]
  }

  ngOnInit(): void {
    if (this.files.length > 0)
      this.selectFile(0);
    else {
      this.selectNewFile();
    }
  }

  hoverOverFile(i: number) {
    this.hoveringOverFileIndex = i;
    if (i != -1) {
      this.fileToDisplay = this.files[i];
    } else {
      if (this.newFileSelected) {
        this.fileToDisplay = this.newFile;
      } else {
        this.fileToDisplay = this.files[this.selectedFileIndex];
      }
    }
  }

  selectNewFile() {
    if (!this.newFile) {
      this.createNewFile();
    }
    this.fileToDisplay = this.newFile;
    this.selectedFileIndex = -1;
    this.newFileSelected = true;
    this.selectedFileChanged.emit(this.newFile);
  }

  selectFile(index: number) {
    this.selectedFileIndex = index;
    this.fileToDisplay = this.files[index];
    this.newFileSelected = false;
    this.selectedFileChanged.emit(this.files[index]);
  }

  createNewFile() {
    if (this.type == FolderType.Dataset) {
      this.newFile = new Dataset();
    } else if (this.type == FolderType.Model) {
      this.newFile = new Model();
    }
  }

  saveNewFile() {
    // TODO
  }

  calcZIndex(i: number) {
    let zIndex = (this.files.length - i - 1)
    if (this.selectedFileIndex == i)
      zIndex = this.files.length + 2;
    if (this.hoveringOverFileIndex == i)
      zIndex = this.files.length + 3;
    return zIndex;
  }

  newFileZIndex() {
    return (this.files.length + 1);
  }

}

export enum FolderType {
  Dataset,
  Model
}