Skip to content

Commit 339ba42

Browse files
committed
refactor(wip): updated board and bucket data layer
1 parent dbbc7f7 commit 339ba42

23 files changed

+4666
-3886
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules\\typescript\\lib"
3+
}

log.txt

Lines changed: 3951 additions & 3492 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 448 additions & 196 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"@ngxs/devtools-plugin": "^3.0.1",
2929
"@ngxs/store": "^3.0.1",
3030
"@types/nedb": "^1.8.5",
31+
"@types/pouchdb-core": "^6.4.0",
32+
"@types/pouchdb-find": "^6.3.2",
3133
"a-color-picker": "^1.0.5",
3234
"babel-polyfill": "^6.26.0",
3335
"bootstrap": "^4.1.1",
@@ -40,8 +42,11 @@
4042
"ngx-color": "^1.3.1",
4143
"ngx-smart-modal": "^6.0.0",
4244
"ngx-toastr": "^8.5.1",
45+
"pouchdb": "^6.4.3",
4346
"pouchdb-adapter-idb": "^6.4.3",
47+
"pouchdb-find": "^6.4.3",
4448
"pretty-checkbox": "^3.0.3",
49+
"relational-pouch": "^3.0.1",
4550
"rxdb": "^7.6.0",
4651
"rxjs": "^6.0.0",
4752
"zone.js": "^0.8.26"
@@ -57,6 +62,7 @@
5762
"@types/jasmine": "~2.8.6",
5863
"@types/jasminewd2": "~2.0.3",
5964
"@types/node": "~8.9.4",
65+
"@types/pouchdb": "^6.3.2",
6066
"codelyzer": "~4.2.1",
6167
"husky": "^0.14.3",
6268
"jasmine-core": "~2.99.1",
@@ -74,6 +80,6 @@
7480
"stylelint-scss": "^3.1.0",
7581
"ts-node": "~5.0.1",
7682
"tslint": "~5.9.1",
77-
"typescript": "~2.7.2"
83+
"typescript": "^2.9.1-insiders.20180525"
7884
}
7985
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<ng-container *ngIf="board as coll">
2-
<h4>{{coll.name}}</h4>
3-
<ng-container *ngFor="let b of bucket|async">
4-
<inkapp-bucket [bucketData]="b"></inkapp-bucket>
1+
<ng-container>
2+
<h4>{{data.name}}</h4>
3+
<ng-container *ngFor="let bucket of buckets|async">
4+
<inkapp-bucket [bucketData]="bucket"></inkapp-bucket>
55
</ng-container>
66
</ng-container>
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, Input } from '@angular/core';
22
import { Store, Select } from '@ngxs/store';
3-
import { InkBucket, InkBoard, InkBoardMeta } from '../../models';
3+
import { InkBucket, InkBoard, InkBoardMeta, InkBucketMeta } from '../../models';
44
import { Observable } from 'rxjs';
5-
import { map, filter } from 'rxjs/operators';
5+
import { map, filter, tap } from 'rxjs/operators';
6+
import { BucketService } from '../../services/bucket.service';
7+
import { LoadBuckets } from '../../store/actions/bucket.action';
68

79
@Component({
810
selector: 'inkapp-board',
9-
templateUrl: './board.component.html',
10-
styles: []
11+
templateUrl: './board.component.html'
1112
})
1213
export class BoardComponent implements OnInit {
13-
bucket: Observable<InkBucket>;
14-
board: InkBoardMeta;
15-
constructor(private store: Store) {
16-
this.store
17-
.select(s => s.board)
18-
.pipe(filter(s => s.length > 0), map(x => x[0]))
19-
.subscribe(r => {
20-
console.log('CColl', r);
21-
this.board = r;
22-
});
23-
}
14+
buckets: Observable<InkBucketMeta[]>;
15+
@Input() data: InkBoardMeta;
16+
constructor(private _store: Store, private _bucketService: BucketService) {}
2417

2518
ngOnInit() {
26-
this.bucket = this.store.select(s => s.bucket).pipe(map(x => x.filter(y => y.boardId === this.board.id)));
19+
this.buckets = this._store
20+
.select(s => s.bucket)
21+
.pipe(map(buckets => buckets.filter(s => s.boardId === this.data._id)));
22+
console.log('get buckets', this.data._id);
23+
this._bucketService.getBucketsInBoard(this.data._id).then(buckets => {
24+
console.log('load buckets', buckets);
25+
this._store.dispatch(new LoadBuckets(buckets));
26+
});
2727
}
2828
}

src/app/components/navbar/navbar.component.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
22
import { Store } from '@ngxs/store';
33
import { CreateBucket } from '../../store/actions/bucket.action';
44
import { map, tap, filter } from 'rxjs/operators';
5+
import { BucketService } from '../../services/bucket.service';
56

67
@Component({
78
selector: 'inkapp-navbar',
@@ -10,18 +11,27 @@ import { map, tap, filter } from 'rxjs/operators';
1011
})
1112
export class NavbarComponent implements OnInit {
1213
currentBoardId: string;
13-
constructor(private store: Store) {}
14+
constructor(private _store: Store, private _bucketService: BucketService) {}
1415

1516
ngOnInit() {
16-
this.store
17+
this._store
1718
.select(s => s.board)
18-
.pipe(filter(s => s.length > 0), map(s => s[0].id))
19+
.pipe(
20+
filter(s => s.length > 0),
21+
map(s => s[0]._id),
22+
tap(y => {
23+
console.log('get boars==>', y);
24+
})
25+
)
1926
.subscribe(r => (this.currentBoardId = r));
2027
}
2128

2229
newBucket() {
23-
if (this.currentBoardId) {
24-
this.store.dispatch(new CreateBucket({ boardId: this.currentBoardId, name: 'Hello-123' }));
30+
if (!this.currentBoardId) {
31+
return;
2532
}
33+
this._bucketService.newBucket({ boardId: this.currentBoardId, name: 'Hello-123' }).then(bucket => {
34+
this._store.dispatch(new CreateBucket(bucket));
35+
});
2636
}
2737
}

src/app/ink.component.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,10 @@ import { RxCollection, RxDatabase } from 'rxdb';
1111
template: '<router-outlet></router-outlet>'
1212
})
1313
export class InkApp implements OnInit {
14-
constructor(private store: Store, private db: DBService, private zone: NgZone) {
14+
constructor(private store: Store, private db: DBService) {
1515
// console.log('cons', this.db.conn);
1616
}
1717
ngOnInit() {
18-
try {
19-
this.getDb();
20-
} catch (e) {
21-
console.log('Unexpected error occurred', e);
22-
}
2318
this.store.dispatch(new ChangeView(InkAppView.ROUND));
2419
}
25-
26-
async getDb() {
27-
this.zone.run(() => {});
28-
const db = await this.db.localDb.getDatabase();
29-
// const d = await db.board.dump(false);
30-
console.log('db');
31-
// const firstDoc = await db.board.findOne().exec();
32-
// console.log('name', firstDoc);
33-
// const f: string = firstDoc.name;
34-
35-
// this.db.localDb
36-
// .getDatabase()
37-
// .then((a: InkDb) => {
38-
// a.board.$.subscribe(f => console.log(f));
39-
// // const foo = a.board.newDocument({ id: 'xyz', name: 'super appu' });
40-
// // foo.save();
41-
// return a;
42-
// })
43-
// .then(db => {
44-
// db.board
45-
// .find()
46-
// .exec()
47-
// .catch();
48-
// console.log();
49-
// // const fgt = db.board.find().$.subscribe(
50-
// // n => {
51-
// // console.log('now', n);
52-
// // },
53-
// // e => {
54-
// // console.log('de', e);
55-
// // }
56-
// // );
57-
// return db;
58-
// })
59-
// .catch(e => {
60-
// console.log('Unexpected error occurred', e);
61-
// });
62-
}
6320
}

src/app/models/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export * from './ink.model';
2-
export * from './inkdb.model';

src/app/models/ink.model.ts

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
1-
import {
2-
InkDbBoardCollection,
3-
InkDbInkCollection,
4-
InkDbBucketCollection,
5-
InkDbSettingsCollection
6-
} from './inkdb.model';
7-
import { RxDatabase } from 'rxdb';
1+
import { RxDatabase, RxDocument, RxCollection } from 'rxdb';
82

93
export enum InkColorType {
104
RGB,
115
HEX,
126
HSL
137
}
148

9+
export interface InkBoardMeta {
10+
name?: string;
11+
_id?: string;
12+
description?: string;
13+
createdAt?: string;
14+
}
1515
export interface InkBucketMeta {
16-
id?: string;
17-
name: string;
16+
name?: string;
17+
_id?: string;
18+
description?: string;
1819
boardId: string;
1920
}
20-
21-
export type InkBucket = InkBucketMeta[];
22-
23-
export interface InkColor {
24-
id?: string;
21+
export interface InkColorMeta {
2522
name?: string;
26-
value: string;
23+
_id?: string;
24+
description?: string;
2725
meta: any;
26+
displayValue: string;
2827
bucketId: string;
2928
}
30-
31-
export type Ink = InkColor[];
32-
33-
export interface InkBoardMeta {
34-
id: string;
35-
name: string;
36-
created: Date;
29+
export interface InkSettingsMeta {
30+
key: string;
31+
_id?: string;
32+
value: string;
3733
}
3834

35+
export type InkBucket = InkBucketMeta[];
36+
export type Ink = InkColorMeta[];
3937
export type InkBoard = InkBoardMeta[];
4038

4139
export enum InkAppView {
@@ -48,9 +46,25 @@ export interface InkAppSettings {
4846
sortBy: string;
4947
}
5048

49+
/* doc methods */
50+
export interface InkDocMethods {
51+
log(): any;
52+
}
53+
54+
/* documents */
55+
export type InkBoardDoc = RxDocument<InkBoardMeta, InkDocMethods>;
56+
export type InkBucketDoc = RxDocument<InkBucketMeta, InkDocMethods>;
57+
export type InkInkDoc = RxDocument<InkColorMeta, InkDocMethods>;
58+
export type InkSettingsDoc = RxDocument<InkSettingsMeta, InkDocMethods>;
59+
/* collections */
60+
export interface InkBoardColl extends RxCollection<InkBoardMeta, InkDocMethods> {}
61+
export interface InkBucketColl extends RxCollection<InkBucketMeta, InkDocMethods> {}
62+
export interface InkInkColl extends RxCollection<InkColorMeta, InkDocMethods> {}
63+
export interface InkSettingsColl extends RxCollection<InkSettingsMeta, InkDocMethods> {}
64+
/* database */
5165
export interface InkDb extends RxDatabase {
52-
board?: InkDbBoardCollection;
53-
ink?: InkDbInkCollection;
54-
bucket?: InkDbBucketCollection;
55-
settings?: InkDbSettingsCollection;
66+
board?: InkBoardColl;
67+
ink?: InkInkColl;
68+
bucket?: InkBucketColl;
69+
settings?: InkSettingsColl;
5670
}

src/app/models/inkdb.model.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<inkapp-navbar></inkapp-navbar>
22
<div class="container">
3-
<inkapp-board></inkapp-board>
3+
<inkapp-board *ngFor="let board of boards" [data]="board"></inkapp-board>
44
</div>

src/app/pages/home/home.component.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { BoardService } from '../../services/board.service';
3+
import { Store } from '@ngxs/store';
4+
import { LoadBoard } from '../../store/actions/board.actions';
5+
import { filter, map } from 'rxjs/operators';
6+
import { InkBoard, InkBoardMeta } from '../../models';
27

38
@Component({
49
selector: 'inkapp-home-page',
510
templateUrl: './home.component.html',
611
styles: []
712
})
813
export class HomePage implements OnInit {
9-
constructor() {}
14+
boards: InkBoardMeta[];
15+
constructor(private _boardService: BoardService, private _store: Store) {}
1016

11-
ngOnInit() {}
17+
async ngOnInit() {
18+
this._store.select(s => s.board).subscribe(b => {
19+
this.boards = b;
20+
});
21+
const boards = await this._boardService.getBoards();
22+
boards.map(b => ({ _id: b._id, name: b.name, description: b.description, createdAt: b.createdAt }));
23+
this._store.dispatch(new LoadBoard(boards));
24+
}
1225
}

0 commit comments

Comments
 (0)