Layer detail refactor
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { DatePipe, NgIf, DecimalPipe } from '@angular/common';
|
||||
import { DatePipe, NgIf, DecimalPipe, JsonPipe } from '@angular/common';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { UntypedFormGroup, UntypedFormBuilder, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatSort, MatSortModule } from '@angular/material/sort';
|
||||
import { MatSort, MatSortModule, MatSortable } from '@angular/material/sort';
|
||||
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Layer } from 'src/app/models/layer.model';
|
||||
@@ -23,7 +23,7 @@ import { MatCardModule } from '@angular/material/card';
|
||||
standalone: true,
|
||||
imports: [FormsModule, ReactiveFormsModule, MatCardModule, MatToolbarModule,
|
||||
MatButtonModule, MatGridListModule, MatFormFieldModule, MatInputModule,
|
||||
NgIf, MatTableModule, MatSortModule, DecimalPipe],
|
||||
NgIf, MatTableModule, MatSortModule, DecimalPipe, JsonPipe],
|
||||
providers: [DatePipe]
|
||||
})
|
||||
export class LayerDetailComponent implements OnInit {
|
||||
@@ -44,25 +44,23 @@ export class LayerDetailComponent implements OnInit {
|
||||
private route$: ActivatedRoute,
|
||||
private datePipe: DatePipe,
|
||||
private notifications$: NotificationsService
|
||||
) { }
|
||||
) {
|
||||
this.form = Layer.getForm(this.fb$);
|
||||
}
|
||||
|
||||
async ngOnInit() {
|
||||
this.form = Layer.getForm(this.fb$);
|
||||
this.document = await this.load();
|
||||
this.dataSource = new MatTableDataSource<Record>(this.document.records);
|
||||
this.dataSource.sort = this.sort;
|
||||
this.document.fillForm(this.form);
|
||||
this.form.disable();
|
||||
this.document.created = `${this.datePipe.transform(this.document.createdAt?.toDate(), 'short')}, ${this.document.createdBy?.userName}`;
|
||||
// this.dataSource.sort.sort({ id: 'code', start: 'desc' } as MatSortable);
|
||||
this.valueSum = this.document.records.map(t => t.value1 || 0).reduce((acc, value) => acc + value, 0);
|
||||
}
|
||||
private async load(): Promise<Layer> {
|
||||
return await Layer.getById(this.route$.snapshot.paramMap.get('id') || "", this.http$);
|
||||
}
|
||||
trackByUid(index : number, item : Record) {
|
||||
return item.id;
|
||||
}
|
||||
|
||||
async export() {
|
||||
if (await Layer.exportToGoogleSheet(this.document.id || "", this.http$)) {
|
||||
this.notifications$.add({
|
||||
|
||||
Reference in New Issue
Block a user