Commit 871e96e9 authored by Konstantin Schulz's avatar Konstantin Schulz

fixed a bug in the handling of corpus resources (introduced by the split application state)

parent c8eefdbc
{
"name": "mc_frontend",
"version": "1.5.1",
"version": "1.5.2",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
......
......@@ -27,10 +27,11 @@ import {Exercise} from 'src/app/models/exercise';
import {Feedback} from 'src/app/models/feedback';
import {PhenomenonMap, PhenomenonMapContent} from 'src/app/models/phenomenonMap';
import {FrequencyItem} from 'src/app/models/frequencyItem';
import {BehaviorSubject, ReplaySubject} from 'rxjs';
import {ReplaySubject} from 'rxjs';
import {ApplicationState} from './models/applicationState';
import {take} from 'rxjs/operators';
import {TextData} from './models/textData';
import {Storage} from '@ionic/storage';
@Injectable({
providedIn: 'root'
......@@ -74,6 +75,7 @@ export class CorpusService {
public http: HttpClient,
public toastCtrl: ToastController,
public helperService: HelperService,
public storage: Storage
) {
this.isMostRecentSetupLoaded = false;
this.helperService.initApplicationState();
......@@ -146,14 +148,16 @@ export class CorpusService {
checkForUpdates(): Promise<void> {
return new Promise((resolve, reject) => {
HelperService.config.pipe(take(1)).subscribe((config: object) => {
// check local storage for necessary updates
const updateInfoJSON: object = JSON.parse(window.localStorage.getItem(config['localStorageKeyUpdateInfo']));
this.getCorpora(updateInfoJSON ? new Date(updateInfoJSON['corpora'].lastAccessTime).getTime() : 0)
.then(() => {
return resolve();
}, () => {
return reject();
});
this.storage.get(config['localStorageKeyUpdateInfo']).then((jsonString: string) => {
// check local storage for necessary updates
const updateInfoJSON: object = JSON.parse(jsonString);
this.getCorpora(updateInfoJSON ? new Date(updateInfoJSON['corpora'].lastAccessTime).getTime() : 0)
.then(() => {
return resolve();
}, () => {
return reject();
});
});
});
});
}
......@@ -169,9 +173,9 @@ export class CorpusService {
HelperService.makeGetRequest(this.http, this.toastCtrl, url, params).then((data: object) => {
if (data) {
const corpusList: CorpusMC[] = data['corpora'] as CorpusMC[];
window.localStorage.setItem(config['localStorageKeyCorpora'], JSON.stringify(corpusList));
this.storage.set(config['localStorageKeyCorpora'], JSON.stringify(corpusList)).then();
const updateInfo: object = {corpora: {lastAccessTime: new Date().getTime()}};
window.localStorage.setItem(config['localStorageKeyUpdateInfo'], JSON.stringify(updateInfo));
this.storage.set(config['localStorageKeyUpdateInfo'], JSON.stringify(updateInfo)).then();
this.processCorpora(corpusList);
return resolve();
} else {
......@@ -346,11 +350,12 @@ export class CorpusService {
public loadCorporaFromLocalStorage() {
HelperService.config.pipe(take(1)).subscribe((config: object) => {
const storedCorporaJSONstring: string = window.localStorage.getItem(HelperService.config['localStorageKeyCorpora']);
if (storedCorporaJSONstring) {
const corpusList: CorpusMC[] = JSON.parse(storedCorporaJSONstring) as CorpusMC[];
this.processCorpora(corpusList);
}
this.storage.get(config['localStorageKeyCorpora']).then((jsonString: string) => {
if (jsonString) {
const corpusList: CorpusMC[] = JSON.parse(jsonString) as CorpusMC[];
this.processCorpora(corpusList);
}
});
});
}
......@@ -382,9 +387,13 @@ export class CorpusService {
this.annisResponse = ar;
if (saveToCache) {
HelperService.applicationState.pipe(take(1)).subscribe((as: ApplicationState) => {
as.currentSetup.currentUrn = this.currentUrn;
as.currentSetup.annisResponse = ar;
this.helperService.saveApplicationState(as).then();
as.currentSetup.annisResponse = null;
as.mostRecentSetup.currentUrn = this.currentUrn;
as.mostRecentSetup.annisResponse = ar;
this.helperService.saveApplicationState(as).then(() => {
as.currentSetup.currentUrn = this.currentUrn;
as.currentSetup.annisResponse = ar;
});
});
}
}
......
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