diff --git a/app/index.html b/app/index.html index 91e50c4..1b8c592 100644 --- a/app/index.html +++ b/app/index.html @@ -23,6 +23,7 @@ + diff --git a/app/js/app.js b/app/js/app.js index 1effed3..abdc48f 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -16,7 +16,8 @@ EiskaltApp.value('settings', { refresh: { hashAndRatio: 5000, chat: 3000, - queues: 5000 + queues: 5000, + search: 3000, }, settings: [ {key: 'Nick', type: 'text'}, @@ -39,6 +40,10 @@ EiskaltApp.config(function ($routeProvider) { controller: 'BrowseCtrl', templateUrl: 'partials/browse.html' }) + .when('/search', { + controller: 'SearchCtrl', + templateUrl: 'partials/search.html' + }) .when('/queue', { controller: 'QueueCtrl', templateUrl: 'partials/queue.html' diff --git a/app/js/controllers/search.js b/app/js/controllers/search.js new file mode 100644 index 0000000..1013a83 --- /dev/null +++ b/app/js/controllers/search.js @@ -0,0 +1,113 @@ +/* Copyright (c) 2017 Lars Kreisz */ +/* License:The MIT License (MIT) */ + +'use strict'; +EiskaltApp.controller('SearchCtrl', function ($scope, $interval, settings, EiskaltRPC) { + $scope.result = []; + $scope.term = ""; + $scope.hubs = []; + $scope.filelists = []; + + var loadHubs = function () { + EiskaltRPC.ListHubsFullDesc().success(function (data) { + $scope.hubs = data; + }); + }; + loadHubs(); + + $scope.loadLists = function () { + EiskaltRPC.ShowLocalLists().success(function (filelists) { + $scope.filelists = filelists; + }); + }; + $scope.loadLists(); + + $scope.refreshSearchResults = function () { + if($scope.hub != null) { + EiskaltRPC.ReturnSearchResults($scope.hub.huburl).success(function (result) { + $scope.result = result; + }); + } + }; + + $scope.refreshSearchPage = function () { + $scope.loadLists(); + $scope.refreshSearchResults(); + }; + + var refreshSearchTimer = $interval($scope.refreshSearchPage, settings.refresh.search); + $scope.$on("$destroy", function(event) { + $interval.cancel(refreshSearchPage); + }); + + $scope.search = function() { + $scope.result = []; + EiskaltRPC.ClearSearchResults($scope.hub.huburl).success(function (status) { + if (status != 0) { + alert("Couldn't clear old results"); + } + }); + EiskaltRPC.SendSearch($scope.term, 0, 0, 0, 0.0, $scope.hub.huburl) + .success(function(status) { + if (status != 0) { + alert('Search failed.'); + } + }); + }; +}); + +EiskaltApp.controller('SearchDownloadCtrl', function ($scope, EiskaltRPC) { + $scope.nonDownloadableFile = true; + $scope.downloadedFileList = false; + + $scope.$watch( + function () { + var item = $scope.$parent.item; + var filelist = item.Nick + "." + item.CID + ".xml.bz2"; + return $scope.filelists.includes(filelist); + }, + function (newValue, oldValue, scope) { + if(oldValue != newValue) { + $scope.downloadedFileList = newValue; + $scope.nonDownloadableFile = !newValue; + } + } + ); + + $scope.init = function(item) { + var filelist = item.Nick + "." + item.CID + ".xml.bz2"; + $scope.downloadedFileList = $scope.filelists.includes(filelist); + $scope.nonDownloadableFile = !$scope.downloadedFileList; + }; + + $scope.downloadFileList = function(item) { + var filelist = item.Nick + "." + item.CID + ".xml.bz2"; + if(!$scope.filelists.includes(filelist)) { + EiskaltRPC.GetFileList($scope.hub.huburl, item.Nick).success(function(filelist) { + if(status != 0) { + alert('Download failed. Maybe still downloading or downloaded already?'); + } + }); + } else { + alert('Filelist already downloaded.'); + } + }; + + $scope.download = function(item) { + var isFolder = item.Filename.endsWith('/'); + var method = isFolder ? EiskaltRPC.DownloadDirFromList : EiskaltRPC.DownloadFileFromList; + var target = (item.Path + item.Filename).replace(/\//g,"\\"); + var filelist = item.Nick + "." + item.CID + ".xml.bz2"; + if($scope.filelists.includes(filelist)) { + method(target, '', filelist).success(function (status) { + if (status == 0) { + $scope.nonDownloadableFile = true; + } else { + alert('Download failed. Maybe still downloading or downloaded already?'); + } + }); + } else { + alert('Download failed. Please download the filelist first'); + } + }; +}); diff --git a/app/partials/navbar.html b/app/partials/navbar.html index 2a60204..d82f8e2 100644 --- a/app/partials/navbar.html +++ b/app/partials/navbar.html @@ -31,6 +31,12 @@ +
  • + + + + +
  • diff --git a/app/partials/search.html b/app/partials/search.html new file mode 100644 index 0000000..9c30cd0 --- /dev/null +++ b/app/partials/search.html @@ -0,0 +1,58 @@ + \ No newline at end of file