added select files feature

This commit is contained in:
hamza zia 2014-09-02 00:15:33 +05:00
parent 091fbb0d41
commit b12247580e
5 changed files with 666 additions and 589 deletions

View File

@ -382,6 +382,13 @@
<i class="fa fa-fw fa-stop"></i> <i class="fa fa-fw fa-stop"></i>
</button> </button>
<button
ng-show="hasStatus(download, 'paused')"
class="btn"
ng-click="selectFiles(download)">
<i class="fa fa-fw fa-list"></i>
</button>
<button <button
class="btn hidden-phone" class="btn hidden-phone"
ng-show="['waiting', 'active'].indexOf( getType(download) )!= -1" ng-show="['waiting', 'active'].indexOf( getType(download) )!= -1"
@ -582,7 +589,7 @@
<li class="label" title="Download Path"><i class="fa fa-fw fa-folder-open">&nbsp;</i> <span class="download-dir">{{download.dir}}</span></li> <li class="label" title="Download Path"><i class="fa fa-fw fa-folder-open">&nbsp;</i> <span class="download-dir">{{download.dir}}</span></li>
</ul> </ul>
<ul class="download-files hidden-phone download-item"> <ul class="download-files hidden-phone download-item">
<li class="label" ng-repeat="file in download.files">{{file.relpath}} ({{file.fmtLength}})</li> <li class="label" ng-repeat="file in download.files" ng-class="{'label-success': file.selected}">{{file.relpath}} ({{file.fmtLength}})</li>
</ul> </ul>
<div ng-show="hasStatus(download, 'active')" class="download-item hidden-phone"> <div ng-show="hasStatus(download, 'active')" class="download-item hidden-phone">
<div class="download-graph" dspeed="download.downloadSpeed" uspeed="download.uploadSpeed" xticks="7" yticks="7" dgraph draw="!download.collapsed"></div> <div class="download-graph" dspeed="download.downloadSpeed" uspeed="download.uploadSpeed" xticks="7" yticks="7" dgraph draw="!download.collapsed"></div>
@ -842,6 +849,37 @@ http://ex1.com/f2.mp4 http://ex2.com/f2.mp4
</script> </script>
<!-- }}} --> <!-- }}} -->
<!-- {{{ select file modal -->
<script type="text/ng-template" id="selectFiles.html">
<div class="modal-header">
<button class="close" ng-click="$dismiss()">x</button>
<h3>Choose files to start download for</h3>
</div>
<form class="form-horizontal modal-body">
<fieldset>
<div class="control-group">
<div ng-repeat="file in selectFiles.files">
<label class="control-label">Select to download </label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" ng-model="file.selected"/>{{file.relpath}}
</label>
</div>
<br><br>
</div>
</div>
</fieldset>
</form>
<div class="modal-footer">
<button class="btn" ng-click="$dismiss()">Cancel</button>
<button class="btn btn-primary" ng-click="$close()">Choose</button>
</div>
</script>
<!-- }}} -->
<!-- {{{ settings modal --> <!-- {{{ settings modal -->
<script type="text/ng-template" id="settings.html"> <script type="text/ng-template" id="settings.html">
<div class="modal-header"> <div class="modal-header">

File diff suppressed because it is too large Load Diff

View File

@ -107,6 +107,30 @@ angular
} }
}; };
scope.selectFiles = {
open: function(files, cb) {
var self = this;
this.files = _.cloneDeep(files);
this.inst = $modal.open({
templateUrl: "selectFiles.html",
scope: scope,
windowClass: "modal-large"
});
this.inst.result.then(function() {
delete self.inst;
if (cb) {
cb(self.files);
}
},
function() {
delete self.inst;
});
}
};
scope.connection = { scope.connection = {
open: function(defaults, cb) { open: function(defaults, cb) {
var self = this; var self = this;
@ -118,6 +142,7 @@ angular
scope: scope, scope: scope,
windowClass: "modal-large", windowClass: "modal-large",
}); });
this.inst.result.then(function() { this.inst.result.then(function() {
delete self.inst; delete self.inst;
if (cb) { if (cb) {
@ -150,6 +175,7 @@ angular
scope: scope, scope: scope,
windowClass: "modal-large", windowClass: "modal-large",
}); });
this.inst.result.then(function() { this.inst.result.then(function() {
delete self.inst; delete self.inst;
if (cb) { if (cb) {
@ -198,10 +224,10 @@ angular
rpc.once('getVersion', [], function(data) { rpc.once('getVersion', [], function(data) {
scope.miscellaneous = data[0]; scope.miscellaneous = data[0];
}); });
_.each([ _.each([
'getUris', 'getTorrents', 'getMetalinks', 'getUris', 'getTorrents', 'getMetalinks', 'selectFiles',
'settings', 'connection', 'server_info', 'about' 'settings', 'connection', 'server_info', 'about'
], function(name) { ], function(name) {
modals.register(name, function() { modals.register(name, function() {

View File

@ -1,142 +1,136 @@
angular angular
.module('webui.ctrls.nav', [ .module('webui.ctrls.nav', [
'webui.services.configuration', 'webui.services.modals', 'webui.services.configuration', 'webui.services.modals',
'webui.services.rpc', 'webui.services.rpc.helpers', 'webui.services.rpc', 'webui.services.rpc.helpers',
'webui.services.settings', 'webui.services.utils' 'webui.services.settings', 'webui.services.utils'
]) ])
.controller('NavCtrl', [ .controller('NavCtrl', [
'$scope', '$modals', '$scope', '$modals',
'$rpc', '$rpchelpers', '$fileSettings', '$rpc', '$rpchelpers', '$fileSettings',
'$globalSettings', '$globalExclude', '$globalSettings', '$globalExclude',
'$utils', '$utils',
function( function(
scope, modals, scope, modals,
rpc, rhelpers, fsettings, rpc, rhelpers, fsettings,
gsettings, gexclude, gsettings, gexclude,
utils utils
) { ) {
scope.isFeatureEnabled = function(f) { return rhelpers.isFeatureEnabled(f) }; scope.isFeatureEnabled = function(f) { return rhelpers.isFeatureEnabled(f) };
// initially collapsed in mobile resolution // initially collapsed in mobile resolution
scope.collapsed = true; scope.collapsed = true;
scope.onDownloadFilter = function() { scope.onDownloadFilter = function() {
// Forward to MainCtrl. // Forward to MainCtrl.
scope.$parent.downloadFilter = scope.downloadFilter; scope.$parent.downloadFilter = scope.downloadFilter;
scope.$parent.onDownloadFilter(); scope.$parent.onDownloadFilter();
}; };
// manage download functions // manage download functions
scope.forcePauseAll = function() { scope.forcePauseAll = function() {
rpc.once('forcePauseAll', []); rpc.once('forcePauseAll', []);
} }
scope.purgeDownloadResult = function() { scope.purgeDownloadResult = function() {
rpc.once('purgeDownloadResult', []); rpc.once('purgeDownloadResult', []);
} }
scope.unpauseAll = function() { scope.unpauseAll = function() {
rpc.once('unpauseAll', []); rpc.once('unpauseAll', []);
} }
scope.addUris = function() { scope.addUris = function() {
modals.invoke( modals.invoke(
'getUris', _.bind(rhelpers.addUris, rhelpers) 'getUris', _.bind(rhelpers.addUris, rhelpers)
); );
}; };
scope.addTorrents = function() { scope.addMetalinks = function() {
modals.invoke( modals.invoke(
'getTorrents', _.bind(rhelpers.addTorrents, rhelpers) 'getMetalinks', _.bind(rhelpers.addMetalinks, rhelpers)
); );
}; };
scope.addMetalinks = function() { scope.addTorrents = function() {
modals.invoke( modals.invoke(
'getMetalinks', _.bind(rhelpers.addMetalinks, rhelpers) 'getTorrents', _.bind(rhelpers.addTorrents, rhelpers)
); );
}; };
scope.addTorrent = function() { scope.changeCSettings = function() {
modals.invoke( modals.invoke(
'getTorrent', _.bind(rhelpers.addTorrents, rhelpers) 'connection', rpc.getConfiguration(), _.bind(rpc.configure, rpc)
); );
}; }
scope.changeCSettings = function() { scope.changeGSettings = function() {
modals.invoke( rpc.once('getGlobalOption', [], function(data) {
'connection', rpc.getConfiguration(), _.bind(rpc.configure, rpc) var starred = utils.getCookie('aria2props');
); if (!starred || !starred.indexOf) starred = [];
} var vals = data[0];
var settings = {};
scope.changeGSettings = function() { // global settings divided into
rpc.once('getGlobalOption', [], function(data) { // file settings + some global specific
var starred = utils.getCookie('aria2props'); // settings
if (!starred || !starred.indexOf) starred = [];
var vals = data[0];
var settings = {};
// global settings divided into _.forEach([fsettings, gsettings], function(sets) {
// file settings + some global specific for (var i in sets) {
// settings if (gexclude.indexOf(i) != -1) continue;
_.forEach([fsettings, gsettings], function(sets) { settings[i] = _.cloneDeep(sets[i]);
for (var i in sets) { settings[i].starred = starred.indexOf(i) != -1;
if (gexclude.indexOf(i) != -1) continue; }
});
settings[i] = _.cloneDeep(sets[i]); for (var i in vals) {
settings[i].starred = starred.indexOf(i) != -1; if (i in gexclude) continue;
}
});
for (var i in vals) { if (!(i in settings)) {
if (i in gexclude) continue; settings[i] = { name: i, val: vals[i], desc: '', starred: starred.indexOf(i) != -1 };
}
if (!(i in settings)) { else {
settings[i] = { name: i, val: vals[i], desc: '', starred: starred.indexOf(i) != -1 }; settings[i].val = vals[i];
} }
}
else { modals.invoke(
settings[i].val = vals[i]; 'settings', _.cloneDeep(settings),
} 'Global Settings', 'Save', function(chsettings) {
}
modals.invoke( var sets = {};
'settings', _.cloneDeep(settings), var starred = [];
'Global Settings', 'Save', function(chsettings) { for (var i in chsettings) {
// no need to change default values
if (settings[i].val != chsettings[i].val)
sets[i] = chsettings[i].val
var sets = {}; if (chsettings[i].starred) {
var starred = []; starred.push(i);
for (var i in chsettings) { }
// no need to change default values };
if (settings[i].val != chsettings[i].val)
sets[i] = chsettings[i].val
if (chsettings[i].starred) { console.log('saving aria2 settings:', sets);
starred.push(i); console.log('saving aria2 starred:', starred);
}
};
console.log('saving aria2 settings:', sets); rpc.once('changeGlobalOption', [sets]);
console.log('saving aria2 starred:', starred); utils.setCookie('aria2props', starred);
});
});
};
rpc.once('changeGlobalOption', [sets]); scope.showServerInfo = function() {
utils.setCookie('aria2props', starred); modals.invoke(
}); 'server_info'
}); );
}; };
scope.showServerInfo = function() { scope.showAbout = function() {
modals.invoke( modals.invoke(
'server_info' 'about'
); );
}; }
scope.showAbout = function() {
modals.invoke(
'about'
);
}
}]); }]);

View File

@ -11,28 +11,28 @@ angular.module('webui.services.rpc.helpers', [
getAria2Version: function() { getAria2Version: function() {
return miscellaneous.version; return miscellaneous.version;
}, },
addUris: function(uris, settings) { addUris: function(uris, settings, cb) {
_.each(uris, function(uri) { _.each(uris, function(uri) {
// passing true to batch all the addUri calls // passing true to batch all the addUri calls
rpc.once('addUri', [uri, settings], angular.noop, true); rpc.once('addUri', [uri, settings], cb, true);
}); });
// now dispatch all addUri syscalls // now dispatch all addUri syscalls
rpc.forceUpdate(); rpc.forceUpdate();
}, },
addTorrents: function(txts, settings) { addTorrents: function(txts, settings, cb) {
_.each(txts, function(txt) { _.each(txts, function(txt) {
// passing true to batch all the addUri calls // passing true to batch all the addUri calls
rpc.once('addTorrent', [txt, [], settings], angular.noop, true); rpc.once('addTorrent', [txt, [], settings], cb, true);
}); });
// now dispatch all addUri syscalls // now dispatch all addUri syscalls
rpc.forceUpdate(); rpc.forceUpdate();
}, },
addMetalinks: function(txts, settings) { addMetalinks: function(txts, settings, cb) {
_.each(txts, function(txt) { _.each(txts, function(txt) {
// passing true to batch all the addUri calls // passing true to batch all the addUri calls
rpc.once('addMetalink', [txt, settings], angular.noop, true); rpc.once('addMetalink', [txt, settings], cb, true);
}); });
// now dispatch all addUri syscalls // now dispatch all addUri syscalls