Skip to content

Commit

Permalink
refactor(ts): header
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Nov 7, 2024
1 parent d809a1f commit 3dd8cc9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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`
Expand Down Expand Up @@ -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()
}
Expand All @@ -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",
Expand All @@ -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() {
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions app/scripts/root-scope.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type RootScope = IRootScopeService & {
globalFilterDef: IDeferred<never>
searchtabs: any
simpleCQP?: string
show_modal: "about" | false
compareTabs: CompareTab[]
graphTabs: GraphTab[]
kwicTabs: KwicTab[]
Expand Down
1 change: 1 addition & 0 deletions app/scripts/settings/config.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type Config = {
modes: {
mode: string
label: LangString
labOnly?: boolean
}[]
order?: number
parallel?: boolean
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/urlparams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 3dd8cc9

Please sign in to comment.