2022-12-21 19:30:24 +01:00
|
|
|
import { DataSource } from '@angular/cdk/collections';
|
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
|
import { Component, ViewChild } from '@angular/core';
|
|
|
|
|
import { UntypedFormGroup, UntypedFormBuilder } from '@angular/forms';
|
|
|
|
|
import { MatPaginator } from '@angular/material/paginator';
|
2022-12-22 15:12:19 +01:00
|
|
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
2022-12-21 19:30:24 +01:00
|
|
|
import { MatSort } from '@angular/material/sort';
|
|
|
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
|
|
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
|
|
|
import moment from 'moment';
|
|
|
|
|
import { AuthService } from 'src/app/auth/auth.service';
|
|
|
|
|
import { DataRow } from 'src/app/models/dataRow.model copy';
|
|
|
|
|
import { DataSet } from 'src/app/models/dataSet.model';
|
2022-12-11 23:40:16 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-data-set-detail',
|
|
|
|
|
templateUrl: './data-set-detail.component.html',
|
|
|
|
|
styleUrls: ['./data-set-detail.component.scss']
|
|
|
|
|
})
|
|
|
|
|
export class DataSetDetailComponent {
|
|
|
|
|
|
2022-12-21 19:30:24 +01:00
|
|
|
public form!: UntypedFormGroup;
|
|
|
|
|
private document!: DataSet;
|
|
|
|
|
|
|
|
|
|
displayedColumns = ['code', 'value', 'desc1'];
|
|
|
|
|
dataSource!: MatTableDataSource<DataRow>;
|
|
|
|
|
|
|
|
|
|
@ViewChild(MatPaginator) paginator!: MatPaginator;
|
|
|
|
|
@ViewChild(MatSort) sort!: MatSort;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private fb$: UntypedFormBuilder,
|
|
|
|
|
private router$: Router,
|
|
|
|
|
private http$: HttpClient,
|
|
|
|
|
private route$: ActivatedRoute,
|
2022-12-22 15:12:19 +01:00
|
|
|
private auth$: AuthService,
|
|
|
|
|
private snackBar: MatSnackBar
|
2022-12-21 19:30:24 +01:00
|
|
|
) { }
|
|
|
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
|
this.form = DataSet.getForm(this.fb$);
|
|
|
|
|
this.document = await this.load();
|
|
|
|
|
this.dataSource = new MatTableDataSource<DataRow>(this.document.dataRows);
|
|
|
|
|
this.dataSource.paginator = this.paginator;
|
|
|
|
|
this.dataSource.sort = this.sort;
|
|
|
|
|
this.document.fillForm(this.form);
|
|
|
|
|
this.form.disable();
|
|
|
|
|
}
|
|
|
|
|
private async load(): Promise<DataSet> {
|
|
|
|
|
return await DataSet.getById(this.route$.snapshot.paramMap.get('id') || "", this.http$);
|
|
|
|
|
}
|
|
|
|
|
trackByUid(index : number, item : DataRow) {
|
|
|
|
|
return item.id;
|
|
|
|
|
}
|
2022-12-22 15:12:19 +01:00
|
|
|
async export() {
|
|
|
|
|
if (await DataSet.exportToGoogleSheet(this.document.id || "", this.http$)) {
|
|
|
|
|
this.snackBar.open("Plik został zapisany na dysku Google", "OK");
|
|
|
|
|
} else {
|
|
|
|
|
this.snackBar.open("Zapis się nie udał.", "OK");
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-11 23:40:16 +01:00
|
|
|
}
|