Skip to content

Commit 7a307b0

Browse files
committed
Complete fetching data from git platforms.
1 parent 336ab99 commit 7a307b0

File tree

14 files changed

+84
-73
lines changed

14 files changed

+84
-73
lines changed

electron/src/book.backend.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ export class BookBackend {
165165
}
166166
break;
167167
case 'book-downloaded':
168-
this.book.desc = join(this.bookPath, 'README.md');
169168
this.book.downloaded = true;
170169

171170
this.book.commit = (msg.data as IBookDownloaded).commit;

electron/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ export default class Main {
4444
request.onBeforeSendHeaders(
4545
filter,
4646
(details, callback) => {
47-
//console.log(details);
47+
console.log(details);
4848
details.requestHeaders['Origin'] = 'capacitor-electron://-';
49+
details.requestHeaders['Access-Control-Allow-Origin'] = "capacitor-electron://-",
4950
details.requestHeaders["Access-Control-Allow-Methods"] = "GET,HEAD,OPTIONS,POST,PUT";
5051
details.requestHeaders["Access-Control-Allow-Headers"] = "Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers";
5152
callback({ requestHeaders: details.requestHeaders });

src/app/book/services/fetch.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from '@angular/core';
2-
import { HttpClient } from '@angular/common/http';
2+
import { HttpClient, HttpHeaders } from '@angular/common/http';
33

44
import { Observable, of } from 'rxjs';
55
import { map, share, catchError } from 'rxjs/operators';
@@ -101,6 +101,7 @@ export class FetchService {
101101
}
102102

103103
let notFound = url === this.path404;
104+
104105
const obs: Observable<CachePage> = this.http
105106
.get(url, {responseType: 'text'})
106107
.pipe(

src/app/home/components/book-list.component.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414
<mat-card-header>
1515
<img mat-card-avatar [src]="book.isFromMainstreamPlatform ? book.writer.avatarUrl : 'assets/images/avatar.png'" />
1616
<mat-card-title>{{book.writer.fullName}}</mat-card-title>
17-
<mat-card-subtitle>{{book.website.uri}}</mat-card-subtitle>
17+
<mat-card-subtitle>
18+
<ion-icon *ngIf="book.writer.location.length > 0" name="location-outline"></ion-icon>{{book.writer.location}}
19+
@{{book.website.uri}}
20+
</mat-card-subtitle>
1821
</mat-card-header>
1922

2023
<mat-card-content fxLayout="row" fxLayoutGap="5px" class="cate-list">
21-
<mat-label>{{book.desc}}</mat-label>
24+
<mat-label><b></b>{{book.desc}}<b></b></mat-label>
25+
</mat-card-content>
26+
27+
<mat-card-content fxLayout="row" fxLayoutGap="5px" class="cate-list">
2228
<mat-chip-list>
2329
<mat-chip class="cate-chip" *ngFor="let cate of book.cateList" (click)="listBooksUnderCate(cate)">
2430
<ion-label>{{cate.name}}</ion-label>
@@ -35,7 +41,7 @@
3541
(click)="openReadingRecordDialog(book)">
3642
<ion-icon name="list-outline"></ion-icon>阅读记录
3743
</button>
38-
<button mat-button *ngIf="book.isFromMainstreamPlatform || book.downloaded" (click)="openReadmeDialog(book)">
44+
<button mat-button *ngIf="book.downloaded" (click)="openReadmeDialog(book)">
3945
<ion-icon name="compass-outline"></ion-icon>README
4046
</button>
4147
<button mat-button *ngIf="book.downloaded" (click)="openBook(book)">

src/app/home/components/book-list.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export class BookListComponent implements OnInit, OnChanges {
5757
private book: BookService,
5858
private cdr: ChangeDetectorRef,
5959
private opMessage: OpMessageService
60-
) {}
60+
) {
61+
this._bookList = book.list;
62+
}
6163

6264
get bookList () {
6365
const bookList = this._bookList.filter(b => filterFn(b, this.filter));

src/app/home/components/new-book-dialog.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ export class NewBookDialog implements OnInit{
6969
ngOnInit() {
7070
this.tempCateList = this.cateList.slice();
7171

72-
this.uriInputControl.setValidators(IsQualifiedAndNotExistedGitRepoValidatorFn(this.book
73-
.list.slice()
74-
));
72+
this.uriInputControl.setValidators(IsQualifiedAndNotExistedGitRepoValidatorFn(this.book.list.slice()));
7573
}
7674

7775
private _filter(val: string): Array<Category> {

src/app/home/home.page.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export class HomePage implements OnInit, AfterViewInit {
6060
private message: MessageService,
6161
private cdr: ChangeDetectorRef,
6262
private book: BookService,
63-
) {}
63+
) {
64+
this.bookList = book.list;
65+
}
6466

6567
private changeFabButton = (button: TAvatarIds) => {
6668
const buttonList = ['currently-reading', 'on-shelf', 'recycled'];
@@ -100,8 +102,6 @@ export class HomePage implements OnInit, AfterViewInit {
100102
}
101103

102104
ngOnInit() {
103-
this.bookList = this.book.list.slice();
104-
105105
this.crud.ipcRenderer.on('book-updated', (ev, msg: IQueryResult) => {
106106
this.opMessage.newMsg(msg.message);
107107
this.book.listUpdated(msg.data as Book);

src/app/home/services/book.service.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class BookService {
3737
private cate: CateService
3838
) {
3939
this.crud.getItems({table: 'Book'})
40-
.then((res: IQueryResult) => {
40+
.subscribe((res: IQueryResult) => {
4141
this.opMessage.newMsg(res.message);
4242
const books = res.data as Book[];
4343
this.list = books.slice();
@@ -79,6 +79,7 @@ export class BookService {
7979
let rawRepo: object;
8080
if(/gitee/.test(site)){
8181
rawRepo = await this.fetchService.getRepoProfile(site, newBook.name, writerName);
82+
8283
newBook.writer = await this.writer.newWriter(writerName, newBook, rawRepo['owner']['login']);
8384
}
8485
else {
@@ -110,9 +111,11 @@ export class BookService {
110111
item: newBook
111112
}
112113

113-
const queryRes:IQueryResult = await this.crud.addItem(query);
114-
this.opMessage.newMsg(queryRes.message);
115-
this.listUpdated(queryRes.data as Book);
114+
this.crud.addItem(query)
115+
.subscribe(res => {
116+
this.opMessage.newMsg(res.message);
117+
this.listUpdated(res.data as Book);
118+
});
116119
}
117120

118121
open = async (book: Book) => {
@@ -124,23 +127,23 @@ export class BookService {
124127
item: book
125128
}
126129

127-
const res: IQueryResult = await this.crud.updateItem(query);
128-
this.opMessage.newMsg(res.message);
129-
this.listUpdated(res.data as Book);
130+
this.crud.updateItem(query).subscribe(res => {
131+
this.opMessage.newMsg(res.message);
132+
this.listUpdated(res.data as Book);
133+
});
130134
}
131135

132136
update = async (book: Book) => {
133-
let query: IQuery;
134-
135137
book.cateList = await this.cate.saveList(book.cateList);
136138

137-
query = {
139+
const query: IQuery = {
138140
table: 'Book',
139141
item: book
140142
}
141-
const queryRes: IQueryResult = await this.crud.updateItem(query);
142-
this.opMessage.newMsg(queryRes.message);
143-
this.listUpdated(queryRes.data as Book);
143+
this.crud.updateItem(query).subscribe(queryRes => {
144+
this.opMessage.newMsg(queryRes.message);
145+
this.listUpdated(queryRes.data as Book);
146+
});
144147
}
145148

146149
recycleRecoverDelete = async (res: IDeleteBookDialogResData) => {
@@ -152,8 +155,9 @@ export class BookService {
152155
item: res.book
153156
}
154157

155-
const queryRes: IQueryResult = await this.crud.deleteItem(query);
156-
this.opMessage.newMsg(queryRes.message);
158+
this.crud.deleteItem(query).subscribe(queryRes => {
159+
this.opMessage.newMsg(queryRes.message);
160+
});
157161
}
158162

159163
if (!res.recycled && res.remove){
@@ -162,9 +166,10 @@ export class BookService {
162166
item: res.book
163167
}
164168

165-
const queryRes:IQueryResult = await this.crud.deleteItem(query);
166-
this.opMessage.newMsg(queryRes.message);
167-
this.listUpdated(res.book, true);
169+
this.crud.deleteItem(query).subscribe(queryRes => {
170+
this.opMessage.newMsg(queryRes.message);
171+
this.listUpdated(res.book, true);
172+
});
168173

169174
return;
170175
}
@@ -178,8 +183,9 @@ export class BookService {
178183
item: res.book
179184
}
180185

181-
const queryRes:IQueryResult = await this.crud.updateItem(query);
182-
this.opMessage.newMsg(queryRes.message);
183-
this.listUpdated(queryRes.data as Book);
186+
this.crud.updateItem(query).subscribe(queryRes => {
187+
this.opMessage.newMsg(queryRes.message);
188+
this.listUpdated(queryRes.data as Book);
189+
});
184190
}
185191
}

src/app/home/services/cate.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class CateService {
2020
private opMessage: OpMessageService,
2121
) {
2222
this.crud.getItems({table: 'Category'})
23-
.then((res: IQueryResult) => {
23+
.subscribe((res: IQueryResult) => {
2424
this.opMessage.newMsg(res.message);
2525
const cates = res.data as Category[];
2626
this.list = cates.slice();
@@ -43,7 +43,7 @@ export class CateService {
4343
item: _cate
4444
}
4545

46-
const res: IQueryResult = await this.crud.addItem(query);
46+
const res: IQueryResult = await this.crud.addItem(query).toPromise();
4747

4848
this.opMessage.newMsg(res.message);
4949
const cate = res.data as Category;

src/app/home/services/fetch.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class FetchService {
7878
header = "Accept: application/vnd.github.v3+json";
7979
}
8080

81-
if(/gitlab/.test(website) && ownerId) {
81+
if(/gitlab/.test(website)) {
8282
url = `https://gitlab.com/api/v4/users/${ownerId}/projects`;
8383
header = `PRIVATE-TOKEN: ${this.tokens.gitlabToken}`;
8484
}

0 commit comments

Comments
 (0)