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