Save DataSet

This commit is contained in:
2022-12-21 18:35:26 +01:00
parent db13b1ab1b
commit 0f28e18ed2
13 changed files with 359 additions and 40 deletions

View File

@@ -34,6 +34,23 @@ mat-form-field {
.load {
text-align: center;
}
.loading-container {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(100, 100, 100, 0.3);
z-index: 1400;
}
.loading-img {
position: absolute;
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
/* for mobile */
@media screen and (max-width: 700px) {
.container {

View File

@@ -19,6 +19,10 @@ export class DataSet extends Base {
Object.assign(this, Object.assign(this, super.deserialize(input)));
return this;
}
override serialize() {
this.number = 0; // will be overrided in backend
return Object.assign({}, this);
}
static getForm(fb: UntypedFormBuilder) {
return fb.group({
id: [null],
@@ -44,27 +48,16 @@ export class DataSet extends Base {
this.createdBy = undefined;
this.modifiedBy = undefined;
}
//API Actions
/*
static add(input: Account, _http: HttpClient, _data: DataService): Promise<string> {
//API Actions
static add(input: DataSet, _http: HttpClient): Promise<string> {
return new Promise((resolve, reject) => {
_http.post<string>(`${environment.api.url}/accounts`, {...input.serialize(), modifiedById: _data.currentUser.id }).subscribe({
_http.post<string>(`${environment.api.url}/datasets`, {...input.serialize(), }).subscribe({
next: (data) => resolve(data),
error: (e) => reject(e)
}
);
});
}
static update(input: Account, _http: HttpClient, _data: DataService): Promise<string> {
return new Promise((resolve, reject) => {
_http.patch<string>(`${environment.api.url}/accounts`, {...input.serialize(), modifiedById: _data.currentUser.id }).subscribe({
next: (data) => resolve(data),
error: (e) => reject(e)
}
);
});
}
*/
static getList(_http: HttpClient): any {
return new Promise((resolve, reject) => {
_http.get<DataSet[]>(`${environment.api.url}/datasets`)
@@ -75,7 +68,6 @@ export class DataSet extends Base {
})
});
}
static getById(id: string, _http: HttpClient): Promise<DataSet> {
return new Promise((resolve, reject) => {
_http.get<DataSet>(`${environment.api.url}/datasets/${id}`).pipe(map(x => new DataSet().deserialize(x))).subscribe({
@@ -98,14 +90,4 @@ export class DataSet extends Base {
})
})
}
/*
static delete(id: string, _http: HttpClient): Promise<string> {
return new Promise((resolve, reject)=> {
_http.delete<string>(`${environment.api.url}/accounts/${id}`).subscribe({
next: (data) => resolve(data),
error: (e) => reject(e)
})
});
}
*/
}

View File

@@ -59,16 +59,9 @@ export class DataSetEditComponent implements OnInit {
if (this.form.invalid) {
return;
}
/*
this.document.loadForm(this.form);
let id;
if (this.route$.snapshot.paramMap.get('id') === 'new') {
id = await DataSet.add(this.document, this.http$, this._data);
} else {
id = await DataSet.update(this.document, this._http, this._data);
}
this._router.navigate(['../../Detail', id], { relativeTo: this._route});
*/
const id = await DataSet.add(this.document, this.http$);
// this._router.navigate(['../../Detail', id], { relativeTo: this._route});
}
generateNumber() {
this.form.patchValue({

View File

@@ -23,9 +23,14 @@
</ng-container>
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header>Źródło</mat-header-cell>
<mat-header-cell *matHeaderCellDef mat-sort-header>Nazwa</mat-header-cell>
<mat-cell *matCellDef="let item">{{item.name}}</mat-cell>
</ng-container>
<ng-container matColumnDef="source">
<mat-header-cell *matHeaderCellDef mat-sort-header>Źródło</mat-header-cell>
<mat-cell *matCellDef="let item">{{item.source}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let item; columns: displayedColumns;" [routerLink]="['Detail/', item.id]"></mat-row>

View File

@@ -11,7 +11,7 @@ import { DataSet } from 'src/app/models/dataSet.model';
styleUrls: ['./data-sets-list.component.scss']
})
export class DataSetsListComponent implements OnInit {
displayedColumns = ['number', 'name'];
displayedColumns = ['number', 'name', 'source'];
dataSource!: MatTableDataSource<DataSet>;
@ViewChild(MatPaginator) paginator!: MatPaginator;