Skip to content

Commit

Permalink
Refactored uTorrentService -> torrentServerService
Browse files Browse the repository at this point in the history
  • Loading branch information
psychowood committed Apr 25, 2016
1 parent 0f6724f commit 35c3b60
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 47 deletions.
10 changes: 5 additions & 5 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ angular
};
})
*/
.controller('NavController', function($scope, uTorrentService, $http, $cookies, $log, $translate, translationsLoader, $rootScope) {
.controller('NavController', function($scope, torrentServerService, $http, $cookies, $log, $translate, translationsLoader, $rootScope) {

translationsLoader('getoptions').then(function(options) {
var langId, lang;
Expand Down Expand Up @@ -215,11 +215,11 @@ angular

$scope.updatedVersion = $cookies.get('updatedVersion');

uTorrentService.init().then(function() {
var ts = uTorrentService.actions().getsettings();
torrentServerService.init().then(function() {
var ts = torrentServerService.actions().getsettings();
ts.$promise.then(function() {
$rootScope.features = uTorrentService.supports;
$rootScope.serverVersion = uTorrentService.getVersion();
$rootScope.features = torrentServerService.supports;
$rootScope.serverVersion = torrentServerService.getVersion();
});
return ts;
}, function() {
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/controllers/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
* Controller of the ngTorrentUiApp
*/
angular.module('ngTorrentUiApp')
.controller('AboutCtrl', function ($scope,uTorrentService) {
$scope.url = uTorrentService.url;
.controller('AboutCtrl', function ($scope,torrentServerService) {
$scope.url = torrentServerService.url;
});
4 changes: 2 additions & 2 deletions app/scripts/controllers/details-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Controller of the ngTorrentUiApp
*/
angular.module('ngTorrentUiApp')
.controller('DetailsDialogCtrl', function($scope, torrent, uTorrentService, toastr, $translate, $window) {
.controller('DetailsDialogCtrl', function($scope, torrent, torrentServerService, toastr, $translate, $window) {
$scope.hasSelection = false;

$scope.filters = {
Expand Down Expand Up @@ -57,7 +57,7 @@ angular.module('ngTorrentUiApp')
fileIndexes.push(torrent.files[i].hash);
}
}
uTorrentService.filePriority().set({
torrentServerService.filePriority().set({
hash: torrent.hash,
priority: $scope.priorityToSet,
f: fileIndexes
Expand Down
6 changes: 3 additions & 3 deletions app/scripts/controllers/issue-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
* Controller of the ngTorrentUiApp
*/
angular.module('ngTorrentUiApp')
.controller('IssueReporterCtrl', function($scope, uTorrentService, $window) {
.controller('IssueReporterCtrl', function($scope, torrentServerService, $window) {
var newIssueBaseUrl = 'https://github.com/psychowood/ng-torrent-ui/issues/new/';
var newMailBaseUrl = 'mailto:ng' + 'torrent' + 'ui' + '@' + 'gmail.com';
$scope.newIssueUrl = newIssueBaseUrl;
// uTorrentService.init().then(function(){
// torrentServerService.init().then(function(){
// });

var getBody = function() {
var version = uTorrentService.getVersion();
var version = torrentServerService.getVersion();
return 'Describe your issue here' +
'%0A' +
'%0A' +
Expand Down
28 changes: 14 additions & 14 deletions app/scripts/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Controller of the ngTorrentUiApp
*/
angular.module('ngTorrentUiApp')
.controller('TorrentsCtrl', function($scope, $window, $uibModal, $filter, $timeout, $log, uTorrentService, Torrent, toastr, $cookies) {
.controller('TorrentsCtrl', function($scope, $window, $uibModal, $filter, $timeout, $log, torrentServerService, Torrent, toastr, $cookies) {

$scope.headerHeight = 350;
// On window resize => resize the app
Expand Down Expand Up @@ -71,7 +71,7 @@ angular.module('ngTorrentUiApp')
$scope.filteredtorrents = [];
$scope.selectedtorrents = [];

var torrentsMap = uTorrentService.cacheMap;
var torrentsMap = torrentServerService.cacheMap;
var reloadTimeout;
$scope.autoreloadTimeout = 5000;
$scope.autoreloadEnabled = ($scope.autoreloadTimeout > 0);
Expand Down Expand Up @@ -125,14 +125,14 @@ angular.module('ngTorrentUiApp')
$scope.addTorrentFilesOrUrl = function(urlOrFiles) {
var add = function(dir, subpath) {
if (typeof urlOrFiles === 'string') {
uTorrentService.addTorrentUrl(urlOrFiles, dir, subpath).then(function() {
torrentServerService.addTorrentUrl(urlOrFiles, dir, subpath).then(function() {
toastr.info('Torrent added succesfully', null, {
timeOut: 1000
});
$scope.newtorrent = '';
});
} else {
if (uTorrentService.uploadTorrent) {
if (torrentServerService.uploadTorrent) {
var i, success = 0;
var callback = function( /* data, status, headers, config */ ) {
success++;
Expand All @@ -145,17 +145,17 @@ angular.module('ngTorrentUiApp')
};
for (i = 0; i < urlOrFiles.length; i++) {
var file = urlOrFiles[i];
uTorrentService.uploadTorrent(file, dir, subpath).success(callback);
torrentServerService.uploadTorrent(file, dir, subpath).success(callback);
}
} else {
toastr.warning('Files upload not supported for ' + uTorrentService.getVersion(), null, {
toastr.warning('Files upload not supported for ' + torrentServerService.getVersion(), null, {
timeOut: 2500
});
}
}
};
if (uTorrentService.supports.getDownloadDirectories === true) {
uTorrentService.getDownloadDirectories().then(function(directories) {
if (torrentServerService.supports.getDownloadDirectories === true) {
torrentServerService.getDownloadDirectories().then(function(directories) {
$scope.directories = directories;

var modalInstance = $uibModal.open({
Expand Down Expand Up @@ -220,7 +220,7 @@ angular.module('ngTorrentUiApp')
return;
}

var service = uTorrentService.actions()[action];
var service = torrentServerService.actions()[action];

if (service) {
var ts = service({
Expand All @@ -242,7 +242,7 @@ angular.module('ngTorrentUiApp')
$scope.setLabel = function(value, item) {
var hashes = getSelectedHashes(item);

var service = uTorrentService.setLabel;
var service = torrentServerService.setLabel;
$scope.labelToSet = '';

if (service) {
Expand Down Expand Up @@ -294,7 +294,7 @@ angular.module('ngTorrentUiApp')
modalInstance.result.then(function(starredItems) {
var obj = angular.toJson(starredItems);
$cookies.put('starredItems', obj);
//uTorrentService.setSetting('webui.ngtorrentui.favorites',obj);
//torrentServerService.setSetting('webui.ngtorrentui.favorites',obj);
$scope.starredItems = starredItems;
}, function() {

Expand Down Expand Up @@ -584,7 +584,7 @@ angular.module('ngTorrentUiApp')
$timeout.cancel(reloadTimeout);
$log.info('reload torrents');
//var reloadingMsg = toastr.info('Refreshing torrents...',null,{timeOut: 0});
var ts = uTorrentService.torrents().list();
var ts = torrentServerService.torrents().list();

//var ptn = $window.ptn;

Expand Down Expand Up @@ -646,7 +646,7 @@ angular.module('ngTorrentUiApp')
$scope.torrents.push(value);
});
$scope.doFilter();
uTorrentService.cacheMap = torrentsMap;
torrentServerService.cacheMap = torrentsMap;
$scope.selectedtorrents = getSelectedAndUpdateGlobals($scope.torrents);
} else {
$log.debug('no changes');
Expand Down Expand Up @@ -827,7 +827,7 @@ angular.module('ngTorrentUiApp')

$scope.$on('$destroy', function() {});

uTorrentService.init().then(function() {
torrentServerService.init().then(function() {
$scope.reload();
}, function() {
$log.error('error', arguments);
Expand Down
10 changes: 5 additions & 5 deletions app/scripts/controllers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Controller of the ngTorrentUiApp
*/
angular.module('ngTorrentUiApp')
.controller('SettingsCtrl', function($scope, uTorrentService, $log, $translate, toastr, $timeout, $cookies) {
.controller('SettingsCtrl', function($scope, torrentServerService, $log, $translate, toastr, $timeout, $cookies) {

var settings = {
conf: [],
Expand All @@ -29,7 +29,7 @@ angular.module('ngTorrentUiApp')
case STARRED_ITEMS:
{
webcookie.ngtorrentui[STARRED_ITEMS] = $scope[STARRED_ITEMS];
uTorrentService.setSetting('webui.cookie', angular.toJson(webcookie));
torrentServerService.setSetting('webui.cookie', angular.toJson(webcookie));
}
break;
}
Expand Down Expand Up @@ -171,8 +171,8 @@ angular.module('ngTorrentUiApp')
return result;
};

uTorrentService.init().then(function() {
var set = uTorrentService.actions().getsettings();
torrentServerService.init().then(function() {
var set = torrentServerService.actions().getsettings();
set.$promise.then(function() {
var i;
var values = set.sort(function(a, b) {
Expand Down Expand Up @@ -210,7 +210,7 @@ angular.module('ngTorrentUiApp')
});

$scope.saveSetting = function(setting) {
var service = uTorrentService.setSetting;
var service = torrentServerService.setSetting;

$log.debug('save setting', setting);

Expand Down
22 changes: 11 additions & 11 deletions app/scripts/services/utorrentservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

/**
* @ngdoc service
* @name ngTorrentUiApp.uTorrentService
* @name ngTorrentUiApp.torrentServerService
* @description
* # uTorrentService
* # torrentServerService for uTorrent
* Factory in the ngTorrentUiApp.
*/
angular.module('ngTorrentUiApp')
Expand Down Expand Up @@ -356,7 +356,7 @@ angular.module('ngTorrentUiApp')
*/
return Torrent;
})
.service('uTorrentService', function($http, $resource, $log, $upload, $q) {
.service('torrentServerService', function($http, $resource, $log, $upload, $q) {

var loading = null;
var data = {
Expand All @@ -376,7 +376,7 @@ angular.module('ngTorrentUiApp')
}
};

var uTorrentService = {
var torrentServerService = {
cacheMap: {},
conf: data,
init: function() {
Expand Down Expand Up @@ -561,12 +561,12 @@ angular.module('ngTorrentUiApp')
};
settings.push(val);
}
uTorrentService.settings = settings;
uTorrentService.supports = {};
torrentServerService.settings = settings;
torrentServerService.supports = {};
if (parseInt(data.build) > 25406) { //Features supported from uTorrent 3+
uTorrentService.supports.getDownloadDirectories = true;
uTorrentService.supports.torrentAddedDate = true;
uTorrentService.supports.torrentCompletedDate = true;
torrentServerService.supports.getDownloadDirectories = true;
torrentServerService.supports.torrentAddedDate = true;
torrentServerService.supports.torrentCompletedDate = true;
}
return settings;
}
Expand All @@ -586,7 +586,7 @@ angular.module('ngTorrentUiApp')
});
},
setSetting: function(setting, value) {
return uTorrentService.setSettings([
return torrentServerService.setSettings([
[setting, value]
]);
},
Expand Down Expand Up @@ -646,5 +646,5 @@ angular.module('ngTorrentUiApp')

}
};
return uTorrentService;
return torrentServerService;
});
10 changes: 5 additions & 5 deletions test/spec/services/utorrentservice.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict';

describe('Service: uTorrentService', function () {
describe('Service: torrentServerService', function () {

// load the service's module
beforeEach(module('ngTorrentUiApp'));

// instantiate service
var uTorrentService;
beforeEach(inject(function (_uTorrentService_) {
uTorrentService = _uTorrentService_;
var torrentServerService;
beforeEach(inject(function (_torrentServerService_) {
torrentServerService = _torrentServerService_;
}));

it('should do something', function () {
expect(!!uTorrentService).toBe(true);
expect(!!torrentServerService).toBe(true);
});

});

0 comments on commit 35c3b60

Please sign in to comment.