Commit 5cbce561 authored by Konstantin Schulz's avatar Konstantin Schulz
Browse files

improved corpus update mechanism

parent 29dbbd0a
{
"name": "mcClient",
"version": "0.3.5",
"version": "0.3.6",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
......
......@@ -11,4 +11,7 @@ page-exercise-parameters {
.matching {
border: 2px solid lightgray;
}
select {
max-width: 95%;
}
}
......@@ -38,7 +38,7 @@ export class HomePage {
refreshCorpora() {
this.isCorpusUpdateInProgress = true;
this.corpusProvider.getCorpora(true).then(() => {
this.corpusProvider.getCorpora(0).then(() => {
this.isCorpusUpdateInProgress = false;
let toast = this.toastCtrl.create({
message: this.corpusUpdateCompletedString,
......
......@@ -98,9 +98,7 @@ export class CorpusProvider {
constructor(public translate: TranslateService,
public http: HttpClient) {
if (!this.availableCorpora) {
this.checkForUpdates().then();
}
this.checkForUpdates().then();
}
getCTStextPassage(urn: string) {
......@@ -114,28 +112,28 @@ export class CorpusProvider {
return this.http.get(fullUrl, {params: {"urn": urn}});
}
getCorpora(fromServer: boolean = false) {
getCorpora(lastUpdateTimeMS: number = 0) {
return new Promise(resolve => {
this.availableCorpora = [];
this.availableAuthors = [];
if (fromServer) {
// get corpora from REST API
let url = HelperProvider.config["backendBaseUrl"] + HelperProvider.config["backendApiCorporaPath"];
this.http.get(url).subscribe((data: object) => {
// get corpora from REST API
let url = HelperProvider.config["backendBaseUrl"] + HelperProvider.config["backendApiCorporaPath"];
this.http.get(url, {params: {"last_update_time": lastUpdateTimeMS.toString()}}).subscribe((data: object) => {
if (data) {
let corpusList: CorpusMC[] = data["corpora"] as CorpusMC[];
window.localStorage.setItem(HelperProvider.config["localStorageKeyCorpora"], JSON.stringify(corpusList));
let updateInfo: object = {corpora: {lastAccessTime: new Date().getTime()}};
window.localStorage.setItem(HelperProvider.config["localStorageKeyUpdateInfo"], JSON.stringify(updateInfo));
this.processCorpora(corpusList);
resolve();
});
}
else {
let storedCorporaJSONstring: string = window.localStorage.getItem(HelperProvider.config["localStorageKeyCorpora"]);
let corpusList: CorpusMC[] = JSON.parse(storedCorporaJSONstring) as CorpusMC[];
this.processCorpora(corpusList);
resolve();
}
}
else {
let storedCorporaJSONstring: string = window.localStorage.getItem(HelperProvider.config["localStorageKeyCorpora"]);
let corpusList: CorpusMC[] = JSON.parse(storedCorporaJSONstring) as CorpusMC[];
this.processCorpora(corpusList);
resolve();
}
});
});
}
......@@ -144,20 +142,8 @@ export class CorpusProvider {
await new Promise(resolve => setTimeout(resolve, 50));
}
// check local storage for necessary updates
let updateInfoJSONstring: string = window.localStorage.getItem(HelperProvider.config["localStorageKeyUpdateInfo"]);
if (!updateInfoJSONstring) {
this.getCorpora(true).then();
}
else {
let corporaLastAccessTime: number = new Date(updateInfoJSONstring).getTime();
if (new Date().getTime() - corporaLastAccessTime > HelperProvider.config["intervalCorporaUpdate"]) {
this.getCorpora(true).then();
}
else {
// check local storage for corpora
this.getCorpora(false).then();
}
}
let updateInfoJSON: object = JSON.parse(window.localStorage.getItem(HelperProvider.config["localStorageKeyUpdateInfo"]));
this.getCorpora(updateInfoJSON ? new Date(updateInfoJSON["corpora"]["lastAccessTime"]).getTime() : 0).then();
}
private processCorpora(corpusList: CorpusMC[]) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment