Skip to content

Commit

Permalink
added settings tab
Browse files Browse the repository at this point in the history
  • Loading branch information
kraiz committed Feb 21, 2015
1 parent 7abfd9d commit 031234e
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 11 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ Look up [this wiki page](https://github.com/kraiz/icecult/wiki).
Changelog
---------

* upcoming:
* feature: added settings tab
* feature: enabled possibility to pause/resume hashing
* feature: updated angular to 1.3.13 and bootstrap to 3.3.2
* bugfix: another error in update check

* 0.4.1:
* bugfix: error in update check

* 0.4.0:
* feature: show available updates in statusbar

Expand Down
2 changes: 2 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<script src="js/controllers/hubs.js"></script>
<script src="js/controllers/browse.js"></script>
<script src="js/controllers/queue.js"></script>
<script src="js/controllers/share.js"></script>
<script src="js/controllers/settings.js"></script>
</head>
<body ng-controller="MainCtrl">
<header class="navbar navbar-default navbar-fixed-top" role="navigation" ng-include src="'partials/navbar.html'"></header>
Expand Down
15 changes: 14 additions & 1 deletion app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ EiskaltApp.value('settings', {
hashAndRatio: 5000,
chat: 3000,
queues: 3000
}
},
settings: [
{key: 'Nick', type: 'text'},
{key: 'Description', type: 'text'},
{key: 'ExternalIp', type: 'text'},
{key: 'MaxUploadSpeedMain', type: 'number', suffix: 'kB/s'},
{key: 'MaxDownloadSpeedMain', type: 'number', suffix: 'kB/s'},
{key: 'DownloadDirectory', type: 'text'},
{key: 'TempDownloadDirectory', type: 'text'},
]
});

EiskaltApp.config(function ($routeProvider) {
Expand All @@ -28,5 +37,9 @@ EiskaltApp.config(function ($routeProvider) {
controller: 'QueueCtrl',
templateUrl: 'partials/queue.html'
})
.when('/settings', {
controller: 'SettingsCtrl',
templateUrl: 'partials/settings.html'
})
.otherwise({redirectTo: '/hubs'});
});
35 changes: 35 additions & 0 deletions app/js/controllers/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

EiskaltApp.controller('SettingsCtrl', function ($scope, $timeout, $modal, settings, EiskaltRPC) {
$scope.settings = settings.settings

$scope.reset = function() {
angular.forEach($scope.settings, function (setting) {
EiskaltRPC.SettingsGetSet(setting.key).success(function(value) {
if (setting.type === 'number') {
value = parseInt(value);
}
setting.value = value;
});
});
EiskaltRPC.ListShare().success(function(shares) {
$scope.shares = shares;
});
};
$scope.reset();

$scope.save = function() {
angular.forEach($scope.settings, function (setting) {
EiskaltRPC.SettingsGetSet(setting.key, setting.value).success(function(success) {
if (success) {
setting.success = true;
$timeout(function() {
delete setting.success;
}, 2000)
} else {
setting.error = true;
}
});
});
};
});
43 changes: 43 additions & 0 deletions app/js/controllers/share.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use strict";

EiskaltApp.controller('ShareCtrl', function ($scope, $modal, settings, EiskaltRPC) {
$scope.directories = []

$scope.refresh = function () {
EiskaltRPC.ListShare().success(function (directories) {
$scope.directories = directories;
});
};
$scope.refresh();

$scope.openAddShareDirModal = function () {
$modal.open({
templateUrl: 'addShareDirModal.html',
controller: 'AddShareDirCtrl'
}).result.then($scope.refresh);
};

$scope.removeShareDir = function (directory) {
if (confirm(
'Are you sure to unshare the directory ' + directory.name + '?\n' +
'Rehashing ' + directory.sizeFormatted + ' may take a while.'
)) {
EiskaltRPC.DelDirFromShare(directory.name).success($scope.refresh);
}
}
});

EiskaltApp.controller('AddShareDirCtrl', function ($scope, $modalInstance, EiskaltRPC) {
$scope.name = "";
$scope.path = "";

$scope.ok = function () {
EiskaltRPC.AddDirInShare($scope.path, $scope.name).success(function (result) {
$modalInstance.close(result === 0);
});
};

$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
});
36 changes: 26 additions & 10 deletions app/js/services/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ angular.module('EiskaltRPC', []).factory('EiskaltRPC', function($http) {
return jsonrpc('hub.pm', {huburl: huburl, nick: nick, message: message});
},
ListHubs: function() {
return jsonrpc('hub.list', {separator: '#'}, true);
return jsonrpc('hub.list', {separator: ''}, true);
},
AddDirInShare: function(directory, virtname) {
return jsonrpc('share.add', {directory: directory, virtname: virtname});
Expand All @@ -69,12 +69,12 @@ angular.module('EiskaltRPC', []).factory('EiskaltRPC', function($http) {
return jsonrpc('share.del', {directory: directory});
},
ListShare: function() {
var promise = jsonrpc('share.list', {separator: '#'});
var promise = jsonrpc('share.list', {separator: ''});
promise.success = function(fn) {
promise.then(function(response) {
var result = response.data.result.replace(/(\r\n|\n|\r)/gm, '');
result = result.replace(/#+$/, '');
result = result.split('#');
result = result.replace(/+$/, '');
result = result.split('');
var shares = [];
while (result.length) {
var data = result.splice(0, 3);
Expand All @@ -96,7 +96,7 @@ angular.module('EiskaltRPC', []).factory('EiskaltRPC', function($http) {
return jsonrpc('list.download', {huburl: huburl, nick: nick});
},
GetChatPub: function(huburl) {
return jsonrpc('hub.getchat', {huburl: huburl, separator: '#'}, true);
return jsonrpc('hub.getchat', {huburl: huburl, separator: ''}, true);
},
SendSearch: function(searchstring, searchtype, sizemode, sizetype, size, huburls) {
return jsonrpc('search.send', { searchstring: searchstring, searchtype: searchtype, sizemode: sizemode, sizetype: sizetype, size: size, huburls: huburls});
Expand All @@ -120,7 +120,7 @@ angular.module('EiskaltRPC', []).factory('EiskaltRPC', function($http) {
return jsonrpc('queue.remove', {target: target});
},
ListQueueTargets: function() {
return jsonrpc('queue.listtargets', {separator: '#'}, true);
return jsonrpc('queue.listtargets', {separator: ''}, true);
},
ListQueue: function() {
return jsonrpc('queue.list');
Expand All @@ -132,7 +132,7 @@ angular.module('EiskaltRPC', []).factory('EiskaltRPC', function($http) {
return jsonrpc('queue.add', {directory: directory, tth: tth, filename: filename, size: size});
},
GetSourcesItem: function(target) {
return jsonrpc('queue.getsources', {target: target, separator: '#'}, true);
return jsonrpc('queue.getsources', {target: target, separator: ''}, true);
},
GetHashStatus: function() {
return jsonrpc('hash.status');
Expand Down Expand Up @@ -161,7 +161,7 @@ angular.module('EiskaltRPC', []).factory('EiskaltRPC', function($http) {
return promise;
},
GetHubUserList: function(huburl) {
return jsonrpc('hub.getusers', {huburl: huburl, separator: '#'}, true);
return jsonrpc('hub.getusers', {huburl: huburl, separator: ''}, true);
},
GetUserInfo: function(nick, huburl) {
var promise = jsonrpc('hub.getuserinfo', {nick: nick, huburl: huburl});
Expand All @@ -177,7 +177,7 @@ angular.module('EiskaltRPC', []).factory('EiskaltRPC', function($http) {
return promise;
},
ShowLocalLists: function() {
return jsonrpc('list.local', {separator: '#'}, true);
return jsonrpc('list.local', {separator: ''}, true);
},
GetClientFileList: function(filelist) {
return jsonrpc('queue.listtargets', {filelist: filelist});
Expand All @@ -192,7 +192,7 @@ angular.module('EiskaltRPC', []).factory('EiskaltRPC', function($http) {
return jsonrpc('list.closeall');
},
ShowOpenedLists: function() {
return jsonrpc('list.listopened', {separator: '#'}, true);
return jsonrpc('list.listopened', {separator: ''}, true);
},
LsDirInList: function(directory, filelist) {
if (directory.length > 0) {
Expand Down Expand Up @@ -231,6 +231,22 @@ angular.module('EiskaltRPC', []).factory('EiskaltRPC', function($http) {
},
GetItemDescbyTarget: function(target) {
return jsonrpc('queue.getiteminfo');
},
QueueClear: function() {
return jsonrpc('queue.clear');
},
SettingsGetSet: function(key, value) {
var promise = jsonrpc('settings.getset', {key: key, value: value});
promise.success = function(fn) {
promise.then(function(response) {
if (angular.isDefined(value)) { // set
fn(response.data.result !== 1);
} else { // get
fn(response.data.result.value);
}
});
};
return promise;
}
};
});
6 changes: 6 additions & 0 deletions app/partials/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
Browse
</a>
</li>
<li ng-class="{active:isActive('/settings')}">
<a href="#/settings">
<span class="glyphicon glyphicon-cog"></span>
Settings
</a>
</li>
</ul>
<div class="navbar-right navbar-status">
<div>
Expand Down
85 changes: 85 additions & 0 deletions app/partials/settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<section ng-controller="ShareCtrl">
<h4>Shares</h4>

<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Path</th>
<th>Size</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="directory in directories">
<td>{{ directory.name }}</td>
<td>{{ directory.path }}</td>
<td>{{ directory.sizeFormatted }}</td>
<td>
<button class="btn btn-danger btn-xs" type="button" title="Remove this share"
ng-click="removeShareDir(directory)">
<span class="glyphicon glyphicon-remove"></span>
</button>
</td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-default btn-success" ng-click="openAddShareDirModal()">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
Add a new directory
</button>

<!-- model dialog for adding a new share -->
<script type="text/ng-template" id="addShareDirModal.html">
<div class="modal-header">
<h3 class="modal-title">Add a new directory</h3>
</div>
<div class="modal-body">
<form class="form-horizontal" ng-model-options="{ updateOn: 'blur' }">
<div class="form-group">
<label for="add_share_name" class="col-sm-3 control-label">Name</label>

<div class="input-group col-sm-7">
<input id="add_share_name" type="text" class="form-control" ng-model="name">
</div>
</div>
<div class="form-group">
<label for="add_share_path" class="col-sm-3 control-label">Path</label>

<div class="input-group col-sm-7">
<input id="add_share_path" type="text" class="form-control" ng-model="path">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">Add</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</script>
</section>

<hr/>

<section>
<h4>Configuration</h4>

<form class="form-horizontal" ng-model-options="{ updateOn: 'blur' }">
<div class="form-group" ng-repeat="setting in settings"
ng-class="{'has-success': setting.success, 'has-error': setting.error}">
<label for="{{ setting.key }}" class="col-sm-3 control-label">{{ setting.key }}</label>

<div class="input-group col-sm-7">
<input id="{{ setting.key }}" type="{{ setting.type }}" class="form-control" ng-model="setting.value">

<div ng-show="{{ setting.suffix != undefined }}" class="input-group-addon">{{ setting.suffix }}</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-7">
<button type="submit" class="btn btn-default" ng-click="reset()">Reset</button>
<button type="submit" class="btn btn-default btn-primary" ng-click="save()">Save</button>
</div>
</div>
</form>
</section>

0 comments on commit 031234e

Please sign in to comment.