Skip to content

Commit

Permalink
refactor(ts): video controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Dec 10, 2024
1 parent 089b522 commit 9176aa7
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 45 deletions.
1 change: 0 additions & 1 deletion app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,5 @@ require("./lib/jquery.tooltip.pack.js")
require("./scripts/main")
require("./scripts/app")

require("./scripts/video_controllers.js")
require("./scripts/backend/struct-service")
require("./scripts/matomo")
1 change: 1 addition & 0 deletions app/scripts/components/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { html, regescape, splitLemgram, safeApply, getConfigurable } from "@/uti
import { loc, locAttribute, locObj } from "@/i18n"
import "@/services/utils"
import "@/components/deptree/deptree"
import "@/video-controller" // May be used by custom code
import { RootScope } from "@/root-scope.types"
import { CqpSearchEvent, SelectWordEvent } from "@/statemachine/types"
import { Token } from "@/backend/kwic-proxy"
Expand Down
50 changes: 50 additions & 0 deletions app/scripts/video-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/** @format */
import angular, { IScope, ui } from "angular"
import "@/video-instance-controller"

type VideoControllerScope = IScope & {
videos: { url: string; type: string }[]
open: () => void
startTime: number
endTime: number
fileName: string
sentence: string
}

angular.module("korpApp").controller("VideoCtrl", [
"$scope",
"$uibModal",
function ($scope: VideoControllerScope, $uibModal: ui.bootstrap.IModalService) {
$scope.videos = []

$scope.open = function () {
let modalInstance
modalInstance = $uibModal.open({
animation: false,
template: require("../markup/sidebar_video.html"),
controller: "VideoInstanceCtrl",
size: "modal-lg",
windowClass: "video-modal-bootstrap",
resolve: {
items() {
return $scope.videos
},
startTime() {
return $scope.startTime
},
endTime() {
return $scope.endTime
},
fileName() {
return $scope.fileName
},
sentence() {
return $scope.sentence
},
},
})
}

$scope.startTime = 0
},
])
Original file line number Diff line number Diff line change
@@ -1,47 +1,21 @@
/** @format */
import angular, { ICompileService, IScope, ITimeoutService, ui } from "angular"
import moment from "moment"

const korpApp = angular.module("korpApp")

korpApp.controller("VideoCtrl", [
"$scope",
"$uibModal",
function ($scope, $uibModal) {
$scope.videos = []

$scope.open = function () {
let modalInstance
modalInstance = $uibModal.open({
animation: false,
template: require("../markup/sidebar_video.html"),
controller: "VideoInstanceCtrl",
size: "modal-lg",
windowClass: "video-modal-bootstrap",
resolve: {
items() {
return $scope.videos
},
startTime() {
return $scope.startTime
},
endTime() {
return $scope.endTime
},
fileName() {
return $scope.fileName
},
sentence() {
return $scope.sentence
},
},
})
}

$scope.startTime = 0
},
])

korpApp.controller("VideoInstanceCtrl", [
type VideoInstanceControllerScope = IScope & {
fileName: string
sentence: string
startTime: string
endTime: string
init: () => void
goToStartTime: () => void
continuePlay: () => void
isPaused: boolean
pauseAfterEndTime: boolean
ok: () => void
}

angular.module("korpApp").controller("VideoInstanceCtrl", [
"$scope",
"$compile",
"$timeout",
Expand All @@ -51,11 +25,22 @@ korpApp.controller("VideoInstanceCtrl", [
"endTime",
"fileName",
"sentence",
function ($scope, $compile, $timeout, $uibModalInstance, items, startTime, endTime, fileName, sentence) {
function (
$scope: VideoInstanceControllerScope,
$compile: ICompileService,
$timeout: ITimeoutService,
$uibModalInstance: ui.bootstrap.IModalInstanceService,
items: { url: string; type: string }[],
startTime: number,
endTime: number,
fileName: string,
sentence: string
) {
$scope.fileName = fileName
$scope.sentence = sentence

const transformSeconds = function (seconds) {
/** Format time as hh:mm:ss if hours > 0, else mm:ss */
const transformSeconds = function (seconds: number) {
let sHours
const d = moment.duration(seconds, "seconds")
const hours = Math.floor(d.asHours())
Expand Down Expand Up @@ -98,7 +83,7 @@ korpApp.controller("VideoInstanceCtrl", [
videoElem.append(srcElem)
}

const video = videoElem[0]
const video = videoElem[0] as HTMLVideoElement

video.addEventListener("durationchange", function () {
video.currentTime = startTime
Expand Down

0 comments on commit 9176aa7

Please sign in to comment.