Commit 6d789b0c authored by Konstantin Schulz's avatar Konstantin Schulz
Browse files

added an update mechanism for the corpus list (every 2 weeks by default)

parent ed9b013a
......@@ -8,7 +8,9 @@
"backendProxyPath": "mc-service/mc/api/v1.0",
"callidusProjectUrl": "https://www.projekte.hu-berlin.de/de/callidus",
"developerMailTo": "mailto:sulzkons@hu-berlin.de",
"intervalCorporaUpdate": 1209600000,
"localStorageKeyCorpora": "mc/corpora",
"localStorageKeyUpdateInfo": "mc/updateInfo",
"machinaCallidaBackendUrl": "https://scm.cms.hu-berlin.de/callidus/mc-backend",
"machinaCallidaFrontendUrl": "https://scm.cms.hu-berlin.de/callidus/mc-frontend",
"maxTextLength": 2000,
......
......@@ -50,6 +50,9 @@
"EXERCISE_TYPE_CLOZE": "Lückentext",
"EXERCISE_TYPE_MATCHING": "Zuordnung",
"FEEDBACK": "Feedback",
"FILE_TYPE_DOCX": "DOCX",
"FILE_TYPE_PDF": "PDF",
"FILE_TYPE_XML": "XML",
"HELP": "Hilfe",
"INSTRUCTION_CHOOSE_FORMAT_AND_IMPORT": "Wähle als Dateiformat das 'Moodle-XML-Format'. Lade anschließend die soeben heruntergeladene XML-Datei hoch und klicke auf 'Import'.",
"INSTRUCTION_COGWHEEL_MORE": "Klicke auf das Zahnrad-Symbol oben rechts, dann auf 'Mehr'.",
......@@ -75,7 +78,6 @@
"PART_OF_SPEECH_PUNCTUATION": "Interpunktion",
"PART_OF_SPEECH_SYMBOL": "Symbol",
"PART_OF_SPEECH_VERB": "Verb",
"PDF": "PDF",
"PHENOMENON_DEPENDENCY": "Dependenz",
"PHENOMENON_LEMMA": "Lemma",
"PHENOMENON_PART_OF_SPEECH": "Wortart",
......@@ -87,6 +89,5 @@
"START": "Anfang",
"TEST": "Test",
"TEXT_TOO_LONG": "Text zu lang, max. Wortzahl: ",
"WELCOME": "Willkommen!",
"XML": "XML"
"WELCOME": "Willkommen!"
}
\ No newline at end of file
......@@ -50,6 +50,9 @@
"EXERCISE_TYPE_CLOZE": "Cloze",
"EXERCISE_TYPE_MATCHING": "Matching",
"FEEDBACK": "Feedback",
"FILE_TYPE_DOCX": "DOCX",
"FILE_TYPE_PDF": "PDF",
"FILE_TYPE_XML": "XML",
"HELP": "Help",
"INSTRUCTION_CHOOSE_FORMAT_AND_IMPORT": "Choose 'Moodle XML format' as file format. Now upload the XML file that you just downloaded, then click on 'Import'.",
"INSTRUCTION_COGWHEEL_MORE": "Click on the cogwheel in the upper right corner, then on 'More'.",
......@@ -75,7 +78,6 @@
"PART_OF_SPEECH_PUNCTUATION": "Punctuation",
"PART_OF_SPEECH_SYMBOL": "Symbol",
"PART_OF_SPEECH_VERB": "Verb",
"PDF": "PDF",
"PHENOMENON_DEPENDENCY": "Dependency",
"PHENOMENON_LEMMA": "Lemma",
"PHENOMENON_PART_OF_SPEECH": "Part of speech",
......@@ -87,6 +89,5 @@
"START": "Start",
"TEST": "Test",
"TEXT_TOO_LONG": "Text too long, max. word count: ",
"WELCOME": "Welcome!",
"XML": "XML"
"WELCOME": "Welcome!"
}
\ No newline at end of file
......@@ -132,6 +132,7 @@ export enum PartOfSpeechTranslation {
}
export enum FileType {
docx = <any>"docx",
pdf = <any>"pdf",
xml = <any>"xml",
pdf = <any>"pdf"
}
......@@ -6,7 +6,6 @@ import {ExerciseProvider} from "../../providers/exercise/exercise";
import {TranslateService} from "@ngx-translate/core";
import {FeedbackPage} from "../feedback/feedback";
import {CorpusProvider} from "../../providers/corpus/corpus";
import {Phenomenon} from "../../models/enum";
@Component({
selector: 'page-home',
......@@ -28,8 +27,12 @@ export class HomePage {
this.navCtrl.push(AuthorPage).then();
}
test() {
let a = Object.values(Phenomenon);
let b = 0;
async test() {
let a = "";
let b = !!a;
let c = new Date().getTime();
let d = new Date(c);
let f = d.getTime() - c;
let g = 0;
}
}
......@@ -30,8 +30,9 @@
<div *ngFor="let node of exerciseProvider.annisResponse?.graph.nodes">{{node.annis_tok}}&#32;</div>
<br>
<br>
<button ion-button block (click)="downloadExercise(FileType[FileType.pdf])">{{ 'PDF' | translate }}</button>
<button ion-button block (click)="downloadExercise(FileType[FileType.xml])">{{ 'XML' | translate }}</button>
<button ion-button block (click)="downloadExercise(FileType[FileType.pdf])">{{ 'FILE_TYPE_PDF' | translate }}</button>
<button ion-button block (click)="downloadExercise(FileType[FileType.xml])">{{ 'FILE_TYPE_XML' | translate }}</button>
<button ion-button block (click)="downloadExercise(FileType[FileType.docx])">{{ 'FILE_TYPE_DOCX' | translate }}</button>
<br>
<br>
<h4>{{ 'EXERCISE_DOWNLOAD_NEXT_STEPS' | translate }}</h4>
......
......@@ -3,7 +3,6 @@ import {IonicPage, NavController, NavParams, ToastController} from 'ionic-angula
import {CorpusProvider} from "../../providers/corpus/corpus";
import {
ExerciseType, ExerciseTypeTranslation,
PartOfSpeechTranslation,
Phenomenon,
PhenomenonTranslation
} from "../../models/enum";
......
......@@ -35,7 +35,7 @@ export class CorpusProvider {
public http: HttpClient) {
this.xml2jsParser = new Parser();
if (!this.availableCorpora) {
this.getCorpora();
this.checkForUpdates().then();
}
}
......@@ -87,29 +87,48 @@ export class CorpusProvider {
return this.http.get(fullUrl, {responseType: 'text'});
}
async getCorpora() {
while (!HelperProvider.config) {
await new Promise(resolve => setTimeout(resolve, 50));
}
this.availableCorpora = [];
this.availableAuthors = [];
// check local storage for corpora
let storedCorporaJSONstring: string = window.localStorage.getItem(HelperProvider.config["localStorageKeyCorpora"]);
if (!storedCorporaJSONstring) {
getCorpora(fromServer: boolean = false) {
if (fromServer) {
// get corpora from REST API
let url = HelperProvider.config["backendBaseUrl"] + HelperProvider.config["backendApiCorporaPath"];
this.http.get(url).subscribe((data: object) => {
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);
});
}
else {
let storedCorporaJSONstring: string = window.localStorage.getItem(HelperProvider.config["localStorageKeyCorpora"]);
let corpusList: CorpusMC[] = JSON.parse(storedCorporaJSONstring) as CorpusMC[];
this.processCorpora(corpusList);
}
}
async checkForUpdates() {
while (!HelperProvider.config) {
await new Promise(resolve => setTimeout(resolve, 50));
}
this.availableCorpora = [];
this.availableAuthors = [];
// check local storage for necessary updates
let updateInfoJSONstring: string = window.localStorage.getItem(HelperProvider.config["localStorageKeyUpdateInfo"]);
if (!updateInfoJSONstring) {
this.getCorpora(true);
}
else {
let corporaLastAccessTime: number = new Date(updateInfoJSONstring).getTime();
if (new Date().getTime() - corporaLastAccessTime > HelperProvider.config["intervalCorporaUpdate"]) {
this.getCorpora(true);
}
else {
// check local storage for corpora
this.getCorpora(false);
}
}
}
private processCorpora(corpusList: CorpusMC[]) {
corpusList.forEach((corpus: CorpusMC) => {
corpus.citations = {};
......
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