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
113 changes: 63 additions & 50 deletions control/content/controllers/mediaHomeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,27 @@
(err, isConfirmed) => {
if (isConfirmed) {
$scope.isBusy = true;
Deeplink.deleteById(item.id, (err, res) => {
if (err) {
SearchEngineService.delete(item.id, (err, result)=>{
if (err){
$scope.isBusy = false;
return console.error(err);
}

MediaContent.delete(item.id).then(() => {
$scope.isBusy = false;
$scope.items = $scope.items.filter((_item) => _item.id !== item.id);
$scope.buildList();
}).catch((err) => {
$scope.isBusy = false;
return console.error(err);
Deeplink.deleteById(item.id, (err, res) => {
if (err) {
$scope.isBusy = false;
return console.error(err);
}

MediaContent.delete(item.id).then(() => {
$scope.isBusy = false;
$scope.items = $scope.items.filter((_item) => _item.id !== item.id);
$scope.buildList();
}).catch((err) => {
$scope.isBusy = false;
return console.error(err);
});
});

});
}
}
Expand Down Expand Up @@ -444,7 +451,7 @@

const searchOptions = {
filter: { '$json._buildfire.index.date1': { $gte: date } },
limit: 50, skip: 0, recordCount: true
limit: 50, skip: 0, recordCount: true, sort:{dateCreated: 1, rank: -1}
};
getRecords(searchOptions, [], function (records) {
$scope.registerAnalyticsEvent(records);
Expand Down Expand Up @@ -516,48 +523,54 @@

if (!$rootScope.loading)
return;

// var rank = ContentHome.info.data.content.rankOfLastItem || 0;
let rank = 0;
for (var index = 0; index < rows.length; index++) {
rank += 10;
rows[index].dateCreated = new Date().getTime();
rows[index].links = [];
rows[index].rank = rank;
rows[index].body = rows[index].bodyHTML;
rows[index].titleIndex = rows[index].title ? rows[index].titleIndex = rows[index].title.toLowerCase() : '';
//MEDIA DATE INDEX
var setMediaDateIndex = new Date().getTime();
if (rows[index].mediaDateIndex) {
setMediaDateIndex = rows[index].mediaDateIndex;
} else if (rows[index].mediaDate) {
setMediaDateIndex = new Date(rows[index].mediaDate).getTime();
} else if (rows[index].dateCreated) {
setMediaDateIndex = new Date(rows[index].dateCreated).getTime();
MediaContent.find({sort:{rank: -1}, limit:1, skip: 0}).then(function (res) {
const result = res.result;
// var rank = ContentHome.info.data.content.rankOfLastItem || 0;
let rank = 0;
if (result && result.length) {
rank = result[0].rank;
}
rows[index].mediaDateIndex = setMediaDateIndex;
rows[index]._buildfire = {
index: {
date1: new Date(),
for (var index = 0; index < rows.length; index++) {
rank += 10;
rows[index].dateCreated = new Date().getTime();
rows[index].links = [];
rows[index].rank = rank;
rows[index].body = rows[index].bodyHTML;
rows[index].titleIndex = rows[index].title ? rows[index].titleIndex = rows[index].title.toLowerCase() : '';
//MEDIA DATE INDEX
var setMediaDateIndex = new Date().getTime();
if (rows[index].mediaDateIndex) {
setMediaDateIndex = rows[index].mediaDateIndex;
} else if (rows[index].mediaDate) {
setMediaDateIndex = new Date(rows[index].mediaDate).getTime();
} else if (rows[index].dateCreated) {
setMediaDateIndex = new Date(rows[index].dateCreated).getTime();
}
};
}
if (validateCsv(rows)) {
MediaContent.insert(rows).then(function (data) {
$rootScope.loading = false;
$scope.isBusy = false;
$scope.items = [];
$scope.searchListItem();
$scope.setDeeplinks();
}, function errorHandler(error) {
console.error(error);
rows[index].mediaDateIndex = setMediaDateIndex;
rows[index]._buildfire = {
index: {
date1: new Date(),
}
};
}
if (validateCsv(rows)) {
MediaContent.insert(rows).then(function (data) {
$rootScope.loading = false;
$scope.isBusy = false;
$scope.items = [];
$scope.searchListItem();
$scope.setDeeplinks();
}, function errorHandler(error) {
console.error(error);
$rootScope.loading = false;
$scope.$apply();
});
} else {
$rootScope.loading = false;
$scope.$apply();
});
} else {
$rootScope.loading = false;
$csv.showInvalidCSV();
}
$csv.showInvalidCSV();
}
})

} else {
$rootScope.loading = false;
$csv.showInvalidCSV();
Expand Down
32 changes: 21 additions & 11 deletions control/content/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,34 @@
return deferred.promise;
};

SearchEngine.prototype.delete = function (id) {
SearchEngine.prototype.delete = function (key, callback) {
var that = this;
var deferred = $q.defer();
if (typeof id == 'undefined') {
return deferred.reject(new Error(MESSAGES.ERROR.ID_NOT_DEFINED));

if (typeof key === 'undefined') {
var error = new Error(MESSAGES.ERROR.ID_NOT_DEFINED);
deferred.reject(error);
callback(error, null);
return deferred.promise;
}
var data = {
id: id,
key,
tag: that._tagName
}
};

Buildfire.services.searchEngine.delete(data, function (err, result) {
if (err) {
return deferred.reject(err);
}
else if (result) {
return deferred.resolve(result);
} else {
return deferred.reject(new Error(MESSAGES.ERROR.NOT_FOUND));
if (err.errorMessage && err.errorMessage === 'Not Found'){
deferred.resolve(true);
callback(null, true);
}
else {
deferred.reject(err);
callback(err, null);
}
} else if (result) {
deferred.resolve(result);
callback(null, result);
}
});
return deferred.promise;
Expand Down
12 changes: 8 additions & 4 deletions widget/js/shared/Deeplink.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ class Deeplink {
deeplinkData: this.deeplinkData,
imageUrl: this.imageUrl
};

buildfire.deeplink.registerDeeplink(options, (err, result) => {

if (err || !result) {
console.error(err, '<<< ERROR WHILE REGISTERING DEEP LINK.');
return callback(err);
}

callback(null, {
callback(null, {
deeplinkId: result && result.data && result.data.deeplinkId ? result.data.deeplinkId : null,
deeplinkData: new Deeplink(result && result.data ? result.data : null)
});
Expand Down Expand Up @@ -74,13 +73,18 @@ class Deeplink {

if (err) {
console.error(err, '<<< ERROR WHILE DELETING DEEP LINK.');
if (err === 'no result found for this deeplink id'){
// Some items may not have a deeplink ID, which can result in this specific error.
// In such cases, we can safely ignore the error and proceed without it.
return callback(null)
}
return callback(err);
}

callback(null);

});

}

}
}