Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/main/posts/detail/post-media-value.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module.exports = ['MediaEndpoint', '_', function (MediaEndpoint, _) {

function MediaValueLink($scope) {
function loadMedia() {
if (!_.isNull($scope.mediaId)) {
$scope.mediaLoaded = true;
if ($scope.mediaId && $scope.mediaId.length > 0) {
$scope.mediaLoaded = false;
MediaEndpoint.get({id: $scope.mediaId}).$promise.then(function (media) {
$scope.media = media;
Expand Down
6 changes: 4 additions & 2 deletions app/main/posts/modify/post-media.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ module.exports = [
'Util',
'Notify',
'$q',
'_',
function (
$http,
MediaEndpoint,
MediaEditService,
Util,
Notify,
$q
$q,
_
) {
return {
restrict: 'E',
Expand Down Expand Up @@ -54,7 +56,7 @@ function (
if (ngModel.$viewValue) {
$scope.mediaId = parseInt(ngModel.$viewValue);
// Load the media from the API
if ($scope.media.id !== $scope.mediaId) {
if ($scope.media.id !== $scope.mediaId && _.isNumber($scope.mediaId)) {
MediaEndpoint.get({id: $scope.mediaId}).$promise.then(function (media) {
$scope.media = media;
// Set initial media state
Expand Down
5 changes: 4 additions & 1 deletion app/main/posts/views/post-preview-media.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ function (
var mediaAttribute = _.find(attributes, function (attribute) {
return attribute.type === 'media';
});
const mediaExists = mediaAttribute &&
!_.isUndefined($scope.post.values[mediaAttribute.key]) &&
!_.isNumber($scope.post.values[mediaAttribute.key]);
// Get the media url and caption
if (mediaAttribute && !_.isUndefined($scope.post.values[mediaAttribute.key])) {
if (mediaExists) {
MediaEndpoint.get({id: $scope.post.values[mediaAttribute.key]}).$promise
.then(function (media) {
$scope.media = media;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('post media value directive', function () {
$rootScope = _$rootScope_;
$scope = _$rootScope_.$new();

element = '<post-media-value media-id="5"></post-media-value>';
element = '<post-media-value media-id="[5]"></post-media-value>';
element = $compile(element)($scope);
$rootScope.$digest();
isolateScope = element.isolateScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('post preview media directive', function () {
id: 1
},
values: {
media_test: 7
media_test: [7]
}
};

Expand Down