public/js/quartz.js in quartz_flow-0.0.3 vs public/js/quartz.js in quartz_flow-0.0.4
- old
+ new
@@ -1,6 +1,29 @@
+/**** IE Hacks ****/
+if ( typeof console === "undefined" )
+{
+ FakeConsole = function(){
+ this.log = function log(s){ };
+ }
+ console = new FakeConsole();
+}
+
+if (!Object.keys) {
+ Object.keys = function (obj) {
+ var keys = [], k;
+ for (k in obj) {
+ if (Object.prototype.hasOwnProperty.call(obj, k)) {
+ keys.push(k);
+ }
+ }
+ return keys;
+ };
+}
+
+/**** End IE Hacks ****/
+
/* Main Angular module */
var quartzModule = angular.module('quartz',[]);
/* Set up URL routes. Different URLs map to different HTML fragments (templates)*/
quartzModule.config(function($routeProvider) {
@@ -41,28 +64,33 @@
$scope.destroyed = false;
$scope.$on("$destroy", function(e){
console.log("Destroy called for TorrentTableCtrl");
$scope.destroyed = true;
+ if ( $scope.currentPageIndex ){
+ $rootScope.torrentTableCurrentPageIndex = $scope.currentPageIndex;
+ }
});
console.log("TorrentTableCtrl called");
// Load the list of torrent data every 1 second.
var refresh = function() {
// http://code.angularjs.org/1.0.8/docs/api/ng.$http
var msg = "Server is unreachable.";
- var fields = ["recommendedName", "dataLength", "state", "infoHash", "downloadRate", "uploadRate","percentComplete","timeLeft","paused"]
+ var fields = ["recommendedName", "dataLength", "state", "infoHash", "downloadRate", "uploadRate","percentComplete","timeLeft","paused","queued"]
$http.get("/torrent_data", {'timeout': 3000, "params": {"fields" : fields } }).
success(function(data,status,headers,config){
$rootScope.torrents = data;
updateTableTorrentData($rootScope);
+ updatePages($scope, $rootScope);
$rootScope.deleteRootscopeError(msg);
}).
error(function(data,status,headers,config){
$rootScope.torrents = [];
updateTableTorrentData($rootScope);
+ updatePages($scope, $rootScope);
if ( status == 0 ){
$rootScope.alerts[msg] = 1;
} else if (data == "Authentication required" ) {
$window.location.href = '/login';
} else {
@@ -122,11 +150,11 @@
$scope.currentPageIndex = n - 1;
if ( $scope.currentPageIndex < 0 )
$scope.currentPageIndex = 0;
if ( $scope.currentPageIndex >= $scope.totalPages )
$scope.currentPageIndex = $scope.totalPages - 1;
- updatePages($scope);
+ updatePages($scope, $rootScope);
updatePagesInfo($scope);
}
$scope.decrementPage = function(){
$scope.setPage($scope.currentPageIndex);
@@ -140,10 +168,11 @@
$scope.magnetToStart = "";
$scope.downloadTorrentFile = function(){
$http.post("/download_torrent", {"url": $scope.torrentToDownload}).
success(function(data,status,headers,config){
+ $scope.torrentToDownload = ''
console.log("huzzah, downloading torrent succeeded");
}).
error(function(data,status,headers,config){
console.log("Crap, downloading torrent failed: " + status + ": " + data);
$scope.errors.push(data);
@@ -151,10 +180,11 @@
}
$scope.startMagnetLink = function(){
$http.post("/start_magnet", {"url": $scope.magnetToStart}).
success(function(data,status,headers,config){
+ $scope.magnetToStart = ''
console.log("huzzah, starting magnet succeeded");
}).
error(function(data,status,headers,config){
console.log("Crap, starting magnet failed: " + status + ": " + data);
$scope.errors.push(data);
@@ -166,14 +196,18 @@
if ( ! torrent ){
return "unknown";
}
var result = torrent.state;
+ result += " ";
if ( torrent.paused ){
- result = result + " (paused)";
+ result = result + "(paused)";
}
+ if ( torrent.queued ){
+ result = result + "(queued)";
+ }
return result;
}
$scope.pauseMenuItem = function(infoHash){
@@ -247,14 +281,18 @@
if ( ! torrent ){
return "unknown";
}
var result = torrent.state;
+ result += " ";
if ( torrent.paused ){
- result = result + " (paused)";
+ result = result + "(paused)";
}
+ if ( torrent.queued ){
+ result = result + "(queued)";
+ }
return result;
}
// Load the list of torrent data every 1 second.
@@ -417,12 +455,10 @@
}
for(var i = 0; i < toDelete.length; i++) {
delete $scope.torrentsForTable[toDelete[i]];
}
- // Set up the current page
- updatePages($scope);
}
var torrentPropsNotToUpdate = { 'downloadRateLimit': 1, 'uploadRateLimit': 1, 'ratio' : 1, 'uploadDuration' : 1 };
/* srcTorrent should be a JSON object representing torrent data retrieved from the server.
@@ -435,25 +471,30 @@
}
}
}
-function updatePages($scope) {
+function updatePages($scope, $rootScope) {
// Set up the current page
var pageSize = 5;
- if( ! $scope.currentPageIndex ) {
- $scope.currentPageIndex = 0;
+ if( typeof($scope.currentPageIndex) == 'undefined') {
+ if ( typeof($rootScope.torrentTableCurrentPageIndex) != 'undefined' ){
+ $scope.currentPageIndex = $rootScope.torrentTableCurrentPageIndex;
+ }
+ else {
+ $scope.currentPageIndex = 0;
+ }
}
$scope.torrentsList = [];
for (var key in $scope.torrentsForTable) {
$scope.torrentsList.push($scope.torrentsForTable[key]);
}
var pageStartIndex = $scope.currentPageIndex * pageSize;
var pageEndIndex = ($scope.currentPageIndex+1) * pageSize;
$scope.currentPage = $scope.torrentsList.slice(pageStartIndex, pageEndIndex);
$scope.totalPages = Math.floor(($scope.torrentsList.length - 1) / pageSize + 1);
- if( ! $scope.pagesInfo || $scope.pagesInfo.length != $scope.totalPages ) {
+ if( typeof($scope.pagesInfo) == 'undefined' || $scope.pagesInfo.length != $scope.totalPages ) {
updatePagesInfo($scope);
}
}
function updatePagesInfo($scope) {