Skip to content

Commit

Permalink
refactor: remove $rootScope._settings
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Jan 20, 2025
1 parent 728c888 commit d0948e9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

### Changed

- Removed `$rootScope.searchtabs()`
- Removed `$rootScope.searchtabs()`, use `$location.search()` to get/set `search_tab` instead
- Removed `$rootScope._settings`, use `import settings from "@/settings"` instead

### Fixed

Expand Down
1 change: 0 additions & 1 deletion app/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ korpApp.run([
$uibModal: ui.bootstrap.IModalService
) {
const s = $rootScope
s._settings = settings

s.extendedCQP = null

Expand Down
32 changes: 20 additions & 12 deletions app/scripts/components/results.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @format */
import angular, { IController } from "angular"
import angular, { IScope } from "angular"
import { html } from "@/util"
import settings from "@/settings"
import "@/components/json_button"
import "@/components/korp-error"
import "@/components/kwic"
Expand All @@ -22,7 +23,10 @@ import "@/controllers/word_picture_controller"
import "@/directives/tab-hash"
import { RootScope } from "@/root-scope.types"

type ResultsController = IController & {
type ResultsScope = IScope & {
showSidebar: boolean
showStatisticsTab: boolean
showWordpicTab: boolean
onSidebarShow: () => void
onSidebarHide: () => void
hasResult: () => boolean
Expand All @@ -33,7 +37,7 @@ type ResultsController = IController & {
// But we're converting directives to components in preparation for exiting AngularJS.
angular.module("korpApp").component("results", {
template: html`
<div ng-show="$ctrl.hasResult()" class="flex" id="results" ng-class="{sidebar_visible : $ctrl.sidebarVisible}">
<div ng-show="hasResult()" class="flex" id="results" ng-class="{sidebar_visible: showSidebar}">
<div class="overflow-auto grow" id="left-column">
<uib-tabset class="tabbable result_tabs" tab-hash="result_tab" active="activeTab">
<uib-tab kwic-ctrl index="0" select="onentry()" deselect="onexit()">
Expand Down Expand Up @@ -68,7 +72,7 @@ angular.module("korpApp").component("results", {
</div>
</uib-tab>
<uib-tab stats-result-ctrl ng-if="$root._settings.statistics != false" select="onentry()" index="2">
<uib-tab stats-result-ctrl ng-if="showStatisticsTab" select="onentry()" index="2">
<uib-tab-heading class="flex gap-2 items-center" ng-class="{loading: loading}">
{{'statistics' | loc:$root.lang}}
<tab-preloader
Expand Down Expand Up @@ -98,7 +102,7 @@ angular.module("korpApp").component("results", {
></json-button>
</uib-tab>
<uib-tab ng-if="$root._settings['word_picture'] != false" wordpic-ctrl index="3">
<uib-tab ng-if="showWordpicTab" wordpic-ctrl index="3">
<uib-tab-heading class="flex gap-2 items-center" ng-class="{loading: loading}">
{{'word_picture' | loc:$root.lang}}
<tab-preloader
Expand Down Expand Up @@ -284,20 +288,24 @@ angular.module("korpApp").component("results", {
<sidebar
class="sidebar shrink-0 ml-2"
on-show="$ctrl.onSidebarShow()"
on-hide="$ctrl.onSidebarHide()"
on-show="onSidebarShow()"
on-hide="onSidebarHide()"
lang="$root.lang"
></sidebar>
</div>
`,
bindings: {},
controller: [
"$scope",
"$rootScope",
function ($rootScope: RootScope) {
const $ctrl = this as ResultsController
$ctrl.onSidebarShow = () => ($ctrl.sidebarVisible = true)
$ctrl.onSidebarHide = () => ($ctrl.sidebarVisible = false)
$ctrl.hasResult = () => !!$rootScope.activeSearch
function ($scope: ResultsScope, $rootScope: RootScope) {
$scope.showSidebar = false
$scope.showStatisticsTab = settings["statistics"] != false
$scope.showWordpicTab = settings["word_picture"] != false

$scope.onSidebarShow = () => ($scope.showSidebar = true)
$scope.onSidebarHide = () => ($scope.showSidebar = false)
$scope.hasResult = () => !!$rootScope.activeSearch
},
],
})
1 change: 0 additions & 1 deletion app/scripts/root-scope.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { CompareResult, MapRequestResult } from "@/backend/backend"

/** Extends the Angular Root Scope interface with properties used by this app. */
export type RootScope = IRootScopeService & {
_settings: Settings
activeSearch: {
/** "word", "lemgram" or "cqp" */
type: string
Expand Down

0 comments on commit d0948e9

Please sign in to comment.