mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
61 lines
961 B
TypeScript
61 lines
961 B
TypeScript
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() {
|
|
console.log(this.data)
|
|
}
|
|
|
|
}
|