diff --git a/app/scripts/components/header.js b/app/scripts/components/header.ts similarity index 89% rename from app/scripts/components/header.js rename to app/scripts/components/header.ts index 5b17bb740..543ce9064 100644 --- a/app/scripts/components/header.js +++ b/app/scripts/components/header.ts @@ -1,5 +1,5 @@ /** @format */ -import angular from "angular" +import angular, { IController, IScope, ITimeoutService, ui } from "angular" import _ from "lodash" import korpLogo from "../../img/korp_slogan.svg" import korpLogoEn from "../../img/korp_slogan_en.svg" @@ -13,6 +13,26 @@ import "@/services/utils" import "@/components/corpus-chooser/corpus-chooser" import "@/components/radio-list" import { matomoSend } from "@/matomo" +import { LocationService } from "@/urlparams" +import { RootScope } from "@/root-scope.types" +import { UtilsService } from "@/services/utils" +import { Labeled } from "@/i18n/types" +import { Config } from "@/settings/config.types" + +type HeaderController = IController & { + citeClick: () => void + getUrl: (modeId: string) => string + getUrlParts: (modeId: string) => string[] + languages: Labeled[] + logoClick: () => void + menu: Config["modes"] + modes: Config["modes"] + visible: Config["modes"] +} + +type HeaderScope = IScope & { + lang: string +} angular.module("korpApp").component("header", { template: html` @@ -132,14 +152,21 @@ angular.module("korpApp").component("header", { "$scope", "$timeout", "utils", - function ($location, $uibModal, $rootScope, $scope, $timeout, utils) { - const $ctrl = this + function ( + $location: LocationService, + $uibModal: ui.bootstrap.IModalService, + $rootScope: RootScope, + $scope: HeaderScope, + $timeout: ITimeoutService, + utils: UtilsService + ) { + const $ctrl = this as HeaderController $scope.lang = $rootScope.lang $ctrl.logoClick = function () { const [baseUrl, modeParam, langParam] = $ctrl.getUrlParts(currentMode) - window.location = baseUrl + modeParam + langParam + window.location.href = baseUrl + modeParam + langParam if (langParam.length > 0) { window.location.reload() } @@ -164,7 +191,7 @@ angular.module("korpApp").component("header", { $rootScope.show_modal = false - let modal = null + let modal: ui.bootstrap.IModalInstanceService | null = null utils.setupHash($rootScope, { key: "display", @@ -182,7 +209,11 @@ angular.module("korpApp").component("header", { $rootScope.show_modal = false } - const modalScope = $rootScope.$new(true) + type ModalScope = IScope & { + clickX: () => void + } + + const modalScope = $rootScope.$new(true) as ModalScope modalScope.clickX = () => closeModals() function showAbout() { @@ -200,8 +231,8 @@ angular.module("korpApp").component("header", { const N_VISIBLE = settings["visible_modes"] $ctrl.modes = _.filter(settings["modes"]) - if (process.env.ENVIRONMENT != "staging") { - $ctrl.modes = _.filter(settings["modes"], (item) => item.labOnly !== true) + if (process.env.ENVIRONMENT == "production") { + $ctrl.modes = _.filter(settings["modes"], (item) => !item.labOnly) } $ctrl.visible = $ctrl.modes.slice(0, N_VISIBLE) diff --git a/app/scripts/root-scope.types.ts b/app/scripts/root-scope.types.ts index b97fb1122..620887827 100644 --- a/app/scripts/root-scope.types.ts +++ b/app/scripts/root-scope.types.ts @@ -15,6 +15,7 @@ export type RootScope = IRootScopeService & { globalFilterDef: IDeferred searchtabs: any simpleCQP?: string + show_modal: "about" | false compareTabs: CompareTab[] graphTabs: GraphTab[] kwicTabs: KwicTab[] diff --git a/app/scripts/settings/config.types.ts b/app/scripts/settings/config.types.ts index 1cacd9a81..ab05bf564 100644 --- a/app/scripts/settings/config.types.ts +++ b/app/scripts/settings/config.types.ts @@ -19,6 +19,7 @@ export type Config = { modes: { mode: string label: LangString + labOnly?: boolean }[] order?: number parallel?: boolean diff --git a/app/scripts/urlparams.ts b/app/scripts/urlparams.ts index 96192b7b6..c26b1edf3 100644 --- a/app/scripts/urlparams.ts +++ b/app/scripts/urlparams.ts @@ -21,6 +21,8 @@ export type HashParams = { corpus?: string /** CQP query for Extended search, possibly with frontend-specific operators */ cqp?: string + /** Modal to show */ + display?: "about" /** Conditions entered for search filters, as Base64-encoded JSON */ global_filter?: string /** Opposite of `show_stats`, used if the `statistics_search_default` setting is enabled */