program-item-factory.js
2.59 KB
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
"use strict";
var program_item_1 = require("./program-item");
var ProgramItemFactory = (function () {
function ProgramItemFactory() {
}
Object.defineProperty(ProgramItemFactory.prototype, "basePath", {
get: function () {
return this._basePath;
},
set: function (bp) {
this._basePath = bp;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ProgramItemFactory.prototype, "programRepository", {
get: function () {
return this._programRepository;
},
set: function (pr) {
this._programRepository = pr;
},
enumerable: true,
configurable: true
});
ProgramItemFactory.prototype.getProgramItem = function (programItemId) {
var _this = this;
return this.programRepository
.findById(programItemId)
.then(function (programItem) {
return _this.prepareProgramItem(programItem.program_item_type, programItem);
});
};
ProgramItemFactory.prototype.prepareProgramItem = function (type, data) {
var programItem = new program_item_1.ProgramItem();
programItem.type = type;
if (type === program_item_1.PROGRAM_ITEM_TYPE_VIDEO) {
return this.prepareVideoItem(programItem, data);
}
else if (type === program_item_1.PROGRAM_ITEM_TYPE_SLIDESHOW) {
return this.prepareSlideshowItem(programItem, data);
}
else {
return null;
}
};
ProgramItemFactory.prototype.prepareSlideshowItem = function (programItem, data) {
var _this = this;
return this._programRepository.findByIds(data.images)
.then(function (images) {
programItem.data = {
speed: data.settings.speed,
effect: data.settings.effect,
images: []
};
for (var _i = 0, images_1 = images; _i < images_1.length; _i++) {
var image = images_1[_i];
programItem.data.images.push(_this.basePath + image.filename);
}
return programItem;
});
};
ProgramItemFactory.prototype.prepareVideoItem = function (programItem, data) {
var _this = this;
return this._programRepository.findById(data.video)
.then(function (data) {
programItem.data = {
video: _this.basePath + data['filename']
};
return programItem;
});
};
return ProgramItemFactory;
}());
exports.ProgramItemFactory = ProgramItemFactory;