This repository has been archived by the owner on Jan 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 258
/
Copy pathvideo.controller.js
135 lines (121 loc) · 4.75 KB
/
video.controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//------------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//------------------------------------------------------------------------------
(function () {
function VideoController($location, VideosService, ImagesService, $stateParams, $state) {
console.info("Initializing VideoController");
var controller = this;
controller.showMoreAudio = false;
controller.showMoreKeywords = false;
controller.showMoreEntities = false;
controller.showMoreConcepts = false;
controller.data = {
video: null,
images: null,
summary: null,
selected: null,
selectedSummary: null,
};
controller.data.videoId = $stateParams.videoId;
controller.selectVideo = function() {
console.log('Selecting video');
controller.data.selected = controller.data.video;
controller.data.selectedSummary = controller.data.summary;
};
controller.selectImage = function(image) {
console.log('Selecting image', image);
controller.data.selected = image;
controller.data.selectedSummary = image.analysis;
};
controller.selectImageWithTag = function(tagType, tagName) {
if (!controller.isVideo()) {
return;
}
var imageWithTag = controller.data.images.find(function(image) {
if (image.analysis) {
switch (tagType) {
case 'image_keywords':
return image.analysis.image_keywords.find(function(keyword) {
return keyword.class === tagName;
});
}
}
return false;
});
if (imageWithTag) {
controller.selectImage(imageWithTag);
// scroll the image to make it visible
var imageDom = document.getElementById(`image-${imageWithTag._id}`);
imageDom.scrollIntoView();
} else {
console.log('No image found matching', tagType, tagName);
}
};
controller.isVideo = function() {
return controller.data.selected && controller.data.selected.type === 'video';
}
VideosService.get($stateParams.videoId).then(function (summary) {
controller.data.images = summary.images;
controller.data.summary = summary;
controller.data.selected = controller.data.video;
controller.data.selectedSummary = summary;
controller.data.video = controller.data.selected = summary.video;
});
controller.reset = function() {
if (controller.data.selected && controller.data.selected.type === 'image') {
console.log('Resetting image', controller.data.selected._id);
ImagesService.reset(controller.data.selected).then(function (targetImage) {
$state.reload();
});
} else {
console.log('Resetting video', controller.data.video._id);
VideosService.reset(controller.data.video._id).then(function (reset) {
// reload the page, it will show empty
$state.reload();
});
}
};
controller.resetImages = function() {
VideosService.resetImages(controller.data.video._id).then(function (reset) {
// reload the page, it will show empty
$state.reload();
});
}
controller.resetAudio = function() {
VideosService.resetAudio(controller.data.video._id).then(function (reset) {
// reload the page, it will show empty
$state.reload();
});
}
controller.delete = function() {
if (controller.data.selected && controller.data.selected.type === 'image') {
var idToRemove = controller.data.selected._id;
console.log('Deleting image', idToRemove);
ImagesService.delete(controller.data.selected).then(function (targetImage) {
controller.data.images = controller.data.images.filter(function(image) {
return image._id !== idToRemove;
});
});
controller.selectVideo();
} else {
console.log('Deleting video', controller.data.video._id);
VideosService.delete(controller.data.video._id).then(function (reset) {
// go back home
$state.go('home');
});
}
};
}
angular.module('app')
.controller('VideoController', ['$location', 'VideosService', 'ImagesService', '$stateParams', '$state', VideoController]);
}());