2021-08-30 10:24:46 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class ObjectQueryService {
|
|
|
|
|
|
|
|
|
|
data : any[] = []
|
|
|
|
|
save: Function = () =>{}
|
|
|
|
|
|
|
|
|
|
constructor() {}
|
|
|
|
|
|
|
|
|
|
Update(select:Function, update:Function, data: any[] = this.data ) {
|
|
|
|
|
|
|
|
|
|
let changes = 0
|
|
|
|
|
|
|
|
|
|
data.forEach((e)=> {
|
|
|
|
|
if(select(e)) {
|
|
|
|
|
changes++
|
|
|
|
|
update(e)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if(changes != 0) {
|
|
|
|
|
this.save()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
select(select:Function, data: any[] = this.data ) {
|
|
|
|
|
return data.filter((e)=>{
|
|
|
|
|
return select(e)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Delete(select:Function, data: any[] = this.data) {
|
|
|
|
|
|
|
|
|
|
let changes = 0
|
|
|
|
|
|
|
|
|
|
data.forEach((e, index)=>{
|
|
|
|
|
if(select(e)) {
|
|
|
|
|
if (index > -1) {
|
|
|
|
|
changes++
|
|
|
|
|
data.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if(changes != 0) this.save()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Insert(inert:any, data: any[] = this.data ) {
|
|
|
|
|
data.push(inert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print() {
|
2022-04-28 09:32:27 +01:00
|
|
|
|
2021-08-30 10:24:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|