file settings landed in angular implementation

This commit is contained in:
hamza zia 2013-02-25 11:50:42 +01:00
parent 6c93dba6ff
commit 708d627ff3
5 changed files with 105 additions and 26 deletions

View File

@ -177,35 +177,78 @@
</div> </div>
<!-- {{{ download template --> <!-- {{{ download template -->
<table ng-repeat="download in getDownloads()" class="download" data-gid="{{download.gid}}"> <table
ng-repeat="download in getDownloads()"
class="download" data-gid="{{download.gid}}">
<tbody> <tbody>
<tr> <tr>
<td ng-click="download.collapsed = !download.collapsed" class="download-overview"> <td
ng-click="download.collapsed = !download.collapsed"
class="download-overview">
<b class="download-name">{{getName(download)}}</b> <b class="download-name">{{getName(download)}}</b>
</td> </td>
<td class="download-controls" rowspan="2"> <td class="download-controls" rowspan="2">
<div class="btn-group"> <div class="btn-group">
<button ng-show="hasStatus(download, 'active')" class="btn download_pause" ng-click="pause(download)"><i class="icon-pause"></i></button> <button
<button ng-show="hasStatus(download, 'paused')" class="btn download_play" ng-click="resume(download)"><i class="icon-play"></i></button> ng-show="hasStatus(download, 'active')"
<button ng-show="canRestart(download)" class="btn download_restart" ng-click="restart(download)"><i class="icon-repeat"></i></button> class="btn"
ng-click="pause(download)">
<i class="icon-pause"></i>
</button>
<button class="btn download_remove hidden-phone" ng-click="remove(download)"><i class="icon-stop"></i></button> <button
ng-show="hasStatus(download, 'paused')"
class="btn"
ng-click="resume(download)">
<i class="icon-play"></i>
</button>
<button class="btn download_settings hidden-phone"><i class="icon-cog"></i></button> <button
ng-show="canRestart(download)"
class="btn"
ng-click="restart(download)">
<i class="icon-repeat"></i>
</button>
<button
class="btn hidden-phone"
ng-click="remove(download)">
<i class="icon-stop"></i>
</button>
<button
class="btn hidden-phone"
ng-show="['waiting', 'active'].indexOf( getType(download) )!= -1"
ng-click="showSettings(download)">
<i class="icon-cog"></i>
</button>
<button class="btn dropdown-toggle"> <button class="btn dropdown-toggle">
<i class="caret"></i> <i class="caret"></i>
</button> </button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li class="visible-phone"><a href="#"><i class="icon-cog"></i> Settings</a></li> <li class="visible-phone">
<a
ng-click="showSettings(download)"
ng-show="['waiting', 'active'].indexOf( getType(download) )!= -1"
href="#"><i class="icon-cog"></i> Settings</a>
</li>
<li ng-show="download.bittorrent"><a href="#" class="torrent_info"><i class="icon-list-alt"></i> Peers</a></li> <li ng-show="download.bittorrent">
<a href="#"><i class="icon-list-alt"></i> Peers</a>
</li>
<li><a href="#" ng-click="download.collapsed = !download.collapsed"><i class="icon-info-sign"></i> More Info</a></li> <li>
<a ng-click="download.collapsed = !download.collapsed"
href="#"><i class="icon-info-sign"></i> More Info</a>
</li>
<li class="visible-phone"><a href="#" ng-click="remove(download)"><i class="icon-remove"></i> Remove</a></li> <li class="visible-phone">
<a ng-click="remove(download)"
href="#"><i class="icon-remove"></i> Remove</a>
</li>
</ul> </ul>
</div> </div>
</td> </td>
@ -406,16 +449,16 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
<!-- }}} --> <!-- }}} -->
<!-- {{{ global settings --> <!-- {{{ global settings -->
<div class="modal hide" modal="globalSettings.shown"> <div class="modal hide" modal="settings.shown">
<div class="modal-header"> <div class="modal-header">
<button class="close" ng-click="globalSettings.close()">x</button> <button class="close" ng-click="settings.close()">x</button>
<h3>{{globalSettings.title}}</h3> <h3>{{settings.title}}</h3>
</div> </div>
<form class="form-horizontal modal-body"> <form class="form-horizontal modal-body">
<fieldset> <fieldset>
<div class="control-group"> <div class="control-group">
<div ng-repeat="(name, set) in globalSettings.settings"> <div ng-repeat="(name, set) in settings.settings">
<label class="control-label">{{name}}</label> <label class="control-label">{{name}}</label>
<div class="controls"> <div class="controls">
@ -431,8 +474,8 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
</form> </form>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn" ng-click="globalSettings.close()">Cancel</button> <button class="btn" ng-click="settings.close()">Cancel</button>
<button class="btn btn-success" ng-click="globalSettings.success()">Save</button> <button class="btn btn-success" ng-click="settings.success()">Save</button>
</div> </div>
</div </div
<!-- }}} --> <!-- }}} -->

View File

@ -1,9 +1,15 @@
angular angular
.module('webui.ctrls.download', [ .module('webui.ctrls.download', [
'webui.services.utils', 'webui.services.rpc', 'webui.services.alerts' 'webui.services.utils', 'webui.services.rpc', 'webui.services.alerts',
'webui.services.settings', 'webui.services.modals'
]) ])
.controller('DownloadCtrl', [ '$scope', '$rpc', '$utils', '$alerts', .controller('DownloadCtrl', [
function(scope, rpc, utils, sett, alerts) { '$scope', '$rpc', '$utils', '$alerts', '$modals',
'$fileSettings', '$activeInclude', '$waitingExclude',
function(
scope, rpc, utils, alerts, modals,
fsettings, activeInclude, waitingExclude
) {
scope.active = [], scope.waiting = [], scope.stopped = []; scope.active = [], scope.waiting = [], scope.stopped = [];
// pause the download // pause the download
@ -144,4 +150,34 @@ function(scope, rpc, utils, sett, alerts) {
return type; return type;
}; };
scope.showSettings = function(d) {
var type = this.getType(d)
, settings = {};
rpc.once('getOption', [d.gid], function(data) {
var vals = data[0];
window.fs = fsettings;
window.ai = activeInclude;
for (var i in fsettings) {
if (type == 'active' && activeInclude.indexOf(i) == -1) continue;
if (type == 'waiting' && waitingExclude.indexOf(i) != -1) continue;
settings[i] = fsettings[i];
settings[i].val = vals[i] || settings[i].val;
}
console.log(type);
modals.invoke('settings', settings, scope.getName(d) + ' settings', function(settings) {
var sets = {};
for (var i in settings) { sets[i] = settings[i].val };
rpc.once('changeOption', [d.gid, sets]);
});
});
return false;
}
}]); }]);

View File

@ -82,7 +82,7 @@ angular
}; };
}); });
scope.globalSettings = { scope.settings = {
shown: false, shown: false,
settings: [], settings: [],
title: 'Settings', title: 'Settings',
@ -104,7 +104,7 @@ angular
_.each([ _.each([
'getUris', 'getTorrents', 'getMetalinks', 'getUris', 'getTorrents', 'getMetalinks',
'globalSettings' 'settings'
], function(name) { ], function(name) {
modals.register(name, function(cb) { modals.register(name, function(cb) {
if (scope[name].open && scope[name].cb) { if (scope[name].open && scope[name].cb) {

View File

@ -54,7 +54,7 @@ angular
_.forEach([fsettings, gsettings], function(sets) { _.forEach([fsettings, gsettings], function(sets) {
for (var i in sets) { for (var i in sets) {
if (i in gexclude) continue; if (gexclude.indexOf(i) != -1) continue;
settings[i] = sets[i]; settings[i] = sets[i];
} }
@ -72,7 +72,7 @@ angular
} }
} }
modals.invoke('globalSettings', settings, 'Global Settings', function(settings) { modals.invoke('settings', settings, 'Global Settings', function(settings) {
var sets = {}; var sets = {};
for (var i in settings) { sets[i] = settings[i].val }; for (var i in settings) { sets[i] = settings[i].val };

View File

@ -281,7 +281,7 @@ angular.module('webui.services.settings', [])
}, },
"index-out": { "index-out": {
val: '', val: undefined,
desc: "Set file path for file with index=INDEX. You can find the file index using the --show-files option. PATH is a relative path to the path specified in --dir option. You can use this option multiple times. Using this option, you can specify the output filenames of BitTorrent downloads." desc: "Set file path for file with index=INDEX. You can find the file index using the --show-files option. PATH is a relative path to the path specified in --dir option. You can use this option multiple times. Using this option, you can specify the output filenames of BitTorrent downloads."
}, },
@ -463,7 +463,7 @@ angular.module('webui.services.settings', [])
}, },
"checksum": { "checksum": {
val: '', val: undefined,
desc: "Set checksum. TYPE is hash type. The supported hash type is listed in Hash Algorithms in aria2c -v. DIGEST is hex digest. For example, setting sha-1 digest looks like this: sha-1=0192ba11326fe2298c8cb4de616f4d4140213838 This option applies only to HTTP(S)/FTP downloads." desc: "Set checksum. TYPE is hash type. The supported hash type is listed in Hash Algorithms in aria2c -v. DIGEST is hex digest. For example, setting sha-1 digest looks like this: sha-1=0192ba11326fe2298c8cb4de616f4d4140213838 This option applies only to HTTP(S)/FTP downloads."
}, },