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">

View File

@ -415,6 +415,7 @@ function(
var cfile = cfiles[i] || (cfiles[i] = {}); var cfile = cfiles[i] || (cfiles[i] = {});
var file = files[i]; var file = files[i];
if (file.path !== cfile.path) { if (file.path !== cfile.path) {
cfile.index = +file.index;
cfile.path = file.path; cfile.path = file.path;
cfile.length = file.length; cfile.length = file.length;
cfile.fmtLength = utils.fmtsize(file.length); cfile.fmtLength = utils.fmtsize(file.length);
@ -426,6 +427,7 @@ function(
cfile.relpath = cfile.relpath.substr(ctx.dir.length + 1); cfile.relpath = cfile.relpath.substr(ctx.dir.length + 1);
} }
} }
cfile.selected = (file.selected === "true");
} }
cfiles.length = files.length; cfiles.length = files.length;
if (cfiles.length) { if (cfiles.length) {
@ -506,6 +508,23 @@ function(
return type; return type;
}; };
scope.selectFiles = function(d) {
console.log('got back files for the torrent ...');
modals.invoke('selectFiles', d.files, function(files) {
var indexes = "";
_.forEach(files, function(f) {
if (f.selected) {
indexes += "," + f.index;
}
});
indexes = indexes.slice(1);
rpc.once('changeOption', [d.gid, {'select-file': indexes}], function(res) {
console.log('changed indexes to:', indexes, res);
})
});
}
scope.showSettings = function(d) { scope.showSettings = function(d) {
var type = scope.getType(d) var type = scope.getType(d)
, settings = {}; , settings = {};

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) {
@ -201,7 +227,7 @@ angular
}); });
_.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

@ -46,21 +46,15 @@ angular
); );
}; };
scope.addTorrents = function() {
modals.invoke(
'getTorrents', _.bind(rhelpers.addTorrents, rhelpers)
);
};
scope.addMetalinks = function() { scope.addMetalinks = function() {
modals.invoke( modals.invoke(
'getMetalinks', _.bind(rhelpers.addMetalinks, rhelpers) 'getMetalinks', _.bind(rhelpers.addMetalinks, rhelpers)
); );
}; };
scope.addTorrent = function() { scope.addTorrents = function() {
modals.invoke( modals.invoke(
'getTorrent', _.bind(rhelpers.addTorrents, rhelpers) 'getTorrents', _.bind(rhelpers.addTorrents, rhelpers)
); );
}; };

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