Commit 7757b27f authored by Konstantin Schulz's avatar Konstantin Schulz
Browse files

configuration moved to a JSON file

parent 3556e3a9
# Welcome to the frontend part of the project CALLIDUS!
## Installation:
## Installation
1. Install Node.js (https://nodejs.org/), including NPM.
2. Clone the git repository: `git clone https://scm.cms.hu-berlin.de/callidus/mc-frontend.git`
3. Go to the new directory: `cd mc-frontend`
......@@ -7,4 +7,8 @@
5. Run `sudo npm i -g ionic`
6. 1. Run `ionic serve` and enjoy!
2. To run it in the background, use: `ionic serve --no-livereload --no-interactive &`
## Configuration
### Backend URL
To change the URL for the backend, use the `ionic.config.json` file (proxies > proxyUrl). By default, the system assumes that backend and frontend are installed on the same machine.
### Other
For all other kinds of configuration, use `src/assets/config.json`.
{
"name": "mcClient",
"integrations": {
"cordova": {}
},
"name": "mcClient",
"proxies": [
{
"path": "/mc-service",
"proxyUrl": "http://localhost:5000/mc/api/v1.0"
}
],
"type": "ionic-angular"
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import {StatusBar} from '@ionic-native/status-bar';
import {HomePage} from '../pages/home/home';
import {TranslateService} from "@ngx-translate/core";
import {HelperProvider} from "../providers/helper/helper";
@Component({
templateUrl: 'app.html'
......@@ -11,13 +12,15 @@ import {TranslateService} from "@ngx-translate/core";
export class MCclient {
rootPage: any = HomePage;
constructor(platform: Platform, statusBar: StatusBar, private translate: TranslateService, private config: Config) {
constructor(platform: Platform, statusBar: StatusBar, private translate: TranslateService, private config: Config,
public helperProvider: HelperProvider) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
});
this.initTranslate();
this.helperProvider.initConfig();
}
initTranslate() {
......
......@@ -60,11 +60,11 @@ class CustomErrorHandler extends IonicErrorHandler {
MCclient
],
providers: [
HelperProvider,
StatusBar,
{provide: ErrorHandler, useClass: CustomErrorHandler},
CorpusProvider,
ExerciseProvider,
HelperProvider
]
})
export class AppModule {
......
{
"backendApiCorporaPath": "corpora",
"backendApiExercisePath": "exercise",
"backendApiFilePath": "file",
"backendApiRawtextPath": "rawtext",
"backendApiValidReffPath": "validReff",
"backendBaseUrl": "",
"backendProxyURl": "mc-service",
"callidusProjectUrl": "https://www.projekte.hu-berlin.de/de/callidus",
"developerMailTo": "mailto:sulzkons@hu-berlin.de",
"localStorageKeyCorpora": "mc/corpora",
"machinaCallidaBackendUrl": "https://scm.cms.hu-berlin.de/callidus/mc-backend",
"machinaCallidaFrontendUrl": "https://scm.cms.hu-berlin.de/callidus/mc-frontend",
"maxTextLength": 2000,
"perseidsCTSapiBaseUrl": "https://cts.perseids.org/api/cts?request=",
"perseidsCTSapiGetCapabilities": "GetCapabilities",
"perseidsCTSapiGetValidReff": "GetValidReff",
"perseidsCTSapiUrnSnippet": "&urn=",
"vivaURN": "urn:custom:latinLit:viva.lat"
}
export class ConfigMC {
public static backendApiCorporaPath: string = "corpora";
public static backendApiExercisePath: string = "exercise";
public static backendApiFilePath: string = "file";
public static backendApiPath: string = "/mc/api/v1.0/";
public static backendApiRawtextPath: string = "rawtext";
public static backendApiValidReffPath: string = "validReff";
public static backendBaseUrl: string = location.protocol.concat("//").concat(window.location.hostname).concat("/mc-service/"); // :5000 /mc-service/
public static callidusProjectUrl: string = "https://www.projekte.hu-berlin.de/de/callidus";
public static developerMailTo: string = "mailto:sulzkons@hu-berlin.de";
public static localStorageKeyCorpora: string = "mc/corpora";
public static machinaCallidaBackendUrl: string = "https://scm.cms.hu-berlin.de/callidus/mc-backend";
public static machinaCallidaFrontendUrl: string = "https://scm.cms.hu-berlin.de/callidus/mc-frontend";
public static maxTextLength: number = 2000;
public static perseidsCTSapiBaseUrl: string = "https://cts.perseids.org/api/cts?request=";
public static perseidsCTSapiGetCapabilities: string = "GetCapabilities";
public static perseidsCTSapiGetValidReff: string = "GetValidReff";
public static perseidsCTSapiUrnSnippet: string = "&urn=";
public static vivaURN: string = "urn:custom:latinLit:viva.lat";
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Ionic App</title>
<title>Machina Callida</title>
<meta name="viewport"
content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
......
import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {ConfigMC} from "../../config";
import {HelperProvider} from "../../providers/helper/helper";
/**
* Generated class for the FeedbackPage page.
......@@ -15,15 +15,15 @@ import {ConfigMC} from "../../config";
templateUrl: 'feedback.html',
})
export class FeedbackPage {
machinaCallidaFrontendUrl = ConfigMC.machinaCallidaFrontendUrl;
machinaCallidaBackendUrl = ConfigMC.machinaCallidaBackendUrl;
callidusProjectUrl = ConfigMC.callidusProjectUrl;
developerMailTo = ConfigMC.developerMailTo;
public machinaCallidaFrontendUrl: string = HelperProvider.config["machinaCallidaFrontendUrl"];
public machinaCallidaBackendUrl: string = HelperProvider.config["machinaCallidaBackendUrl"];
public callidusProjectUrl: string = HelperProvider.config["callidusProjectUrl"];
public developerMailTo: string = HelperProvider.config["developerMailTo"];
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
openUrl(url: string){
openUrl(url: string) {
window.open(url, '_system', 'location=yes');
}
......
......@@ -3,17 +3,9 @@ import {NavController, NavParams} from 'ionic-angular';
import {AuthorPage} from "../author/author";
import {HttpClient} from "@angular/common/http";
import {ExerciseProvider} from "../../providers/exercise/exercise";
import {CorpusProvider} from "../../providers/corpus/corpus";
import {TranslateService} from "@ngx-translate/core";
import {
ExerciseType,
ExerciseTypeTranslation, MoodleExerciseType,
PartOfSpeech,
PartOfSpeechTranslations,
Phenomenon
} from "../../models/enum";
import {HelperProvider} from "../../providers/helper/helper";
import {FeedbackPage} from "../feedback/feedback";
import {CorpusProvider} from "../../providers/corpus/corpus";
@Component({
selector: 'page-home',
......@@ -27,9 +19,8 @@ export class HomePage {
constructor(public navCtrl: NavController, public navParams: NavParams,
public http: HttpClient,
public exerciseProvider: ExerciseProvider,
public corpusProvider: CorpusProvider,
public translate: TranslateService,
public helperProvider: HelperProvider) {
public corpusProvider: CorpusProvider) {
}
goToAuthorPage() {
......@@ -37,12 +28,6 @@ export class HomePage {
}
test() {
let c = ExerciseTypeTranslation[ExerciseTypeTranslation[ExerciseType.cloze]];
let e = ExerciseTypeTranslation[ExerciseType.cloze];
let a = ExerciseTypeTranslation.cloze;
let b = ExerciseTypeTranslation.cloze.valueOf();
let f = ExerciseTypeTranslation.cloze.toString();
let g = ExerciseTypeTranslation[ExerciseType.cloze].toString();
let d = 0;
let d = 1;
}
}
......@@ -6,8 +6,8 @@ import {ExerciseProvider} from "../../providers/exercise/exercise";
import {TranslateService} from "@ngx-translate/core";
import {CorpusProvider} from "../../providers/corpus/corpus";
import {ExerciseTypeTranslation, FileType, MoodleExerciseType} from "../../models/enum";
import {ConfigMC} from "../../config";
import {FeedbackPage} from "../feedback/feedback";
import {HelperProvider} from "../../providers/helper/helper";
/**
* Generated class for the PreviewPage page.
......@@ -55,7 +55,7 @@ export class PreviewPage {
formData.append("partially_correct_feedback", this.exerciseProvider.exercise.feedback.partiallyCorrect);
formData.append("incorrect_feedback", this.exerciseProvider.exercise.feedback.incorrect);
formData.append("general_feedback", this.exerciseProvider.exercise.feedback.general);
let url = ConfigMC.backendBaseUrl + ConfigMC.backendApiPath + ConfigMC.backendApiExercisePath;
let url = HelperProvider.config["backendBaseUrl"] + HelperProvider.config["backendApiExercisePath"];
this.http.post(url, formData).subscribe((ar: AnnisResponse) => {
let maxGapLength = Math.max.apply(Math, Object.keys(ar.solution).map(key => ar.solution[key].length));
ar.graph.nodes.forEach((node) => {
......@@ -74,7 +74,7 @@ export class PreviewPage {
let uriParts: string[] = this.exerciseProvider.annisResponse.uri.split("/");
let fileId: string = uriParts[uriParts.length - 1];
let fileTypeString: string = "?type=" + type;
let url = ConfigMC.backendBaseUrl + ConfigMC.backendApiPath + ConfigMC.backendApiFilePath;
let url = HelperProvider.config["backendBaseUrl"] + HelperProvider.config["backendApiFilePath"];
window.open(url + "/" + fileId + fileTypeString, "_blank");
}
}
......@@ -12,7 +12,6 @@ import {
import {ExerciseProvider} from "../../providers/exercise/exercise";
import {PreviewPage} from "../preview/preview";
import {TranslateService} from "@ngx-translate/core";
import {ConfigMC} from "../../config";
import {FeedbackPage} from "../feedback/feedback";
import {HelperProvider} from "../../providers/helper/helper";
......@@ -53,12 +52,12 @@ export class ShowTextPage {
this.corpusProvider.currentText = data["text"];
});
this.translateService.get("TEXT_TOO_LONG").subscribe((value) => {
this.textTooLongString = value + ConfigMC.maxTextLength;
this.textTooLongString = value + HelperProvider.config["maxTextLength"];
});
}
generateExercise() {
if (this.corpusProvider.currentText.length > ConfigMC.maxTextLength) {
if (this.corpusProvider.currentText.length > HelperProvider.config["maxTextLength"]) {
let toast = this.toastCtrl.create({
message: this.textTooLongString,
duration: 3000,
......
......@@ -8,9 +8,9 @@ import {GetValidReff} from "../../models/getValidReff";
import {RequestMC} from "../../models/requestMC";
import {Reply} from "../../models/reply";
import {Reff} from "../../models/reff";
import {ConfigMC} from "../../config";
import {TextRange} from "../../models/textRange";
import {Citation} from "../../models/citation";
import {HelperProvider} from "../helper/helper";
/*
Generated class for the CorpusProvider provider.
......@@ -73,30 +73,34 @@ export class CorpusProvider {
}
getCTStextPassage(urn: string) {
let url = ConfigMC.backendBaseUrl + ConfigMC.backendApiPath + ConfigMC.backendApiRawtextPath;
let url = HelperProvider.config["backendBaseUrl"] + HelperProvider.config["backendApiRawtextPath"];
return this.http.get(url, {params: {"urn": urn}});
}
getCTSvalidReff(urn: string) {
if (urn.includes(ConfigMC.vivaURN)){
let fullUrl: string = ConfigMC.backendBaseUrl + ConfigMC.backendApiPath + ConfigMC.backendApiValidReffPath;
let config: object = HelperProvider.config;
if (urn.includes(config["vivaURN"])) {
let fullUrl: string = config["backendBaseUrl"] + config["backendApiValidReffPath"];
return this.http.get(fullUrl, {params: {"urn": urn}});
}
let fullUrl: string = ConfigMC.perseidsCTSapiBaseUrl + ConfigMC.perseidsCTSapiGetValidReff + ConfigMC.perseidsCTSapiUrnSnippet + urn;
let fullUrl: string = config["perseidsCTSapiBaseUrl"] + config["perseidsCTSapiGetValidReff"] + config["perseidsCTSapiUrnSnippet"] + urn;
return this.http.get(fullUrl, {responseType: 'text'});
}
getCorpora() {
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(ConfigMC.localStorageKeyCorpora);
let storedCorporaJSONstring: string = window.localStorage.getItem(HelperProvider.config["localStorageKeyCorpora"]);
if (!storedCorporaJSONstring) {
// get corpora from REST API
let url = ConfigMC.backendBaseUrl + ConfigMC.backendApiPath + ConfigMC.backendApiCorporaPath;
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(ConfigMC.localStorageKeyCorpora, JSON.stringify(corpusList));
window.localStorage.setItem(HelperProvider.config["localStorageKeyCorpora"], JSON.stringify(corpusList));
this.processCorpora(corpusList);
});
}
......
......@@ -10,6 +10,18 @@ import {Injectable} from '@angular/core';
@Injectable()
export class HelperProvider {
public static config: object;
constructor(public http: HttpClient) {
}
initConfig() {
this.http.get("assets/config.json").subscribe((config: object) => {
HelperProvider.config = config;
if (!HelperProvider.config["backendBaseUrl"]) {
HelperProvider.config["backendBaseUrl"] = location.protocol.concat("//").concat(window.location.hostname).concat(location.port ? `:${location.port}` : "").concat("/").concat(HelperProvider.config["backendProxyURl"]).concat("/");
}
});
}
}
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