DataSet - createdBy & createdAt

This commit is contained in:
2022-12-27 22:22:21 +01:00
parent 360928b928
commit 149734cb19
10 changed files with 82 additions and 72 deletions

View File

@@ -19,8 +19,8 @@ export class Base implements Deserializable, Serializable {
} }
deserialize(input: any): this { deserialize(input: any): this {
if (input.createdAt) { input.createdAt = moment(input.createdAt); } if (input.createdAt) { input.createdAt = moment(input.createdAt).utc(true); }
if (input.modifiedAt) { input.modifiedAt = moment(input.modifiedAt); } if (input.modifiedAt) { input.modifiedAt = moment(input.modifiedAt).utc(true); }
if (input.createdBy) { input.createdBy = new User(input.createdBy); } if (input.createdBy) { input.createdBy = new User(input.createdBy); }
if (input.modifiedBy) { input.modifiedBy = new User(input.modifiedBy); } if (input.modifiedBy) { input.modifiedBy = new User(input.modifiedBy); }
Object.assign(this, input); Object.assign(this, input);

View File

@@ -10,6 +10,7 @@ export class DataSet extends Base {
source?: string; source?: string;
name?: string; name?: string;
dataRows: DataRow[] = []; dataRows: DataRow[] = [];
created?: string;
constructor(data: Partial<DataSet> = {}) { constructor(data: Partial<DataSet> = {}) {
super(); super();
@@ -34,6 +35,8 @@ export class DataSet extends Base {
modifiedAt: '', modifiedAt: '',
createdBy: '', createdBy: '',
modifiedBy: '', modifiedBy: '',
modified: '',
created: ''
}); });
} }
fillForm(form: UntypedFormGroup) { fillForm(form: UntypedFormGroup) {
@@ -92,10 +95,12 @@ export class DataSet extends Base {
}) })
}) })
} }
static parseGoogleSheet(sheetId: string, _http: HttpClient): Promise<DataRow[]> { static parseGoogleSheet(sheetId: string, _http: HttpClient): Promise<any> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
_http.get<DataRow[]>(`${environment.api.url}/datasets/parseGoogleSheet/${sheetId}`, _http.get<any>(`${environment.api.url}/datasets/parseGoogleSheet/${sheetId}`,
).pipe(map(data => data.map(x => new DataRow().deserialize(x)))) ).pipe(map(data => {
data.dataRows = data.dataRows.map((x: any) => new DataRow().deserialize(x))
}))
.subscribe({ .subscribe({
next: (data) => { next: (data) => {
resolve(data); resolve(data);

View File

@@ -1,52 +1,53 @@
<div> <div>
<form [formGroup]="form" novalidate> <form [formGroup]="form" novalidate>
<mat-card appearance="outlined"> <mat-card appearance="outlined">
<mat-toolbar color="secondary"> <mat-toolbar color="secondary">
Szczegóły warstwy danych Szczegóły warstwy danych
<span class="fill-to-right"></span> <span class="fill-to-right"></span>
<button mat-button (click)="export()">Eksportuj do Google</button> <button mat-button (click)="export()">Eksportuj do Google</button>
</mat-toolbar> </mat-toolbar>
<mat-card-content> <mat-card-content>
<mat-grid-list cols="2" rowHeight="90px"> <mat-grid-list cols="2" rowHeight="90px">
<mat-grid-tile> <mat-grid-tile>
<mat-form-field class="detail-input"> <mat-form-field class="detail-input">
<mat-label>Nazwa</mat-label> <mat-label>Nazwa</mat-label>
<input matInput formControlName="name"> <input matInput formControlName="name">
</mat-form-field> </mat-form-field>
</mat-grid-tile> </mat-grid-tile>
<mat-grid-tile>
<mat-form-field class="detail-input">
<input matInput formControlName="source">
</mat-form-field>
</mat-grid-tile>
</mat-grid-list>
<mat-table #table [dataSource]="dataSource" [trackBy]="trackByUid" matSort class="animate"> <mat-grid-tile>
<mat-form-field class="detail-input">
<ng-container matColumnDef="code"> <mat-label>Źródło</mat-label>
<mat-header-cell *matHeaderCellDef mat-sort-header>MPK</mat-header-cell> <input matInput formControlName="source">
<mat-cell *matCellDef="let item">{{item.code}}</mat-cell> </mat-form-field>
</ng-container> </mat-grid-tile>
<ng-container matColumnDef="desc1">
<mat-header-cell *matHeaderCellDef mat-sort-header>Konto</mat-header-cell>
<mat-cell *matCellDef="let item">{{item.desc1}}</mat-cell>
</ng-container>
<ng-container matColumnDef="value"> <mat-grid-tile *ngIf="document">
<mat-header-cell *matHeaderCellDef mat-sort-header>Wartość</mat-header-cell> <mat-form-field class="detail-input">
<mat-cell *matCellDef="let item" align="right">{{item.value | number:'1.2-2'}}</mat-cell> <mat-label>Utworzono</mat-label>
</ng-container> <input matInput disabled [value]="document.created">
</mat-form-field>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row> </mat-grid-tile>
<mat-row *matRowDef="let item; columns: displayedColumns;"></mat-row> </mat-grid-list>
</mat-table>
<mat-paginator #paginator <mat-table #table [dataSource]="dataSource" [trackBy]="trackByUid" matSort class="animate">
[pageSize]="50"
[pageSizeOptions]="[5, 10, 20]"> <ng-container matColumnDef="code">
</mat-paginator> <mat-header-cell *matHeaderCellDef mat-sort-header>MPK</mat-header-cell>
</mat-card-content> <mat-cell *matCellDef="let item">{{item.code}}</mat-cell>
</mat-card> </ng-container>
</form>
</div> <ng-container matColumnDef="value">
<mat-header-cell *matHeaderCellDef mat-sort-header>Wartość</mat-header-cell>
<mat-cell *matCellDef="let item">{{item.value | number:'1.2-2'}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let item; columns: displayedColumns;"></mat-row>
</mat-table>
<mat-paginator #paginator [pageSize]="50" [pageSizeOptions]="[5, 10, 20]">
</mat-paginator>
</mat-card-content>
</mat-card>
</form>
</div>

View File

@@ -1,10 +1,11 @@
import { DataSource } from '@angular/cdk/collections'; import { DataSource } from '@angular/cdk/collections';
import { DatePipe, DecimalPipe } from '@angular/common';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Component, ViewChild } from '@angular/core'; import { Component, ViewChild } from '@angular/core';
import { UntypedFormGroup, UntypedFormBuilder } from '@angular/forms'; import { UntypedFormGroup, UntypedFormBuilder } from '@angular/forms';
import { MatPaginator } from '@angular/material/paginator'; import { MatPaginator } from '@angular/material/paginator';
import { MatSnackBar } from '@angular/material/snack-bar'; import { MatSnackBar } from '@angular/material/snack-bar';
import { MatSort } from '@angular/material/sort'; import { MatSort, MatSortable } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table'; import { MatTableDataSource } from '@angular/material/table';
import { Router, ActivatedRoute } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import moment from 'moment'; import moment from 'moment';
@@ -20,9 +21,9 @@ import { DataSet } from 'src/app/models/dataSet.model';
export class DataSetDetailComponent { export class DataSetDetailComponent {
public form!: UntypedFormGroup; public form!: UntypedFormGroup;
private document!: DataSet; public document!: DataSet;
displayedColumns = ['code', 'value', 'desc1']; displayedColumns = ['code', 'value'];
dataSource!: MatTableDataSource<DataRow>; dataSource!: MatTableDataSource<DataRow>;
@ViewChild(MatPaginator) paginator!: MatPaginator; @ViewChild(MatPaginator) paginator!: MatPaginator;
@@ -34,7 +35,8 @@ export class DataSetDetailComponent {
private http$: HttpClient, private http$: HttpClient,
private route$: ActivatedRoute, private route$: ActivatedRoute,
private auth$: AuthService, private auth$: AuthService,
private snackBar: MatSnackBar private snackBar: MatSnackBar,
private datePipe: DatePipe
) { } ) { }
async ngOnInit() { async ngOnInit() {
@@ -45,6 +47,8 @@ export class DataSetDetailComponent {
this.dataSource.sort = this.sort; this.dataSource.sort = this.sort;
this.document.fillForm(this.form); this.document.fillForm(this.form);
this.form.disable(); 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);
} }
private async load(): Promise<DataSet> { private async load(): Promise<DataSet> {
return await DataSet.getById(this.route$.snapshot.paramMap.get('id') || "", this.http$); return await DataSet.getById(this.route$.snapshot.paramMap.get('id') || "", this.http$);

View File

@@ -21,11 +21,8 @@
<mat-grid-tile> <mat-grid-tile>
<mat-form-field class="detail-input"> <mat-form-field class="detail-input">
<mat-select placeholder="Źródło" formControlName="source" (selectionChange)="generateNumber()"> <mat-select placeholder="Źródło" formControlName="source">
<mat-option value="CSV">CSV</mat-option>
<mat-option value="GoogleSheet">GoogleSheet</mat-option> <mat-option value="GoogleSheet">GoogleSheet</mat-option>
<mat-option value="SAP">SAP</mat-option>
<mat-option value="Symfonia">Symfonia</mat-option>
</mat-select> </mat-select>
<mat-error *ngIf="form.controls['source'].touched && form.controls['source'].invalid"> <mat-error *ngIf="form.controls['source'].touched && form.controls['source'].invalid">
Pole obowiązkowe Pole obowiązkowe

View File

@@ -53,11 +53,6 @@ export class DataSetEditComponent implements OnInit {
const id = await DataSet.add(this.document, this.http$); const id = await DataSet.add(this.document, this.http$);
this.router$.navigate(['../../Detail', id], { relativeTo: this.route$ }); this.router$.navigate(['../../Detail', id], { relativeTo: this.route$ });
} }
generateNumber() {
this.form.patchValue({
name: `${this.form.controls['source'].value}-${moment().format("YYYY")}${moment().format("MM")}${moment().format("DD")}${moment().format("HH")}${moment().format("mm")}`
})
}
async onFileSelected(event: any) { async onFileSelected(event: any) {
const file = event.target.files[0]; const file = event.target.files[0];
this.document.dataRows = await DataSet.parseFile(file, this.http$); this.document.dataRows = await DataSet.parseFile(file, this.http$);

View File

@@ -2,9 +2,11 @@
<div class="list-header"> <div class="list-header">
<mat-grid-list cols="10" rowHeight="60"> <mat-grid-list cols="10" rowHeight="60">
<mat-grid-tile> <mat-grid-tile>
<!--
<button mat-button routerLink="Edit/new"> <button mat-button routerLink="Edit/new">
Dodaj Dodaj
</button> </button>
-->
</mat-grid-tile> </mat-grid-tile>
<mat-grid-tile [colspan]="8"> <mat-grid-tile [colspan]="8">
<mat-form-field class="searchListInput"> <mat-form-field class="searchListInput">

View File

@@ -1,7 +1,7 @@
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Component, OnInit, ViewChild } from '@angular/core'; import { Component, OnInit, ViewChild } from '@angular/core';
import { MatPaginator } from '@angular/material/paginator'; import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort'; import { MatSort, MatSortable } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table'; import { MatTableDataSource } from '@angular/material/table';
import { DataSet } from 'src/app/models/dataSet.model'; import { DataSet } from 'src/app/models/dataSet.model';
@@ -19,12 +19,15 @@ export class DataSetsListComponent implements OnInit {
constructor( constructor(
private _http: HttpClient private _http: HttpClient
) { } ) {
console.log(Intl.DateTimeFormat().resolvedOptions().timeZone);
}
async ngOnInit() { async ngOnInit() {
this.dataSource = new MatTableDataSource(await DataSet.getList(this._http)); this.dataSource = new MatTableDataSource(await DataSet.getList(this._http));
this.dataSource.paginator = this.paginator; this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort; this.dataSource.sort = this.sort;
this.dataSource.sort.sort({ id: 'number', start: 'desc' } as MatSortable);
} }
applyFilter(event: Event) { applyFilter(event: Event) {

View File

@@ -1,5 +1,5 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule, DatePipe } from '@angular/common';
import { DataSetsRoutingModule } from './data-sets-routing.module'; import { DataSetsRoutingModule } from './data-sets-routing.module';
import { DataSetsListComponent } from './data-sets-list/data-sets-list.component'; import { DataSetsListComponent } from './data-sets-list/data-sets-list.component';
import { MaterialModule } from 'src/app/material.module'; import { MaterialModule } from 'src/app/material.module';
@@ -19,6 +19,9 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
MaterialModule, MaterialModule,
FormsModule, FormsModule,
ReactiveFormsModule ReactiveFormsModule
],
providers: [
DatePipe
] ]
}) })
export class DataSetsModule { } export class DataSetsModule { }

View File

@@ -5,8 +5,8 @@
export const environment = { export const environment = {
production: false, production: false,
api: { api: {
url: "http://localhost:5400/api" //url: "http://localhost:5400/api"
//url: "https://diuna.bim-it.pl/api" url: "https://diuna.bim-it.pl/api"
}, },
google: { google: {
clientId: "107631825312-bkfe438ehr9k9ecb2h76g802tj6advma.apps.googleusercontent.com" clientId: "107631825312-bkfe438ehr9k9ecb2h76g802tj6advma.apps.googleusercontent.com"