WIP: DataSets Module
This commit is contained in:
97
Frontend/src/app/models/dataSet.model.ts
Normal file
97
Frontend/src/app/models/dataSet.model.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { Base } from './base.model';
|
||||
import { UntypedFormBuilder, Validators, UntypedFormGroup } from '@angular/forms';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { DataService } from '../services/data.service';
|
||||
import { map } from 'rxjs';
|
||||
import { DataRow } from './dataRow.model copy';
|
||||
|
||||
export class DataSet extends Base {
|
||||
number?: string;
|
||||
name?: string;
|
||||
dataRows: DataRow[] = [];
|
||||
|
||||
constructor(data: Partial<DataSet> = {}) {
|
||||
super();
|
||||
Object.assign(this, data);
|
||||
}
|
||||
override deserialize(input: any): this {
|
||||
Object.assign(this, Object.assign(this, super.deserialize(input)));
|
||||
return this;
|
||||
}
|
||||
static getForm(fb: UntypedFormBuilder) {
|
||||
return fb.group({
|
||||
id: [null],
|
||||
number: ['', Validators.required],
|
||||
name: ['', Validators.required],
|
||||
createdAt: '',
|
||||
modifiedAt: '',
|
||||
createdBy: '',
|
||||
modifiedBy: '',
|
||||
});
|
||||
}
|
||||
fillForm(form: UntypedFormGroup) {
|
||||
form.patchValue(this);
|
||||
form.patchValue({
|
||||
createdBy: this.createdBy?.userName,
|
||||
modifiedBy: this.modifiedBy?.userName
|
||||
});
|
||||
}
|
||||
loadForm(form: UntypedFormGroup) {
|
||||
for (let field of Object.keys(form.controls)) {
|
||||
this[field as keyof DataSet] = form.controls[field].value;
|
||||
}
|
||||
this.createdBy = undefined;
|
||||
this.modifiedBy = undefined;
|
||||
}
|
||||
//API Actions
|
||||
/*
|
||||
static add(input: Account, _http: HttpClient, _data: DataService): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
_http.post<string>(`${environment.api.url}/accounts`, {...input.serialize(), modifiedById: _data.currentUser.id }).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`)
|
||||
.pipe(map(data => data.map(x => new DataSet().deserialize(x))))
|
||||
.subscribe({
|
||||
next: (data) => resolve(data),
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
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({
|
||||
next: (data) => resolve(data),
|
||||
error: (e) => reject(e)
|
||||
})
|
||||
});
|
||||
}
|
||||
/*
|
||||
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)
|
||||
})
|
||||
});
|
||||
}
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user