Skip to content

Commit

Permalink
Merge pull request #140 from kaltura/revert-upgrade-v2-to-v7
Browse files Browse the repository at this point in the history
Revert upgrade v2 player to v7 functionality.
  • Loading branch information
nireliyahu authored Nov 30, 2022
2 parents f1d8884 + 44dc017 commit ffc1130
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 279 deletions.
2 changes: 1 addition & 1 deletion app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var cl = function (val) {
// Declare app level module which depends on filters, and services
var KMCModule = angular.module('KMCModule',
['pascalprecht.translate', 'ngRoute', 'KMC.controllers', 'KMC.filters',
'KMC.services', 'KMC.directives', 'ngAnimate', 'LocalStorageModule', 'KMCmenu', 'JSONedit', 'ui.bootstrap']);
'KMC.services', 'KMC.directives', 'ngAnimate', 'LocalStorageModule', 'KMCmenu', 'JSONedit']);

KMCModule.config(['$routeProvider', '$locationProvider', '$httpProvider', '$tooltipProvider', '$translateProvider', function ($routeProvider, $locationProvider, $httpProvider, $tooltipProvider, $translateProvider) {
$translateProvider.useStaticFilesLoader({
Expand Down
90 changes: 3 additions & 87 deletions app/js/controllers/playerListCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,9 @@

/* Controllers */

angular.module('KMCModule')
.controller('PlayerUpgradeModeCtrl',
function ($scope, $modalInstance, settings) {
$scope.playerId = '';
$scope.mode = '';

$scope.close = function (result) {
if (!result) {
return $modalInstance.close();
}

$modalInstance.close({
mode: this.mode,
templateId: Number(this.playerId)
});
};

$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};

$scope.validate = function () {
if (!this.mode) {
return false;
}

if (this.mode === 'template' && (this.playerId === '') || isNaN(this.playerId)) {
return false;
}

return true;
};

angular.extend($scope, settings);
})
.controller('PlayerListCtrl',
['apiService', 'loadINI', '$location', '$rootScope', '$scope', '$filter', '$modal', '$timeout', '$log', "$compile", "$window", 'localStorageService', 'requestNotificationChannel', 'PlayerService', '$q', 'utilsSvc', 'PermissionsService',
function (apiService, loadINI, $location, $rootScope, $scope, $filter, $modal, $timeout, $log, $compile, $window, localStorageService, requestNotificationChannel, PlayerService, $q, utilsSvc, PermissionsService) {
angular.module('KMCModule').controller('PlayerListCtrl',
['apiService', 'loadINI', '$location', '$rootScope', '$scope', '$filter', '$modal', '$timeout', '$log', "$compile", "$window", 'localStorageService', 'requestNotificationChannel', 'PlayerService', '$q', 'utilsSvc',
function (apiService, loadINI, $location, $rootScope, $scope, $filter, $modal, $timeout, $log, $compile, $window, localStorageService, requestNotificationChannel, PlayerService, $q, utilsSvc) {
// start request to show the spinner. When data is rendered, the onFinishRender directive will hide the spinner
requestNotificationChannel.requestStarted('list');
$rootScope.lang = 'en-US';
Expand All @@ -53,21 +18,6 @@ angular.module('KMCModule')
}
return version;
};

$scope.v7UpgradeAllowed = false;

var checkV7UpgradeAllowed = function () {
PermissionsService.hasPermission('FEATURE_V3_STUDIO_PERMISSION')
.then(function (result) {
$scope.v7UpgradeAllowed = result;
}, function (reason) {
$log.error('Failed to check permissions: ' + reason);
$scope.v7UpgradeAllowed = false;
});
};

checkV7UpgradeAllowed();

// init search
$scope.search = '';
$scope.searchSelect2Options = {};
Expand Down Expand Up @@ -372,40 +322,6 @@ angular.module('KMCModule')
return upgradeProccess.promise;
};

$scope.upgradeV7 = function(player) {
var modal = $modal.open({
templateUrl: 'templates/playerUpgradeMode.html',
controller: 'PlayerUpgradeModeCtrl',
resolve: {
settings: function () {
return {};
}
}
});
modal.result.then(function (result) {
if (result) {
var confirmMsg = $filter('translate')('Do you want to convert this V2 player to a V7 player?<br/><br/>' +
'Player\'s customization and configuration will be lost<br/>' +
'Player\'s embeds will need to be modified.<br/><br/>' +
'This option is mostly relevant for KAF Browse, Search and Embed players.');

var confirmModal = utilsSvc.confirm($filter('translate')('Convert to Player V7 confirmation'), confirmMsg, $filter('translate')('Convert'));
confirmModal.result.then(function (confirmResult) {
if (confirmResult) {
PlayerService.playerUpgradeV7(player, result.mode, result.templateId)
.then(function () {
$scope.data.splice($scope.data.indexOf(player), 1);
$scope.triggerLayoutChange();
}, function (reason) {
var msg = reason.replaceAll('\n', '<br/>');
utilsSvc.alert($filter('translate')('Upgrade failure'), msg);
});
}
});
}
});
};

// updater an outdated player
$scope.update = function (player) {
var upgradeProccess = $q.defer();
Expand Down
187 changes: 2 additions & 185 deletions app/js/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ KMCServices.factory('sortSvc', [function () {
}]
);

KMCServices.factory('PlayerService', ['$http', '$modal', '$log', '$q', 'apiService', '$filter', 'localStorageService', '$location', 'utilsSvc', 'PlayerDataService',
function ($http, $modal, $log, $q, apiService, $filter, localStorageService, $location, utilsSvc, PlayerDataService) {
KMCServices.factory('PlayerService', ['$http', '$modal', '$log', '$q', 'apiService', '$filter', 'localStorageService', '$location', 'utilsSvc',
function ($http, $modal, $log, $q, apiService, $filter, localStorageService, $location, utilsSvc) {
var playersCache = {};
var currentPlayer = {};
var previewEntry;
Expand Down Expand Up @@ -534,42 +534,6 @@ KMCServices.factory('PlayerService', ['$http', '$modal', '$log', '$q', 'apiServi
);
return deferred.promise;
},
'playerUpgradeV7': function(playerObj, mode, templateId) {
var deferred = $q.defer();

function getV7PlayerConf(playerObj, mode, templateId) {
switch (mode) {
case 'default':
return PlayerDataService.getDefaultV7PlayerConf(playerObj.name, playerObj.description);
case 'template':
return PlayerDataService.getV7PlayerConfFromTemplate(playerObj.name, templateId);
default:
var confDeferred = $q.defer();
confDeferred.reject($filter('translate')('Unknown upgrade mode "') + mode + '"');
return confDeferred.promise;
}
}

var paramsPromise = getV7PlayerConf(playerObj, mode, templateId);

paramsPromise.then(function (request) {
request['service'] = 'uiConf';
request['action'] = 'update';
request['id'] = playerObj.id;

apiService.doRequest(request).then(function (result) {
deferred.resolve(result);
}, function (msg) {
var rejectText = $filter('translate')('Upgrade player action was rejected: ');
deferred.reject(rejectText + msg);
}
);
}, function (msg) {
deferred.reject(msg);
});

return deferred.promise;
},
'playerUpdate': function (playerObj, html5lib, isPlaylist) {
// use the upgradePlayer service to convert the old XML config to the new json config object
var deferred = $q.defer();
Expand Down Expand Up @@ -623,126 +587,6 @@ KMCServices.factory('PlayerService', ['$http', '$modal', '$log', '$q', 'apiServi
}])
;

KMCServices.factory('PlayerDataService', ['apiService', '$q', '$filter',
function (apiService, $q, $filter) {
function validateV7Player(player) {
return player.tags && player.tags.includes('kalturaPlayerJs');
}

function cleanupV7PlayerConfig(playerConfig) {
playerConfig['uiConf:confFile'] = ' ';
playerConfig['uiConf:swfUrlVersion'] = '';
playerConfig['uiConf:html5Url'] = '';

return playerConfig;
}

var playerDataService = {
getDefaultV7PlayerConf: function (name, description) {
var deferred = $q.defer();
var result = {
'uiConf:objectType': 'KalturaUiConf',
'uiConf:objType': 1,
'uiConf:description': description || '',
'uiConf:height': 395,
'uiConf:width': 560,
'uiConf:swfUrl': '/',
'uiConf:name': name,
'uiConf:tags': 'kalturaPlayerJs,player,ovp',
'uiConf:config': '{\n' +
'\t"disableUserCache": false,\n' +
'\t"plugins": {\n' +
'\t\t"kava": {},\n' +
'\t\t"playkit-js-hotspots": {},\n' +
'\t\t"navigation": {},\n' +
'\t\t"playkit-js-transcript": {\n' +
'\t\t\t"position": "bottom",\n' +
'\t\t\t"showTime": true,\n' +
'\t\t\t"expandOnFirstPlay": false,\n' +
'\t\t\t"downloadDisabled": true,\n' +
'\t\t\t"printDisabled": true\n' +
'\t\t},\n' +
'\t\t"playkit-js-info": {},\n' +
'\t\t"dualscreen": {},\n' +
'\t\t"timeline": {},\n' +
'\t\t"ivq": {},\n' +
'\t\t"kalturaCuepoints": {},\n' +
'\t\t"uiManagers": {},\n' +
'\t\t"playlist": {}\n' +
'\t},\n' +
'\t"viewability": {\n' +
'\t\t"playerThreshold": 50\n' +
'\t},\n' +
'\t"provider": {\n' +
'\t\t"env": {}\n' +
'\t},\n' +
'\t"playback": {\n' +
'\t\t"enabled": true\n' +
'\t},\n' +
'\t"playlist": {\n' +
'\t\t"options": {},\n' +
'\t\t"countdown": {}\n' +
'\t}\n' +
'}',
'uiConf:confVars': '{"versions":{"kaltura-ovp-player":"{latest}","playkit-navigation":"{latest}",' +
'"playkit-transcript":"{latest}","playkit-hotspots":"{latest}","playkit-info":"{latest}",' +
'"playkit-dual-screen":"{latest}","playkit-ivq":"{latest}","playkit-playlist":"{latest}",' +
'"playkit-timeline":"{latest}","playkit-kaltura-cuepoints":"{latest}"},"langs":["en"]}',
'uiConf:creationMode': 2,
};

result = cleanupV7PlayerConfig(result);

deferred.resolve(result);
return deferred.promise;
},

getV7PlayerConfFromTemplate: function (name, playerId) {
var deferred = $q.defer();
apiService.setCache(false);
var request = {
'service': 'uiConf',
'action': 'get',
'id': playerId
};
apiService.doRequest(request).then(function (result) {
if (!validateV7Player(result)) {
deferred.reject($filter('translate')('The provided player ID is not a V7 player.\nPlayer ID: ') + result.id);
return;
}
// validate result to catch invalid JSON configs
if (typeof result.config === 'string') {
try {
angular.fromJson(result.config);
var ignoredFields = ['id', 'name', 'description', 'partnerId', 'objTypeAsString', 'createdAt', 'updatedAt', 'version'];
var template = {
'uiConf:name': name,
};

Object.entries(result).forEach(function(entry) {
var key = entry[0];
var value = entry[1];
if (!ignoredFields.includes(key)) {
template['uiConf:' + key] = value;
}
});

template = cleanupV7PlayerConfig(template);
deferred.resolve(template);
} catch (e) {
deferred.reject($filter('translate')('The template player configuration object is not valid.\nPlayer ID: ') + result.id);
}
}
}, function () {
deferred.reject($filter('translate')('The provided player ID does not exist.\nPlayer ID: ') + playerId);
}
);
return deferred.promise;
}
};
return playerDataService;
}]);

KMCServices.factory('requestNotificationChannel', ['$rootScope', function ($rootScope) {
// private notification messages
var _START_REQUEST_ = '_START_REQUEST_';
Expand Down Expand Up @@ -1103,30 +947,3 @@ KMCServices.factory('playerTemplates', ['$http', function ($http) {
};

}]);
KMCServices.factory('PermissionsService', ['apiService', '$q', function (apiService, $q) {
var permissionsService = {
hasPermission: function (permission) {
var deferred = $q.defer();
apiService.setCache(false);
var request = {
'service': 'permission',
'action': 'getCurrentPermissions'
};
apiService.doRequest(request).then(function (data) {
if (!data) {
deferred.resolve(false);
} else {
var permissions = data.split(',');
var hasPermission = permissions.includes(permission);
deferred.resolve(hasPermission);
}
}, function (reason) {
deferred.reject(reason);
});

return deferred.promise;
}
};

return permissionsService;
}]);
6 changes: 0 additions & 6 deletions app/view/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ <h2 id="pageHeader">
{{'Update'|
translate}}
</button>
<button type="button" class="btn btn-link"
ng-show="v7UpgradeAllowed"
ng-click="upgradeV7(item)"><span class="glyphicon glyphicon-arrow-up"></span>
{{'Convert to Player V7'|
translate}}
</button>
</div>
</td>
</tr>
Expand Down

0 comments on commit ffc1130

Please sign in to comment.