feat: add basic delete

This commit is contained in:
Johannes Millan 2019-10-18 17:08:39 +02:00
parent 02138a0162
commit 4f60374320
5 changed files with 42 additions and 28 deletions

View file

@ -25,7 +25,10 @@ export class NgxRxdbCollectionService<T> implements OnDestroy {
return this.dbService.db;
}
constructor(private dbService: NgxRxdbService, @Inject('RXDB_FEATURE_CONFIG') private config: NgxRxdbCollectionConfig) {
constructor(
private dbService: NgxRxdbService,
@Inject('RXDB_FEATURE_CONFIG') private config: NgxRxdbCollectionConfig,
) {
this._config = config;
}
@ -49,6 +52,18 @@ export class NgxRxdbCollectionService<T> implements OnDestroy {
return this._isInitialized.asObservable();
}
docsCustom(rules?: any, sortBy?: string, limit?: number): Observable<RxDocument<T>[]> {
return this.collectionLoaded$().pipe(
filter(isInitialized => !!isInitialized),
switchMap(() => this.collection
.find(rules)
.sort(sortBy)
.limit(50)
.$
)
);
}
docs(rules?: any, sortBy?: string, limit?: number): Observable<RxDocument<T>[]> {
return this.collectionLoaded$().pipe(
filter(isInitialized => !!isInitialized),

View file

@ -61,6 +61,7 @@ export class NgxRxdbService implements OnDestroy {
* to ensure the database exists before the angular-app starts up
*/
async initDb(config: NgxRxdbConfig) {
console.log('INIT DB');
try {
const db: RxDatabase = await RxDB.create<any>({
...DEFAULT_CONFIG,
@ -74,6 +75,8 @@ export class NgxRxdbService implements OnDestroy {
await this.initCollections(config.options.schemas);
console.log('RxdbService: created collections bulk');
}
console.log(config);
if (config && config.options && config.options.dumpPath) {
// fetch dump json
const dump = await (await fetch(config.options.dumpPath)).json();
@ -120,6 +123,8 @@ export class NgxRxdbService implements OnDestroy {
}
async createCollection(schemaConfig: NgxRxdbCollectionConfig) {
console.log('CREATE COLLECTION');
// TODO this needs to be fixed to be available initially
await promiseTimeout(2500);

View file

@ -16,7 +16,7 @@
[dragulaModel]="(filteredTasks)"
[dragula]="listId"
class="task-list-inner">
<task *ngFor="let task of (filteredTasks); trackBy: trackByFn; let i = index;"
<task *ngFor="let task of (filteredTasks); trackBy: trackByFn;"
[isBacklog]="isBacklog"
[task]="task">
</task>

View file

@ -69,8 +69,9 @@ export class TaskListComponent implements OnDestroy, OnInit {
}
@Input() set tasks(tasks: TaskWithSubTasks[]) {
console.log(tasks);
if (!tasks) {
console.log(tasks);
return;
}
this.tasksIN = tasks;

View file

@ -1,33 +1,14 @@
import shortid from 'shortid';
import {
debounceTime,
distinctUntilChanged,
filter,
first,
map,
shareReplay,
switchMap,
take,
withLatestFrom
} from 'rxjs/operators';
import {debounceTime, distinctUntilChanged, filter, first, map, shareReplay, switchMap, take, tap, withLatestFrom} from 'rxjs/operators';
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import {
DEFAULT_TASK,
DropListModelSource,
SHORT_SYNTAX_REG_EX,
ShowSubTasksMode,
Task,
TaskWithIssueData,
TaskWithSubTasks
} from './task.model';
import {DEFAULT_TASK, DropListModelSource, SHORT_SYNTAX_REG_EX, ShowSubTasksMode, Task, TaskWithIssueData, TaskWithSubTasks} from './task.model';
import {select, Store} from '@ngrx/store';
import {
AddSubTask,
AddTask,
AddTaskReminder,
AddTimeSpent,
DeleteTask,
FocusLastActiveTask,
FocusTask,
LoadTaskState,
@ -82,7 +63,6 @@ import {
selectTasksWithMissingIssueData,
selectTasksWorkedOnOrDoneFlat,
selectTaskWithSubTasksByRepeatConfigId,
selectTodaysDoneTasksWithSubTasks,
selectTodaysTasksWithSubTasks,
selectTotalTimeWorkedOnTodaysTasks
} from './store/task.selectors';
@ -157,7 +137,7 @@ export class TaskService {
// $and: [{isDone: {$eq: false}}],
});
doneTasks$: Observable<TaskWithSubTasks[]> = this.selectTodos({
doneTasks$: Observable<TaskWithSubTasks[]> = this.selectTodos({
// $and: [{isDone: {$eq: true}}],
});
@ -265,7 +245,12 @@ export class TaskService {
}
selectTodos(rulesObject = {}): Observable<any[]> {
return this._ngxRxdbCollectionService.docs(rulesObject, '-created');
console.time('CHANGE COLLECTION');
return this._ngxRxdbCollectionService.docsCustom(rulesObject, '-created').pipe(
tap(() => {
console.timeEnd('CHANGE COLLECTION');
})
);
}
@ -314,8 +299,11 @@ export class TaskService {
const task = this.createNewTaskWithDefaults(title, additionalFields);
clean(task);
console.log(task);
console.time('SAVE');
console.time('CHANGE COLLECTION');
this._ngxRxdbCollectionService.insert(task).subscribe((v) => {
console.log('SAVE SUCCESS', v);
console.timeEnd('SAVE');
});
// this._store.dispatch(new AddTask({
// task: this.createNewTaskWithDefaults(title, additionalFields),
@ -342,7 +330,12 @@ export class TaskService {
}
remove(task: TaskWithSubTasks) {
this._store.dispatch(new DeleteTask({task}));
console.time('DELETE');
console.time('CHANGE COLLECTION');
this._ngxRxdbCollectionService.remove(task.id).subscribe(() => {
console.timeEnd('DELETE');
});
// this._store.dispatch(new DeleteTask({task}));
}