Skip to content

Commit

Permalink
refactor(ts): corpus chooser util
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Sep 30, 2024
1 parent 8be8844 commit b4eeeb3
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 236 deletions.
22 changes: 16 additions & 6 deletions app/scripts/components/corpus_chooser/corpus-chooser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import settings from "@/settings"
import * as authenticationProxy from "@/components/auth/auth"
import { html } from "@/util"
import { loc } from "@/i18n"
import * as treeUtil from "./util"
import {
filterCorporaOnCredentials,
getAllSelected,
initCorpusStructure,
recalcFolderStatus,
updateLimitedAccess,
} from "./util"
import "@/components/corpus_chooser/corpus-time-graph"
import "@/components/corpus_chooser/info-box"
import "@/components/corpus_chooser/tree"
Expand Down Expand Up @@ -149,7 +155,7 @@ angular.module("korpApp").component("corpusChooser", {
return prev
}, {})

$ctrl.root = treeUtil.initCorpusStructure(ccCorpora, corpusIds)
$ctrl.root = initCorpusStructure(ccCorpora, corpusIds)

$ctrl.totalCount = Object.values(ccCorpora).length
$ctrl.totalNumberOfTokens = $ctrl.root.tokens
Expand Down Expand Up @@ -190,7 +196,7 @@ angular.module("korpApp").component("corpusChooser", {
}

$ctrl.onSelect = function () {
const currentCorpora = treeUtil.getAllSelected($ctrl.root)
const currentCorpora = getAllSelected($ctrl.root)
select(currentCorpora)
}

Expand All @@ -208,13 +214,17 @@ angular.module("korpApp").component("corpusChooser", {

$ctrl.updateLimitedAccess = function () {
if ($ctrl.root) {
treeUtil.updateLimitedAccess($ctrl.root, $ctrl.credentials)
updateLimitedAccess($ctrl.root, $ctrl.credentials)
}
}

function select(corporaIds, quiet = false) {
const selection = treeUtil.filterCorporaOnCredentials(settings.corpora, corporaIds, $ctrl.credentials)
treeUtil.recalcFolderStatus($ctrl.root)
const selection = filterCorporaOnCredentials(
Object.values(settings.corpora),
corporaIds,
$ctrl.credentials
)
recalcFolderStatus($ctrl.root)
$ctrl.updateSelectedCount(selection)
// used when there is only one corpus selected to show name
if (selection.length == 1) {
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/components/corpus_chooser/tree.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @format */
import angular from "angular"
import * as treeUtil from "./util"
import { getAllCorpora } from "./util"
import settings from "@/settings"
var collapsedImg = require("../../../img/collapsed.png")
import { collatorSort, html } from "@/util"
Expand Down Expand Up @@ -97,7 +97,7 @@ angular.module("korpApp").component("ccTree", {
return
}

const corporaIds = treeUtil.getAllCorpora(folder)
const corporaIds = getAllCorpora(folder)
if (selectOnly(e)) {
$ctrl.selectOnly(corporaIds)
} else {
Expand Down
226 changes: 0 additions & 226 deletions app/scripts/components/corpus_chooser/util.js

This file was deleted.

Loading

0 comments on commit b4eeeb3

Please sign in to comment.