Skip to content

Commit

Permalink
Dummy tasks progress back-end and connection the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
iNecas committed Jan 15, 2014
1 parent 538db3d commit a2a2475
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 10 deletions.
38 changes: 38 additions & 0 deletions app/controllers/api/v2/dyntasks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Copyright 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

class Api::V2::DyntasksController < Api::V2::ApiController

before_filter :authorize

def rules
test = lambda do
# TODO
return true
end
{
:index => test,
}
end

api :GET, "/organizations/:organization_id/dyntasks", "List dynflow tasks for uuids"
param :uuids, Array, :desc => 'List of uuids to fetch info about'
def index
uuids = Array(params[:uuids])
# TODO: remove after upading to angular >= 1.1.3 supporting arrays in query params
# https://github.com/angular/angular.js/commit/2a2123441c2b749b8f316a24c3ca3f77a9132a01
uuids = uuids.map { |uuid| uuid.split(',') }.flatten

render :json => uuids.map { |uuid| { :uuid => uuid, :progress => rand } }
end

end
2 changes: 2 additions & 0 deletions config/routes/api/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class ActionDispatch::Routing::Mapper
##############################
##############################

api_resources :dyntasks, :only => [:index]

api_resources :organizations do
api_resources :products, :only => [:index]
api_resources :environments do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@


<div class="details fl">
<taskprogress uuid="1234-1234-1234-1234"></taskprogress>
<taskprogress uuid="1"></taskprogress>

<taskprogress uuid="2"></taskprogress>
<div class="divider"></div>

<section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,57 @@
have received a copy of GPLv2 along with this software; if not, see
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
**/
angular.module('Bastion.widgets')
.factory('tasksStatusProvider', ['$timeout', '$resource', function($timeout, $resource) {
var callbacks = {},
timoutId,
taskResource = $resource('/katello/api/dyntasks',
{},
{query: {method:'GET', isArray: true}});

angular.module('Bastion.widgets').directive('taskprogress', [function() {
return {
restrict: 'E',
templateUrl: 'widgets/views/task-progress.html',
scope: {
uuid: '@',
function updateProgress() {
var uuids = []
angular.forEach(callbacks, function(callback, uuid) { uuids.push(uuid); })
if (uuids.length == 0) {
return;
}
taskResource.query({'uuids[]': uuids}, function(tasks) {
angular.forEach(tasks, function(task) {
var callback = callbacks[task.uuid]
if (callback) {
callback(task.progress*100);
}
});
});
}
};
}]);
function scheduleUpdate() {
// save the timeoutId for canceling
timeoutId = $timeout(function() {
updateProgress();
scheduleUpdate(); // schedule the next update
}, 1500);
}
scheduleUpdate();
return {
register: function(uuid, callback) { callbacks[uuid] = callback; },
unregister: function(uuid) { delete callbacks[uuid]; }
};
}])
.directive('taskprogress',
['tasksStatusProvider', function(tasksStatusProvider) {
return {
restrict: 'E',
templateUrl: 'widgets/views/task-progress.html',
scope: {
uuid: '@',
},
link: function (scope, element, args) {
tasksStatusProvider.register(args.uuid, function(progress) {
scope.progress = progress;
});
element.bind('$destroy', function() {
tasksStatusProvider.unregister(args.uuid);
});
}
}
}]);
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ <h4>
<span class="info-label">{{ "Task" | i18n }}</span>
<span class="info-value">Synchronization</span>
</div>
<progress percent="percent"></progress>
<progress percent="progress"></progress>
</section>

0 comments on commit a2a2475

Please sign in to comment.