Skip to content

Commit

Permalink
refactor: controller scope hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Oct 3, 2024
1 parent fd8ff01 commit bdb08bd
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 47 deletions.
13 changes: 4 additions & 9 deletions app/scripts/components/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,7 @@ angular.module("korpApp").component("results", {
<korp-error ng-if="error"></korp-error>
</uib-tab>
<uib-tab
example-ctrl="example-ctrl"
ng-repeat="kwicTab in $root.kwicTabs"
select="onentry()"
deselect="onexit()"
>
<uib-tab example-ctrl ng-repeat="kwicTab in $root.kwicTabs" select="onentry()" deselect="onexit()">
<uib-tab-heading ng-class="{not_loading: progress == 100, loading : loading}">
KWIC
<span ng-click="closeTab($index, $event)" tab-spinner="tab-spinner"> </span>
Expand Down Expand Up @@ -182,7 +177,7 @@ angular.module("korpApp").component("results", {
></trend-diagram>
</uib-tab>
<uib-tab ng-repeat="promise in $root.compareTabs" compare-ctrl="compare-ctrl">
<uib-tab ng-repeat="promise in $root.compareTabs" compare-ctrl>
<uib-tab-heading class="compare_tab" ng-class="{loading : loading}">
{{'compare_vb' | loc:$root.lang}}
<span tab-spinner="tab-spinner" ng-click="closeTab($index, $event)"> </span>
Expand Down Expand Up @@ -224,7 +219,7 @@ angular.module("korpApp").component("results", {
</div>
</uib-tab>
<uib-tab ng-repeat="promise in $root.mapTabs" map-ctrl="map-ctrl" select="onentry()">
<uib-tab ng-repeat="promise in $root.mapTabs" map-ctrl select="onentry()">
<uib-tab-heading class="map_tab" ng-class="{loading : loading}">
{{ 'map' | loc:$root.lang}}
<span tab-spinner="tab-spinner" ng-click="closeTab($index, $event)"> </span>
Expand Down Expand Up @@ -273,7 +268,7 @@ angular.module("korpApp").component("results", {
<uib-tab
ng-repeat="inData in $root.textTabs"
text-reader-ctrl="text-reader-ctrl"
text-reader-ctrl
select="onentry()"
deselect="onexit()"
>
Expand Down
7 changes: 3 additions & 4 deletions app/scripts/controllers/comparison_controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/** @format */
import _ from "lodash"
import angular, { IScope } from "angular"
import angular from "angular"
import settings from "@/settings"
import { stringifyFunc } from "@/stringify.js"
import { locAttribute } from "@/i18n"
import { CompareTab, RootScope } from "@/root-scope.types"
import { SavedSearch } from "@/local-storage"
import { CompareItem, CompareTables } from "@/services/backend"
import { TabHashScope } from "@/directives/tab-hash"

type CompareCtrlScope = IScope & {
type CompareCtrlScope = TabHashScope & {
closeTab: (index: number, e: Event) => void
cmp1: SavedSearch
cmp2: SavedSearch
Expand All @@ -21,8 +22,6 @@ type CompareCtrlScope = IScope & {
rowClick: (row: CompareItem, cmp_index: number) => void
stringify: (x: string) => string
tables: CompareTables
newDynamicTab: any // TODO Defined in tabHash (services.js)
closeDynamicTab: any // TODO Defined in tabHash (services.js)
}

angular.module("korpApp").directive("compareCtrl", () => ({
Expand Down
9 changes: 4 additions & 5 deletions app/scripts/controllers/example_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { KorpResponse, ProgressReport } from "@/backend/types"
import { KorpQueryResponse } from "@/backend/kwic-proxy"
import { UtilsService } from "@/services/utils"
import "@/services/utils"
import { TabHashScope } from "@/directives/tab-hash"

const korpApp = angular.module("korpApp")

type ScopeBase = Omit<KwicCtrlScope, "makeRequest"> & IRepeatScope
type ScopeBase = Omit<KwicCtrlScope, "makeRequest"> & IRepeatScope & TabHashScope

type ExampleCtrlScope = ScopeBase & {
$parent: { $parent: any }
$parent: { $parent: TabHashScope }
closeTab: (idx: number, e: Event) => void
hitsPictureData?: any
hitspictureClick?: (page: number) => void
Expand All @@ -24,8 +25,6 @@ type ExampleCtrlScope = ScopeBase & {
onExampleProgress: (progressObj: ProgressReport, isPaging?: boolean) => void
setupReadingWatch: () => void
superRenderResult: (data: KorpResponse<KorpQueryResponse>) => void
newDynamicTab: any // TODO Defined in tabHash (services.js)
closeDynamicTab: any // TODO Defined in tabHash (services.js)
}

class ExampleCtrl extends KwicCtrl {
Expand Down Expand Up @@ -157,7 +156,7 @@ class ExampleCtrl extends KwicCtrl {
}

s.isActive = () => {
return s.tabindex == s.$parent.$parent.tabset.active
return s.tabindex == s.activeTab
}

if (s.kwicTab.queryParams) {
Expand Down
10 changes: 4 additions & 6 deletions app/scripts/controllers/kwic_controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @format */
import angular, { IController, IScope, ITimeoutService } from "angular"
import angular, { IController, ITimeoutService } from "angular"
import _ from "lodash"
import settings from "@/settings"
import kwicProxyFactory, { ApiKwic, KorpQueryParams, KorpQueryResponse, type KwicProxy } from "@/backend/kwic-proxy"
Expand All @@ -8,13 +8,11 @@ import { LocationService } from "@/urlparams"
import { KorpResponse, ProgressReport } from "@/backend/types"
import { UtilsService } from "@/services/utils"
import "@/services/utils"
import { TabHashScope } from "@/directives/tab-hash"

angular.module("korpApp").directive("kwicCtrl", () => ({ controller: KwicCtrl }))

export type KwicCtrlScope = IScope & {
$parent: {
tabset: any
}
export type KwicCtrlScope = TabHashScope & {
active?: boolean
aborted?: boolean
buildQueryOptions: (isPaging: boolean) => KorpQueryParams
Expand Down Expand Up @@ -295,7 +293,7 @@ export class KwicCtrl implements IController {
}

s.isActive = () => {
return s.tabindex == s.$parent.tabset.active
return s.tabindex == s.activeTab
}

s.countCorpora = () => {
Expand Down
7 changes: 3 additions & 4 deletions app/scripts/controllers/map_controller.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/** @format */
import _ from "lodash"
import angular, { IScope, ITimeoutService } from "angular"
import angular, { ITimeoutService } from "angular"
import settings from "@/settings"
import { regescape } from "@/util"
import { MapTab, RootScope } from "@/root-scope.types"
import { AppSettings } from "@/settings/app-settings.types"
import { MapRequestResult } from "@/services/backend"
import { MapResult, Point } from "@/map_services"
import { WithinParameters } from "@/backend/types"
import { TabHashScope } from "@/directives/tab-hash"

type MapControllerScope = IScope & {
type MapControllerScope = TabHashScope & {
center: AppSettings["map_center"]
error: boolean
selectedGroups: string[]
Expand All @@ -19,8 +20,6 @@ type MapControllerScope = IScope & {
useClustering: boolean
promise: MapTab
restColor: string
newDynamicTab: any // TODO Defined in tabHash (services.js)
closeDynamicTab: any // TODO Defined in tabHash (services.js)
closeTab: (idx: number, e: Event) => void
newKWICSearch: (marker: MarkerEvent) => void
toggleMarkerGroup: (groupName: string) => void
Expand Down
8 changes: 4 additions & 4 deletions app/scripts/controllers/statistics_controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @format */
import _ from "lodash"
import angular, { IScope, ITimeoutService } from "angular"
import angular, { ITimeoutService } from "angular"
import settings from "@/settings"
import currentMode from "@/mode"
import statsProxyFactory, { StatsProxy } from "@/backend/stats-proxy"
Expand All @@ -12,9 +12,9 @@ import { SearchParams } from "@/statistics.types"
import { SlickgridColumn } from "@/statistics"
import { SearchesService } from "@/services/searches"
import "@/services/searches"
import { TabHashScope } from "@/directives/tab-hash"

type StatsResultCtrlScope = IScope & {
$parent: any
type StatsResultCtrlScope = TabHashScope & {
$root: RootScope
aborted: boolean
activate: () => void
Expand Down Expand Up @@ -89,7 +89,7 @@ angular.module("korpApp").directive("statsResultCtrl", () => ({
}

s.isActive = () => {
return s.tabindex == s.$parent.$parent.tabset.active
return s.tabindex == s.activeTab
}

s.resetView = () => {
Expand Down
7 changes: 3 additions & 4 deletions app/scripts/controllers/text_reader_controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @format */
import _ from "lodash"
import angular, { ICompileService, IScope } from "angular"
import angular, { ICompileService } from "angular"
import statemachine from "../statemachine"
import settings from "@/settings"
import "@/services/backend"
Expand All @@ -10,14 +10,13 @@ import { CorpusTransformed } from "@/settings/config-transformed.types"
import { BackendService } from "@/services/backend"
import { kebabize } from "@/util"
import { ApiKwic, Token } from "@/backend/kwic-proxy"
import { TabHashScope } from "@/directives/tab-hash"

type TextReaderControllerScope = IScope & {
type TextReaderControllerScope = TabHashScope & {
loading: boolean
inData: TextTab
data: { corpus: string; document: TextReaderData; sentenceData: TextTab["sentenceData"] }
corpusObj: CorpusTransformed
newDynamicTab: () => void
closeDynamicTab: () => void
closeTab: (idx: number, e: Event) => void
onentry: () => void
onexit: () => void
Expand Down
7 changes: 3 additions & 4 deletions app/scripts/controllers/trend_diagram_controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/** @format */
import angular from "angular"
import { TabHashScope } from "@/directives/tab-hash"
import { GraphTab, RootScope } from "@/root-scope.types"
import angular, { IScope } from "angular"

type GraphCtrlScope = IScope & {
type GraphCtrlScope = TabHashScope & {
closeTab: (idx: number, e: Event) => void
data: GraphTab
loading: boolean
onProgress: (progress: number) => void
progress: number
updateLoading: (loading: boolean) => void
newDynamicTab: any // TODO Defined in tabHash (services.js)
closeDynamicTab: any // TODO Defined in tabHash (services.js)
}

angular.module("korpApp").directive("graphCtrl", () => ({
Expand Down
10 changes: 4 additions & 6 deletions app/scripts/controllers/word_picture_controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @format */
import _ from "lodash"
import angular, { IScope, ITimeoutService } from "angular"
import angular, { ITimeoutService } from "angular"
import settings from "@/settings"
import lemgramProxyFactory, { ApiRelation, KorpRelationsResponse, LemgramProxy } from "@/backend/lemgram-proxy"
import { isLemgram, lemgramToString, unregescape } from "@/util"
Expand All @@ -10,9 +10,9 @@ import { KorpResponse, ProgressReport } from "@/backend/types"
import { WordPictureDefItem } from "@/settings/app-settings.types"
import { SearchesService } from "@/services/searches"
import "@/services/searches"
import { TabHashScope } from "@/directives/tab-hash"

type WordpicCtrlScope = IScope & {
$parent: any
type WordpicCtrlScope = TabHashScope & {
$root: RootScope
aborted: boolean
activate: () => void
Expand Down Expand Up @@ -41,8 +41,6 @@ type WordpicCtrlScope = IScope & {
}
tabindex: number
wordPic: boolean
newDynamicTab: any // TODO Defined in tabHash (services.js)
closeDynamicTab: any // TODO Defined in tabHash (services.js)
}

/** A relation item modified for showing. */
Expand Down Expand Up @@ -171,7 +169,7 @@ angular.module("korpApp").directive("wordpicCtrl", () => ({
}

s.isActive = () => {
return s.tabindex == s.$parent.$parent.tabset.active
return s.tabindex == s.activeTab
}

s.renderResult = (data, query) => {
Expand Down
8 changes: 7 additions & 1 deletion app/scripts/directives/tab-hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { UtilsService } from "@/services/utils"
import { LocationService } from "@/urlparams"
import "@/services/utils"

type TabHashScope = IScope & {
type UiBootstrapTabsetScope = IScope & {
tabset: {
tabs: any[]
}
}

export type TabHashScope = UiBootstrapTabsetScope & {
activeTab: number
fixedTabs: Record<number, any>
maxTab: number
Expand Down

0 comments on commit bdb08bd

Please sign in to comment.