separated angular components into modules
This commit is contained in:
parent
489f12ea1e
commit
567d6f8179
11
angular.html
11
angular.html
|
@ -43,6 +43,7 @@
|
||||||
<script src="js/filters/bytes.js"></script>
|
<script src="js/filters/bytes.js"></script>
|
||||||
<script src="js/filters/path.js"></script>
|
<script src="js/filters/path.js"></script>
|
||||||
|
|
||||||
|
<script src="js/services/constants.js"></script>
|
||||||
<script src="js/services/deps.js"></script>
|
<script src="js/services/deps.js"></script>
|
||||||
<script src="js/services/base64.js"></script>
|
<script src="js/services/base64.js"></script>
|
||||||
<script src="js/services/utils.js"></script>
|
<script src="js/services/utils.js"></script>
|
||||||
|
@ -99,7 +100,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="dropdown" id="stop_downloads">
|
<li class="dropdown" ng-show="false">
|
||||||
<a class="dropdown-toggle" href="#">
|
<a class="dropdown-toggle" href="#">
|
||||||
Manage <b class="caret"></b>
|
Manage <b class="caret"></b>
|
||||||
</a>
|
</a>
|
||||||
|
@ -113,7 +114,7 @@
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<ul class="nav">
|
<ul class="nav" ng-show="false">
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a href="#" class="dropdown-toggle" >
|
<a href="#" class="dropdown-toggle" >
|
||||||
Settings <b class="caret"></b>
|
Settings <b class="caret"></b>
|
||||||
|
@ -128,7 +129,7 @@
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<ul class="nav pull-right">
|
<ul class="nav pull-right" ng-show="false">
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a href="#" class="dropdown-toggle" >
|
<a href="#" class="dropdown-toggle" >
|
||||||
About <b class="caret"></b>
|
About <b class="caret"></b>
|
||||||
|
@ -150,6 +151,10 @@
|
||||||
<!-- {{{ downloads -->
|
<!-- {{{ downloads -->
|
||||||
<div role="main" class="container" ng-controller="DownloadCtrl">
|
<div role="main" class="container" ng-controller="DownloadCtrl">
|
||||||
|
|
||||||
|
<div ng-show="!getDownloads().length" class="hero-unit">
|
||||||
|
<h3>Currently no downloads in line to display, use the Add download button to start downloading files!</h3>
|
||||||
|
</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>
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
app.controller('DownloadCtrl', [ '$scope', '$rpc', '$utils',
|
angular
|
||||||
|
.module('webui.ctrls.download', [
|
||||||
|
'webui.services.utils', 'webui.services.rpc'
|
||||||
|
])
|
||||||
|
.controller('DownloadCtrl', [ '$scope', '$rpc', '$utils',
|
||||||
function(scope, rpc, utils) {
|
function(scope, rpc, utils) {
|
||||||
|
|
||||||
scope.active = [], scope.waiting = [], scope.stopped = [];
|
scope.active = [], scope.waiting = [], scope.stopped = [];
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
app.controller('ModalCtrl', ['$_', '$scope', '$rpc', function(_, scope, rpc) {
|
angular
|
||||||
|
.module('webui.ctrls.modal', [
|
||||||
|
'webui.services.rpc', 'webui.services.deps'
|
||||||
|
])
|
||||||
|
.controller('ModalCtrl', ['$_', '$scope', '$rpc', function(_, scope, rpc) {
|
||||||
scope.uris = '';
|
scope.uris = '';
|
||||||
scope.addUris = function() {
|
scope.addUris = function() {
|
||||||
console.log(scope.uris);
|
console.log(scope.uris);
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
app.controller('NavCtrl', ['$scope', '$name', function(scope, name) {
|
angular
|
||||||
|
.module('webui.ctrls.nav', ['webui.services.constants', 'webui.services.modals'])
|
||||||
|
.controller('NavCtrl', ['$scope', '$name', '$modals', function(scope, name, modals) {
|
||||||
scope.name = name;
|
scope.name = name;
|
||||||
|
|
||||||
// initially collapsed in mobile resolution
|
// initially collapsed in mobile resolution
|
||||||
|
|
|
@ -20,7 +20,9 @@ var draw = function(canvas, chunks, fillStyle) {
|
||||||
// put chunkbar and bitfield attributes in a canvas element
|
// put chunkbar and bitfield attributes in a canvas element
|
||||||
// to use the directive, draw is optional and canvas is
|
// to use the directive, draw is optional and canvas is
|
||||||
// only drawn when it is true if given
|
// only drawn when it is true if given
|
||||||
app.directive('chunkbar', ['$utils', function(utils) {
|
angular
|
||||||
|
.module('webui.directives.chunkbar', ['webui.services.utils'])
|
||||||
|
.directive('chunkbar', ['$utils', function(utils) {
|
||||||
return function(scope, elem, attrs) {
|
return function(scope, elem, attrs) {
|
||||||
var bitfield = "", pieces = 0, canDraw = true;
|
var bitfield = "", pieces = 0, canDraw = true;
|
||||||
var update = function() {
|
var update = function() {
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// graph takes dspeed and uspeed, it queries them every second and draws
|
// graph takes dspeed and uspeed, it queries them every second and draws
|
||||||
// the last 20 secs, it also takes draw as an optional attribute and only
|
// the last 20 secs, it also takes draw as an optional attribute and only
|
||||||
// draws the graph when it is true, if not given then graph is always drawn
|
// draws the graph when it is true, if not given then graph is always drawn
|
||||||
app.directive('dgraph', ['$', '$filter', '$parse', function($, filter, parse) {
|
angular
|
||||||
|
.module('webui.directives.dgraph', ['webui.filters.bytes', 'webui.services.deps'])
|
||||||
|
.directive('dgraph', ['$', '$filter', '$parse', function($, filter, parse) {
|
||||||
return function(scope, elem, attrs) {
|
return function(scope, elem, attrs) {
|
||||||
var canDraw = true;
|
var canDraw = true;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
app.filter('changeLength', function() {
|
angular
|
||||||
|
.module('webui.filters.bytes', [])
|
||||||
|
.filter('changeLength', function() {
|
||||||
return function(len, pref) {
|
return function(len, pref) {
|
||||||
len = parseFloat(len);
|
len = parseFloat(len);
|
||||||
if(len <= (1<<10)) return len.toFixed(1) + " " + pref;
|
if(len <= (1<<10)) return len.toFixed(1) + " " + pref;
|
||||||
|
@ -6,21 +8,18 @@ app.filter('changeLength', function() {
|
||||||
else if(len <= (1<<30)) return (len/(1<<20)).toFixed(1) + " M" + pref;
|
else if(len <= (1<<30)) return (len/(1<<20)).toFixed(1) + " M" + pref;
|
||||||
else return (len/(1<<30)).toFixed(1) + " G" + pref;
|
else return (len/(1<<30)).toFixed(1) + " G" + pref;
|
||||||
};
|
};
|
||||||
});
|
})
|
||||||
|
.filter('blength', ['$filter', function(filter) {
|
||||||
app.filter('blength', ['$filter', function(filter) {
|
|
||||||
return function(len) {
|
return function(len) {
|
||||||
return filter('changeLength')(len, 'B');
|
return filter('changeLength')(len, 'B');
|
||||||
};
|
};
|
||||||
}]);
|
}])
|
||||||
|
.filter('bspeed', ['$filter', function(filter) {
|
||||||
app.filter('bspeed', ['$filter', function(filter) {
|
|
||||||
return function(speed) {
|
return function(speed) {
|
||||||
return filter('changeLength')(speed, 'B/s');
|
return filter('changeLength')(speed, 'B/s');
|
||||||
};
|
};
|
||||||
}]);
|
}])
|
||||||
|
.filter('time', function() {
|
||||||
app.filter('time', function() {
|
|
||||||
return function(time) {
|
return function(time) {
|
||||||
time = parseFloat(time);
|
time = parseFloat(time);
|
||||||
if (isNaN(time) || !isFinite(time)) return " infinite";
|
if (isNaN(time) || !isFinite(time)) return " infinite";
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// returns the relative path from base
|
// returns the relative path from base
|
||||||
app.filter('prelative', function() {
|
angular.module('webui.filters.path', [])
|
||||||
|
.filter('prelative', function() {
|
||||||
return function(path, base) {
|
return function(path, base) {
|
||||||
return path.replace(/\\/g, '/')
|
return path.replace(/\\/g, '/')
|
||||||
.replace(base.replace(/\\/, '/'), '.');
|
.replace(base.replace(/\\/, '/'), '.');
|
||||||
|
|
11
js/init.js
11
js/init.js
|
@ -1,10 +1,15 @@
|
||||||
var app = angular.module('app', []);
|
angular.module('webui', [
|
||||||
|
'webui.services.utils', 'webui.services.deps', 'webui.services.base64',
|
||||||
|
'webui.services.constants', 'webui.services.rpc',
|
||||||
|
'webui.filters.bytes', 'webui.filters.path',
|
||||||
|
'webui.directives.chunkbar', 'webui.directives.dgraph',
|
||||||
|
'webui.ctrls.download', 'webui.ctrls.nav', 'webui.ctrls.modal'
|
||||||
|
]);
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
angular.bootstrap(document, [
|
angular.bootstrap(document, [
|
||||||
// external deps
|
// external deps
|
||||||
'ui.bootstrap.collapse', 'ui.bootstrap.dropdownToggle',
|
'ui.bootstrap.collapse', 'ui.bootstrap.dropdownToggle',
|
||||||
|
'webui'
|
||||||
'app'
|
|
||||||
])
|
])
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
app.factory('$base64', [function() {
|
angular
|
||||||
|
.module('webui.services.base64', [])
|
||||||
|
.factory('$base64', [function() {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
var a64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
var a64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
||||||
a256 = {
|
a256 = {
|
||||||
|
|
5
js/services/constants.js
Normal file
5
js/services/constants.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
angular
|
||||||
|
.module('webui.services.constants', [])
|
||||||
|
.constant('$name', 'webui-aria2')
|
||||||
|
.constant('$globalTimeout', 5000)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
app.constant('$name', 'webui-aria2');
|
angular
|
||||||
app.constant('$globalTimeout', 5000);
|
.module('webui.services.deps', [])
|
||||||
|
.value('$', $)
|
||||||
app.value('$', $);
|
.value('$_', _)
|
||||||
app.value('$_', _);
|
.value('$json', JSON);
|
||||||
app.value('$json', JSON);
|
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
app.factory('$jsoncall', ['$', '$json', '$base64', function($, JSON, base64) {
|
angular
|
||||||
|
.module('webui.services.rpc.jsoncall', [
|
||||||
|
'webui.services.deps', 'webui.services.base64'])
|
||||||
|
.factory('$jsoncall', ['$', '$json', '$base64', function($, JSON, base64) {
|
||||||
return {
|
return {
|
||||||
init: function(conf) {
|
init: function(conf) {
|
||||||
this.avgTimeout = 2000;
|
this.avgTimeout = 2000;
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
app.factory('$rpc', ['$syscall', '$globalTimeout', function(syscall, time) {
|
angular
|
||||||
|
.module('webui.services.rpc', [
|
||||||
|
'webui.services.rpc.syscall', 'webui.services.constants'
|
||||||
|
])
|
||||||
|
.factory('$rpc', ['$syscall', '$globalTimeout', function(syscall, time) {
|
||||||
var subscriptions = []
|
var subscriptions = []
|
||||||
, configurations = [{ host: 'localhost', port: 6800 }]
|
, configurations = [{ host: 'localhost', port: 6800 }]
|
||||||
, timeout = null
|
, timeout = null
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
app.factory('$sockcall', ['$_', '$json', '$name', '$utils', function(_, JSON, name, utils) {
|
angular
|
||||||
|
.module('webui.services.rpc.sockcall', [
|
||||||
|
'webui.services.deps', 'webui.services.utils', 'webui.services.base64'
|
||||||
|
])
|
||||||
|
.factory('$sockcall', ['$_', '$json', '$name', '$utils', function(_, JSON, name, utils) {
|
||||||
|
|
||||||
var sockRPC = {
|
var sockRPC = {
|
||||||
// true when sockrpc is ready to be used,
|
// true when sockrpc is ready to be used,
|
||||||
// false when either initializing
|
// false when either initializing
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
app.factory('$syscall', ['$log', '$jsoncall', '$sockcall', function(log, jsonRPC, sockRPC) {
|
angular
|
||||||
|
.module('webui.services.rpc.syscall', [
|
||||||
|
'webui.services.rpc.jsoncall', 'webui.services.rpc.sockcall',
|
||||||
|
'webui.services.utils'
|
||||||
|
])
|
||||||
|
.factory('$syscall', ['$log', '$jsoncall', '$sockcall', function(log, jsonRPC, sockRPC) {
|
||||||
return {
|
return {
|
||||||
// called to initialize the rpc interface, call everytime configuration changes
|
// called to initialize the rpc interface, call everytime configuration changes
|
||||||
// conf has the following structure:
|
// conf has the following structure:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
app.factory('$utils', function() {
|
angular.module('webui.services.utils', [])
|
||||||
|
.factory('$utils', function() {
|
||||||
return {
|
return {
|
||||||
getFileName: function(path) {
|
getFileName: function(path) {
|
||||||
var seed = path.split(/[/\\]/);
|
var seed = path.split(/[/\\]/);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user