diff --git a/Frontend/src/app/models/dataSet.model.ts b/Frontend/src/app/models/dataSet.model.ts index 65417ed..7a3a7b6 100644 --- a/Frontend/src/app/models/dataSet.model.ts +++ b/Frontend/src/app/models/dataSet.model.ts @@ -15,8 +15,9 @@ export class DataSet extends Base { super(); Object.assign(this, data); } - override deserialize(input: any): this { + override deserialize(input: any): this { Object.assign(this, Object.assign(this, super.deserialize(input))); + if (this.dataRows) { this.dataRows = this.dataRows.map(x => new DataRow().deserialize(x)); } return this; } override serialize() { diff --git a/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.html b/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.html index e95ac6b..0689999 100644 --- a/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.html +++ b/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.html @@ -1 +1,50 @@ -

data-set-detail works!

+
+
+ + + Szczegóły warstwy danych + + + + + + Nazwa + + + + + + + + + + + + + + + MPK + {{item.code}} + + + + Konto + {{item.desc1}} + + + + Wartość + {{item.value | number:'1.2-2'}} + + + + + + + + + +
+
\ No newline at end of file diff --git a/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.scss b/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.scss index e69de29..b199958 100644 --- a/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.scss +++ b/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.scss @@ -0,0 +1 @@ +@import "../../../main-view/main-view.component.scss"; \ No newline at end of file diff --git a/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.ts b/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.ts index 11fb272..5436f28 100644 --- a/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.ts +++ b/Frontend/src/app/modules/data-sets/data-set-detail/data-set-detail.component.ts @@ -1,4 +1,15 @@ -import { Component } from '@angular/core'; +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'; +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'; @Component({ selector: 'app-data-set-detail', @@ -7,4 +18,36 @@ import { Component } from '@angular/core'; }) export class DataSetDetailComponent { + public form!: UntypedFormGroup; + private document!: DataSet; + + displayedColumns = ['code', 'value', 'desc1']; + dataSource!: MatTableDataSource; + + @ViewChild(MatPaginator) paginator!: MatPaginator; + @ViewChild(MatSort) sort!: MatSort; + + constructor( + private fb$: UntypedFormBuilder, + private router$: Router, + private http$: HttpClient, + private route$: ActivatedRoute, + private auth$: AuthService + ) { } + + async ngOnInit() { + this.form = DataSet.getForm(this.fb$); + this.document = await this.load(); + this.dataSource = new MatTableDataSource(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 { + return await DataSet.getById(this.route$.snapshot.paramMap.get('id') || "", this.http$); + } + trackByUid(index : number, item : DataRow) { + return item.id; + } } diff --git a/Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.ts b/Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.ts index fc2ca18..068fc4e 100644 --- a/Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.ts +++ b/Frontend/src/app/modules/data-sets/data-set-edit/data-set-edit.component.ts @@ -33,49 +33,39 @@ export class DataSetEditComponent implements OnInit { private fb$: UntypedFormBuilder, private router$: Router, private http$: HttpClient, - private data$: DataService, private route$: ActivatedRoute, - private dialog$: MatDialog, private auth$: AuthService ) { } async ngOnInit() { this.form = DataSet.getForm(this.fb$); - this.document = await this.load(); + this.document = new DataSet({ + id: uuidv4(), createdById: this.auth$.user.id, createdAt: moment(), + modifiedAt: moment() + }) this.document.fillForm(this.form); } - private load(): Promise { - return new Promise((resolve) => { - const id = this.route$.snapshot.paramMap.get('id') || ""; - if (this.route$.snapshot.paramMap.get('id') === 'new') { - resolve(new DataSet({ id: uuidv4(), createdById: this.auth$.user.id, createdAt: moment(), - modifiedAt: moment() })) // new element - return; - } - resolve(DataSet.getById(id, this.http$)) - }); - } async save() { if (this.form.invalid) { return; } this.document.loadForm(this.form); 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]; - this.document.dataRows = await DataSet.parseFile(file, this.http$); + this.document.dataRows = await DataSet.parseFile(file, this.http$); this.dataSource = new MatTableDataSource(this.document.dataRows); this.dataSource.paginator = this.paginator; this.dataSource.sort = this.sort; } - trackByUid(index : number, item : DataRow) { + trackByUid(index: number, item: DataRow) { return item.id; } } diff --git a/WebAPI/Controllers/DataSetsController.cs b/WebAPI/Controllers/DataSetsController.cs index 8c5fac6..10651a9 100644 --- a/WebAPI/Controllers/DataSetsController.cs +++ b/WebAPI/Controllers/DataSetsController.cs @@ -2,6 +2,7 @@ using Google.Apis.Auth; using Google.Apis.Http; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Identity.Client.Platforms.Features.DesktopOs.Kerberos; using Microsoft.IdentityModel.Tokens; @@ -47,6 +48,22 @@ namespace WebAPI.Controllers return BadRequest(e.ToString()); } } + [HttpGet] + [Route("{id}")] + public IActionResult Get(Guid id) + { + try + { + return Ok(db.DataSets + .Include(x => x.CreatedBy) + .Include(x => x.DataRows) + .Where(x => x.Id == id && !x.IsDeleted).First()); + } + catch (Exception e) + { + return BadRequest(e.ToString()); + } + } [HttpPost] [DisableRequestSizeLimit] [Route("parseFile")]